Commits

Anonymous committed 7a62b3b

adding autoblanking

  • Participants
  • Parent commits 42a8a06

Comments (0)

Files changed (2)

docs/grammar_elements.en.yhtml2

 
     p   >>
         The special cardinality values can be generated with the
-        ¬#cardfuncs Cardinality Functions¬.  The value «-3» is reserved for the
-        indention system. Other negative values are reserved and may not be
-        used.
+        ¬#cardfuncs Cardinality Functions¬. Other negative values are reserved
+        and may not be used.
         >>
 
     h4 > Composing
     p > «indent(*thing)»
 
     p   >>
-        Indent thing by one level. Inserts «-3» as cardinality before thing.
+        Indent thing by one level.
         >>
 
     h4 > Parsing
         Temporary enable automated whitespace removing while parsing «thing».
         Whitespace removing is enabled by default. This function is for
         temporary enabling whitespace removing after it was disabled with the
-        ¬#contiguous contiguous function¬.
+        «contiguous» function.
         >>
 
     h4 > Parsing

pypeg2/__init__.py

         self._memory = {}
         self._got_endl = True
         self._contiguous = False
+        self._got_regex = False
 
     def parse(self, text, thing, filename=None):
         """(Partially) parse text following thing as grammar and return the
             # make sure that we're not having this type error
             compose = None
 
-        def terminal_indent():
+        def terminal_indent(do_blank=False):
+            self._got_regex = False
             if self._got_endl:
                 result = self.indent * self.indention_level
                 self._got_endl = False
                 return result
+            elif do_blank and self.whitespace:
+                if self._contiguous:
+                    return ""
+                else:
+                    return blank(thing, self)
             else:
                 return ""
 
         elif isinstance(grammar, (RegEx, _RegEx)):
             m = grammar.match(str(thing))
             if m:
-                result = terminal_indent() + str(thing)
+                result = terminal_indent(do_blank=self._got_regex) + str(thing)
             else:
                 raise ValueError(repr(thing) + " does not match "
                         + grammar.pattern)
+            self._got_regex = True
 
         elif isinstance(grammar, (str, Literal)):
             result = terminal_indent() + str(grammar)