T910-014: Improve App

- Allow just subclassing App.process_unit, by providing a default main
  that iterates on units and calls process_unit on each

- Allow passing args to python App programmatically
This commit is contained in:
Raphaël AMIARD
2020-09-10 11:37:44 +02:00
parent 039b5aa93e
commit eff5ae2cd9
10 changed files with 79 additions and 16 deletions

View File

@@ -0,0 +1,12 @@
import lexer_example
@with_lexer(foo_lexer)
grammar foo_grammar {
@main_rule main_rule <- Example("example")
}
@abstract class FooNode : Node {
}
class Example : FooNode implements TokenNode {
}

View File

@@ -0,0 +1 @@
example hello1

View File

@@ -0,0 +1 @@
example hello2

View File

@@ -0,0 +1 @@
example hello3

View File

@@ -0,0 +1,10 @@
import libfoolang as lfl
class App(lfl.App):
def process_unit(self, unit):
unit.root.dump()
if __name__ == '__main__':
App.run(['input3', 'input1', 'input2'])

View File

@@ -0,0 +1,4 @@
Example input1:1:1-1:8: example
Example input2:1:1-1:8: example
Example input3:1:1-1:8: example
Done

View File

@@ -0,0 +1,20 @@
"""
Test python App class.
"""
from langkit.dsl import ASTNode
from utils import build_and_run
class FooNode(ASTNode):
pass
class Example(FooNode):
token_node = True
build_and_run(lkt_file='expected_concrete_syntax.lkt', py_script='main.py',
types_from_lkt=True)
print('Done')

View File

@@ -0,0 +1 @@
driver: python