2 files changed, 55 insertions(+), 1 deletion(-)
viff/sfdl/grammar.py           |    5 +++
viff/test/sfdl/test_grammar.py |   51 ++++++++++++++++++++++++++++++++++++++++


# HG changeset patch
# User Martin Geisler <[EMAIL PROTECTED]>
# Date 1227518476 -3600
# Node ID d94925dfcd0f2ff83dc0cbf4efe7e9455fef6fd5
# Parent  f10262f030b9a3c42f031b61f82b8da5dcbc5286
Parsing of full programs, with tests.

diff --git a/viff/sfdl/grammar.py b/viff/sfdl/grammar.py
--- a/viff/sfdl/grammar.py
+++ b/viff/sfdl/grammar.py
@@ -82,6 +82,9 @@
             + LPAREN + Optional(delimitedList(Group(func_arg))) + RPAREN \
             + LCURLY + func_body + RCURLY
 
+        self.program_body = program_body \
+            = ZeroOrMore(Group(type_dec | const_dec)) \
+            + ZeroOrMore(Group(func_dec))
         self.program = program = Keyword("program") + ident \
-            + LCURLY + RCURLY
+            + LCURLY + program_body + RCURLY
         program.ignore(cppStyleComment)
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
@@ -323,5 +323,56 @@
                              }
                            """)
 
+    def test_program(self):
+        src = """
+               program p {
+                 type Byte = Int<8>;
+               }
+              """
+        self.assertParse(self.grammar.program, src,
+                         ['program', 'p',
+                          ['type', 'Byte', 'Int', '<', '8', '>']])
+
+        src = """
+               program p {
+                 const x = 10;
+               }
+              """
+        self.assertParse(self.grammar.program, src,
+                         ['program', 'p', ['const', 'x', '10']])
+
+        src = """
+               program p {
+                 function Boolean f() {
+                   f = true;
+                 }
+               }
+              """
+        self.assertParse(self.grammar.program, src,
+                         ['program', 'p',
+                          ['function', 'Boolean', 'f',
+                           ['f', 'true']]])
+
+        src = """
+               program p {
+                 function Boolean f() {
+                   f = true;
+                 }
+                 const trailing_const = 1;
+               }
+              """
+        self.assertNoParse(self.grammar.program, src)
+
+        src = """
+               program p {
+                 function Boolean f() {
+                   f = true;
+                 }
+                 type trailing_type = Int<32>;
+               }
+              """
+        self.assertNoParse(self.grammar.program, src)
+
+
 if SFDLGrammar is None:
     TestGrammar.skip = "Could not import SFDLGrammar, missing pyparsing?"
_______________________________________________
viff-patches mailing list
[email protected]
http://lists.viff.dk/listinfo.cgi/viff-patches-viff.dk

Reply via email to