Anonymous avatar Anonymous committed a29c812

fixing code of parse() and compose()

Comments (0)

Files changed (5)

 	rm -f pyPEG2.tar.gz
 	ln -s `ls dist/pyPEG2-*.tar.gz | tail -n1` pyPEG2.tar.gz
 	scp docs/*.html docs/format.css pyPEG2.tar.gz *.txt samples/* dragon:fdik.org/pyPEG2/
+	make register
 
 register:
 	$(PYTHON) setup.py register

docs/heading.en.yinc2

 div id="headline" {
     p > pyPEG – a PEG Parser-Interpreter in Python
     div class="small" {
-        "pyPEG 2.1.2 of Sa May 26 2012 – Copyleft 2009-2012, "
+        "pyPEG 2.2.0 of Sa May 26 2012 – Copyleft 2009-2012, "
         a "http://fdik.org", "Volker Birk";
     }
     div id=python1 p {

pypeg2/__init__.py

 This program is under GNU General Public License 2.0.
 """
 
-__version__ = 2.1
+__version__ = 2.2
 __author__ = "Volker Birk"
 __license__ = "This program is under GNU General Public License 2.0."
 __url__ = "http://fdik.org/pyPEG"
         if thing is None or type(thing) == FunctionType:
             result = text, None
 
-        elif type(thing) == str:
+        elif isinstance(thing, Keyword):
+            m = type(thing).regex.match(text)
+            if m and m.group(0) == str(thing):
+                t, r = text[len(thing):], None
+                t = self._skip(t)
+                result = t, r
+                update_pos(text, t, pos)
+            else:
+                result = text, syntax_error("expecting " + repr(thing))
+
+        elif isinstance(thing, str):
             if text.startswith(thing):
                 t, r = text[len(thing):], None
                 t = self._skip(t)
                 result = text, syntax_error("expecting match on "
                         + thing.pattern)
 
-        elif isinstance(thing, Keyword):
-            m = type(thing).regex.match(text)
-            if m and m.group(0) == str(thing):
-                t, r = text[len(thing):], None
-                t = self._skip(t)
-                result = t, r
-                update_pos(text, t, pos)
-            else:
-                result = text, syntax_error("expecting " + repr(thing))
-
         elif _issubclass(thing, Symbol):
             m = thing.regex.match(text)
             if m:
 
         # non-terminal constructs
 
-        elif type(thing) == attr.Class:
+        elif isinstance(thing, attr.Class):
             t, r = self._parse(text, thing.thing, pos)
             if type(r) == SyntaxError:
                 if thing.subtype == "Flag":
                 else:
                     result = t, attr(thing.name, r)
 
-        elif type(thing) == tuple:
+        elif isinstance(thing, tuple):
             L = []
             t = text
             flag = True
             else:
                 result = text, r
 
-        elif type(thing) == list:
+        elif isinstance(thing, list):
             found = False
             for e in thing:
                 t, r = self._parse(text, e, pos)
             else:
                 result = self.compose(thing, grammar(thing, self))
 
-        elif isinstance(grammar, (str, int, float, complex, bool, bytes)):
+        elif isinstance(grammar, str):
             result = terminal_indent() + str(grammar)
 
         elif isinstance(grammar, RegEx):
             else:
                 raise ValueError(repr(thing) + " is not in " + repr(grammar))
 
-        elif type(grammar) == attr.Class:
+        elif isinstance(grammar, attr.Class):
             if grammar.subtype == "Flag":
                 if getattr(thing, grammar.name):
                     result = terminal_indent() + compose(grammar.thing)
             else:
                 result = self.compose(getattr(thing, grammar.name), grammar.thing)
 
-        elif type(grammar) == list:
+        elif isinstance(grammar, list):
             found = False
             for g in grammar:
                 try:
                 raise ValueError("none of the options in " + repr(grammar)
                         + " found")
 
-        elif type(grammar) == tuple:
+        elif isinstance(grammar, tuple):
             def compose_tuple(thing, things, grammar):
                 text = []
                 multiple, card = 1, 1
 This program is under GNU General Public License 2.0.
 """
 
-__version__ = 2.1
+__version__ = 2.2
 __author__ = "Volker Birk"
 __license__ = "This program is under GNU General Public License 2.0."
 __url__ = "http://fdik.org/pyPEG"
 
 setup(
     name='pyPEG2',
-    version='2.1.2',
+    version='2.2.0',
     author='Volker Birk',
     author_email='vb@dingens.org',
     packages=['pypeg2', 'pypeg2.test'],
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.