2 files changed, 49 insertions(+) viff/sfdl/grammar.py | 12 ++++++++++++ viff/test/sfdl/test_grammar.py | 37 +++++++++++++++++++++++++++++++++++++
# HG changeset patch # User Martin Geisler <[EMAIL PROTECTED]> # Date 1227518457 -3600 # Node ID 0763eaf0c1dd39d41795810bfeb29329c674cfff # Parent d7a1eac0ed9675650ef09894e672cffcd554cc49 Parsing of data types. diff --git a/viff/sfdl/grammar.py b/viff/sfdl/grammar.py --- a/viff/sfdl/grammar.py +++ b/viff/sfdl/grammar.py @@ -37,6 +37,18 @@ self.const_dec = const_dec \ = Keyword("const") + ident + EQUAL + const_expr + SCOLON + + self.data_type = data_type = Forward() + self.struct_field = struct_field = Group(data_type + ident) + self.struct_type = struct_type = Keyword("struct") \ + + "{" + delimitedList(struct_field) + "}" + self.known_type = known_type \ + = (Keyword("Int") + "<" + const_expr + ">") \ + | Keyword("Boolean") | struct_type | Keyword("void") + data_type << (known_type | ident) \ + + ZeroOrMore(Group('[' + const_expr + ']')) + + self.expr = expr = Forward() self.qual_ident = qual_ident = ident \ + ZeroOrMore(("[" + expr + "]") | ("." + ident)) 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 @@ -92,6 +92,43 @@ self.assertNoParse(self.grammar.const_dec, "const x;") self.assertNoParse(self.grammar.const_dec, "const x 123;") + def test_known_type(self): + self.assertParse(self.grammar.known_type, "Boolean", ['Boolean']) + self.assertParse(self.grammar.known_type, "void", ['void']) + + def test_int_type(self): + self.assertParse(self.grammar.known_type, "Int<8>", + ['Int', '<', '8', '>']) + self.assertParse(self.grammar.known_type, "Int<MAX>", + ['Int', '<', 'MAX', '>']) + self.assertParse(self.grammar.known_type, "Int<MAX+1>", + ['Int', '<', ['MAX', '+', '1'], '>']) + + def test_struct_type(self): + self.assertParse(self.grammar.struct_type, "struct { Boolean x }", + ['struct', '{', ['Boolean', 'x'], '}']) + self.assertParse(self.grammar.struct_type, + "struct { Boolean x, Boolean y }", + ['struct', '{', + ['Boolean', 'x'], + ['Boolean', 'y'], + '}']) + self.assertParse(self.grammar.struct_type, + "struct { struct { Boolean x } y }", + ['struct', '{', + ['struct', + '{', + ['Boolean', 'x'], + '}', 'y'], + '}']) + + def test_data_type(self): + self.assertParse(self.grammar.data_type, "Boolean[4]", + ['Boolean', ['[', '4', ']']]) + self.assertParse(self.grammar.data_type, "Int<MAX>[MIN]", + ['Int', '<', 'MAX', '>', ['[', 'MIN', ']']]) + + def test_qual_ident(self): self.assertParse(self.grammar.qual_ident, "x.y", ['x', '.', 'y']) self.assertParse(self.grammar.qual_ident, "x[10]", _______________________________________________ viff-patches mailing list viff-patches@viff.dk http://lists.viff.dk/listinfo.cgi/viff-patches-viff.dk