Skip to content

Commit 937bd39

Browse files
author
Allen Short
committed
resurrect term spans. provide trace hook for grammar execution.
1 parent ca2e6ee commit 937bd39

18 files changed

+836
-427
lines changed

bin/stage

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import os
55
import glob
66
import shutil
77
from ometa.runtime import ParseError
8-
from ometa.grammar import OMeta
8+
from ometa.grammar import OMeta, TreeTransformerGrammar
99
from ometa.builder import writePython
1010

1111

@@ -38,9 +38,12 @@ def stage_pkg(parsley_dir, stage_dir, pkg):
3838
pyfn = os.path.join(stage_gen_dir, grammarname + '.py')
3939
print "{src:38} => {dst}".format(src=os.path.relpath(filename, parsley_dir),
4040
dst=os.path.relpath(pyfn, parsley_dir))
41-
g = OMeta(grammar)
41+
if grammar.startswith('#TreeTransformer'):
42+
g = TreeTransformerGrammar(grammar)
43+
else:
44+
g = OMeta(grammar)
4245
tree = g.parseGrammar(grammarname)
43-
source = writePython(tree)
46+
source = writePython(tree, grammar)
4447
pythonFile = open(pyfn, 'w')
4548
pythonFile.write(source)
4649

ometa/_generated/parsley.py

Lines changed: 464 additions & 296 deletions
Large diffs are not rendered by default.

ometa/_generated/parsley_termactions.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,13 @@ class parsley_termactions(GrammarBase):
55
def rule_ruleValue(self):
66
_locals = {'self': self}
77
self.locals['ruleValue'] = _locals
8+
self._trace(' ws', (11, 14), self.input.position)
89
_G_apply_1, lastError = self._apply(self.rule_ws, "ws", [])
910
self.considerError(lastError, 'ruleValue')
11+
self._trace(" '->'", (14, 19), self.input.position)
1012
_G_exactly_2, lastError = self.exactly('->')
1113
self.considerError(lastError, 'ruleValue')
14+
self._trace(' term', (19, 24), self.input.position)
1215
_G_apply_3, lastError = self._apply(self.rule_term, "term", [])
1316
self.considerError(lastError, 'ruleValue')
1417
_locals['tt'] = _G_apply_3
@@ -20,15 +23,20 @@ def rule_ruleValue(self):
2023
def rule_semanticPredicate(self):
2124
_locals = {'self': self}
2225
self.locals['semanticPredicate'] = _locals
26+
self._trace(' ws', (64, 67), self.input.position)
2327
_G_apply_5, lastError = self._apply(self.rule_ws, "ws", [])
2428
self.considerError(lastError, 'semanticPredicate')
29+
self._trace(" '?('", (67, 72), self.input.position)
2530
_G_exactly_6, lastError = self.exactly('?(')
2631
self.considerError(lastError, 'semanticPredicate')
32+
self._trace(' term', (72, 77), self.input.position)
2733
_G_apply_7, lastError = self._apply(self.rule_term, "term", [])
2834
self.considerError(lastError, 'semanticPredicate')
2935
_locals['tt'] = _G_apply_7
36+
self._trace(' ws', (80, 83), self.input.position)
3037
_G_apply_8, lastError = self._apply(self.rule_ws, "ws", [])
3138
self.considerError(lastError, 'semanticPredicate')
39+
self._trace(" ')'", (83, 87), self.input.position)
3240
_G_exactly_9, lastError = self.exactly(')')
3341
self.considerError(lastError, 'semanticPredicate')
3442
_G_python_10, lastError = eval('t.Predicate(tt)', self.globals, _locals), None
@@ -39,15 +47,20 @@ def rule_semanticPredicate(self):
3947
def rule_semanticAction(self):
4048
_locals = {'self': self}
4149
self.locals['semanticAction'] = _locals
50+
self._trace(' ws', (124, 127), self.input.position)
4251
_G_apply_11, lastError = self._apply(self.rule_ws, "ws", [])
4352
self.considerError(lastError, 'semanticAction')
53+
self._trace(" '!('", (127, 132), self.input.position)
4454
_G_exactly_12, lastError = self.exactly('!(')
4555
self.considerError(lastError, 'semanticAction')
56+
self._trace(' term', (132, 137), self.input.position)
4657
_G_apply_13, lastError = self._apply(self.rule_term, "term", [])
4758
self.considerError(lastError, 'semanticAction')
4859
_locals['tt'] = _G_apply_13
60+
self._trace(' ws', (140, 143), self.input.position)
4961
_G_apply_14, lastError = self._apply(self.rule_ws, "ws", [])
5062
self.considerError(lastError, 'semanticAction')
63+
self._trace(" ')'", (143, 147), self.input.position)
5164
_G_exactly_15, lastError = self.exactly(')')
5265
self.considerError(lastError, 'semanticAction')
5366
_G_python_16, lastError = eval('t.Action(tt)', self.globals, _locals), None
@@ -59,22 +72,27 @@ def rule_application(self):
5972
_locals = {'self': self}
6073
self.locals['application'] = _locals
6174
def _G_optional_17():
75+
self._trace(' indentation', (178, 190), self.input.position)
6276
_G_apply_18, lastError = self._apply(self.rule_indentation, "indentation", [])
6377
self.considerError(lastError, None)
6478
return (_G_apply_18, self.currentError)
6579
def _G_optional_19():
6680
return (None, self.input.nullError())
6781
_G_or_20, lastError = self._or([_G_optional_17, _G_optional_19])
6882
self.considerError(lastError, 'application')
83+
self._trace(' name', (191, 196), self.input.position)
6984
_G_apply_21, lastError = self._apply(self.rule_name, "name", [])
7085
self.considerError(lastError, 'application')
7186
_locals['name'] = _G_apply_21
7287
def _G_or_22():
88+
self._trace("'('", (221, 224), self.input.position)
7389
_G_exactly_23, lastError = self.exactly('(')
7490
self.considerError(lastError, None)
91+
self._trace(' term_arglist', (224, 237), self.input.position)
7592
_G_apply_24, lastError = self._apply(self.rule_term_arglist, "term_arglist", [])
7693
self.considerError(lastError, None)
7794
_locals['args'] = _G_apply_24
95+
self._trace(" ')'", (242, 246), self.input.position)
7896
_G_exactly_25, lastError = self.exactly(')')
7997
self.considerError(lastError, None)
8098
_G_python_26, lastError = eval('t.Apply(name, self.rulename, args)', self.globals, _locals), None

0 commit comments

Comments
 (0)