mirror of
https://github.com/AdaCore/langkit.git
synced 2026-02-12 12:28:12 -08:00
57 lines
1.2 KiB
Python
57 lines
1.2 KiB
Python
"""
|
|
Test that the "is_ghost" AST node predicate works in the Python API.
|
|
"""
|
|
|
|
from __future__ import absolute_import, division, print_function
|
|
|
|
import os.path
|
|
|
|
from langkit.diagnostics import Diagnostics
|
|
from langkit.dsl import ASTNode, EnumNode, Field, T
|
|
from langkit.parsers import Grammar, List, Or, Tok
|
|
|
|
from lexer_example import Token
|
|
from utils import build_and_run
|
|
|
|
|
|
Diagnostics.set_lang_source_dir(os.path.abspath(__file__))
|
|
|
|
|
|
class FooNode(ASTNode):
|
|
pass
|
|
|
|
|
|
class Enum(EnumNode):
|
|
alternatives = ['null', 'example', 'default']
|
|
|
|
|
|
class PlusQualifier(EnumNode):
|
|
qualifier = True
|
|
|
|
|
|
class Param(FooNode):
|
|
name = Field(type=T.Name)
|
|
mode = Field(type=T.Enum)
|
|
has_plus = Field(type=T.PlusQualifier)
|
|
|
|
|
|
class Name (FooNode):
|
|
tok = Field(type=T.Token)
|
|
|
|
|
|
foo_grammar = Grammar('main_rule')
|
|
foo_grammar.add_rules(
|
|
main_rule=List(Param(foo_grammar.name,
|
|
foo_grammar.mode,
|
|
foo_grammar.plus)),
|
|
name=Name(Tok(Token.Identifier, keep=True)),
|
|
mode=Or(
|
|
Enum.alt_null('null'),
|
|
Enum.alt_example('example'),
|
|
Enum.alt_default(),
|
|
),
|
|
plus=PlusQualifier('+'),
|
|
)
|
|
build_and_run(foo_grammar, 'main.py')
|
|
print('Done')
|