Minor fixes to yywrap and how prefixes and outfiles are handled
authorNick Downing <downing.nick@gmail.com>
Sat, 28 Jul 2018 02:27:39 +0000 (12:27 +1000)
committerNick Downing <downing.nick@gmail.com>
Sat, 28 Jul 2018 02:27:39 +0000 (12:27 +1000)
ast.py
flex_dfa.py
regex.py

diff --git a/ast.py b/ast.py
index 263ac4c..7f3b70e 100644 (file)
--- a/ast.py
+++ b/ast.py
@@ -40,7 +40,7 @@ class Item(element.Element):
     parent_start_conditions,
     continued_action
   ):
-    raise NotImplementedException
+    raise NotImplementedError
 
 class PLex(element.Element):
   # internal classes
@@ -375,7 +375,7 @@ class PLex(element.Element):
           return 'ast.PLex.Section1.Options.Option({0:s})'.format(', '.join(params))
         # GENERATE END
         def post_process(self, section):
-          raise NotImplementedException
+          raise NotImplementedError
 
       class BoolOption(Option):
         # GENERATE ELEMENT(bool value) BEGIN
@@ -2747,7 +2747,7 @@ class PLex(element.Element):
       outfile = '',
       perf_report = False,
       posix_compat = False,
-      prefix = '',
+      prefix = 'yy',
       read = False,
       reentrant = False,
       reject = False,
@@ -3734,14 +3734,14 @@ class PLex(element.Element):
         sys.stderr.write('warning: ignoring %option meta-ecs\n')
       if self.never_interactive:
         sys.stderr.write('warning: ignoring %option never-interactive\n')
-      if len(self.outfile):
-        sys.stderr.write('warning: ignoring %option outfile\n')
+      #if len(self.outfile):
+      #  sys.stderr.write('warning: ignoring %option outfile\n')
       if self.perf_report:
         sys.stderr.write('warning: ignoring %option perf-report\n')
       if self.posix_compat:
         sys.stderr.write('warning: ignoring %option posix-compat\n')
-      if len(self.prefix):
-        sys.stderr.write('warning: ignoring %option prefix\n')
+      #if self.prefix != 'yy':
+      #  sys.stderr.write('warning: ignoring %option prefix\n')
       if self.read:
         sys.stderr.write('warning: ignoring %option read\n')
       if self.reentrant:
index c0d2066..1bd97c8 100644 (file)
@@ -287,8 +287,6 @@ def generate(plex, skel_file, out_file):
       plex[0].out_file
     if len(plex[0].outfile) else
       'lex.{0:s}.c'.format(plex[0].prefix)
-    if len(plex[0].prefix) else
-      'lex.yy.c'
     )
   with open(skel_file, 'r') as fin:
     with open(out_file, 'w+') as fout:
@@ -300,7 +298,7 @@ def generate(plex, skel_file, out_file):
 {0:s}/* GENERATE END */
 '''.format(
               ''
-            if len(plex[0].prefix) == 0 else
+            if plex[0].prefix == 'yy' else
               ''.join(
                 [
                   '#define yy{0:s} {1:s}{2:s}\n'.format(
@@ -384,9 +382,11 @@ def generate(plex, skel_file, out_file):
 '''.format(
               ''
             if plex[0].yywrap else
-              '''#define yywrap() (/*CONSTCOND*/1)
+              '''#define {0:s}wrap() (/*CONSTCOND*/1)
 #define YY_SKIP_YYWRAP
-'''
+'''.format(
+                plex[0].prefix
+              )
             )
           )
         elif line == '/* GENERATE TABLES */\n':
@@ -574,5 +574,7 @@ YY_RULE_SETUP
             )
           )
         else:
+          if plex[0].prefix != 'yy':
+            line = line.replace('yywrap', '{0:s}wrap'.format(plex[0].prefix))
           fout.write(line)
         line = fin.readline()
index ca07332..0fc24a5 100644 (file)
--- a/regex.py
+++ b/regex.py
@@ -40,7 +40,7 @@ class Regex(element.Element):
     for i in self:
       i.add_to_groups(groups)
   def to_nfa_state(self, _nfa, next_state):
-    raise NotImplementedException
+    raise NotImplementedError
   def add_to_nfa(self, _nfa):
     _nfa.start_state.append(self.to_nfa_state(_nfa, 0))