class BarNode(FooNode): _prop = Property(No(FooNode))
class Example(FooNode): result = Property(prop)
class FooNode(ASTNode): id_bool = Property(lambda id=T.Bool: id, public=True) id_int = Property(lambda id=T.Int: id, public=True) id_bigint = Property(lambda id=T.BigInt: id, public=True) id_char = Property(lambda id=T.Character: id, public=True) id_token = Property(lambda id=T.Token: id, public=True) id_sym = Property(lambda id=T.Symbol: id, public=True) id_unit = Property(lambda id=T.AnalysisUnit: id, public=True) id_root_node = Property(lambda id=T.FooNode: id, public=True) id_name = Property(lambda id=T.Name: id, public=True) # Test for enums id_unit_kind = Property(lambda id=T.AnalysisUnitKind: id, public=True) # Test for arrays id_node_array = Property(lambda id=T.FooNode.entity.array: id, public=True) id_bigint_array = Property(lambda id=T.BigInt.array: id, public=True)
class Ref(Atom): token_node = True prop1 = Property(3) prop2 = Property(3) prop3 = Property(3)
class FuncDecl(Decl): name = Field() args = Field() expr = Field() decl_kind = Property(DeclKind.func)
class BarNode(FooNode): prop_2 = Property(lambda x=LongType: x) prop = Property(expr)
class Atom(Expr): # Warning: both concrete subclasses override this (concrete derived # property). prop1 = Property(1)
class Name(FooNode): token_node = True class Decl(FooNode): name = Field() refs = Field() env_spec = EnvSpec(add_to_env_kv(key=Self.name.symbol, value=Self), add_env()) class Ref(FooNode): name = Field() env_spec = EnvSpec( add_to_env_kv(key=Self.name.symbol, value=Self, resolver=FooNode.resolve_ref)) @langkit_property(public=True) def resolve(): return Self.node_env.get(Self.name).at(0) emit_and_print_errors(lkt_file='foo.lkt') run('Bad return type', Property(Self.node_env.get('foo'))) run('Has dynamic variable', Property(Self.node_env.get('foo').at(0), dynamic_vars=[Env])) run('Has arguments', Property(lambda i=T.Int: Self.node_env.get('foo').at(i))) print('Done')
class Example(FooNode): p = Property(expr) calling = Property(calling_expr)
class BarNode(FooNode): prop = Property(expr, public=True)
class Id(Name): token_node = True sym = Property( Self.symbol, doc="Shortcut to get the symbol of this node" )
class Example(FooNode): token_node = True p = Property(expr.symbol, public=True)
class ExampleNode(MiddleNode): get_random_node = Property(No(astnode))
class LiteralList(Literal.list): prop = Property(prop_fn(), memoized=prop_memoized)
class Decl(FooNode): decl_kind = AbstractProperty(DeclKind, public=True) with_kind = Property(DeclAndKind.new(dcl=Self, knd=Self.decl_kind), public=True)
class BarNode(FooNode): prop = Property(prop_lambda, warn_on_unused=False)
class ListNode(FooNode): nb_list = Field() prop = Property(Self.nb_list.map(lambda i, _: i), public=True)
class FooNode(ASTNode): root_node = Property(Self.unit.root.as_bare_entity, public=True)
class ListNode(FooNode): nb_list = Field() prop = Property(expr, public=True)
class Sequence(FooNode.list): all_items = Property(Entity.map(lambda i: i), public=True) example_items = Property(Entity.filtermap( lambda i: i.cast_or_raise(T.Example), lambda i: i.is_a(T.Example)), public=True)
class Lit(Atom): token_node = True prop1 = Property(2) prop2 = Property(2) prop3 = Property(2)
class Example(FooNode): prop = Property(True, public=True)
class VarDecl(Decl): name = Field() expr = Field() decl_kind = Property(DeclKind.var)
class FooNode(ASTNode): prop = Property(Literal(0), public=True)
class ExampleNode(FooNode): b = Property(lit, public=True)
class ExampleNode(FooNode): body = Field() prop = Property(match_expr)
class Plus(Expression): left = Field() right = Field() result = Property(Self.left.result + Self.right.result)
class BarNode(BarCode): base_prop = Property(lambda x=Symbol: 12)
class BarNode(FooNode): prop_2 = Property(lambda x=Int: x, public=True) prop = Property(expr, public=True)
class Example(FooNode): get_num = Property(2)