[pypy-svn] r11431 - in pypy/dist/pypy/module/parser/recparser: . ebnf python

ludal at codespeak.net ludal at codespeak.net
Mon Apr 25 18:40:14 CEST 2005


Author: ludal
Date: Mon Apr 25 18:40:14 2005
New Revision: 11431

Modified:
   pypy/dist/pypy/module/parser/recparser/ebnf/lexer.py
   pypy/dist/pypy/module/parser/recparser/grammar.py
   pypy/dist/pypy/module/parser/recparser/python/lexer.py
Log:
 * just small cleanups posponning the big changes later


Modified: pypy/dist/pypy/module/parser/recparser/ebnf/lexer.py
==============================================================================
--- pypy/dist/pypy/module/parser/recparser/ebnf/lexer.py	(original)
+++ pypy/dist/pypy/module/parser/recparser/ebnf/lexer.py	Mon Apr 25 18:40:14 2005
@@ -25,6 +25,13 @@
     def context(self):
         return self.pos
 
+    def offset(self, ctx=None):
+        if ctx is None:
+            return self.pos
+        else:
+            assert type(ctx)==int
+            return ctx
+
     def restore(self, ctx ):
         self.pos = ctx
 

Modified: pypy/dist/pypy/module/parser/recparser/grammar.py
==============================================================================
--- pypy/dist/pypy/module/parser/recparser/grammar.py	(original)
+++ pypy/dist/pypy/module/parser/recparser/grammar.py	Mon Apr 25 18:40:14 2005
@@ -25,6 +25,12 @@
         source has been found
         """
 
+    def offset(self, ctx=None):
+        """Returns the position we're at so far in the source
+        optionnally provide a context and you'll get the offset
+        of the context"""
+        return -1
+
     def current_line(self):
         """Returns the current line number"""
         return 0
@@ -113,9 +119,26 @@
         /!\ If the sets of element didn't match the current grammar
         element, then the <source> is restored as it was before the
         call to the match() method
+
+        returns None if no match or an object build by builder
         """
         return None
     
+    def parse(self, source):
+        """Returns a simplified grammar if the rule matched at the source
+        current context or None"""
+        # **NOT USED** **NOT IMPLEMENTED**
+        # To consider if we need to improve speed in parsing
+        pass
+
+    def first_set(self):
+        """Returns a list of possible tokens that can start this rule
+        None means the rule can be empty
+        """
+        # **NOT USED** **NOT IMPLEMENTED**
+        # To consider if we need to improve speed in parsing
+        pass
+
     def __str__(self):
         return self.display(0)
 
@@ -150,6 +173,9 @@
         """
         if DEBUG>1:
             print "try alt:", self.display()
+        # Here we stop at the first match we should
+        # try instead to get the longest alternative
+        # to see if this solve our problems with infinite recursion
         for rule in self.args:
             m = rule.match( source, builder )
             if m:

Modified: pypy/dist/pypy/module/parser/recparser/python/lexer.py
==============================================================================
--- pypy/dist/pypy/module/parser/recparser/python/lexer.py	(original)
+++ pypy/dist/pypy/module/parser/recparser/python/lexer.py	Mon Apr 25 18:40:14 2005
@@ -92,6 +92,13 @@
     def restore(self, ctx):
         self.stack_pos = ctx
 
+    def offset(self, ctx=None):
+        if ctx is None:
+            return self.stack_pos
+        else:
+            assert type(ctx)==int
+            return ctx
+
     def _next(self):
         """returns the next token from source"""
         inp = self.input



More information about the Pypy-commit mailing list