Skip to content

Commit

Permalink
Added '\n' end matcher so end-of-line is also seen as skip terminator
Browse files Browse the repository at this point in the history
  • Loading branch information
PieterOlivier committed Oct 29, 2024
1 parent 93b4205 commit ff5f36d
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 43 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,6 @@ module lang::rascal::tests::concrete::recovery::RascalRecoveryTests

import lang::rascal::\syntax::Rascal;

import ParseTree;
import util::ErrorRecovery;
import IO;
import util::Maybe;

import lang::rascal::tests::concrete::recovery::RecoveryTestSupport;

bool debugging = false;
Expand Down Expand Up @@ -56,40 +51,34 @@ test bool rascalIfMissingExpr() = checkRecovery(#FunctionDeclaration, "void f(){

test bool rascalIfBodyEmpty() = checkRecovery(#start[Module], "module A void f(){1;} void g(){if(1){}} void h(){1;}", ["{", "} "]);

// Not working yet:
/*
test bool rascalMissingOpeningParen() {
Tree t = parseRascal("module A void f){} void g() { }");
println("error text: <getErrorText(findFirstError(t))>");
return getErrorText(findFirstError(t)) == "a}";
}
test bool rascalFunFunMissingCloseParen() {
Tree t = parseRascal("module A void f(){void g({}} void h(){}");
println("error text: <getErrorText(findFirstError(t))>");
return getErrorText(findFirstError(t)) == "a}";
}
test bool rascalIfMissingOpeningParen() {
Tree t = parseRascal("module A void f(){if 1){}}", visualize=false);
println("error text: <getErrorText(findFirstError(t))>");
return getErrorText(findFirstError(t)) == ";";
}
test bool rascalIfMissingCloseParen() {
Tree t = parseRascal("module A void f(){if(1{}}", visualize=false);
println("error text: <getErrorText(findFirstError(t))>");
return getErrorText(findFirstError(t)) == ";";
}
test bool rascalIfMissingSemi() {
Tree t = parseRascal("module A void f(){if (true) {a}}");
println("error text: <getErrorText(findFirstError(t))>");
return getErrorText(findFirstError(t)) == ";";
}
*/
test bool rascalMissingOpeningParen() = checkRecovery(#start[Module],
"module A
void f) {
}
void g() {
}", ["}
",") {"]);

test bool rascalFunFunMissingCloseParen() = checkRecovery(#start[Module], "module A void f(){void g({}} void h(){}", ["void g({}", "} "]);

test bool rascalIfMissingOpeningParen() = checkRecovery(#start[Module],
"module A void f() {
if 1) {
1;
}}", ["1) "]);

test bool rascalIfMissingCloseParen() = checkRecovery(#start[Module],
"module A
void f() {
if (1 {
1;
}}", ["1 "]);

test bool rascalIfMissingSemi() = checkRecovery(#start[Module],
"module A
void f() {
if (true) {
a
}
}", ["{", "}
"]);
Original file line number Diff line number Diff line change
Expand Up @@ -495,7 +495,7 @@ bool checkErrors(Tree t, list[str] expectedErrors) {
for (error <- errors) {
str errorText = getErrorText(error);
if (errorText notin expectedErrors) {
println("Unexpected error: <errorText>");
println("Unexpected error: \'<errorText>\'");
println("All errors found:");
printErrors(errors);
return false;
Expand Down
5 changes: 5 additions & 0 deletions src/org/rascalmpl/parser/uptr/recovery/ToTokenRecoverer.java
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,11 @@ private List<InputMatcher> findEndMatchers(AbstractStackNode<IConstructor> stack
AbstractStackNode<IConstructor>[] prod = stackNode.getProduction();
addEndMatchers(prod, prod.length-1, matchers, new HashSet<>());

IConstructor parentProduction = stackNode.getParentProduction();
if (parentProduction != null && ProductionAdapter.isContextFree(parentProduction)) {
matchers.add(new LiteralMatcher("\n"));
}

return matchers;
}

Expand Down

0 comments on commit ff5f36d

Please sign in to comment.