Search in sources :

Example 1 with ParserManager

use of dyvilx.tools.parsing.ParserManager in project Dyvil by Dyvil.

the class Template method parse.

@Override
public void parse() {
    // class NAME { }
    final CodeClass theClass = new CodeClass(null, this.name, AttributeList.of(Modifiers.PUBLIC));
    final ClassBody classBody = new ClassBody(theClass);
    theClass.setBody(classBody);
    this.addClass(theClass);
    this.templateClass = theClass;
    // func generate(spec, writer) -> void = { ... }
    final CodeMethod genMethod = new CodeMethod(theClass, Name.fromRaw("generate"), Types.VOID, AttributeList.of(Modifiers.PUBLIC | Modifiers.OVERRIDE));
    final StatementList directives = new StatementList();
    genMethod.setValue(directives);
    classBody.addMethod(genMethod);
    this.genMethod = genMethod;
    // func main(args) -> void
    final CodeMethod mainMethod = new CodeMethod(theClass, Name.fromRaw("main"), Types.VOID, AttributeList.of(Modifiers.PUBLIC | Modifiers.STATIC));
    classBody.addMethod(mainMethod);
    this.mainMethod = mainMethod;
    // Parse
    new ParserManager(DyvilSymbols.INSTANCE, this.tokens.iterator(), this.markers).parse(new BlockParser(this, directives));
}
Also used : ParserManager(dyvilx.tools.parsing.ParserManager) BlockParser(dyvilx.tools.gensrc.parser.BlockParser) CodeMethod(dyvilx.tools.compiler.ast.method.CodeMethod) StatementList(dyvilx.tools.compiler.ast.statement.StatementList) CodeClass(dyvilx.tools.compiler.ast.classes.CodeClass) ClassBody(dyvilx.tools.compiler.ast.classes.ClassBody)

Example 2 with ParserManager

use of dyvilx.tools.parsing.ParserManager in project Dyvil by Dyvil.

the class ClassUnit method parse.

@Override
public void parse() {
    new ParserManager(DyvilSymbols.INSTANCE, this.tokens.iterator(), this.markers).parse(new SourceFileParser(this));
    this.tokens = null;
}
Also used : ParserManager(dyvilx.tools.parsing.ParserManager) SourceFileParser(dyvilx.tools.compiler.parser.header.SourceFileParser)

Example 3 with ParserManager

use of dyvilx.tools.parsing.ParserManager 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 4 with ParserManager

use of dyvilx.tools.parsing.ParserManager 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

ParserManager (dyvilx.tools.parsing.ParserManager)4 TokenList (dyvilx.tools.parsing.TokenList)2 DyvilLexer (dyvilx.tools.parsing.lexer.DyvilLexer)2 MarkerList (dyvilx.tools.parsing.marker.MarkerList)2 LineSource (dyvil.source.LineSource)1 ClassBody (dyvilx.tools.compiler.ast.classes.ClassBody)1 CodeClass (dyvilx.tools.compiler.ast.classes.CodeClass)1 IContext (dyvilx.tools.compiler.ast.context.IContext)1 IValue (dyvilx.tools.compiler.ast.expression.IValue)1 CodeMethod (dyvilx.tools.compiler.ast.method.CodeMethod)1 StatementList (dyvilx.tools.compiler.ast.statement.StatementList)1 ExpressionParser (dyvilx.tools.compiler.parser.expression.ExpressionParser)1 SourceFileParser (dyvilx.tools.compiler.parser.header.SourceFileParser)1 BlockParser (dyvilx.tools.gensrc.parser.BlockParser)1