Search in sources :

Example 11 with StatementList

use of dyvilx.tools.compiler.ast.statement.StatementList in project Dyvil by Dyvil.

the class FuncDirective method convertBlock.

protected static StatementList convertBlock(StatementList block) {
    final StatementList value = new StatementList();
    // new StringWriter()
    final ConstructorCall newStringWriter = new ConstructorCall(null, Template.LazyTypes.StringWriter, ArgumentList.EMPTY);
    // let writer = new StringWriter()
    final Variable writer = new Variable(Name.fromRaw("writer"), Template.LazyTypes.Writer, newStringWriter);
    writer.getAttributes().addFlag(Modifiers.FINAL | Modifiers.GENERATED);
    // { let writer = new StringWriter; { ... }; writer.toString }
    value.add(new VariableStatement(writer));
    value.add(block);
    value.add(new MethodCall(null, new FieldAccess(writer), Names.toString));
    return value;
}
Also used : Variable(dyvilx.tools.compiler.ast.field.Variable) VariableStatement(dyvilx.tools.compiler.ast.statement.VariableStatement) StatementList(dyvilx.tools.compiler.ast.statement.StatementList) ConstructorCall(dyvilx.tools.compiler.ast.expression.access.ConstructorCall) FieldAccess(dyvilx.tools.compiler.ast.expression.access.FieldAccess) MethodCall(dyvilx.tools.compiler.ast.expression.access.MethodCall)

Example 12 with StatementList

use of dyvilx.tools.compiler.ast.statement.StatementList in project Dyvil by Dyvil.

the class ScopeDirectiveParser method parse.

@Override
public void parse(IParserManager pm, IToken token) {
    final int type = token.type();
    switch(this.mode) {
        case OPEN_PAREN:
            if (type == BaseSymbols.OPEN_PARENTHESIS) {
                this.directive = new ScopeDirective();
                pm.pushParser(new ExpressionParser(this.directive::setValue));
                this.mode = CLOSE_PAREN;
                return;
            }
        // Fallthrough
        case BODY:
            if (type == BaseSymbols.OPEN_CURLY_BRACKET) {
                final StatementList body = new StatementList();
                pm.pushParser(new BlockParser(body));
                this.directive.setBlock(body);
                this.mode = BODY_END;
                return;
            }
            this.list.add(this.directive);
            pm.popParser(true);
            return;
        case CLOSE_PAREN:
            if (type == BaseSymbols.CLOSE_PARENTHESIS) {
                this.mode = BODY;
                return;
            }
            pm.report(token, "directive.close_paren");
            return;
        case BODY_END:
            assert type == BaseSymbols.CLOSE_CURLY_BRACKET;
            this.list.add(this.directive);
            pm.popParser();
    }
}
Also used : StatementList(dyvilx.tools.compiler.ast.statement.StatementList) ExpressionParser(dyvilx.tools.compiler.parser.expression.ExpressionParser) ScopeDirective(dyvilx.tools.gensrc.ast.directive.ScopeDirective)

Aggregations

StatementList (dyvilx.tools.compiler.ast.statement.StatementList)12 ExpressionParser (dyvilx.tools.compiler.parser.expression.ExpressionParser)4 FieldAccess (dyvilx.tools.compiler.ast.expression.access.FieldAccess)3 Variable (dyvilx.tools.compiler.ast.field.Variable)3 AttributeList (dyvilx.tools.compiler.ast.attribute.AttributeList)2 IValue (dyvilx.tools.compiler.ast.expression.IValue)2 VariableStatement (dyvilx.tools.compiler.ast.statement.VariableStatement)2 SourcePosition (dyvil.source.position.SourcePosition)1 ClassBody (dyvilx.tools.compiler.ast.classes.ClassBody)1 CodeClass (dyvilx.tools.compiler.ast.classes.CodeClass)1 CodeConstructor (dyvilx.tools.compiler.ast.constructor.CodeConstructor)1 LambdaExpr (dyvilx.tools.compiler.ast.expression.LambdaExpr)1 ThisExpr (dyvilx.tools.compiler.ast.expression.ThisExpr)1 ConstructorCall (dyvilx.tools.compiler.ast.expression.access.ConstructorCall)1 FieldAssignment (dyvilx.tools.compiler.ast.expression.access.FieldAssignment)1 InitializerCall (dyvilx.tools.compiler.ast.expression.access.InitializerCall)1 MethodCall (dyvilx.tools.compiler.ast.expression.access.MethodCall)1 IVariable (dyvilx.tools.compiler.ast.field.IVariable)1 CodeMethod (dyvilx.tools.compiler.ast.method.CodeMethod)1 ArgumentList (dyvilx.tools.compiler.ast.parameter.ArgumentList)1