use of dyvilx.tools.parsing.marker.MarkerList in project Dyvil by Dyvil.
the class IDataMember method checkAssign.
default IValue checkAssign(MarkerList markers, IContext context, SourcePosition position, IValue receiver, IValue newValue) {
if (this.hasModifier(Modifiers.FINAL) && !context.isConstructor()) {
markers.add(Markers.semanticError(position, this.getKind().getName() + ".assign.final", this.getName()));
}
final IType type = this.getType();
final ITypeContext typeContext = receiver == null ? ITypeContext.NULL : receiver.getType();
final TypeChecker.MarkerSupplier markerSupplier = (errorPosition, expected, actual) -> {
final String kindName = this.getKind().getName();
final Marker marker = Markers.semanticError(errorPosition, kindName + ".assign.type", this.getName());
marker.addInfo(Markers.getSemantic(kindName + ".type", expected));
marker.addInfo(Markers.getSemantic("value.type", actual));
return marker;
};
return TypeChecker.convertValue(newValue, type, typeContext, markers, context, markerSupplier);
}
use of dyvilx.tools.parsing.marker.MarkerList in project Dyvil by Dyvil.
the class DyvilREPL method evaluate.
public void evaluate(String code) {
this.context.startEvaluation(code);
final MarkerList markers = this.context.getMarkers();
final TokenList tokens = new DyvilLexer(markers, DyvilSymbols.INSTANCE).tokenize(code);
SemicolonInference.inferSemicolons(tokens.first());
this.parser.reset();
new ParserManager(DyvilSymbols.INSTANCE, tokens.iterator(), markers).parse(this.parser);
this.context.endEvaluation();
}
use of dyvilx.tools.parsing.marker.MarkerList in project Dyvil by Dyvil.
the class CompleteCommand method execute.
@Override
public void execute(DyvilREPL repl, String argument) {
final IContext context = repl.getContext().getContext();
if (argument == null) {
// REPL Variables
this.printREPLMembers(repl, "");
return;
}
final int dotIndex = argument.lastIndexOf('.');
if (dotIndex <= 0) {
// REPL Variable Completions
this.printREPLMembers(repl, Qualifier.qualify(argument));
return;
}
final String expression = argument.substring(0, dotIndex);
final String memberStart = Qualifier.qualify(argument.substring(dotIndex + 1));
final MarkerList markers = new MarkerList(Markers.INSTANCE);
final TokenList tokens = new DyvilLexer(markers, DyvilSymbols.INSTANCE).tokenize(expression);
new ParserManager(DyvilSymbols.INSTANCE, tokens.iterator(), markers).parse(new ExpressionParser((IValue value) -> {
value.resolveTypes(markers, context);
value = value.resolve(markers, context);
value.checkTypes(markers, context);
if (!markers.isEmpty()) {
// Print Errors, if any
final boolean colors = repl.getCompiler().config.useAnsiColors();
final StringBuilder buffer = new StringBuilder();
markers.log(new LineSource(expression), buffer, colors);
repl.getOutput().println(buffer);
}
try {
this.printCompletions(repl, memberStart, value);
} catch (Throwable throwable) {
throwable.printStackTrace(repl.getErrorOutput());
}
}));
}
Aggregations