summaryrefslogtreecommitdiff
path: root/event_rpcgen.py
diff options
context:
space:
mode:
authorNiels Provos <provos@gmail.com>2009-07-03 17:43:26 +0000
committerNiels Provos <provos@gmail.com>2009-07-03 17:43:26 +0000
commit6469598e568a62072c35a3e9322ad09e102b81a7 (patch)
treed977c0c9374337b00e763c2defd4a45840a37349 /event_rpcgen.py
parentfbb181d1aaa0cbc22ac8c1ce91a8f2216be95ed9 (diff)
downloadlibevent-6469598e568a62072c35a3e9322ad09e102b81a7.tar.gz
Allow C identifiers as struct names; allow multiple comments in .rpc files; from Zack Weinberg; plus a tiny tweak
svn:r1336
Diffstat (limited to 'event_rpcgen.py')
-rwxr-xr-xevent_rpcgen.py25
1 files changed, 16 insertions, 9 deletions
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: