return 'ast.PLex.Name({0:s})'.format(', '.join(params))
# GENERATE END
- class SectionCodeBlocks(Section):
+ class Section1Or2(Section):
+ class CodeBlock(Item):
+ # GENERATE ELEMENT() BEGIN
+ def __init__(
+ self,
+ tag = 'PLex_Section1Or2_CodeBlock',
+ attrib = {},
+ text = '',
+ children = []
+ ):
+ Item.__init__(
+ self,
+ tag,
+ attrib,
+ text,
+ children
+ )
+ def copy(self, factory = None):
+ result = Item.copy(
+ self,
+ CodeBlock if factory is None else factory
+ )
+ return result
+ def __repr__(self):
+ params = []
+ self.repr_serialize(params)
+ return 'ast.PLex.Section1Or2.CodeBlock({0:s})'.format(', '.join(params))
+ # GENERATE END
+ def post_process(
+ self,
+ plex,
+ section,
+ name_to_start_condition,
+ all_start_conditions,
+ inclusive_start_conditions
+ ):
+ section.code_blocks.append(self)
+
# GENERATE ELEMENT(list(ref) code_blocks) BEGIN
def __init__(
self,
- tag = 'PLex_SectionCodeBlocks',
+ tag = 'PLex_Section1Or2',
attrib = {},
text = '',
children = [],
def copy(self, factory = None):
result = PLex.Section.copy(
self,
- SectionCodeBlocks if factory is None else factory
+ Section1Or2 if factory is None else factory
)
result.code_blocks = self.code_blocks
return result
def __repr__(self):
params = []
self.repr_serialize(params)
- return 'ast.PLex.SectionCodeBlocks({0:s})'.format(', '.join(params))
- # GENERATE END
-
- class CodeBlock(Item):
- # GENERATE ELEMENT() BEGIN
- def __init__(
- self,
- tag = 'PLex_CodeBlock',
- attrib = {},
- text = '',
- children = []
- ):
- Item.__init__(
- self,
- tag,
- attrib,
- text,
- children
- )
- def copy(self, factory = None):
- result = Item.copy(
- self,
- CodeBlock if factory is None else factory
- )
- return result
- def __repr__(self):
- params = []
- self.repr_serialize(params)
- return 'ast.PLex.CodeBlock({0:s})'.format(', '.join(params))
+ return 'ast.PLex.Section1Or2({0:s})'.format(', '.join(params))
# GENERATE END
- def post_process(
- self,
- plex,
- section,
- name_to_start_condition,
- all_start_conditions,
- inclusive_start_conditions
- ):
- section.code_blocks.append(self)
- class Section1(SectionCodeBlocks):
+ class Section1(Section1Or2):
class Options(Item):
class Option(element.Element):
# GENERATE ELEMENT() BEGIN
yymore = False,
yywrap = False
):
- PLex.SectionCodeBlocks.__init__(
+ PLex.Section1Or2.__init__(
self,
tag,
attrib,
yywrap
)
def serialize(self, ref_list, indent = 0):
- PLex.SectionCodeBlocks.serialize(self, ref_list, indent)
+ PLex.Section1Or2.serialize(self, ref_list, indent)
self.set('ecs', element.serialize_bool(self.ecs))
self.set('meta_ecs', element.serialize_bool(self.meta_ecs))
self.set('reject', element.serialize_bool(self.reject))
self.set('yymore', element.serialize_bool(self.yymore))
self.set('yywrap', element.serialize_bool(self.yywrap))
def deserialize(self, ref_list):
- PLex.SectionCodeBlocks.deserialize(self, ref_list)
+ PLex.Section1Or2.deserialize(self, ref_list)
self.ecs = element.deserialize_bool(self.get('ecs', 'false'))
self.meta_ecs = element.deserialize_bool(self.get('meta_ecs', 'false'))
self.reject = element.deserialize_bool(self.get('reject', 'false'))
self.yymore = element.deserialize_bool(self.get('yymore', 'false'))
self.yywrap = element.deserialize_bool(self.get('yywrap', 'false'))
def copy(self, factory = None):
- result = PLex.SectionCodeBlocks.copy(
+ result = PLex.Section1Or2.copy(
self,
Section1 if factory is None else factory
)
result.yywrap = self.yywrap
return result
def repr_serialize(self, params):
- PLex.SectionCodeBlocks.repr_serialize(self, params)
+ PLex.Section1Or2.repr_serialize(self, params)
if self.ecs != False:
params.append(
'ecs = {0:s}'.format(repr(self.ecs))
inclusive_start_conditions
)
- class Section2(SectionCodeBlocks):
+ class Section2(Section1Or2):
class StartConditions(element.Element):
# GENERATE ELEMENT(bool wildcard) BEGIN
def __init__(
children = [],
code_blocks = []
):
- PLex.SectionCodeBlocks.__init__(
+ PLex.Section1Or2.__init__(
self,
tag,
attrib,
code_blocks
)
def copy(self, factory = None):
- result = PLex.SectionCodeBlocks.copy(
+ result = PLex.Section1Or2.copy(
self,
Section2 if factory is None else factory
)
'PLex_StartCondition': PLex.StartCondition,
'PLex_Section': PLex.Section,
'PLex_Name': PLex.Name,
- 'PLex_SectionCodeBlocks': PLex.SectionCodeBlocks,
- 'PLex_CodeBlock': PLex.CodeBlock,
+ 'PLex_Section1Or2': PLex.Section1Or2,
+ 'PLex_Section1Or2_CodeBlock': PLex.Section1Or2.CodeBlock,
'PLex_Section1': PLex.Section1,
'PLex_Section1_Options': PLex.Section1.Options,
'PLex_Section1_Options_Option': PLex.Section1.Options.Option,
with open(out_file, 'w+') as fout:
line = fin.readline()
while len(line):
- if line == '/* GENERATE SECTION1 */\n':
+ if line == '/* GENERATE YYWRAP */\n':
fout.write(
- '''/* GENERATE SECTION1 BEGIN */
-{0:s}/* GENERATE SECTION1 END*/
-'''.format(
- ''.join([element.get_text(i, 0) for i in plex[0].code_blocks])
- )
- )
- elif line == '/* GENERATE STARTCONDDECL */\n':
- fout.write(
- '''/* GENERATE STARTCONDDECL BEGIN */
-{0:s}/* GENERATE STARTCONDDECL END*/
+ '''/* GENERATE YYWRAP BEGIN */
+{0:s}/* GENERATE YYWRAP END */
'''.format(
- ''.join(
- [
- '#define {0:s} {1:d}\n'.format(
- plex.start_conditions[i].name,
- i
- )
- for i in range(len(plex.start_conditions))
- ]
- )
+ ''
+ if plex[0].yywrap else
+ '''#define yywrap() (/*CONSTCOND*/1)
+#define YY_SKIP_YYWRAP
+'''
)
)
elif line == '/* GENERATE TABLES */\n':
)
)
)
+ elif line == '/* GENERATE SECTION1 */\n':
+ fout.write(
+ '''/* GENERATE SECTION1 BEGIN */
+{0:s}/* GENERATE SECTION1 END */
+'''.format(
+ ''.join([element.get_text(i, 0) for i in plex[0].code_blocks])
+ )
+ )
+ elif line == '/* GENERATE STARTCONDDECL */\n':
+ fout.write(
+ '''/* GENERATE STARTCONDDECL BEGIN */
+{0:s}/* GENERATE STARTCONDDECL END*/
+'''.format(
+ ''.join(
+ [
+ '#define {0:s} {1:d}\n'.format(
+ plex.start_conditions[i].name,
+ i
+ )
+ for i in range(len(plex.start_conditions))
+ ]
+ )
+ )
+ )
elif line == '/* GENERATE SECTION2INITIAL */\n':
fout.write(
'''/* GENERATE SECTION2INITIAL BEGIN */
---- lex.yy.c.orig 2018-06-29 12:12:25.644004319 +1000
-+++ lex.yy.c 2018-06-30 09:47:14.740034867 +1000
+--- lex.yy.c.orig 2018-07-02 15:42:45.835849543 +1000
++++ lex.yy.c 2018-07-02 15:43:03.847849811 +1000
@@ -1,6 +1,3 @@
-
-#line 2 "lex.yy.c"
#define YY_INT_ALIGNED short int
/* A lexical scanner generated by flex */
-@@ -351,179 +348,8 @@
+@@ -321,6 +318,7 @@
+ }
+ #define YY_AT_BOL() (YY_CURRENT_BUFFER_LVALUE->yy_at_bol)
+
++/* GENERATE YYWRAP */
+ typedef flex_uint8_t YY_CHAR;
+
+ FILE *yyin = NULL, *yyout = NULL;
+@@ -351,179 +349,8 @@
(yy_hold_char) = *yy_cp; \
*yy_cp = '\0'; \
(yy_c_buf_p) = yy_cp;
extern int yy_flex_debug;
int yy_flex_debug = 0;
-@@ -553,10 +379,10 @@
+@@ -553,10 +380,10 @@
#define YY_MORE_ADJ (yy_more_len)
#define YY_RESTORE_YY_MORE_OFFSET
char *yytext;
#ifndef YY_NO_UNISTD_H
/* Special case for "unistd.h", since it is non-ANSI. We include it way
-@@ -780,9 +606,7 @@
+@@ -780,9 +607,7 @@
}
{
while ( /*CONSTCOND*/1 ) /* loops until end-of-file is reached */
{
-@@ -820,7 +644,7 @@
+@@ -820,7 +645,7 @@
*(yy_state_ptr)++ = yy_current_state;
++yy_cp;
}
yy_find_action:
yy_current_state = *--(yy_state_ptr);
-@@ -828,7 +652,7 @@
+@@ -828,7 +653,7 @@
find_rule: /* we branch to this label when backing up */
for ( ; ; ) /* until we find what rule we matched */
{
{
yy_act = yy_acclist[(yy_lp)];
if ( yy_act & YY_TRAILING_HEAD_MASK ||
-@@ -870,24 +694,7 @@
+@@ -870,24 +695,7 @@
switch ( yy_act )
{ /* beginning of action switch */
case YY_END_OF_BUFFER:
{
-@@ -1862,4 +1669,4 @@
+@@ -1862,4 +1670,4 @@
#define YYTABLES_NAME "yytables"