org.snapscript.parse.SyntaxTreeBuilder Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of snap-all Show documentation
Show all versions of snap-all Show documentation
Dynamic scripting for the JVM
package org.snapscript.parse;
public class SyntaxTreeBuilder {
private final SourceProcessor processor;
private final GrammarIndexer indexer;
public SyntaxTreeBuilder(GrammarIndexer indexer) {
this.processor = new SourceProcessor(100);
this.indexer = indexer;
}
public SyntaxTree create(String resource, String text, String grammar) {
char[] array = text.toCharArray();
if(array.length == 0) {
throw new ParseException("Source text is empty for '" + resource + "'");
}
SourceCode source = processor.process(text);
char[] original = source.getOriginal();
char[] compress = source.getSource();
short[] lines = source.getLines();
short[]types = source.getTypes();
return new SyntaxTree(indexer, resource, grammar, original, compress, lines, types);
}
}