mirror of
https://github.com/AdaCore/langkit.git
synced 2026-02-12 12:28:12 -08:00
30 lines
698 B
Python
30 lines
698 B
Python
from __future__ import absolute_import, division, print_function
|
|
|
|
import sys
|
|
|
|
import libfoolang as lfl
|
|
|
|
|
|
print('main.py: Running...')
|
|
|
|
|
|
def parse(filename, content, rule):
|
|
result = ctx.get_from_buffer(filename, content, rule=rule)
|
|
if result.diagnostics:
|
|
print('Errors in {}:'.format(filename))
|
|
for d in result.diagnostics:
|
|
print(' {}'.format(d))
|
|
sys.exit(1)
|
|
return result
|
|
|
|
|
|
ctx = lfl.AnalysisContext()
|
|
|
|
n1 = parse('foo1.txt', 'def f(x) = x + 2', lfl.default_grammar_rule).root
|
|
n2 = parse('foo2.txt', '3', lfl.GrammarRule.expr_rule).root
|
|
|
|
print("{} ({})".format(n1.text, type(n1)))
|
|
print("{} ({})".format(n2.text, type(n2)))
|
|
|
|
print('main.py: Done.')
|