Search in sources :

Example 1 with BlockParser

use of dyvilx.tools.gensrc.parser.BlockParser 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)

Aggregations

ClassBody (dyvilx.tools.compiler.ast.classes.ClassBody)1 CodeClass (dyvilx.tools.compiler.ast.classes.CodeClass)1 CodeMethod (dyvilx.tools.compiler.ast.method.CodeMethod)1 StatementList (dyvilx.tools.compiler.ast.statement.StatementList)1 BlockParser (dyvilx.tools.gensrc.parser.BlockParser)1 ParserManager (dyvilx.tools.parsing.ParserManager)1