Java 类org.antlr.v4.runtime.VocabularyImpl 实例源码

项目:codebuff    文件:Grammar.java   
/**
 * Gets a {@link Vocabulary} instance describing the vocabulary used by the
 * grammar.
 */

public Vocabulary getVocabulary() {
    return new VocabularyImpl(getTokenLiteralNames(), getTokenSymbolicNames());
}
项目:goworks    文件:AbstractGrammarDebuggerEditorKit.java   
@Override
public void read(Reader in, Document doc, int pos) throws IOException, BadLocationException {
    FileObject fileObject = NbEditorUtilities.getFileObject(doc);
    if (fileObject.hasExt("linterp") || fileObject.hasExt("pinterp")) {
        super.read(in, doc, pos);
        return;
    }

    String data = readAllText(in, 0);
    byte[] binary = DatatypeConverter.parseBase64Binary(data);
    int inputSize = readInteger(binary, 0);
    InputStream inputStream = new ByteArrayInputStream(binary, 4, inputSize);
    super.read(new InputStreamReader(inputStream, UTF_8), doc, pos);

    // read the token names
    int literalNamesOffset = 4 + inputSize;
    int literalNamesSize = readInteger(binary, literalNamesOffset);
    String[] literalNames = readStrings(binary, literalNamesOffset + 4, literalNamesSize);

    int symbolicNamesOffset = literalNamesOffset + 4 + literalNamesSize;
    int symbolicNamesSize = readInteger(binary, symbolicNamesOffset);
    String[] symbolicNames = readStrings(binary, symbolicNamesOffset + 4, symbolicNamesSize);

    doc.putProperty(PROP_VOCABULARY, new VocabularyImpl(literalNames, symbolicNames));

    // read the rule names
    int ruleNamesOffset = symbolicNamesOffset + 4 + symbolicNamesSize;
    int ruleNamesSize = readInteger(binary, ruleNamesOffset);
    String[] ruleNames = readStrings(binary, ruleNamesOffset + 4, ruleNamesSize);
    doc.putProperty(PROP_RULE_NAMES, ruleNames);

    // read the mode names
    int modeNamesOffset = ruleNamesOffset + 4 + ruleNamesSize;
    int modeNamesSize = readInteger(binary, modeNamesOffset);
    String[] modeNames = readStrings(binary, modeNamesOffset + 4, modeNamesSize);
    doc.putProperty(PROP_MODE_NAMES, modeNames);

    // read the trace
    int traceOffset = modeNamesOffset + 4 + modeNamesSize;
    int traceSize = readInteger(binary, traceOffset);
    byte[] traceData = Arrays.copyOfRange(binary, traceOffset + 4, traceOffset + 4 + traceSize);
    doc.putProperty(PROP_TRACE, traceData);
}
项目:antlrworks2    文件:AbstractGrammarDebuggerEditorKit.java   
@Override
public void read(Reader in, Document doc, int pos) throws IOException, BadLocationException {
    FileObject fileObject = NbEditorUtilities.getFileObject(doc);
    if (fileObject.hasExt("linterp") || fileObject.hasExt("pinterp")) {
        super.read(in, doc, pos);
        return;
    }

    String data = readAllText(in, 0);
    byte[] binary = DatatypeConverter.parseBase64Binary(data);
    int inputSize = readInteger(binary, 0);
    InputStream inputStream = new ByteArrayInputStream(binary, 4, inputSize);
    super.read(new InputStreamReader(inputStream, UTF_8), doc, pos);

    // read the token names
    int literalNamesOffset = 4 + inputSize;
    int literalNamesSize = readInteger(binary, literalNamesOffset);
    String[] literalNames = readStrings(binary, literalNamesOffset + 4, literalNamesSize);

    int symbolicNamesOffset = literalNamesOffset + 4 + literalNamesSize;
    int symbolicNamesSize = readInteger(binary, symbolicNamesOffset);
    String[] symbolicNames = readStrings(binary, symbolicNamesOffset + 4, symbolicNamesSize);

    doc.putProperty(PROP_VOCABULARY, new VocabularyImpl(literalNames, symbolicNames));

    // read the rule names
    int ruleNamesOffset = symbolicNamesOffset + 4 + symbolicNamesSize;
    int ruleNamesSize = readInteger(binary, ruleNamesOffset);
    String[] ruleNames = readStrings(binary, ruleNamesOffset + 4, ruleNamesSize);
    doc.putProperty(PROP_RULE_NAMES, ruleNames);

    // read the mode names
    int modeNamesOffset = ruleNamesOffset + 4 + ruleNamesSize;
    int modeNamesSize = readInteger(binary, modeNamesOffset);
    String[] modeNames = readStrings(binary, modeNamesOffset + 4, modeNamesSize);
    doc.putProperty(PROP_MODE_NAMES, modeNames);

    // read the trace
    int traceOffset = modeNamesOffset + 4 + modeNamesSize;
    int traceSize = readInteger(binary, traceOffset);
    byte[] traceData = Arrays.copyOfRange(binary, traceOffset + 4, traceOffset + 4 + traceSize);
    doc.putProperty(PROP_TRACE, traceData);
}