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