mirror of
https://github.com/AdaCore/langkit.git
synced 2026-02-12 12:28:12 -08:00
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:
@@ -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 {
|
||||
}
|
||||
1
testsuite/tests/python_api/python_app/input1
Normal file
1
testsuite/tests/python_api/python_app/input1
Normal file
@@ -0,0 +1 @@
|
||||
example hello1
|
||||
1
testsuite/tests/python_api/python_app/input2
Normal file
1
testsuite/tests/python_api/python_app/input2
Normal file
@@ -0,0 +1 @@
|
||||
example hello2
|
||||
1
testsuite/tests/python_api/python_app/input3
Normal file
1
testsuite/tests/python_api/python_app/input3
Normal file
@@ -0,0 +1 @@
|
||||
example hello3
|
||||
10
testsuite/tests/python_api/python_app/main.py
Normal file
10
testsuite/tests/python_api/python_app/main.py
Normal 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'])
|
||||
4
testsuite/tests/python_api/python_app/test.out
Normal file
4
testsuite/tests/python_api/python_app/test.out
Normal 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
|
||||
20
testsuite/tests/python_api/python_app/test.py
Normal file
20
testsuite/tests/python_api/python_app/test.py
Normal 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')
|
||||
1
testsuite/tests/python_api/python_app/test.yaml
Normal file
1
testsuite/tests/python_api/python_app/test.yaml
Normal file
@@ -0,0 +1 @@
|
||||
driver: python
|
||||
Reference in New Issue
Block a user