mirror of
https://gitlab.kit.edu/uskyk/typicalc.git
synced 2024-11-08 18:30:42 +00:00
Fix parser issue
This commit is contained in:
parent
c115baa4d4
commit
1dc5f861c3
@ -19,7 +19,7 @@ import java.util.Set;
|
||||
*
|
||||
* @see LambdaTerm
|
||||
*/
|
||||
public class LambdaParser { // TODO: document syntax above ^ ?
|
||||
public class LambdaParser {
|
||||
/**
|
||||
* lexer to translate a String into tokens
|
||||
*/
|
||||
@ -152,10 +152,13 @@ public class LambdaParser { // TODO: document syntax above ^ ?
|
||||
if (left.isError()) {
|
||||
return left;
|
||||
}
|
||||
while (ATOM_START_TOKENS.contains(token.getType()) || token.getType() == TokenType.LAMBDA) {
|
||||
while (ATOM_START_TOKENS.contains(token.getType())
|
||||
|| token.getType() == TokenType.LAMBDA || token.getType() == TokenType.LET) {
|
||||
Result<LambdaTerm, ParseError> atom;
|
||||
if (token.getType() == TokenType.LAMBDA) {
|
||||
atom = new Result<>(parseAbstraction());
|
||||
} else if (token.getType() == TokenType.LET) {
|
||||
atom = new Result<>(parseLet());
|
||||
} else {
|
||||
atom = parseAtom();
|
||||
}
|
||||
|
@ -10,6 +10,7 @@ import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
|
||||
class LambdaParserTest {
|
||||
private static final VarTerm X = new VarTerm("x");
|
||||
private static final VarTerm Y = new VarTerm("y");
|
||||
|
||||
@Test
|
||||
void varTerm() {
|
||||
@ -155,6 +156,23 @@ class LambdaParserTest {
|
||||
assertEquals(new AppTerm(new AbsTerm(X, X), new AbsTerm(X, X)), term.unwrap());
|
||||
}
|
||||
|
||||
@Test
|
||||
void bugFoundByJohanna() {
|
||||
// original term: (λx.λy.y (x y)) (λz. λa. z g a) let f = λx. let g = λy. y in g x in f 3
|
||||
// reduced:
|
||||
LambdaParser parser = new LambdaParser("(λx.x) let id = λy.y in id");
|
||||
Result<LambdaTerm, ParseError> term = parser.parse();
|
||||
if (term.isError()) {
|
||||
System.err.println(term.unwrapError());
|
||||
System.err.println(term.unwrapError().getCause());
|
||||
}
|
||||
assertEquals(new AppTerm(
|
||||
new AbsTerm(X, X),
|
||||
new LetTerm(new VarTerm("id"), new AbsTerm(Y, Y), new VarTerm("id"))
|
||||
),
|
||||
term.unwrap());
|
||||
}
|
||||
|
||||
@Test
|
||||
void complicatedIdentity() {
|
||||
LambdaParser parser = new LambdaParser("(λx. x) (λx. x) λx. x");
|
||||
|
Loading…
Reference in New Issue
Block a user