Commits

Volker Birk  committed d3254d2

add thing.compose()

  • Participants
  • Parent commits 5d98b5e

Comments (0)

Files changed (2)

File docs/parser_engine.en.yhtml2

         term "filename"
             > filename where text is origin from
         term "autoblank"
-            > add blanks if grammar would possibly be violated otherwise; default: True
+            > add blanks while composing if grammar would possibly be violated otherwise; default: True
     }
 
     h3 id=parser_init > Method init()
     h4 > Synopsis
     p > «compose(self, thing, grammar=None)»
 
-    p > Compose text using «thing» with «grammar».
+    p   >>
+        Compose text using «thing» with «grammar». If «thing.compose()»
+        exists, execute it, otherwise use «grammar» to compose.
+        >>
 
     h4 > Arguments
 

File pypeg2/__init__.py

         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
+        autoblank           add blanks while composing if grammar would possibly
+                            be violated otherwise
                             default: True
     """
 
             else:
                 return ""
 
+        try:
+            thing.compose
+        except AttributeError:
+            pass
+        else:
+            return thing.compose()
+
         if not grammar:
             try:
                 grammar = type(thing).grammar