mirror of
https://gitlab.kit.edu/uskyk/typicalc.git
synced 2024-11-08 18:30:42 +00:00
Only accept ASCII characters in type assumption name
This commit is contained in:
parent
c7c313650c
commit
a176d299ce
@ -17,6 +17,7 @@ import java.util.regex.Pattern;
|
||||
*/
|
||||
public class TypeAssumptionParser {
|
||||
|
||||
private static final Pattern TYPE_NAME_PATTERN = Pattern.compile("[a-zA-Z][a-zA-Z0-9]*");
|
||||
private static final Pattern TYPE_VARIABLE_PATTERN = Pattern.compile("t(\\d+)");
|
||||
|
||||
/**
|
||||
@ -28,7 +29,11 @@ public class TypeAssumptionParser {
|
||||
public Result<Map<VarTerm, TypeAbstraction>, ParseError> parse(Map<String, String> assumptions) {
|
||||
Map<VarTerm, TypeAbstraction> typeAssumptions = new LinkedHashMap<>();
|
||||
for (Map.Entry<String, String> entry : assumptions.entrySet()) {
|
||||
VarTerm var = new VarTerm(entry.getKey());
|
||||
String typeName = entry.getKey();
|
||||
if (!TYPE_NAME_PATTERN.matcher(typeName).matches()) {
|
||||
return new Result<>(null, ParseError.UNEXPECTED_CHARACTER);
|
||||
}
|
||||
VarTerm var = new VarTerm(typeName);
|
||||
Result<TypeAbstraction, ParseError> typeAbs = parseType(entry.getValue());
|
||||
if (typeAbs.isError()) {
|
||||
return new Result<>(typeAbs);
|
||||
|
@ -1,9 +1,4 @@
|
||||
/**
|
||||
* The util package contains classes used in all components of the application.
|
||||
*/
|
||||
@NonNullFields
|
||||
@NonNullApi
|
||||
package edu.kit.typicalc.util;
|
||||
|
||||
import org.springframework.lang.NonNullApi;
|
||||
import org.springframework.lang.NonNullFields;
|
||||
package edu.kit.typicalc.util;
|
@ -209,6 +209,14 @@ class TypeAssumptionParserTest {
|
||||
assertTrue(type.isError());
|
||||
assertEquals(entry.getValue(), type.unwrapError());
|
||||
}
|
||||
TypeAssumptionParser parser = new TypeAssumptionParser();
|
||||
Result<Map<VarTerm, TypeAbstraction>, ParseError> type = parser.parse(Map.of("föhn", "int"));
|
||||
assertTrue(type.isError());
|
||||
assertEquals(ParseError.UNEXPECTED_CHARACTER, type.unwrapError());
|
||||
parser = new TypeAssumptionParser();
|
||||
type = parser.parse(Map.of("1typ", "int"));
|
||||
assertTrue(type.isError());
|
||||
assertEquals(ParseError.UNEXPECTED_CHARACTER, type.unwrapError());
|
||||
}
|
||||
|
||||
@Test
|
||||
|
Loading…
Reference in New Issue
Block a user