Allow C identifiers as struct names; allow multiple comments in .rpc files; from Zack Weinberg; plus a tiny tweak

svn:r1336
This commit is contained in:
Niels Provos 2009-07-03 17:43:26 +00:00
parent fbb181d1aa
commit 6469598e56
3 changed files with 18 additions and 10 deletions

View File

@ -39,6 +39,7 @@ Changes in 2.0.2-alpha:
o Raise RpcGenError in event_rpcgen.py; from jmanison and Zack Weinberg 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 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 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: Changes in 2.0.1-alpha:

View File

@ -5,20 +5,29 @@
# #
# Generates marshaling code based on libevent. # 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 sys
import re import re
#
_NAME = "event_rpcgen.py" _NAME = "event_rpcgen.py"
_VERSION = "0.1" _VERSION = "0.1"
_STRUCT_RE = '[a-z][a-z_0-9]*'
# Globals # Globals
line_count = 0 line_count = 0
white = re.compile(r'^\s+') white = re.compile(r'\s+')
cppcomment = re.compile(r'\/\/.*$') cppcomment = re.compile(r'\/\/.*$')
nonident = re.compile(r'[^a-zA-Z0-9_]') 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 = [] headerdirect = []
cppdirect = [] cppdirect = []
@ -1351,8 +1360,7 @@ def ProcessOneEntry(factory, newstruct, entry):
elif entry_type == 'string' and not fixed_length: elif entry_type == 'string' and not fixed_length:
newentry = factory.EntryString(entry_type, name, tag) newentry = factory.EntryString(entry_type, name, tag)
else: else:
res = re.match(r'^struct\[(%s)\]$' % _STRUCT_RE, res = structref.match(entry_type)
entry_type, re.IGNORECASE)
if res: if res:
# References another struct defined in our file # References another struct defined in our file
newentry = factory.EntryStruct(entry_type, name, tag, res.group(1)) newentry = factory.EntryStruct(entry_type, name, tag, res.group(1))
@ -1426,8 +1434,8 @@ def GetNextStruct(file):
line = line[:-1] line = line[:-1]
if not have_c_comment and re.search(r'/\*', line): if not have_c_comment and re.search(r'/\*', line):
if re.search(r'/\*.*\*/', line): if re.search(r'/\*.*?\*/', line):
line = re.sub(r'/\*.*\*/', '', line) line = re.sub(r'/\*.*?\*/', '', line)
else: else:
line = re.sub(r'/\*.*$', '', line) line = re.sub(r'/\*.*$', '', line)
have_c_comment = 1 have_c_comment = 1
@ -1456,8 +1464,7 @@ def GetNextStruct(file):
headerdirect.append(line) headerdirect.append(line)
continue continue
if not re.match(r'^struct %s {$' % _STRUCT_RE, if not structdef.match(line):
line, re.IGNORECASE):
raise RpcGenError('Missing struct on line %d: %s' raise RpcGenError('Missing struct on line %d: %s'
% (line_count, line)) % (line_count, line))
else: else:

View File

@ -1,7 +1,7 @@
/* tests data packing and unpacking */ /* tests data packing and unpacking */
struct msg { struct msg {
string from_name = 1; string /* sender */ from_name = 1; /* be verbose */
string to_name = 2; string to_name = 2;
optional struct[kill] attack = 3; optional struct[kill] attack = 3;
array struct[run] run = 4; array struct[run] run = 4;