mirror of
https://github.com/sigmasternchen/xtext-core
synced 2025-03-15 08:18:55 +00:00
fixed problem with empty paths in token analysis
empty paths are keep the state of the prefix including the empty flag which causes empty paths in alternatives to be lost. fix: create new token state with prefix (reset empty flag)
This commit is contained in:
parent
aad95fa670
commit
2cd6e454d7
2 changed files with 25 additions and 3 deletions
|
@ -1122,11 +1122,10 @@ public class HoistingProcessorTest extends AbstractXtextTests {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testRepeatableContextWithEmptyPath_bug_expectCorrectResult() throws Exception {
|
public void testRepeatablyQuantifiedContextWithEmptyPath_bug_expectCorrectResult() throws Exception {
|
||||||
// @formatter:off
|
// @formatter:off
|
||||||
String model =
|
String model =
|
||||||
MODEL_PREAMBLE +
|
MODEL_PREAMBLE +
|
||||||
"hoistingDebug\n" +
|
|
||||||
"S: A C+ ;\n" +
|
"S: A C+ ;\n" +
|
||||||
"A: $$ p0 $$?=> 'a' " +
|
"A: $$ p0 $$?=> 'a' " +
|
||||||
" | $$ p1 $$?=> 'a' 'b' ;\n" +
|
" | $$ p1 $$?=> 'a' 'b' ;\n" +
|
||||||
|
@ -1142,4 +1141,26 @@ public class HoistingProcessorTest extends AbstractXtextTests {
|
||||||
assertTrue(guard.hasTerminal());
|
assertTrue(guard.hasTerminal());
|
||||||
assertEquals("(((" + getSyntaxForEofToken(2) + " && " + getSyntaxForKeywordToken("c", 2) + ") || (p0)) && (" + getSyntaxForKeywordToken("b", 2) + " || (p1)))", guard.render());
|
assertEquals("(((" + getSyntaxForEofToken(2) + " && " + getSyntaxForKeywordToken("c", 2) + ") || (p0)) && (" + getSyntaxForKeywordToken("b", 2) + " || (p1)))", guard.render());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testRecursiveContextWithEmptyPath_bug_expectCorrectResult() throws Exception {
|
||||||
|
// @formatter:off
|
||||||
|
String model =
|
||||||
|
MODEL_PREAMBLE +
|
||||||
|
"S: a=A c=C ;\n" +
|
||||||
|
"A: $$ p0 $$?=> 'a' " +
|
||||||
|
" | $$ p1 $$?=> 'a' 'b' ;\n" +
|
||||||
|
"C: {C} \n" +
|
||||||
|
" | 'c' C ;\n";
|
||||||
|
// @formatter:off
|
||||||
|
XtextResource resource = getResourceFromString(model);
|
||||||
|
Grammar grammar = ((Grammar) resource.getContents().get(0));
|
||||||
|
hoistingProcessor.init(grammar);
|
||||||
|
AbstractRule rule = getRule(grammar, "A");
|
||||||
|
|
||||||
|
HoistingGuard guard = hoistingProcessor.findHoistingGuard(rule.getAlternatives());
|
||||||
|
assertFalse(guard.isTrivial());
|
||||||
|
assertTrue(guard.hasTerminal());
|
||||||
|
assertEquals("(((" + getSyntaxForEofToken(2) + " && " + getSyntaxForKeywordToken("c", 2) + ") || (p0)) && (" + getSyntaxForKeywordToken("b", 2) + " || (p1)))", guard.render());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -317,7 +317,8 @@ public class TokenAnalysis {
|
||||||
return result;
|
return result;
|
||||||
} else {
|
} else {
|
||||||
// Actions, Predicates, JavaActions, ...
|
// Actions, Predicates, JavaActions, ...
|
||||||
return prefix;
|
// create new state with out empty flag
|
||||||
|
return new TokenAnalysisPaths(prefix);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}.doSwitch(path);
|
}.doSwitch(path);
|
||||||
|
|
Loading…
Reference in a new issue