Add support for .tlo TableLook files from SPSS 15 and earlier.
[pspp] / src / output / spv / binary-parser-generator
index a62456c4b3498a22316ce465eac03cc351ff388d..ccae0e474e42c3f773249311e83ee469b672f2cc 100644 (file)
@@ -104,6 +104,13 @@ def get_token():
     elif line.startswith('...'):
         token = (line[:3], )
         line = line[3:]
+    elif line.startswith('"'):
+        n = 1
+        while n < len(line) and (line[n] != '"'):
+            n += 1
+        s = line[1:n].encode()
+        line = line[n+1:]
+        token = ('bytes', struct.pack('<h', len(s)) + s)
     elif line[0].isalnum() or line[0] == '-':
         n = 1
         while n < len(line) and (line[n].isalnum() or line[n] == '-'):
@@ -136,9 +143,11 @@ def usage():
     argv0 = os.path.basename(sys.argv[0])
     print('''\
 %(argv0)s, parser generator for SPV binary members
-usage: %(argv0)s GRAMMAR header
-       %(argv0)s GRAMMAR code HEADER_NAME
-  where GRAMMAR contains grammar definitions\
+usage: %(argv0)s GRAMMAR header PREFIX
+       %(argv0)s GRAMMAR code PREFIX HEADER_NAME
+  where GRAMMAR contains grammar definitions,
+        PREFIX is the identifier prefix to use,
+    and HEADER_NAME is the name of the header to include.
 ''' % {"argv0": argv0})
     sys.exit(0)
 
@@ -326,7 +335,7 @@ def print_members(p, indent):
                         array_suffix = '[%d]' % item.n
                 else:
                     n_stars += 1
-            
+
             print("%s%s %s%s%s;" % (indent, typename, '*' * n_stars,
                                     name_to_id(item.name),
                                     array_suffix))
@@ -391,7 +400,7 @@ class Parser_Context(object):
     indent, '_be' if endian == 'big' else '', limit,
     indent, self.bail))
         return limit
-        
+
 
 def print_parser_items(name, production, indent, accessor, ctx):
     for item_idx in range(len(production)):
@@ -547,7 +556,7 @@ def print_parser_items(name, production, indent, accessor, ctx):
                         indent, accessor, item.name, choice_name[-2:]))
                     print('')
                     choice = choice[1:]
-                
+
                 print_parser_items(name, choice, indent + '    ',
                                    accessor + choice_name + '.', ctx)
                 i += 1
@@ -641,7 +650,7 @@ def print_free_items(name, production, indent, accessor, ctx):
                 print('%s%sif (p->%s%s == %s) {' % (
                     indent, '} else ' if i else '', accessor, item.name,
                     value_name))
-                
+
                 print_free_items(name, choice, indent + '    ',
                                  accessor + choice_name + '.', ctx)
                 i += 1
@@ -764,7 +773,7 @@ def print_print_items(name, production, indent, accessor, ctx):
                 print('%s%sif (p->%s%s == %s) {' % (
                     indent, '} else ' if i else '', accessor, item.name,
                     value_name))
-                
+
                 print_print_items(name, choice, indent + '    ',
                                   accessor + choice_name + '.', ctx)
                 i += 1
@@ -797,7 +806,7 @@ void
 def name_to_id(s):
     return s[0].lower() + ''.join(['_%c' % x.lower() if x.isupper() else x
                                    for x in s[1:]]).replace('-', '_')
-    
+
 
 if __name__ == "__main__":
     argv0 = sys.argv[0]