Search in sources :

Example 16 with IContext

use of dyvilx.tools.compiler.ast.context.IContext 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

IContext (dyvilx.tools.compiler.ast.context.IContext)16 IValue (dyvilx.tools.compiler.ast.expression.IValue)5 CombiningContext (dyvilx.tools.compiler.ast.context.CombiningContext)3 SourcePosition (dyvil.source.position.SourcePosition)2 IMember (dyvilx.tools.compiler.ast.member.IMember)2 IMethod (dyvilx.tools.compiler.ast.method.IMethod)2 IType (dyvilx.tools.compiler.ast.type.IType)2 TypeChecker (dyvilx.tools.compiler.transform.TypeChecker)2 MarkerList (dyvilx.tools.parsing.marker.MarkerList)2 NonNull (dyvil.annotation.internal.NonNull)1 TreeSet (dyvil.collection.mutable.TreeSet)1 Modifiers (dyvil.reflect.Modifiers)1 LineSource (dyvil.source.LineSource)1 IClass (dyvilx.tools.compiler.ast.classes.IClass)1 IValueConsumer (dyvilx.tools.compiler.ast.consumer.IValueConsumer)1 ThisExpr (dyvilx.tools.compiler.ast.expression.ThisExpr)1 WriteableExpression (dyvilx.tools.compiler.ast.expression.WriteableExpression)1 FieldAccess (dyvilx.tools.compiler.ast.expression.access.FieldAccess)1 FieldAssignment (dyvilx.tools.compiler.ast.expression.access.FieldAssignment)1 VoidValue (dyvilx.tools.compiler.ast.expression.constant.VoidValue)1