2 files changed, 11 insertions(+), 7 deletions(-)
viff/sfdl/grammar.py           |    8 ++++++--
viff/test/sfdl/test_grammar.py |   10 +++++-----


# HG changeset patch
# User Martin Geisler <[EMAIL PROTECTED]>
# Date 1227518476 -3600
# Node ID afb975f68296d2d278c1dbe449a4d61fc0e2fa5a
# Parent  26aeb27a29aa51078f6e9487febfb0a0939e5111
Parsing of integer types.

diff --git a/viff/sfdl/grammar.py b/viff/sfdl/grammar.py
--- a/viff/sfdl/grammar.py
+++ b/viff/sfdl/grammar.py
@@ -77,15 +77,16 @@
         self.struct_field = struct_field = Group(data_type + ident)
         self.struct_type = struct_type = Keyword("struct") \
             + "{" + delimitedList(struct_field) + "}"
+        self.int_type = int_type = Keyword("Int") + "<" + const_expr + ">"
         self.known_type = known_type \
-            = (Keyword("Int") + "<" + const_expr + ">") \
-            | Keyword("Boolean") | struct_type | Keyword("void")
+            = int_type | Keyword("Boolean") | struct_type | Keyword("void")
         data_type << (known_type | ident) \
             + ZeroOrMore(Group('[' + const_expr + ']'))
 
         self.type_dec = type_dec \
             = Keyword("type") + ident + EQUAL + data_type + SCOLON
 
+        int_type.setParseAction(self.parse_int_type)
 
         self.expr = expr = Forward()
         self.qual_ident = qual_ident = ident \
@@ -160,3 +161,6 @@
                 else:
                     result = op(result, sym)
             return result
+    
+    def parse_int_type(self, s, loc, toks):
+        return attrdict(bitsize=toks[2])
diff --git a/viff/test/sfdl/test_grammar.py b/viff/test/sfdl/test_grammar.py
--- a/viff/test/sfdl/test_grammar.py
+++ b/viff/test/sfdl/test_grammar.py
@@ -119,13 +119,13 @@
 
     def test_int_type(self):
         self.assertParse(self.grammar.known_type, "Int<8>",
-                         ['Int', '<', 8, '>'])
+                         [attrdict(bitsize=8)])
 
         self.grammar.global_scope['MAX'] = 10
         self.assertParse(self.grammar.known_type, "Int<MAX>",
-                         ['Int', '<', 10, '>'])
+                         [attrdict(bitsize=10)])
         self.assertParse(self.grammar.known_type, "Int<MAX+1>",
-                         ['Int', '<', 11, '>'])
+                         [attrdict(bitsize=11)])
 
     def test_struct_type(self):
         self.assertParse(self.grammar.struct_type, "struct { Boolean x }",
@@ -151,7 +151,7 @@
         self.grammar.global_scope['MIN'] = 17
         self.grammar.global_scope['MAX'] = 4
         self.assertParse(self.grammar.data_type, "Int<MAX>[MIN]",
-                         ['Int', '<', 4, '>', ['[', 17, ']']])
+                         [attrdict(bitsize=4), ['[', 17, ']']])
 
     def test_type_dec(self):
         self.assertParse(self.grammar.type_dec, "type x = Boolean;",
@@ -357,7 +357,7 @@
               """
         self.assertParse(self.grammar.program, src,
                          ['program', 'p',
-                          ['type', 'Byte', 'Int', '<', 8, '>']])
+                          ['type', 'Byte', attrdict(bitsize=8)]])
 
         src = """
                program p {
_______________________________________________
viff-patches mailing list
[email protected]
http://lists.viff.dk/listinfo.cgi/viff-patches-viff.dk

Reply via email to