Allow yylex() caller to specify factory for yy_element_space, yy_element_token
authorNick Downing <nick@ndcode.org>
Mon, 21 Jan 2019 00:44:15 +0000 (11:44 +1100)
committerNick Downing <nick@ndcode.org>
Mon, 21 Jan 2019 00:44:15 +0000 (11:44 +1100)
skel/skel_py_element.py

index d65d933..9c7e244 100644 (file)
@@ -138,7 +138,7 @@ def yy_set_bol(at_bol):
 
 # GENERATE SECTION2
 
-def yylex():
+def yylex(factory = element.Element, *args, **kwargs):
   global \
     yyin, \
     yy_threads0, \
@@ -155,8 +155,8 @@ def yylex():
 
   # GENERATE SECTION2INITIAL
 
-  yy_element_space = element.Element('root')
-  yy_element_token = element.Element('root')
+  yy_element_space = factory(*args, **kwargs)
+  yy_element_token = factory(*args, **kwargs)
   while True:
     while yytext_len:
       block = yy_buffer_stack[-1].next
@@ -299,8 +299,9 @@ def yylex():
         0,
         yytext_len,
         yy_element_stack.pop(),
-        element.Element,
-        'root'
+        factory,
+        *args,
+        **kwargs
       )
  
       try: