Anonymous avatar Anonymous committed 7dd4e1d

exec for Python 2.7 and 3.x

Comments (0)

Files changed (6)

-PYTHON=python3.2
+PYTHON=python2.7
 
 .PHONY: docs test_docs clean push dist test register deploy
 

docs/grammar_elements.en.yhtml2

 page "pyPEG – Grammar Elements", "counter-reset: chapter 1;" {
     h1 id=gelements > Grammar Elements
 
+    p   >>
+        ƒCaveat: pyPEG 2.x is written for Python 3. That means, it accepts
+        Unicode strings only.  You can use it with Python 2.7 by writing
+        «u'string'» instead of «'string'» or with the following import (you
+        don't need that for Python 3):
+        >>
+
+    Code | from __future__ import unicode_literals
+
+    p   >>
+        The samples in this documentation are written for Python 3, too. To
+        execute them with Python 2.7, you'll need this import:
+        >>
+
+    Code | from __future__ import print_function
+
     h2 id=basic > Basic Grammar Elements
 
     h3 id=literals > str instances and Literal

docs/heading.en.yinc2

 div id="headline" {
     p > pyPEG – a PEG Parser-Interpreter in Python
     div class="small" {
-        "pyPEG 2.8.2 of Fr Dec 07 2012 – Copyleft 2009-2012, "
+        "pyPEG 2.9.0 of Su Dec 09 2012 – Copyleft 2009-2012, "
         a "http://fdik.org", "Volker Birk";
     }
     div id=python1 p
         >>
-        Requires Python 2.7 or 3.x`br`
+        Requires Python 3.x or 2.7`br`
         Older versions: ¬http://fdik.org/pyPEG1 pyPEG 1.x¬
         >>
 }

pypeg2/__init__.py

     pass
 
 
-__version__ = 2.8
+__version__ = 2.9
 __author__ = "Volker Birk"
 __license__ = "This program is under GNU General Public License 2.0."
 __url__ = "http://fdik.org/pyPEG"
 import re
 import sys
 import weakref
-import warnings
-from functools import reduce
+if __debug__:
+    import warnings
 from types import FunctionType
 from collections import namedtuple
 try:
     return _card(0, thing)
 
 
-def csl(*thing, separator=","):
-    """Generate a grammar for a simple comma separated list."""
+def _csl(separator, *thing):
     # reduce unnecessary recursions
     if len(thing) == 1:
         L = [thing[0]]
         L.append(tuple(L2))
         return tuple(L)
 
+try:
+    # Python 3.x
+    _exec = eval("exec")
+    _exec('''
+def csl(*thing, separator=","):
+    """Generate a grammar for a simple comma separated list."""
+    return _csl(separator, *thing)
+''')
+except SyntaxError:
+    # Python 2.7
+    csl = lambda *thing: _csl(",", *thing)
+
 
 def attr(name, thing=word, subtype=None):
     """Generate an Attribute with that name, referencing the thing.
     pass
 
 
-__version__ = 2.8
+__version__ = 2.9
 __author__ = "Volker Birk"
 __license__ = "This program is under GNU General Public License 2.0."
 __url__ = "http://fdik.org/pyPEG"
 from distutils.core import setup
 
-_version = '2.8.2'
+_version = '2.9.0'
 
 setup(
     name='pyPEG2',
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.