org.snapscript.parse.GrammarIndexer Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of snap Show documentation
Show all versions of snap Show documentation
Dynamic scripting for the JVM
package org.snapscript.parse;
import java.util.ArrayList;
import java.util.List;
public class GrammarIndexer {
private final List literals;
private final List values;
public GrammarIndexer() {
this.literals = new ArrayList();
this.values = new ArrayList();
}
public List list(){
return literals;
}
public String literal(String value) {
int index = literals.indexOf(value);
if (index == -1) {
literals.add(value);
return value;
}
return literals.get(index);
}
public String resolve(int index) {
return literals.get(index);
}
public int index(String value) {
int index = values.indexOf(value);
int size = values.size();
if (index == -1) {
values.add(value);
return size;
}
return index;
}
public String value(int index) {
return values.get(index);
}
}