Handle empty lambda term in parser

This commit is contained in:
Arne Keller 2021-01-29 08:12:45 +01:00
parent b403d62d1d
commit 878130ebba
4 changed files with 13 additions and 1 deletions

View File

@ -184,7 +184,7 @@
<executions> <executions>
<execution> <execution>
<id>checkstyle</id> <id>checkstyle</id>
<phase>validate</phase> <phase>test</phase>
<goals> <goals>
<goal>check</goal> <goal>check</goal>
</goals> </goals>

View File

@ -88,6 +88,8 @@ public class LambdaParser {
case LET: case LET:
Result<LetTerm, ParseError> let = parseLet(); Result<LetTerm, ParseError> let = parseLet();
return new Result<>(let.unwrap(), let.getError()); return new Result<>(let.unwrap(), let.getError());
case EOF:
return new Result<>(null, ParseError.TOO_FEW_TOKENS);
default: default:
return parseApplication(); return parseApplication();
} }

View File

@ -12,6 +12,11 @@ public enum ParseError {
*/ */
TOO_MANY_TOKENS, TOO_MANY_TOKENS,
/**
* some tokens were required, but not provided
*/
TOO_FEW_TOKENS,
/** /**
* the string contained a character not allowed in that context * the string contained a character not allowed in that context
*/ */

View File

@ -77,4 +77,9 @@ class LambdaParserTest {
new BooleanTerm(true) new BooleanTerm(true)
)); ));
} }
@Test
void miscellaneousTerms() {
LambdaParser parser = new LambdaParser("");
assertEquals(parser.parse().unwrapError(), ParseError.TOO_FEW_TOKENS);
}
} }