2 files changed, 27 insertions(+), 4 deletions(-)
viff/sfdl/grammar.py           |    8 ++++++--
viff/test/sfdl/test_grammar.py |   23 +++++++++++++++++++++--


# HG changeset patch
# User Martin Geisler <[EMAIL PROTECTED]>
# Date 1227518476 -3600
# Node ID bcc1d60786c59a8270aeb84fead22bec80267640
# Parent  ca37920c34868b17549b5bcf0fa17bbf07f05ebb
imported patch const-type-refactor

diff --git a/viff/sfdl/grammar.py b/viff/sfdl/grammar.py
--- a/viff/sfdl/grammar.py
+++ b/viff/sfdl/grammar.py
@@ -30,10 +30,14 @@
 
         self.ident = ident = Word(alphas + "_", alphanums + "_")
 
+        const_op = oneOf(".bitSize .length")
+
         self.const_atom = const_atom \
-            = Word(nums) | delimitedList(ident, '.')
+            = Word(nums) | ident + ZeroOrMore(~const_op + "." + ident)
         self.const_expr = const_expr \
-            = operatorPrecedence(const_atom, [(oneOf("+ -"), 2, opAssoc.LEFT)])
+            = operatorPrecedence(const_atom,
+                                 [(const_op,     1, opAssoc.LEFT),
+                                  (oneOf("+ -"), 2, opAssoc.LEFT)])
         self.const_dec = const_dec \
             = Keyword("const") + ident + EQUAL + const_expr + SCOLON
 
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
@@ -68,8 +68,6 @@
     def test_const_atom(self):
         self.assertParse(self.grammar.const_atom, "123", ['123'])
         self.assertParse(self.grammar.const_atom, "foo", ['foo'])
-        self.assertParse(self.grammar.const_atom, "x.y", ['x', 'y'])
-        self.assertParse(self.grammar.const_atom, "x.y.z", ['x', 'y', 'z'])
 
         self.assertNoParse(self.grammar.const_atom, "x.10")
         self.assertNoParse(self.grammar.const_atom, "10.x")
@@ -83,6 +81,27 @@
         self.assertNoParse(self.grammar.const_expr, "10 +")
         self.assertNoParse(self.grammar.const_expr, "x y")
 
+    def test_const_expr_bitsize(self):
+        # Bit size of an integer:
+        self.assertParse(self.grammar.const_expr, "32.bitSize",
+                         [['32', '.bitSize']])
+        # Bit size of a declared variable:
+        self.assertParse(self.grammar.const_expr, "x.bitSize",
+                         [['x', '.bitSize']])
+        # Bit size of a compound expression:
+        self.assertParse(self.grammar.const_expr, "(10 + x).bitSize",
+                         [[['10', '+', 'x'], '.bitSize']])
+
+        self.assertNoParse(self.grammar.const_expr, ".bitSize")
+
+    def test_const_expr_length(self):
+        # Length of an array in a struct:
+        self.assertParse(self.grammar.const_expr, "n.length",
+                         [['n', '.length']])
+
+        self.assertParse(self.grammar.const_expr, "x.y.length",
+                         [['x', '.', 'y', '.length']])
+
     def test_const_dec(self):
         self.assertParse(self.grammar.const_dec, "const x = 10;",
                          ['const', 'x', '10'])
_______________________________________________
viff-patches mailing list
viff-patches@viff.dk
http://lists.viff.dk/listinfo.cgi/viff-patches-viff.dk

Reply via email to