use of dyvilx.tools.parsing.marker.MarkerList in project Dyvil by Dyvil.
the class NamedGenericType method checkCount.
private IType checkCount(MarkerList markers, ITypeParametric generic, String kind, IType type) {
final int genericArity = generic.typeArity();
if (genericArity <= 0) {
markers.add(Markers.semanticError(this.position, "type.generic." + kind + ".not_generic", type));
return type.atPosition(this.position);
}
if (genericArity != this.arguments.size()) {
final Marker marker = Markers.semanticError(this.position, "type.generic." + kind + ".count_mismatch", type);
marker.addInfo(Markers.getSemantic("type.generic.argument_count", this.arguments.size()));
marker.addInfo(Markers.getSemantic("type.generic.parameter_count", genericArity));
markers.add(marker);
}
return type.getConcreteType(typeParameter -> this.arguments.get(typeParameter.getIndex())).atPosition(this.position);
}
use of dyvilx.tools.parsing.marker.MarkerList in project Dyvil by Dyvil.
the class TypeAlias method ensureResolved.
// Phases
private void ensureResolved() {
if (this.resolved) {
return;
}
final MarkerList markers = this.enclosingHeader instanceof ISourceHeader ? ((ISourceHeader) this.enclosingHeader).getMarkers() : null;
this.resolveTypes(markers, this.enclosingHeader.getContext());
}
use of dyvilx.tools.parsing.marker.MarkerList in project Dyvil by Dyvil.
the class Colorizer method colorize.
public static String colorize(String text, REPLContext context) {
final TextSource source = new TextSource(text);
final TokenList tokens = new DyvilLexer(new MarkerList(Markers.INSTANCE), DyvilSymbols.INSTANCE).tokenize(text);
// Split into lines
final int lineCount = source.lineCount();
final StringBuilder[] lines = new StringBuilder[lineCount];
for (int i = 0; i < lineCount; i++) {
lines[i] = new StringBuilder(source.line(i + 1));
}
// iterate, starting from the last token
for (IToken token = tokens.last(); token != null && token.type() != Tokens.EOF; token = token.prev()) {
final String color = tokenColor(token, context);
if (color != null) {
// insert ANSI color codes before and after the token
final StringBuilder line = lines[token.startLine() - 1];
line.insert(token.endColumn(), Console.ANSI_RESET);
line.insert(token.startColumn(), color);
}
}
// Merge back together
final StringBuilder first = lines[0];
for (int i = 1; i < lineCount; i++) {
first.append('\n').append(lines[i]);
}
return first.toString();
}
use of dyvilx.tools.parsing.marker.MarkerList in project Dyvil by Dyvil.
the class TryParserManager method tryParse.
public boolean tryParse(IParserManager pm, Parser parser, IToken token, int flags) {
final TokenIterator tokens = pm.getTokens();
final MarkerList markers = pm.getMarkers();
this.reset(markers, tokens);
// Have to rewind one token because the TryParserManager assumes the TokenIterator is at the beginning
// (i.e. no tokens have been returned by next() yet)
tokens.setNext(token);
if (!this.parse(parser, markers, flags)) {
// Reset to the next token and restore split tokens
this.setNextAndReset(token);
return false;
}
this.reset();
tokens.setNext(tokens.lastReturned());
return true;
}
use of dyvilx.tools.parsing.marker.MarkerList in project Dyvil by Dyvil.
the class TryParserManager method parse.
public boolean parse(Parser parser, MarkerList markers, int flags) {
this.parser = parser;
this.hasSyntaxErrors = false;
this.markers = new MarkerList(markers.getI18n());
this.reportErrors = (flags & REPORT_ERRORS) != 0;
IToken token = null;
while (true) {
if (this.reparse) {
this.reparse = false;
} else {
token = this.tokens.next();
if (token.type() == Tokens.EOF) {
break;
}
}
if (this.skip > 0) {
this.skip--;
continue;
}
if (this.parser == null) {
if ((flags & EXIT_ON_ROOT) != 0) {
return this.success(markers);
}
this.reportUnparsed(token);
continue;
}
if (!this.reportErrors && this.parser.reportErrors()) {
if (this.hasSyntaxErrors) {
return this.success(markers);
}
this.reportErrors = true;
}
try {
this.parser.parse(this, token);
} catch (Exception ex) {
this.reportError(token, ex);
return this.success(markers);
}
if (this.hasSyntaxErrors && !this.reportErrors) {
return this.success(markers);
}
}
this.parseRemaining(token);
this.reparse = false;
return this.success(markers);
}
Aggregations