Commits

Juancarlo Añez  committed 6d1d503 Merge

Merge from default branch.

  • Participants
  • Parent commits 768aabe, 767c9ff
  • Branches 1.0

Comments (0)

Files changed (5)

 
 **tip**
     * Also memoize exception results.
+    * Also memoize advancing over whitespace and comments.
     * Work with unicode while rendering.
     * Added a table of contents to this *README*.
 

File grako/buffering.py

         self.original_text = text
         self.text = text
         self.filename = filename if filename is not None else ''
-        self.whitespace = set(whitespace if whitespace else string.whitespace)
+        self.whitespace = set(whitespace if whitespace is not None else string.whitespace)
         self.ignorecase = ignorecase
         self.trace = trace
         self.nameguard = nameguard

File grako/grammars.py

     return repr(obj).lstrip('u')
 
 class ModelContext(ParseContext):
-    def __init__(self, rules, text, filename, trace):
-        super(ModelContext, self).__init__(trace=trace)
+    def __init__(self, rules, text, filename, trace, **kwargs):
+        super(ModelContext, self).__init__(trace=trace, **kwargs)
         self.rules = {rule.name :rule for rule in rules}
         self._buffer = Buffer(text, filename=filename)
         self._buffer.goto(0)
             rule._first_set = F[rule.name]
         return F
 
-    def parse(self, text, start=None, filename=None, trace=False,):
+    def parse(self, text, start=None, filename=None, trace=False, **kwargs):
         try:
             try:
-                ctx = ModelContext(self.rules, text, filename, trace=trace)
+                ctx = ModelContext(self.rules, text, filename, trace=trace, **kwargs)
                 start_rule = ctx._find_rule(start) if start else self.rules[0]
                 return start_rule.parse(ctx)
             except FailedCut as e:

File grako/parsing.py

 
     def _call(self, name, node_name=None, force_list=False):
         self._rule_stack.append(name)
-        if name[0].islower():
-            self._next_token()
         pos = self._pos
         try:
             self._trace_event('ENTER ')
         rule = self._find_rule(name)
         self._push_ast()
         try:
+            if name[0].islower():
+                self._next_token()
             rule()
             node = self.ast
             if not node:

File grako/test/buffering_test.py

     def test_pos_consistency(self):
         line = col = 0
         for p, c in enumerate(self.text):
-            bl, bc = self.buf.line_info(p)[:2]
+            bl, bc = self.buf.line_info(p)[1:3]
             d = self.buf.next()
 #            print('tx', line, col, c.encode('string-escape'))
 #            print('bu', bl, bc, d.encode('string-escape'))
                 line += 1
             else:
                 col += 1
+
     def test_next_consisntency(self):
         while not self.buf.atend():
-            bl, bc = self.buf.line_info()[:2]
+            bl, bc = self.buf.line_info()[1:3]
 #            print('li', bl, bc)
 #            print('bu', self.buf.line, self.buf.col)
             self.assertEqual(bl, self.buf.line)
     def test_goto_consistency(self):
         for _ in range(100):
             self.buf.goto(random.randrange(len(self.text)))
-            bl, bc = self.buf.line_info()[:2]
+            bl, bc = self.buf.line_info()[1:3]
 #            print('li', bl, bc)
 #            print('bu', self.buf.line, self.buf.col)
             self.assertEqual(bl, self.buf.line)
             self.assertEqual(line, self.buf.get_line(n))
 
 def suite():
-    pass
+    return unittest.TestLoader().loadTestsFromTestCase(BufferingTests)
 
 def main():
-    unittest.main()
+    unittest.TextTestRunner(verbosity=2).run(suite())
 
 if __name__ == '__main__':
     main()