How to use the lark.tree.Tree function in lark

To help you get started, we’ve selected a few lark 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 lark-parser / lark / tests / test_parser.py View on Github external
def test_relative_rule_import_rename(self):
            l = _Lark_open('test_relative_rule_import_rename.lark',
                           rel_to=__file__)
            x = l.parse('xaabby')
            self.assertEqual(x.children, [
                'x',
                Tree('ab', ['a', Tree('ab', ['a', 'b']), 'b']),
                'y'])
github tartiflette / tartiflette / tests / unit / sdl / transformer / test_cleaning_transformer.py View on Github external
def test_CleaningTransformer_value(str_value, expected_value):
    full_sdl = """
    type Test {{
        fieldName(arg: Int = {}): String
    }}
    """.format(
        str_value
    )

    expected = Tree(
        "document",
        [
            Tree(
                "type_system_definition",
                [
                    Tree(
                        "type_definition",
                        [
                            Tree(
                                "object_type_definition",
                                [
                                    Token("TYPE", "type"),
                                    Token("IDENT", "Test"),
                                    Tree(
                                        "fields_definition",
                                        [
github tartiflette / tartiflette / tests / unit / sdl / transformer / test_cleaning_transformer.py View on Github external
),
                                                                    Tree(
                                                                        "type",
                                                                        [
                                                                            Tree(
                                                                                "named_type",
                                                                                [
                                                                                    Token(
                                                                                        "IDENT",
                                                                                        "Int",
                                                                                    )
                                                                                ],
                                                                            )
                                                                        ],
                                                                    ),
                                                                    Tree(
                                                                        "default_value",
                                                                        [
                                                                            Tree(
                                                                                "value",
                                                                                [
                                                                                    expected_value
                                                                                ],
                                                                            )
                                                                        ],
                                                                    ),
                                                                ],
                                                            )
                                                        ],
                                                    ),
                                                    Tree(
                                                        "type",
github tartiflette / tartiflette / tests / unit / sdl / test_parse_graphql_sdl_to_ast.py View on Github external
                            Tree('enum_value_definition', [
                                Tree('enum_value', [
                                    Tree('name', [
                                        Token('IDENT', 'INACTIVE'),
                                    ]),
                                ]),
                            ]),
                            Tree('enum_value_definition', [
                                Tree('enum_value', [
                                    Tree('name', [
                                        Token('IDENT', 'SUSPENDED'),
                                    ]),
                                ]),
                            ]),
                        ]),
                    ]),
                ]),
github lark-parser / lark / tests / test_trees.py View on Github external
def test_iter_subtrees_topdown(self):
        expected = [Tree('a', [Tree('b', 'x'), Tree('c', 'y'), Tree('d', 'z')]),
                    Tree('b', 'x'), Tree('c', 'y'), Tree('d', 'z')]
        nodes = list(self.tree1.iter_subtrees_topdown())
        self.assertEqual(nodes, expected)
github tartiflette / tartiflette / tests / unit / sdl / test_parse_graphql_sdl_to_ast_full_sdl.py View on Github external
Tree('enum_type_definition', [
                    Token('ENUM', 'enum'),
                    Tree('name', [
                        Token('IDENT', 'Episode'),
                    ]),
                    Tree('directives', [
                        Tree('directive', [
                            Tree('name', [
                                Token('IDENT', 'link_db'),
                            ]),
                            Tree('arguments', [
                                Tree('argument', [
                                    Tree('name', [
                                        Token('IDENT', 'table'),
                                    ]),
                                    Tree('value', [
                                        Tree('string_value', [
                                            Token('STRING', '"movies.slug"'),
                                        ]),
                                    ]),
                                ]),
                            ]),
                        ]),
                    ]),
                    Tree('enum_values_definition', [
                        Tree('enum_value_definition', [
                            Tree('enum_value', [
                                Tree('name', [
                                    Token('IDENT', 'A_NEW_HOPE'),
                                ]),
                            ]),
                        ]),
github tartiflette / tartiflette / tests / unit / sdl / transformer / test_cleaning_transformer.py View on Github external
fieldName(arg: Int = {}): String
    }}
    """.format(
        str_value
    )

    expected = Tree(
        "document",
        [
            Tree(
                "type_system_definition",
                [
                    Tree(
                        "type_definition",
                        [
                            Tree(
                                "object_type_definition",
                                [
                                    Token("TYPE", "type"),
                                    Token("IDENT", "Test"),
                                    Tree(
                                        "fields_definition",
                                        [
                                            Tree(
                                                "field_definition",
                                                [
                                                    Token(
                                                        "IDENT", "fieldName"
                                                    ),
                                                    Tree(
                                                        "arguments_definition",
                                                        [
github lark-parser / lark / tests / test_parser.py View on Github external
def test_relative_rule_import_subrule_no_conflict(self):
            l = _Lark_open(
                'test_relative_rule_import_subrule_no_conflict.lark',
                rel_to=__file__)
            x = l.parse('xaby')
            self.assertEqual(x.children, [Tree('expr', [
                'x',
                Tree('startab', [
                    Tree('grammars__ab__expr', ['a', 'b']),
                ]),
                'y'])])
            self.assertRaises((ParseError, UnexpectedInput),
                              l.parse, 'xaxabyby')
github tartiflette / tartiflette / tests / unit / sdl / test_parse_graphql_sdl_to_ast.py View on Github external
                        Tree('union_member_types', [
                            Tree('named_type', [
                                Tree('name', [
                                    Token('IDENT', 'Foo'),
                                ]),
                            ]),
                            Tree('named_type', [
                                Tree('name', [
                                    Token('IDENT', 'Bar'),
                                ]),
                            ]),
                            Tree('named_type', [
                                Tree('name', [
                                    Token('IDENT', 'Baz'),
                                ]),
                            ]),
                        ]),