Skip to content

Commit

Permalink
Merge pull request #2064 from usethesource/recovery/end-of-line-token
Browse files Browse the repository at this point in the history
Added '\n' end matcher so end-of-line is also seen as skip terminator
  • Loading branch information
PieterOlivier authored Oct 31, 2024
2 parents 93b4205 + 377cb8c commit 79267ce
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 45 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,9 @@ test bool picoMissingSemi() = checkRecovery(#Program, "begin declare input : nat
od
input := input - 1
od
end", ["input := input - 1
od"]);
end", ["od
end", "input := input - 1
"]);

test bool picoTypoSmall() = checkRecovery(#Program, "begin declare;
while input do
Expand Down
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 79267ce

Please sign in to comment.