Adding VariableCollectorVisitor.

This commit is contained in:
Rob Greene 2018-06-10 10:37:34 -05:00
parent d17aa69d8c
commit edb91e9f96
2 changed files with 29 additions and 0 deletions
api/src/main/java/io/github/applecommander/bastokenizer/api

@ -10,6 +10,7 @@ import io.github.applecommander.bastokenizer.api.visitors.LineNumberTargetCollec
import io.github.applecommander.bastokenizer.api.visitors.PrettyPrintVisitor;
import io.github.applecommander.bastokenizer.api.visitors.PrintVisitor;
import io.github.applecommander.bastokenizer.api.visitors.ReassignmentVisitor;
import io.github.applecommander.bastokenizer.api.visitors.VariableCollectorVisitor;
import io.github.applecommander.bastokenizer.api.visitors.VariableReportVisitor;
/**
@ -67,6 +68,10 @@ public class Visitors {
return new LineNumberTargetCollector();
}
public static VariableCollectorVisitor variableCollectorVisitor() {
return new VariableCollectorVisitor();
}
public static Visitor variableReportVisitor() {
return new VariableReportVisitor();
}

@ -0,0 +1,24 @@
package io.github.applecommander.bastokenizer.api.visitors;
import java.util.HashSet;
import java.util.Set;
import io.github.applecommander.bastokenizer.api.Visitor;
import io.github.applecommander.bastokenizer.api.model.Token;
import io.github.applecommander.bastokenizer.api.model.Token.Type;
public class VariableCollectorVisitor implements Visitor {
private Set<String> variableNames = new HashSet<>();
public Set<String> getVariableNames() {
return this.variableNames;
}
@Override
public Token visit(Token token) {
if (token.type == Type.IDENT) {
variableNames.add(token.text);
}
return Visitor.super.visit(token);
}
}