From ff5f36dc214ce28b14acc28fec0bb2111805580d Mon Sep 17 00:00:00 2001 From: Pieter Olivier Date: Tue, 29 Oct 2024 08:01:29 +0100 Subject: [PATCH 1/2] Added '\n' end matcher so end-of-line is also seen as skip terminator --- .../concrete/recovery/RascalRecoveryTests.rsc | 73 ++++++++----------- .../concrete/recovery/RecoveryTestSupport.rsc | 2 +- .../uptr/recovery/ToTokenRecoverer.java | 5 ++ 3 files changed, 37 insertions(+), 43 deletions(-) diff --git a/src/org/rascalmpl/library/lang/rascal/tests/concrete/recovery/RascalRecoveryTests.rsc b/src/org/rascalmpl/library/lang/rascal/tests/concrete/recovery/RascalRecoveryTests.rsc index 1d54ed8ab92..2b51fb9a1f3 100644 --- a/src/org/rascalmpl/library/lang/rascal/tests/concrete/recovery/RascalRecoveryTests.rsc +++ b/src/org/rascalmpl/library/lang/rascal/tests/concrete/recovery/RascalRecoveryTests.rsc @@ -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; @@ -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: "); - return getErrorText(findFirstError(t)) == "a}"; -} - -test bool rascalFunFunMissingCloseParen() { - Tree t = parseRascal("module A void f(){void g({}} void h(){}"); - - println("error text: "); - return getErrorText(findFirstError(t)) == "a}"; -} - -test bool rascalIfMissingOpeningParen() { - Tree t = parseRascal("module A void f(){if 1){}}", visualize=false); - - println("error text: "); - return getErrorText(findFirstError(t)) == ";"; -} - -test bool rascalIfMissingCloseParen() { - Tree t = parseRascal("module A void f(){if(1{}}", visualize=false); - - println("error text: "); - return getErrorText(findFirstError(t)) == ";"; -} - -test bool rascalIfMissingSemi() { - Tree t = parseRascal("module A void f(){if (true) {a}}"); - - println("error text: "); - return getErrorText(findFirstError(t)) == ";"; -} -*/ \ No newline at end of file +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 + } +}", ["{", "} +"]); diff --git a/src/org/rascalmpl/library/lang/rascal/tests/concrete/recovery/RecoveryTestSupport.rsc b/src/org/rascalmpl/library/lang/rascal/tests/concrete/recovery/RecoveryTestSupport.rsc index 49cbc602f5f..5a8b4ededac 100644 --- a/src/org/rascalmpl/library/lang/rascal/tests/concrete/recovery/RecoveryTestSupport.rsc +++ b/src/org/rascalmpl/library/lang/rascal/tests/concrete/recovery/RecoveryTestSupport.rsc @@ -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: "); + println("Unexpected error: \'\'"); println("All errors found:"); printErrors(errors); return false; diff --git a/src/org/rascalmpl/parser/uptr/recovery/ToTokenRecoverer.java b/src/org/rascalmpl/parser/uptr/recovery/ToTokenRecoverer.java index 65b28406824..307c71838f8 100644 --- a/src/org/rascalmpl/parser/uptr/recovery/ToTokenRecoverer.java +++ b/src/org/rascalmpl/parser/uptr/recovery/ToTokenRecoverer.java @@ -184,6 +184,11 @@ private List findEndMatchers(AbstractStackNode stack AbstractStackNode[] 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; } From 377cb8cdd95c3cd28e10bd9ed7629f3b632cf0fc Mon Sep 17 00:00:00 2001 From: Pieter Olivier Date: Tue, 29 Oct 2024 14:42:13 +0100 Subject: [PATCH 2/2] Fixed Pico test --- .../rascal/tests/concrete/recovery/PicoRecoveryTests.rsc | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/org/rascalmpl/library/lang/rascal/tests/concrete/recovery/PicoRecoveryTests.rsc b/src/org/rascalmpl/library/lang/rascal/tests/concrete/recovery/PicoRecoveryTests.rsc index b4317d500ff..231b4513dc7 100644 --- a/src/org/rascalmpl/library/lang/rascal/tests/concrete/recovery/PicoRecoveryTests.rsc +++ b/src/org/rascalmpl/library/lang/rascal/tests/concrete/recovery/PicoRecoveryTests.rsc @@ -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