Skip to content
Snippets Groups Projects
Commit 5207e3b7 authored by René Schöne's avatar René Schöne
Browse files

Allow generic types for tokens and underscores in type names.

parent 2301950e
No related branches found
No related tags found
No related merge requests found
......@@ -122,7 +122,8 @@ public class AstDeclParser implements AutoCloseable, Closeable {
if (in.peek() == ':') {
accept(':');
skipWhitespace();
String extendsName = parseName();
// allow generic type for tokens
String extendsName = parseName(true);
component.add("e", extendsName);
skipWhitespace();
} else {
......@@ -168,21 +169,38 @@ public class AstDeclParser implements AutoCloseable, Closeable {
}
private boolean isNameChar(int chr) {
return chr != EOF && (chr == '.' || Character.isLetterOrDigit(chr));
return chr != EOF && (chr == '.' || Character.isLetterOrDigit(chr) || chr == '_');
}
private String chrToStr(int chr) {
return chr != EOF ? String.format("%c", chr) : "EOF";
}
String parseName() throws IOException, JsonParser.SyntaxError {
private String parseName() throws IOException, JsonParser.SyntaxError {
return parseName(false);
}
private String parseName(boolean allowGeneric) throws IOException, JsonParser.SyntaxError {
int next = in.peek();
if (!isNameChar(next)) {
throw new JsonParser.SyntaxError(
String.format("Error: expected name or typename, found %s", chrToStr(next)));
}
StringBuilder name = new StringBuilder();
while (isNameChar(in.peek())) {
while (true) {
int peek = in.peek();
if (allowGeneric && peek == '<') {
// add everything until closing '>' is found, and then break
while (in.peek() != '>') {
name.append((char) in.pop());
}
// also add final '>'
name.append((char) in.pop());
break;
}
if (!isNameChar(peek)) {
break;
}
name.append((char) in.pop());
}
return name.toString();
......
......@@ -402,7 +402,7 @@ public class JsonBuilder {
JsonObject comp = c.object();
if (!comp.get("e").stringValue("").isEmpty()) {
comp.set("e",
typeRef(type.lookupType(comp.get("e").stringValue("")).singletonValue()));
typeRef(type.lookupType(stripGenericPart(comp.get("e").stringValue(""))).singletonValue()));
}
}
} catch (IOException e) {
......@@ -433,6 +433,11 @@ public class JsonBuilder {
return obj;
}
private String stripGenericPart(String s) {
int ltIndex = s.indexOf('<');
return ltIndex == -1 ? s : s.substring(0, ltIndex);
}
/**
* Registers subtype as being a subtype of type.
*/
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment