Browse Source

syntax relaxation: allow semicolon

Vladislav Folts 10 years ago
parent
commit
904fd29ee2

+ 6 - 1
src/eberon/eberon_grammar.js

@@ -67,10 +67,14 @@ function makeMethodHeading(identdef, formalParameters){
 function makeFieldList(identdef, identList, type, formalParameters){
 function makeFieldList(identdef, identList, type, formalParameters){
     return context(
     return context(
         or(makeMethodHeading(identdef, formalParameters),
         or(makeMethodHeading(identdef, formalParameters),
-           and(identList, ":", type)),
+               and(identList, ":", type)),
         Context.FieldListDeclaration);
         Context.FieldListDeclaration);
 }
 }
 
 
+function makeFieldListSequence(base){
+    return and(base, optional(";"));
+}
+
 function makeForInit(ident, expression, assignment){
 function makeForInit(ident, expression, assignment){
     return or(makeInPlaceInit(ident, expression, EbContext.InPlaceVariableInitFor), 
     return or(makeInPlaceInit(ident, expression, EbContext.InPlaceVariableInitFor), 
               and(ident, assignment));
               and(ident, assignment));
@@ -93,6 +97,7 @@ exports.language = {
         makeProcedureHeading,
         makeProcedureHeading,
         makeProcedureDeclaration,
         makeProcedureDeclaration,
         makeFieldList, 
         makeFieldList, 
+        makeFieldListSequence,
         makeForInit,
         makeForInit,
         makeArrayDimensions,
         makeArrayDimensions,
         makeFormalArray,
         makeFormalArray,

+ 2 - 1
src/grammar.js

@@ -27,6 +27,7 @@ function make(makeIdentdef,
               makeProcedureHeading, 
               makeProcedureHeading, 
               makeProcedureDeclaration,
               makeProcedureDeclaration,
               makeFieldList,
               makeFieldList,
+              makeFieldListSequence,
               makeForInit,
               makeForInit,
               makeArrayDimensions,
               makeArrayDimensions,
               makeFormalArray,
               makeFormalArray,
@@ -157,7 +158,7 @@ var fieldList = makeFieldList(
         type,
         type,
         function(stream, context){return formalParameters(stream, context);}
         function(stream, context){return formalParameters(stream, context);}
         );
         );
-var fieldListSequence = and(fieldList, repeat(and(";", fieldList)));
+var fieldListSequence = makeFieldListSequence(and(fieldList, repeat(and(";", fieldList))));
 
 
 var arrayType = and("ARRAY", 
 var arrayType = and("ARRAY", 
                     context(and(makeArrayDimensions(constExpression), "OF", type), 
                     context(and(makeArrayDimensions(constExpression), "OF", type), 

+ 5 - 0
src/oberon/oberon_grammar.js

@@ -53,6 +53,10 @@ function makeFieldList(identdef, identList, type){
     return context(and(identList, ":", type), Context.FieldListDeclaration);
     return context(and(identList, ":", type), Context.FieldListDeclaration);
 }
 }
 
 
+function makeFieldListSequence(base){
+    return base;
+}
+
 function makeForInit(ident, expression, assignment){
 function makeForInit(ident, expression, assignment){
     return and(ident, assignment);
     return and(ident, assignment);
 }
 }
@@ -73,6 +77,7 @@ exports.language = {
         makeProcedureHeading,
         makeProcedureHeading,
         makeProcedureDeclaration,
         makeProcedureDeclaration,
         makeFieldList,
         makeFieldList,
+        makeFieldListSequence,
         makeForInit,
         makeForInit,
         makeArrayDimensions,
         makeArrayDimensions,
         makeFormalArray,
         makeFormalArray,

+ 2 - 1
test/test_unit_eberon.js

@@ -1033,6 +1033,7 @@ exports.suite = {
     },
     },
 "syntax relaxation": testWithGrammar(
 "syntax relaxation": testWithGrammar(
     grammar.declarationSequence, 
     grammar.declarationSequence, 
-    pass("PROCEDURE p; END;")
+    pass("PROCEDURE p; END;",
+         "TYPE T = RECORD field: INTEGER; END;")
     )
     )
 };
 };

+ 5 - 0
test/test_unit_oberon.js

@@ -105,5 +105,10 @@ exports.suite = {
     grammar.procedureDeclaration,
     grammar.procedureDeclaration,
     pass(),
     pass(),
     fail(["PROCEDURE p; END", "not parsed"])
     fail(["PROCEDURE p; END", "not parsed"])
+    ),
+"syntax strictness": testWithGrammar(
+    grammar.procedureDeclaration,
+    pass(),
+    fail(["TYPE T = RECORD field: INTEGER; END;", "not parsed"])
     )
     )
 };
 };