[Xorp-cvs] SF.net SVN: xorp:[11667] trunk/xorp/xrl/scripts/Xif
bms_fbsd at users.sourceforge.net
bms_fbsd at users.sourceforge.net
Thu Dec 3 15:22:37 PST 2009
Revision: 11667
http://xorp.svn.sourceforge.net/xorp/?rev=11667&view=rev
Author: bms_fbsd
Date: 2009-12-03 23:22:37 +0000 (Thu, 03 Dec 2009)
Log Message:
-----------
Add support for optional list<> type specifications to
the syntax of the XIF IDL format.
Obtained from: xorp-thrift branch
Modified Paths:
--------------
trunk/xorp/xrl/scripts/Xif/parse.py
trunk/xorp/xrl/scripts/Xif/util.py
trunk/xorp/xrl/scripts/Xif/xiftypes.py
Modified: trunk/xorp/xrl/scripts/Xif/parse.py
===================================================================
--- trunk/xorp/xrl/scripts/Xif/parse.py 2009-12-03 23:20:53 UTC (rev 11666)
+++ trunk/xorp/xrl/scripts/Xif/parse.py 2009-12-03 23:22:37 UTC (rev 11667)
@@ -1,7 +1,7 @@
# Python imports
import string, re, sys
from xiftypes import *
-from util import quit
+from util import quit, warn
# XIF specific imports
@@ -91,6 +91,7 @@
# arg format is <name>[<type>]
# ^ ^
+ # list types may *optionally* carry a member type hint.
xrl_args = []
for t in toks:
@@ -104,11 +105,27 @@
validate_name(file, lineno, "Atom", name, '_-')
+ lab = string.find(type, "<")
+ member_type = None
+ if lab != -1:
+ rab = string.find(type, ">")
+ if rab == -1:
+ quit(file, lineno, "Invalid type spec \"%s\"" % type)
+ member_type = type[lab + 1:rab]
+ type = type[:lab]
+
if xrl_atom_type.has_key(type) == 0:
quit(file, lineno, "Atom type \"%s\" not amongst those known %s"
% (type, xrl_atom_type.keys()))
- xrl_args.append(XrlArg(name, type))
+ xa = XrlArg(name, type)
+ if type == 'list':
+ # TODO: Force syntax check that member_type is present.
+ if xrl_atom_type.has_key(member_type) == 0:
+ warn(file, lineno, "Member atom type \"%s\" not amongst those known %s" % (member_type, xrl_atom_type.keys()))
+ xa.set_member_type(member_type)
+
+ xrl_args.append(xa)
return xrl_args
""" Fill in any missing separators in Xrl to make parsing trivial"""
Modified: trunk/xorp/xrl/scripts/Xif/util.py
===================================================================
--- trunk/xorp/xrl/scripts/Xif/util.py 2009-12-03 23:20:53 UTC (rev 11666)
+++ trunk/xorp/xrl/scripts/Xif/util.py 2009-12-03 23:22:37 UTC (rev 11667)
@@ -4,9 +4,12 @@
# -----------------------------------------------------------------------------
# Utility methods and structures
-def quit(file, lineno, reason):
+def warn(file, lineno, reason):
print "In Xrl starting at line %d in %s:" % (lineno, file)
print "\t", reason
+
+def quit(file, lineno, reason):
+ warn(file, lineno, reason)
sys.exit(1)
def file_write_string(fname, data):
Modified: trunk/xorp/xrl/scripts/Xif/xiftypes.py
===================================================================
--- trunk/xorp/xrl/scripts/Xif/xiftypes.py 2009-12-03 23:20:53 UTC (rev 11666)
+++ trunk/xorp/xrl/scripts/Xif/xiftypes.py 2009-12-03 23:22:37 UTC (rev 11667)
@@ -20,6 +20,7 @@
self._name = name
self._type = type
self._note = annotation
+ self._member_type = None
def name(self):
return self._name
def type(self):
@@ -27,6 +28,11 @@
def cpp_type(self):
tuple = xrl_atom_type[self._type]
return tuple[0]
+ def set_member_type(self, member_type):
+ self._member_type = member_type
+ def member_type(self):
+ """If type is list, the type of the members embedded within."""
+ return self._member_type
def accessor(self):
tuple = xrl_atom_type[self._type]
return tuple[1]
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
More information about the Xorp-cvs
mailing list