Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added '\n' end matcher so end-of-line is also seen as skip terminator #2064

Merged
merged 2 commits into from
Oct 31, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
PieterOlivier marked this conversation as resolved.
Show resolved Hide resolved
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
Loading