Search in sources :

Example 6 with MarkerList

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);
}
Also used : IValue(dyvilx.tools.compiler.ast.expression.IValue) ITypeContext(dyvilx.tools.compiler.ast.generic.ITypeContext) IValueConsumer(dyvilx.tools.compiler.ast.consumer.IValueConsumer) IContext(dyvilx.tools.compiler.ast.context.IContext) TypeChecker(dyvilx.tools.compiler.transform.TypeChecker) IType(dyvilx.tools.compiler.ast.type.IType) MemberKind(dyvilx.tools.compiler.ast.member.MemberKind) WriteableExpression(dyvilx.tools.compiler.ast.expression.WriteableExpression) IMember(dyvilx.tools.compiler.ast.member.IMember) Types(dyvilx.tools.compiler.ast.type.builtin.Types) Formatting(dyvilx.tools.compiler.config.Formatting) Marker(dyvilx.tools.parsing.marker.Marker) SourcePosition(dyvil.source.position.SourcePosition) Markers(dyvilx.tools.compiler.util.Markers) BytecodeException(dyvilx.tools.compiler.backend.exception.BytecodeException) MarkerList(dyvilx.tools.parsing.marker.MarkerList) NonNull(dyvil.annotation.internal.NonNull) Modifiers(dyvil.reflect.Modifiers) MethodWriter(dyvilx.tools.compiler.backend.MethodWriter) IClass(dyvilx.tools.compiler.ast.classes.IClass) TypeChecker(dyvilx.tools.compiler.transform.TypeChecker) Marker(dyvilx.tools.parsing.marker.Marker) ITypeContext(dyvilx.tools.compiler.ast.generic.ITypeContext) IType(dyvilx.tools.compiler.ast.type.IType)

Example 7 with MarkerList

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();
}
Also used : ParserManager(dyvilx.tools.parsing.ParserManager) MarkerList(dyvilx.tools.parsing.marker.MarkerList) DyvilLexer(dyvilx.tools.parsing.lexer.DyvilLexer) TokenList(dyvilx.tools.parsing.TokenList)

Example 8 with MarkerList

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());
        }
    }));
}
Also used : ParserManager(dyvilx.tools.parsing.ParserManager) MarkerList(dyvilx.tools.parsing.marker.MarkerList) IContext(dyvilx.tools.compiler.ast.context.IContext) IValue(dyvilx.tools.compiler.ast.expression.IValue) LineSource(dyvil.source.LineSource) DyvilLexer(dyvilx.tools.parsing.lexer.DyvilLexer) TokenList(dyvilx.tools.parsing.TokenList) ExpressionParser(dyvilx.tools.compiler.parser.expression.ExpressionParser)

Aggregations

MarkerList (dyvilx.tools.parsing.marker.MarkerList)8 IContext (dyvilx.tools.compiler.ast.context.IContext)3 TokenList (dyvilx.tools.parsing.TokenList)3 DyvilLexer (dyvilx.tools.parsing.lexer.DyvilLexer)3 SourcePosition (dyvil.source.position.SourcePosition)2 IClass (dyvilx.tools.compiler.ast.classes.IClass)2 IValue (dyvilx.tools.compiler.ast.expression.IValue)2 IType (dyvilx.tools.compiler.ast.type.IType)2 Types (dyvilx.tools.compiler.ast.type.builtin.Types)2 Markers (dyvilx.tools.compiler.util.Markers)2 ParserManager (dyvilx.tools.parsing.ParserManager)2 Marker (dyvilx.tools.parsing.marker.Marker)2 IToken (dyvilx.tools.parsing.token.IToken)2 NonNull (dyvil.annotation.internal.NonNull)1 Name (dyvil.lang.Name)1 Modifiers (dyvil.reflect.Modifiers)1 LineSource (dyvil.source.LineSource)1 TextSource (dyvil.source.TextSource)1 IValueConsumer (dyvilx.tools.compiler.ast.consumer.IValueConsumer)1 WriteableExpression (dyvilx.tools.compiler.ast.expression.WriteableExpression)1