Commits

Anonymous committed 5d98b5e

extending documentation

Comments (0)

Files changed (4)

docs/index.en.yhtml2

 
     Code
         ||
-        >>> compose(f)
-        'int f(int a, long b){do_this;do_that;}'
+        >>> compose(f, autoblank=False)
+        'intf(inta, longb){do_this;do_that;}'
         ||
 
     p   >>
         As you can see, for composing first there is a lack of whitespace. This
-        is because we used the automated whitespace removing functionality of ƒpyPEG,
-        which is enabled by default. To improve on that we have to extend our
-        «grammar» templates a little bit. For that case, there are callback
-        function objects in ƒpyPEG. They're only executed by «compose()» and ignored
-        by «parse()». And as usual, there are predefined ones for the common
-        cases. Let's try that out. First let's add «blank» between things which
-        should be separated:
+        is because we used the automated whitespace removing functionality of
+        ƒpyPEG while parsing (which is enabled by default) but we disabled the
+        automated adding of blanks if violating syntax otherwise. To improve on
+        that we have to extend our «grammar» templates a little bit. For that
+        case, there are callback function objects in ƒpyPEG. They're only
+        executed by «compose()» and ignored by «parse()». And as usual, there
+        are predefined ones for the common cases. Let's try that out. First
+        let's add «blank» between things which should be separated:
         >>
 
     Code
         >>
 
     Code    ||
-            >>> compose(f)
+            >>> compose(f, autoblank=False)
             'int◊ ◊f(int◊ ◊a, long◊ ◊b){do_this;do_that;}'
             ||
 

docs/parser_engine.en.yhtml2

             > original text to parse; set for decorated syntax errors
         term "filename"
             > filename where text is origin from
+        term "autoblank"
+            > add blanks if grammar would possibly be violated otherwise; default: True
     }
 
     h3 id=parser_init > Method init()
     h3 id=compose > Function compose()
 
     h4 > Synopsis
-    p > «compose(thing, grammar=None, indent="    ")»
+    p > «compose(thing, grammar=None, indent="    ", autoblank=True
 
     p > Compose text using «thing» with «grammar».
 
         term "thing" > «thing» containing other things with «grammar»
         term "grammar" > «grammar» to use to compose thing; default: «thing.grammar»
         term "indent" > string to use to indent while composing; default: four spaces
+        term "autoblank"
+            > add blanks if grammar would possibly be violated otherwise; default: True
     }
 
     h4 > Returns

pypeg2/__init__.py

     return r
 
 
-def compose(thing, grammar=None, indent="    "):
+def compose(thing, grammar=None, indent="    ", autoblank=True):
     """Compose text using thing with grammar.
 
     Arguments:
                         default: thing.grammar
         indent          string to use to indent while composing
                         default: four spaces
+        autoblank       add blanks if grammar would possibly be
+                        violated otherwise
+                        default: True
 
     Returns text
 
 
     parser = Parser()
     parser.indent = indent
+    parser.autoblank = autoblank
     return parser.compose(thing, grammar)
 
 
         text                original text to parse; set for decorated syntax
                             errors
         filename            filename where text is origin from
+        autoblank           add blanks if grammar would possibly be
+                            violated otherwise
+                            default: True
     """
 
     def __init__(self):
         self.indention_level = 0
         self.text = None
         self.filename = None
+        self.autoblank = True
         self._memory = {}
         self._got_endl = True
         self._contiguous = False
                 self._got_endl = False
                 return result
             elif do_blank and self.whitespace:
-                if self._contiguous:
+                if self._contiguous or not self.autoblank:
                     return ""
                 else:
                     return blank(thing, self)

samples/sample1.py

 
 The comment parameter is set to C style /* comments */
 
->>> f = parse("int f(int a, long b) { do_this; do_that; } /* hello */", Function, comment=comment_c)
+>>> f = parse("int f(int a, long b) { do_this; do_that; }", Function, comment=comment_c)
 
 Because function has a name() in its grammar, we can access this now as an
 attribute. With Python 2.7 this gives Symbol(u'f'), with Python 3.2 it gives Symbol('f'):