2 files changed, 12 insertions(+), 4 deletions(-)
viff/sfdl/grammar.py           |   10 +++++++++-
viff/test/sfdl/test_grammar.py |    6 +++---


# HG changeset patch
# User Martin Geisler <[EMAIL PROTECTED]>
# Date 1227518476 -3600
# Node ID fa87aafa06f27b55019438b4fda77b7a976be5ca
# Parent  afb975f68296d2d278c1dbe449a4d61fc0e2fa5a
imported patch array-types

diff --git a/viff/sfdl/grammar.py b/viff/sfdl/grammar.py
--- a/viff/sfdl/grammar.py
+++ b/viff/sfdl/grammar.py
@@ -54,6 +54,7 @@
         DOT = Suppress(".")
         LCURLY, RCURLY = Suppress("{"), Suppress("}")
         LPAREN, RPAREN = Suppress("("), Suppress(")")
+        LBRACK, RBRACK = Suppress("["), Suppress("]")
 
         self.ident = ident = Word(alphas + "_", alphanums + "_")
 
@@ -81,12 +82,13 @@
         self.known_type = known_type \
             = int_type | Keyword("Boolean") | struct_type | Keyword("void")
         data_type << (known_type | ident) \
-            + ZeroOrMore(Group('[' + const_expr + ']'))
+            + ZeroOrMore(LBRACK + const_expr + RBRACK)
 
         self.type_dec = type_dec \
             = Keyword("type") + ident + EQUAL + data_type + SCOLON
 
         int_type.setParseAction(self.parse_int_type)
+        data_type.setParseAction(self.parse_data_type)
 
         self.expr = expr = Forward()
         self.qual_ident = qual_ident = ident \
@@ -164,3 +166,9 @@
     
     def parse_int_type(self, s, loc, toks):
         return attrdict(bitsize=toks[2])
+
+    def parse_data_type(self, s, loc, toks):
+        if len(toks) == 2:
+            return attrdict(length=toks[1])
+        else:
+            return toks
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
@@ -147,17 +147,17 @@
 
     def test_data_type(self):
         self.assertParse(self.grammar.data_type, "Boolean[4]",
-                         ['Boolean', ['[', 4, ']']])
+                         [attrdict(length=4)])
         self.grammar.global_scope['MIN'] = 17
         self.grammar.global_scope['MAX'] = 4
         self.assertParse(self.grammar.data_type, "Int<MAX>[MIN]",
-                         [attrdict(bitsize=4), ['[', 17, ']']])
+                         [attrdict(length=17)])
 
     def test_type_dec(self):
         self.assertParse(self.grammar.type_dec, "type x = Boolean;",
                          ['type', 'x', 'Boolean'])
         self.assertParse(self.grammar.type_dec, "type x = AnotherType[4];",
-                         ['type', 'x', 'AnotherType', ['[', 4, ']']])
+                         ['type', 'x', attrdict(length=4)])
 
 
     def test_qual_ident(self):
_______________________________________________
viff-patches mailing list
[email protected]
http://lists.viff.dk/listinfo.cgi/viff-patches-viff.dk

Reply via email to