How to use the hy.lex.tokenize.tokenize function in hy

To help you get started, we’ve selected a few hy examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github hylang / hy / tests / lang / test_expression.py View on Github external
def test_fn_split():
    """Test if we can get a statement something right."""
    one, two = tokenize(code)
    assert one.get_invocation() == {
        "function": "+",
        "args": [
            1, 1
        ]
    }
    assert two.get_invocation() == {
        "function": "fn",
        "args": [
            "foo", "bar"
        ]
github hylang / hy / tests / lexer / test_list_lexing.py View on Github external
def test_string_in_list():
    """ String in list """
    fn = tokenize('(fn [1 2 "three four" 5])')[0]
    assert fn == [
        "fn", [1, 2, "three four", 5]
    ]
github hylang / hy / tests / lexer / test_basic_lexing.py View on Github external
'el',
            ['+',
                1,
                2,
                ['==',
                    1,
                    20
                ],
                ['-',
                    1,
                    1
                ],
            ]
        ],
        ['fn1', 'foo', 'bar']
    ] == tokenize("(fn el (+ 1 2 (== 1 20) (- 1 1)))(fn1 foo bar)")
github hylang / hy / tests / lexer / test_basic_lexing.py View on Github external
def test_mid_recurse_comment():
    """ Test some crazy recursion with a comment """

    assert [
        ['fn',
            'one',
            ['fn', 'two'],
            ['fn', 'three'],
        ]
    ] == tokenize("""
(fn one ; this is a test
github hylang / hy / tests / lexer / test_list_lexing.py View on Github external
def test_list_recurse():
    """ test we can recurse lists """
    fn = tokenize("(fn [1 2 3 4 [5 6 7]])")[0]
    assert fn == [
        "fn", [1, 2, 3, 4, [5, 6, 7]]
    ]
github hylang / hy / tests / lexer / test_list_lexing.py View on Github external
def test_list_lex():
    """test basic lexing of lists"""
    fn = tokenize("(fn [1 2 3 4])")[0]
    assert fn == [
        "fn", [1, 2, 3, 4]
    ]
github hylang / hy / tests / lexer / test_list_lexing.py View on Github external
def test_list_recurse_with_comment():
    """ test we can recurse lists """
    fn = tokenize("""
(fn [1 ; this is a test
     2 3 4 [5 6 7]])
""")[0]
    assert fn == [
        "fn", [1, 2, 3, 4, [5, 6, 7]]
    ]
github hylang / hy / hy / lang / natives.py View on Github external
def _lex(*args):
    ret = []
    for thing in args:
        ret.append(_hy_tok(thing))
    return ret
github hylang / hy / hy / lang / importer.py View on Github external
def _hy_import_file(fd, name):
    m = forge_module(
        name,
        fd,
        tokenize(open(fd, 'r').read())
    )
    return m