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;
}
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();
}
}
Aggregations