2017-02-15 15:35:44 +01:00
|
|
|
"""
|
2017-03-03 15:10:05 +01:00
|
|
|
Test that the "is_ghost" AST node predicate works in the Python API.
|
2017-02-15 15:35:44 +01:00
|
|
|
"""
|
|
|
|
|
|
2017-04-25 14:19:50 +02:00
|
|
|
from __future__ import absolute_import, division, print_function
|
2017-02-24 10:25:54 +01:00
|
|
|
|
2019-02-06 15:35:55 +01:00
|
|
|
from langkit.dsl import ASTNode, Field, T
|
2018-01-26 11:30:18 +01:00
|
|
|
from langkit.parsers import Grammar, List, Or
|
2017-02-15 15:35:44 +01:00
|
|
|
|
|
|
|
|
from lexer_example import Token
|
|
|
|
|
from utils import build_and_run
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class FooNode(ASTNode):
|
|
|
|
|
pass
|
|
|
|
|
|
|
|
|
|
|
2019-02-06 15:35:55 +01:00
|
|
|
class Enum(FooNode):
|
|
|
|
|
enum_node = True
|
2017-02-15 15:35:44 +01:00
|
|
|
alternatives = ['null', 'example', 'default']
|
|
|
|
|
|
|
|
|
|
|
2019-02-06 15:35:55 +01:00
|
|
|
class PlusQualifier(FooNode):
|
|
|
|
|
enum_node = True
|
2017-06-20 11:08:18 +02:00
|
|
|
qualifier = True
|
|
|
|
|
|
|
|
|
|
|
2017-02-15 15:35:44 +01:00
|
|
|
class Param(FooNode):
|
|
|
|
|
name = Field(type=T.Name)
|
|
|
|
|
mode = Field(type=T.Enum)
|
2017-06-20 11:08:18 +02:00
|
|
|
has_plus = Field(type=T.PlusQualifier)
|
2017-02-15 15:35:44 +01:00
|
|
|
|
|
|
|
|
|
|
|
|
|
class Name (FooNode):
|
2018-01-26 14:59:51 +01:00
|
|
|
token_node = True
|
2017-02-15 15:35:44 +01:00
|
|
|
|
|
|
|
|
|
|
|
|
|
foo_grammar = Grammar('main_rule')
|
|
|
|
|
foo_grammar.add_rules(
|
2017-06-20 11:08:18 +02:00
|
|
|
main_rule=List(Param(foo_grammar.name,
|
|
|
|
|
foo_grammar.mode,
|
|
|
|
|
foo_grammar.plus)),
|
2018-01-26 11:30:18 +01:00
|
|
|
name=Name(Token.Identifier),
|
2017-02-15 15:35:44 +01:00
|
|
|
mode=Or(
|
|
|
|
|
Enum.alt_null('null'),
|
|
|
|
|
Enum.alt_example('example'),
|
|
|
|
|
Enum.alt_default(),
|
|
|
|
|
),
|
2017-06-20 11:08:18 +02:00
|
|
|
plus=PlusQualifier('+'),
|
2017-02-15 15:35:44 +01:00
|
|
|
)
|
|
|
|
|
build_and_run(foo_grammar, 'main.py')
|
2017-02-24 10:25:54 +01:00
|
|
|
print('Done')
|