Search in sources :

Example 26 with IntegerList

use of org.antlr.v4.runtime.misc.IntegerList in project antlr4 by antlr.

the class BaseBrowserTest method getTokenTypesViaATN.

public IntegerList getTokenTypesViaATN(String input, LexerATNSimulator lexerATN) {
    ANTLRInputStream in = new ANTLRInputStream(input);
    IntegerList tokenTypes = new IntegerList();
    int ttype;
    do {
        ttype = lexerATN.match(in, Lexer.DEFAULT_MODE);
        tokenTypes.add(ttype);
    } while (ttype != Token.EOF);
    return tokenTypes;
}
Also used : IntegerList(org.antlr.v4.runtime.misc.IntegerList) ANTLRInputStream(org.antlr.v4.runtime.ANTLRInputStream)

Example 27 with IntegerList

use of org.antlr.v4.runtime.misc.IntegerList in project antlr4 by antlr.

the class BaseNodeTest method getTokenTypesViaATN.

public IntegerList getTokenTypesViaATN(String input, LexerATNSimulator lexerATN) {
    ANTLRInputStream in = new ANTLRInputStream(input);
    IntegerList tokenTypes = new IntegerList();
    int ttype;
    do {
        ttype = lexerATN.match(in, Lexer.DEFAULT_MODE);
        tokenTypes.add(ttype);
    } while (ttype != Token.EOF);
    return tokenTypes;
}
Also used : IntegerList(org.antlr.v4.runtime.misc.IntegerList) ANTLRInputStream(org.antlr.v4.runtime.ANTLRInputStream)

Example 28 with IntegerList

use of org.antlr.v4.runtime.misc.IntegerList in project antlr4 by antlr.

the class BaseCppTest method getTypesFromString.

//	public void minimizeDFA(DFA dfa) {
//		DFAMinimizer dmin = new DFAMinimizer(dfa);
//		dfa.minimized = dmin.minimize();
//	}
IntegerList getTypesFromString(Grammar g, String expecting) {
    IntegerList expectingTokenTypes = new IntegerList();
    if (expecting != null && !expecting.trim().isEmpty()) {
        for (String tname : expecting.replace(" ", "").split(",")) {
            int ttype = g.getTokenType(tname);
            expectingTokenTypes.add(ttype);
        }
    }
    return expectingTokenTypes;
}
Also used : IntegerList(org.antlr.v4.runtime.misc.IntegerList) STGroupString(org.stringtemplate.v4.STGroupString) BaseRuntimeTest.antlrOnString(org.antlr.v4.test.runtime.BaseRuntimeTest.antlrOnString)

Example 29 with IntegerList

use of org.antlr.v4.runtime.misc.IntegerList in project antlr4 by antlr.

the class BaseGoTest method getTypesFromString.

IntegerList getTypesFromString(Grammar g, String expecting) {
    IntegerList expectingTokenTypes = new IntegerList();
    if (expecting != null && !expecting.trim().isEmpty()) {
        for (String tname : expecting.replace(" ", "").split(",")) {
            int ttype = g.getTokenType(tname);
            expectingTokenTypes.add(ttype);
        }
    }
    return expectingTokenTypes;
}
Also used : IntegerList(org.antlr.v4.runtime.misc.IntegerList) STGroupString(org.stringtemplate.v4.STGroupString) BaseRuntimeTest.antlrOnString(org.antlr.v4.test.runtime.BaseRuntimeTest.antlrOnString)

Example 30 with IntegerList

use of org.antlr.v4.runtime.misc.IntegerList in project antlr4 by tunnelvisionlabs.

the class Tool method generateInterpreterData.

private void generateInterpreterData(Grammar g) {
    StringBuilder content = new StringBuilder();
    content.append("token literal names:\n");
    String[] names = g.getTokenLiteralNames();
    for (String name : names) {
        content.append(name).append("\n");
    }
    content.append("\n");
    content.append("token symbolic names:\n");
    names = g.getTokenSymbolicNames();
    for (String name : names) {
        content.append(name).append("\n");
    }
    content.append("\n");
    content.append("rule names:\n");
    names = g.getRuleNames();
    for (String name : names) {
        content.append(name).append("\n");
    }
    content.append("\n");
    if (g.isLexer()) {
        content.append("channel names:\n");
        content.append("DEFAULT_TOKEN_CHANNEL\n");
        content.append("HIDDEN\n");
        for (String channel : g.channelValueToNameList) {
            content.append(channel).append("\n");
        }
        content.append("\n");
        content.append("mode names:\n");
        for (String mode : ((LexerGrammar) g).modes.keySet()) {
            content.append(mode).append("\n");
        }
    }
    content.append("\n");
    IntegerList serializedATN = ATNSerializer.getSerialized(g.atn, Arrays.asList(g.getRuleNames()));
    content.append("atn:\n");
    content.append(serializedATN.toString());
    try {
        Writer fw = getOutputFileWriter(g, g.name + ".interp");
        try {
            fw.write(content.toString());
        } finally {
            fw.close();
        }
    } catch (IOException ioe) {
        errMgr.toolError(ErrorType.CANNOT_WRITE_FILE, ioe);
    }
}
Also used : IntegerList(org.antlr.v4.runtime.misc.IntegerList) IOException(java.io.IOException) Writer(java.io.Writer) OutputStreamWriter(java.io.OutputStreamWriter) BufferedWriter(java.io.BufferedWriter) StringWriter(java.io.StringWriter)

Aggregations

IntegerList (org.antlr.v4.runtime.misc.IntegerList)42 Test (org.junit.Test)12 STGroupString (org.stringtemplate.v4.STGroupString)7 ANTLRInputStream (org.antlr.v4.runtime.ANTLRInputStream)6 ATN (org.antlr.v4.runtime.atn.ATN)6 LexerATNSimulator (org.antlr.v4.runtime.atn.LexerATNSimulator)6 ArrayList (java.util.ArrayList)5 TokenStream (org.antlr.v4.runtime.TokenStream)5 DFA (org.antlr.v4.runtime.dfa.DFA)5 IntervalSet (org.antlr.v4.runtime.misc.IntervalSet)5 BaseRuntimeTest.antlrOnString (org.antlr.v4.test.runtime.BaseRuntimeTest.antlrOnString)5 ParserATNFactory (org.antlr.v4.automata.ParserATNFactory)4 DOTGenerator (org.antlr.v4.tool.DOTGenerator)4 Rule (org.antlr.v4.tool.Rule)4 HashMap (java.util.HashMap)3 ATNState (org.antlr.v4.runtime.atn.ATNState)3 BlockStartState (org.antlr.v4.runtime.atn.BlockStartState)3 MockIntTokenStream (org.antlr.v4.test.runtime.MockIntTokenStream)3 RuntimeTestUtils.getTokenTypesViaATN (org.antlr.v4.test.runtime.RuntimeTestUtils.getTokenTypesViaATN)3 BufferedWriter (java.io.BufferedWriter)2