1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283 |
- package frontend.Ivannosys;
- import API.Imports;
- import common.Instruction;
- import common.Log;
- import compiler.IvannosysCompiler;
- import grammar.IvannosysGrammarBaseVisitor;
- import grammar.IvannosysGrammarParser;
- import grammar.IvannosysGrammarVisitor;
- import java.util.LinkedList;
- import org.antlr.v4.runtime.tree.ParseTree;
- /**
- *
- * @author Eugenio ThiS claSS provideS an empty implementation of
- * {@link IvannosysGrammarVisitor}, which can be extended to create a viSitor
- * which only needS to handle a SubS of the available methodS.
- *
- * operationS with no return type.
- */
- public class IvannosysVisitor extends IvannosysGrammarBaseVisitor<String> {
- protected IvannosysCompiler compiler;
- protected LinkedList<String> importSequence = new LinkedList<>();
- protected String extensionLibrary = "go";
- protected Log errors;
- public IvannosysVisitor(ParseTree tree, String[] tokens, IvannosysCompiler comp) throws Exception {
- super();
- errors = new Log();
- compiler = comp;
- System.out.println("IvannosysVisitor");
- this.visit(tree);
- }
- @Override
- public String visitImport_part(IvannosysGrammarParser.Import_partContext ctx) {
- String alias = "";
- if (ctx.ID() != null) {
- alias = ctx.ID().getText();
- }
- try {
- String path = ctx.T_STRING().getText().replace("\"", "");
- // Verificar importacao ciclica
- if (importSequence.contains(path)) {
- return "";
- }
- importSequence.add(path);
- Imports.Add(path, alias);
- // System.out.println("Visitor import " + alias + " >> " + path);
- // compiler.LoadPackage(alias, path.replace("\"", ""));
- // throw new Exception(String.format("O pacote '%Set' não foi encontrado no path.", path));
- } catch (Exception ex) {
- errors.AddError(
- (Instruction) new Instruction()
- .Set("class", "Import")
- .Set("msg", ex.getMessage())
- .Set("line", ctx.getStart().getLine())
- .Set("col", ctx.getStart().getCharPositionInLine()));
- } finally {
- return super.visitImport_part(ctx); //To change body of generated methods, choose Tools | Templates.
- }
- }
- public Log Error() {
- return errors;
- }
- }
- // for (String token : tokens) {
- // if (!token.startsWith("'")) {
- // continue;
- // }
- // ts.addPalavraReservada(token);
- // }
|