Skip to content

Commit

Permalink
Update ANTLR reader to consume all input in readAll. Fixes #244
Browse files Browse the repository at this point in the history
  • Loading branch information
mikera committed Dec 15, 2023
1 parent 42dec36 commit 6bcf124
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@ form

singleForm: form EOF;

forms: (form | commented) * ;
forms: (form | commented) *;

allForms: forms EOF;

dataStructure:
list | vector | set | map;
Expand Down
13 changes: 11 additions & 2 deletions convex-core/src/main/java/convex/core/lang/reader/AntlrReader.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
import convex.core.lang.reader.antlr.ConvexListener;
import convex.core.lang.reader.antlr.ConvexParser;
import convex.core.lang.reader.antlr.ConvexParser.AddressContext;
import convex.core.lang.reader.antlr.ConvexParser.AllFormsContext;
import convex.core.lang.reader.antlr.ConvexParser.BlobContext;
import convex.core.lang.reader.antlr.ConvexParser.BoolContext;
import convex.core.lang.reader.antlr.ConvexParser.CharacterContext;
Expand Down Expand Up @@ -440,8 +441,16 @@ public void exitSingleForm(SingleFormContext ctx) {
// Nothing
}

@Override
public void enterAllForms(AllFormsContext ctx) {
// Nothing

}


@Override
public void exitAllForms(AllFormsContext ctx) {
// Nothing
}

}

Expand Down Expand Up @@ -500,7 +509,7 @@ public static ParseTree getParseTree(CharStream cs) {
CommonTokenStream tokens = new CommonTokenStream(lexer);
ConvexParser parser = new ConvexParser(tokens);
parser.removeErrorListeners();
ParseTree tree = parser.forms();
ParseTree tree = parser.allForms();
return tree;
}

Expand Down
5 changes: 5 additions & 0 deletions convex-core/src/test/java/convex/core/lang/ReaderTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,11 @@ public void testColonIssue462() {
assertThrows(ParseException.class,()->Reader.readAll(s462));

}

@Test
public void testExtraInputRegression244() {
assertThrows(ParseException.class,()->Reader.readAll("'(42))))"));
}

@Test
public void testSymbolsRegressionCases() {
Expand Down

0 comments on commit 6bcf124

Please sign in to comment.