1. Benjamin Dauvergne
  2. pymeta

Commits

Benjamin Dauvergne  committed 8d4f9f0 Draft

add the index consumed by operator
---
pymeta/boot.py | 53 ++++++++++++++++++++++++++++++++++++++++++++++-------
pymeta/builder.py | 7 +++++++
pymeta/grammar.py | 2 ++
pymeta/runtime.py | 9 +++++++++
4 files changed, 64 insertions(+), 7 deletions(-)

  • Participants
  • Parent commits 58b6a30
  • Branches default

Comments (0)

Files changed (4)

File pymeta/boot.py

View file
  • Ignore whitespace
         self.considerError(lastError)
         _G_apply_2, lastError = self._apply(self.rule_token, "token", [_G_python_1])
         self.considerError(lastError)
-        def _G_consumed_by_3():
+        def _G_index_consumed_by_3():
             def _G_many_1():
                 def _G_or_1():
                     _G_apply_1, lastError = self._apply(self.rule_escapedChar, "escapedChar", [])
             _G_many_2, lastError = self.many(_G_many_1)
             self.considerError(lastError)
             return (_G_many_2, self.currentError)
-        _G_consumed_by_4, lastError = self.consumed_by(_G_consumed_by_3)
+        _G_index_consumed_by_4, lastError = self.index_consumed_by(_G_index_consumed_by_3)
         self.considerError(lastError)
-        _locals['c'] = _G_consumed_by_4
+        _locals['c'] = _G_index_consumed_by_4
         _G_python_5, lastError = eval('"\'"', self.globals, _locals), None
         self.considerError(lastError)
         _G_apply_6, lastError = self._apply(self.rule_token, "token", [_G_python_5])
             _G_python_6, lastError = eval('self.builder.consumedby(e)', self.globals, _locals), None
             self.considerError(lastError)
             return (_G_python_6, self.currentError)
-        _G_or_12, lastError = self._or([_G_or_1, _G_or_2, _G_or_3, _G_or_4, _G_or_5, _G_or_6, _G_or_7, _G_or_8, _G_or_9, _G_or_10, _G_or_11])
+        def _G_or_12():
+            _G_python_1, lastError = eval('"@<"', self.globals, _locals), None
+            self.considerError(lastError)
+            _G_apply_2, lastError = self._apply(self.rule_token, "token", [_G_python_1])
+            self.considerError(lastError)
+            _G_apply_3, lastError = self._apply(self.rule_expr, "expr", [])
+            self.considerError(lastError)
+            _locals['e'] = _G_apply_3
+            _G_python_4, lastError = eval("'>'", self.globals, _locals), None
+            self.considerError(lastError)
+            _G_apply_5, lastError = self._apply(self.rule_token, "token", [_G_python_4])
+            self.considerError(lastError)
+            _G_python_6, lastError = eval('self.builder.index_consumedby(e)', self.globals, _locals), None
+            self.considerError(lastError)
+            return (_G_python_6, self.currentError)
+        _G_or_13, lastError = self._or([_G_or_1, _G_or_2, _G_or_3, _G_or_4, _G_or_5, _G_or_6, _G_or_7, _G_or_8, _G_or_9, _G_or_10, _G_or_11, _G_or_12])
         self.considerError(lastError)
-        return (_G_or_12, self.currentError)
+        return (_G_or_13, self.currentError)
 
 
     def rule_expr2(self):
             self.considerError(lastError)
             return (_G_python_6, self.currentError)
         def _G_or_2():
+            _G_python_1, lastError = eval('True', self.globals, _locals), None
+            self.considerError(lastError)
+            _G_apply_2, lastError = self._apply(self.rule_expr5, "expr5", [_G_python_1])
+            self.considerError(lastError)
+            _locals['e'] = _G_apply_2
+            def _G_many1_3():
+                _G_python_1, lastError = eval("'||'", self.globals, _locals), None
+                self.considerError(lastError)
+                _G_apply_2, lastError = self._apply(self.rule_token, "token", [_G_python_1])
+                self.considerError(lastError)
+                _G_python_3, lastError = eval('True', self.globals, _locals), None
+                self.considerError(lastError)
+                _G_apply_4, lastError = self._apply(self.rule_expr5, "expr5", [_G_python_3])
+                self.considerError(lastError)
+                return (_G_apply_4, self.currentError)
+            _G_many1_4, lastError = self.many(_G_many1_3, _G_many1_3())
+            self.considerError(lastError)
+            _locals['es'] = _G_many1_4
+            _G_python_5, lastError = eval('es.insert(0, e)', self.globals, _locals), None
+            self.considerError(lastError)
+            _G_python_6, lastError = eval('self.builder._xor(es)', self.globals, _locals), None
+            self.considerError(lastError)
+            return (_G_python_6, self.currentError)
+        def _G_or_3():
             _G_python_1, lastError = eval('False', self.globals, _locals), None
             self.considerError(lastError)
             _G_apply_2, lastError = self._apply(self.rule_expr5, "expr5", [_G_python_1])
             self.considerError(lastError)
             return (_G_apply_2, self.currentError)
-        _G_or_3, lastError = self._or([_G_or_1, _G_or_2])
+        _G_or_4, lastError = self._or([_G_or_1, _G_or_2, _G_or_3])
         self.considerError(lastError)
-        return (_G_or_3, self.currentError)
+        return (_G_or_4, self.currentError)
 
 
     def rule_ruleValue(self):

File pymeta/builder.py

View file
  • Ignore whitespace
     def consumedby(self, exprs):
         return ["ConsumedBy", exprs]
 
+    def consumedby(self, exprs):
+        return ["IndexConsumedBy", exprs]
+
     def range(self, c1, c2):
         return ["Range", c1, c2]
 
         fname = self._newThunkFor("consumed_by", expr)
         return self._expr("consumed_by", "self.consumed_by(%s)" % (fname,))
 
+    def generate_IndexConsumedBy(self, expr):
+        fname = self._newThunkFor("index_consumed_by", expr)
+        return self._expr("index_consumed_by", "self.index_consumed_by(%s)" % (fname,))
+
     def generate_Range(self, c1, c2):
         """
         Create a call to self.range(c1, c2)

File pymeta/grammar.py

View file
  • Ignore whitespace
           |token('(') expr:e token(')') -> e
           |token('[') expr:e token(']') -> self.builder.listpattern(e)
           |token('<') expr:e token('>') -> self.builder.consumedby(e)
+          |token("@<") expr:e token('>') -> self.builder.index_consumedby(e)
 
 expr2 = token('~') (token('~') expr2:e -> self.builder.lookahead(e)
                        |expr2:e -> self.builder._not(e))
       | ['Python' :code]        -> self.builder.expr(code)
       | ['List' opt:exprs]      -> self.builder.listpattern(exprs)
       | ['ConsumedBy' opt:expr] -> self.builder.consumedby(expr)
+      | ['IndexConsumedBy' opt:expr] -> self.builder.index_consumedby(expr)
       | ['Range' :c1 :c2]       -> self.builder.range(c1, c2)
       | ['Interleave' opt:exprs] -> self.builder.interleave(exprs)
       )

File pymeta/runtime.py

View file
  • Ignore whitespace
             consumed = ''.join(consumed)
         return consumed, r[1]
 
+    def index_consumed_by(self, f):
+        """
+            Try to parse f, if successful return the start and end offset of
+            the full string matching it.
+        """
+        m = self.input
+        r = f()
+        return [m.position, self.input.position], r[1]
+
     def range(self, c1, c2):
         m = self.input
         x, e = self.rule_anything()