From 6469598e568a62072c35a3e9322ad09e102b81a7 Mon Sep 17 00:00:00 2001 From: Niels Provos Date: Fri, 3 Jul 2009 17:43:26 +0000 Subject: [PATCH] Allow C identifiers as struct names; allow multiple comments in .rpc files; from Zack Weinberg; plus a tiny tweak svn:r1336 --- ChangeLog | 1 + event_rpcgen.py | 25 ++++++++++++++++--------- test/regress.rpc | 2 +- 3 files changed, 18 insertions(+), 10 deletions(-) diff --git a/ChangeLog b/ChangeLog index 1aa2f003..bfebd19f 100644 --- a/ChangeLog +++ b/ChangeLog @@ -39,6 +39,7 @@ Changes in 2.0.2-alpha: o Raise RpcGenError in event_rpcgen.py; from jmanison and Zack Weinberg o Fix preamble of rpcgen-generated files to rely on event2 includes; based on work by jmansion; patch from Zack Weinberg. o Allow specifying the output filename for rpcgen; based on work by jmansion; patch from Zack Weinberg. + o Allow C identifiers as struct names; allow multiple comments in .rpc files; from Zack Weinberg Changes in 2.0.1-alpha: diff --git a/event_rpcgen.py b/event_rpcgen.py index b47d2a6d..c401fab2 100755 --- a/event_rpcgen.py +++ b/event_rpcgen.py @@ -5,20 +5,29 @@ # # Generates marshaling code based on libevent. +# TODO: +# 1) use optparse to allow the strategy shell to parse options, and +# to allow the instantiated factory (for the specific output language) +# to parse remaining options +# 2) move the globals into a class that manages execution (including the +# progress outputs that space stderr at the moment) +# 3) emit other languages + import sys import re -# _NAME = "event_rpcgen.py" _VERSION = "0.1" -_STRUCT_RE = '[a-z][a-z_0-9]*' # Globals line_count = 0 -white = re.compile(r'^\s+') +white = re.compile(r'\s+') cppcomment = re.compile(r'\/\/.*$') nonident = re.compile(r'[^a-zA-Z0-9_]') +structref = re.compile(r'^struct\[([a-zA-Z_][a-zA-Z0-9_]*)\]$') +structdef = re.compile(r'^struct +[a-zA-Z_][a-zA-Z0-9_]* *{$') + headerdirect = [] cppdirect = [] @@ -1351,8 +1360,7 @@ def ProcessOneEntry(factory, newstruct, entry): elif entry_type == 'string' and not fixed_length: newentry = factory.EntryString(entry_type, name, tag) else: - res = re.match(r'^struct\[(%s)\]$' % _STRUCT_RE, - entry_type, re.IGNORECASE) + res = structref.match(entry_type) if res: # References another struct defined in our file newentry = factory.EntryStruct(entry_type, name, tag, res.group(1)) @@ -1426,8 +1434,8 @@ def GetNextStruct(file): line = line[:-1] if not have_c_comment and re.search(r'/\*', line): - if re.search(r'/\*.*\*/', line): - line = re.sub(r'/\*.*\*/', '', line) + if re.search(r'/\*.*?\*/', line): + line = re.sub(r'/\*.*?\*/', '', line) else: line = re.sub(r'/\*.*$', '', line) have_c_comment = 1 @@ -1456,8 +1464,7 @@ def GetNextStruct(file): headerdirect.append(line) continue - if not re.match(r'^struct %s {$' % _STRUCT_RE, - line, re.IGNORECASE): + if not structdef.match(line): raise RpcGenError('Missing struct on line %d: %s' % (line_count, line)) else: diff --git a/test/regress.rpc b/test/regress.rpc index c0170a78..0ee904e9 100644 --- a/test/regress.rpc +++ b/test/regress.rpc @@ -1,7 +1,7 @@ /* tests data packing and unpacking */ struct msg { - string from_name = 1; + string /* sender */ from_name = 1; /* be verbose */ string to_name = 2; optional struct[kill] attack = 3; array struct[run] run = 4;