mirror of
https://gitlab.kit.edu/uskyk/typicalc.git
synced 2024-11-08 18:30:42 +00:00
Error messages for Type Assumptions now show up correctly
This commit is contained in:
parent
dc69e14c04
commit
700f4bbde5
@ -17,6 +17,7 @@ import java.util.regex.Pattern;
|
|||||||
public class TypeAssumptionParser {
|
public class TypeAssumptionParser {
|
||||||
|
|
||||||
public static final Pattern TYPE_NAME_PATTERN = Pattern.compile("[a-zA-Z][a-zA-Z0-9]*");
|
public static final Pattern TYPE_NAME_PATTERN = Pattern.compile("[a-zA-Z][a-zA-Z0-9]*");
|
||||||
|
public static final Pattern NEGATED_TYPE_NAME_PATTERN = Pattern.compile("(?![a-zA-Z][a-zA-Z0-9]*)");
|
||||||
private static final Pattern TYPE_VARIABLE_PATTERN = Pattern.compile("t(\\d+)");
|
private static final Pattern TYPE_VARIABLE_PATTERN = Pattern.compile("t(\\d+)");
|
||||||
|
|
||||||
private static final Set<TokenType> END_TOKENS
|
private static final Set<TokenType> END_TOKENS
|
||||||
@ -33,7 +34,11 @@ public class TypeAssumptionParser {
|
|||||||
for (Map.Entry<String, String> entry : assumptions.entrySet()) {
|
for (Map.Entry<String, String> entry : assumptions.entrySet()) {
|
||||||
String typeName = entry.getKey();
|
String typeName = entry.getKey();
|
||||||
if (!TYPE_NAME_PATTERN.matcher(typeName).matches()) {
|
if (!TYPE_NAME_PATTERN.matcher(typeName).matches()) {
|
||||||
return new Result<>(null, ParseError.UNEXPECTED_CHARACTER);
|
Matcher matcher = NEGATED_TYPE_NAME_PATTERN.matcher(typeName);
|
||||||
|
if (matcher.find()) {
|
||||||
|
return new Result<>(null, ParseError.UNEXPECTED_CHARACTER.withCharacter(
|
||||||
|
typeName.charAt(matcher.start()), matcher.start(), typeName));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
VarTerm var = new VarTerm(typeName);
|
VarTerm var = new VarTerm(typeName);
|
||||||
Result<TypeAbstraction, ParseError> typeAbs = parseTypeDefinition(entry.getValue());
|
Result<TypeAbstraction, ParseError> typeAbs = parseTypeDefinition(entry.getValue());
|
||||||
@ -133,7 +138,7 @@ public class TypeAssumptionParser {
|
|||||||
case ARROW:
|
case ARROW:
|
||||||
if (type == null) {
|
if (type == null) {
|
||||||
// there was no type in front of the arrow
|
// there was no type in front of the arrow
|
||||||
return new Result<>(null, ParseError.UNEXPECTED_TOKEN.withToken(t, ""));
|
return new Result<>(null, ParseError.UNEXPECTED_TOKEN.withToken(t, lexer.getTerm()));
|
||||||
}
|
}
|
||||||
// recursive call, keep open parentheses count
|
// recursive call, keep open parentheses count
|
||||||
Result<Pair<Type, Integer>, ParseError> nextType = parseType(lexer, parenCount);
|
Result<Pair<Type, Integer>, ParseError> nextType = parseType(lexer, parenCount);
|
||||||
@ -144,7 +149,7 @@ public class TypeAssumptionParser {
|
|||||||
case EOF:
|
case EOF:
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
return new Result<>(null, ParseError.UNEXPECTED_TOKEN.withToken(t, ""));
|
return new Result<>(null, ParseError.UNEXPECTED_TOKEN.withToken(t, lexer.getTerm()));
|
||||||
}
|
}
|
||||||
// update type based on Result
|
// update type based on Result
|
||||||
if (typeResult != null && typeResult.isError()) {
|
if (typeResult != null && typeResult.isError()) {
|
||||||
@ -158,7 +163,7 @@ public class TypeAssumptionParser {
|
|||||||
}
|
}
|
||||||
if (parenCount - removedParens < 0) {
|
if (parenCount - removedParens < 0) {
|
||||||
// too many closing parenthesis
|
// too many closing parenthesis
|
||||||
return new Result<>(null, ParseError.UNEXPECTED_TOKEN.withToken(t, ""));
|
return new Result<>(null, ParseError.UNEXPECTED_TOKEN.withToken(t, lexer.getTerm()));
|
||||||
} else if (END_TOKENS.contains(t.getType())) {
|
} else if (END_TOKENS.contains(t.getType())) {
|
||||||
// potential end of type
|
// potential end of type
|
||||||
if (parenCount - removedParens == 0) {
|
if (parenCount - removedParens == 0) {
|
||||||
|
Loading…
Reference in New Issue
Block a user