Fix --defines command line option and fix escaping of "'\"'", for building flex
authorNick Downing <downing.nick@gmail.com>
Tue, 24 Jul 2018 09:43:25 +0000 (19:43 +1000)
committerNick Downing <downing.nick@gmail.com>
Tue, 24 Jul 2018 09:43:34 +0000 (19:43 +1000)
bison_lr1dfa.py
bootstrap_pyacc.py

index 6da6aca..9395d3b 100644 (file)
@@ -256,6 +256,17 @@ class BisonLR1DFA:
     # n_nonterminals == self.goto_pointer.shape[0]
     self.n_terminals = n_terminals
 
+escapes = {
+  0x07: '\\a',
+  0x08: '\\b',
+  0x09: '\\t',
+  0x0a: '\\n',
+  0x0b: '\\v',
+  0x0c: '\\f',
+  0x0d: '\\r',
+  0x22: '\\"',
+  0x5c: '\\\\'
+}
 def generate(pyacc, skel_file, out_file, defines_file = None):
   lr1dfa = pyacc.to_lr1().to_lalr1()
 
@@ -389,6 +400,8 @@ typedef union YYSTYPE YYSTYPE;
                   '"{0:s}"'.format(i.name)
                 if len(i.name) else
                   '"\'{0:s}\'"'.format(
+                    escapes[i.character_set[0]]
+                  if i.character_set[0] in escapes else
                     chr(i.character_set[0])
                   if i.character_set[0] >= 0x20 else
                     '\\\\x{0:02x}'.format(i.character_set[0])
index 2d08a30..4d4c87f 100755 (executable)
@@ -12,7 +12,7 @@ try:
   opts, args = getopt.getopt(
     sys.argv[1:],
     'do:S:',
-    ['defines', 'defines=', 'outfile=', 'skel=']
+    ['defines=', 'outfile=', 'skel=']
   )
 except getopt.GetoptError as err:
   sys.stderr.write('{0:s}\n'.format(str(err)))