Package org.antlr.v4.runtime

Examples of org.antlr.v4.runtime.CharStream


            "PLUS : '+';\n" +
            "MULT : '*';\n" +
            "WS : ' '+;\n");
        // Tokens: 012345678901234567
        // Input:  x = 3 * 0 + 2 * 0;
        CharStream input = new ANTLRInputStream("x = 3 * 0 + 2 * 0;");
        LexerInterpreter lexEngine = g.createLexerInterpreter(input);
        TokenStream tokens = createTokenStream(lexEngine);

        String result = tokens.LT(1).getText();
        String expecting = "x";
View Full Code Here


            "PLUS : '+';\n" +
            "MULT : '*';\n" +
            "WS : ' '+;\n");
        // Tokens: 012345678901234567
        // Input:  x = 3 * 0 + 2 * 0;
        CharStream input = new ANTLRInputStream("x = 3 * 0 + 2 * 0;");
        LexerInterpreter lexEngine = g.createLexerInterpreter(input);
        TokenStream tokens = createTokenStream(lexEngine);

        String result = tokens.LT(2).getText();
        String expecting = " ";
View Full Code Here

            "PLUS : '+';\n" +
            "MULT : '*';\n" +
            "WS : ' '+;\n");
        // Tokens: 012345678901234567
        // Input:  x = 3 * 0 + 2 * 0;
        CharStream input = new ANTLRInputStream("x = 3 * 0 + 2 * 0;");
        LexerInterpreter lexEngine = g.createLexerInterpreter(input);
        TokenStream tokens = createTokenStream(lexEngine);

        int i = 1;
        Token t = tokens.LT(i);
View Full Code Here

            "PLUS : '+';\n" +
            "MULT : '*';\n" +
            "WS : ' '+;\n");
        // Tokens: 012345678901234567
        // Input:  x = 3 * 0 + 2 * 0;
        CharStream input = new ANTLRInputStream("x = 3 * 0 + 2 * 0;");
        LexerInterpreter lexEngine = g.createLexerInterpreter(input);
        TokenStream tokens = createTokenStream(lexEngine);

        Token t = tokens.LT(1);
        while ( t.getType()!=Token.EOF ) {
View Full Code Here

            "PLUS : '+';\n" +
            "MULT : '*';\n" +
            "WS : ' '+;\n");
        // Tokens: 012345678901234567
        // Input:  x = 3 * 0 + 2 * 0;
        CharStream input = new ANTLRInputStream("x = 3 * 0 + 2 * 0;");
        LexerInterpreter lexEngine = g.createLexerInterpreter(input);
        TokenStream tokens = createTokenStream(lexEngine);

        tokens.consume(); // get x into buffer
        Token t = tokens.LT(-1);
View Full Code Here

    checkLexerMatches(lg, "a", expecting);
  }

  protected void checkLexerMatches(LexerGrammar lg, String inputString, String expecting) {
    ATN atn = createATN(lg, true);
    CharStream input = new ANTLRInputStream(inputString);
    ATNState startState = atn.modeNameToStartState.get("DEFAULT_MODE");
    DOTGenerator dot = new DOTGenerator(lg);
    System.out.println(dot.getDOT(startState, true));

    List<String> tokenTypes = getTokenTypes(lg, atn, input);
View Full Code Here

    assertEquals(IntStream.EOF, input.LA(1));
    assertEquals("\uFFFF", input.getBuffer());
  }

    @Test public void test2CharAhead() throws Exception {
       CharStream input = createStream("xy");
       assertEquals('x', input.LA(1));
       assertEquals('y', input.LA(2));
       assertEquals(IntStream.EOF, input.LA(3));
     }
View Full Code Here

    assertEquals("01234", input.getBuffer());
       assertEquals(IntStream.EOF, input.LA(6));
     }

    @Test public void testBufferWrapSize1() throws Exception {
       CharStream input = createStream("01234", 1);
        assertEquals('0', input.LA(1));
        input.consume();
        assertEquals('1', input.LA(1));
        input.consume();
        assertEquals('2', input.LA(1));
        input.consume();
        assertEquals('3', input.LA(1));
        input.consume();
        assertEquals('4', input.LA(1));
        input.consume();
       assertEquals(IntStream.EOF, input.LA(1));
     }
View Full Code Here

        input.consume();
       assertEquals(IntStream.EOF, input.LA(1));
     }

    @Test public void testBufferWrapSize2() throws Exception {
       CharStream input = createStream("01234", 2);
        assertEquals('0', input.LA(1));
        input.consume();
        assertEquals('1', input.LA(1));
        input.consume();
        assertEquals('2', input.LA(1));
        input.consume();
        assertEquals('3', input.LA(1));
        input.consume();
        assertEquals('4', input.LA(1));
        input.consume();
       assertEquals(IntStream.EOF, input.LA(1));
     }
View Full Code Here

     * @side if {@code charStreamL} is not null, add the {@link CharStream} instance representing {@code source}
     *       into {@code charStreamL}
     * @throws none
     */
    public ParserT getParser(String source, List<CharStream> charStreamL) {
        CharStream charStream = new ANTLRInputStream(source);
        if (charStreamL != null) {
            charStreamL.add(charStream);
        }
        LexerT lexer = createLexer(charStream);
        CommonTokenStream tokens = new CommonTokenStream(lexer);
View Full Code Here

TOP

Related Classes of org.antlr.v4.runtime.CharStream

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.