Package org.antlr.runtime

Examples of org.antlr.runtime.Token


      fillBuffer();
   
    if (tokenSource instanceof Lexer) {
      if (tokens.isEmpty())
        return "";
      Token lastToken = (Token) tokens.get(tokens.size() - 1);
      if (lastToken instanceof CommonToken) {
        CommonToken commonStop = (CommonToken) lastToken;
        CharStream charStream = ((Lexer) tokenSource).getCharStream();
        String result = charStream.substring(0, commonStop.getStopIndex());
        return result;
View Full Code Here


   * Get next token.  If an exception is thrown by the underlying lexer,
   * keep calling it, and append an invalid token at the very end.
   */
  @Override
  public Token nextToken() {
    Token token = null;
    CoffeeSymbol symbol = null;
    try {
      symbol = aptanaScanner.nextToken();
      if (symbol == null || symbol.getId() < 0) {
        logger.warn("Unexpected symbol " + symbol, new Exception());
        token = CommonToken.INVALID_TOKEN;
      }
      else if (symbol.getId() == Terminals.EOF) {
        token = CommonToken.EOF_TOKEN;
      }
      else {
        token = new BeaverToken(symbol);
        if (((CommonToken) token).getStopIndex() >= input.size()) {
          assert false: "Token stop index overflows " + symbol + " in:\n<<<" + content + ">>>";
        }
      }
    }
    catch (Exception e) {
      // Xtext wants token to be CommonToken, INVALID_TOKEN_TYPE, and HIDDEN_CHANNEL
      String text = e.getLocalizedMessage();
      if (text == null)
        text = "simply " + e.getClass().getSimpleName();
      CommonToken ct = new CommonToken(Token.INVALID_TOKEN_TYPE,
          text);
      ct.setChannel(Token.HIDDEN_CHANNEL);
      if (prevToken != null) {
        int start = prevToken.getStopIndex() + 1;
        int stop = start + 1; // TODO: get more informative errors with length of token
        ct.setStartIndex(start);
        ct.setStopIndex(stop);
      }
      token = ct;
    }
    token.setTokenIndex(tokenIndex);
    if (symbol != null && symbol.hidden)
      token.setChannel(Token.HIDDEN_CHANNEL);
    tokenIndex++;
    if (token instanceof CommonToken) {
      if (prevToken != null && token.getType() > 0) {
        if (((CommonToken)token).getStartIndex() < prevToken.getStartIndex()) {
          assert false: "Position not follows, prevToken: " + prevToken + ", token: " + token;
        }
      }     
      prevToken = (CommonToken)token;
View Full Code Here

                    String target = qualifiedIdentifier();
                    if (state.failed)
                        return null;
                   
                    // function name
                    Token id = match(input,
                            DRL6Lexer.ID,
                            null,
                            null,
                            DroolsEditorType.IDENTIFIER);
                    if (state.failed)
                        return null;
                    if (state.backtracking == 0) {
                        imp.target(target).functionName(id.getText());
                    }

                    return (imp != null) ? imp.getDescr() : null;
                } finally {
                    helper.end(AccumulateImportDescrBuilder.class,
View Full Code Here

                global.type(type);
            if (state.failed)
                return null;

            // identifier
            Token id = match(input,
                    DRL6Lexer.ID,
                    null,
                    null,
                    DroolsEditorType.IDENTIFIER_TYPE);
            if (state.failed)
                return null;
            if (state.backtracking == 0) {
                global.identifier(id.getText());
                helper.setParaphrasesValue(DroolsParaphraseTypes.GLOBAL,
                        id.getText());
            }

        } catch (RecognitionException re) {
            reportError(re);
        } finally {
View Full Code Here

                    null,
                    DroolsEditorType.KEYWORD);
            if (state.failed)
                return null;

            Token id = match(input,
                    DRL6Lexer.ID,
                    null,
                    null,
                    DroolsEditorType.IDENTIFIER);
            if (state.failed)
                return null;
            window = id.getText();

            if (state.backtracking == 0) {
                declare.name(window);
            }
View Full Code Here

     */
    private void enumerative(EnumDeclarationDescrBuilder declare) {
        EnumLiteralDescrBuilder literal = null;
        String lit = null;
        try {
            Token enumLit = match(input,
                    DRL6Lexer.ID,
                    null,
                    null,
                    DroolsEditorType.IDENTIFIER);
            lit = enumLit.getText();
            if (state.failed)
                return;
        } catch (RecognitionException re) {
            reportError(re);
        }
View Full Code Here

                if (state.backtracking == 0)
                    function.returnType(type);
            }

            // name
            Token id = match(input,
                    DRL6Lexer.ID,
                    null,
                    null,
                    DroolsEditorType.IDENTIFIER);
            if (state.failed)
                return null;
            if (state.backtracking == 0) {
                function.name(id.getText());
                helper.setParaphrasesValue(DroolsParaphraseTypes.FUNCTION,
                        "\"" + id.getText() + "\"");
            }

            // arguments
            parameters(function,
                    true);
View Full Code Here

     * @return
     * @throws org.antlr.runtime.RecognitionException
     */
    String stringId() throws RecognitionException {
        if (input.LA(1) == DRL6Lexer.ID) {
            Token id = match(input,
                    DRL6Lexer.ID,
                    null,
                    null,
                    DroolsEditorType.IDENTIFIER);
            if (state.failed)
                return null;
            return id.getText();
        } else if (input.LA(1) == DRL6Lexer.STRING) {
            Token id = match(input,
                    DRL6Lexer.STRING,
                    null,
                    null,
                    DroolsEditorType.IDENTIFIER);
            if (state.failed)
                return null;
            return StringUtils.unescapeJava(safeStripStringDelimiters(id.getText()));
        } else {
            throw new MismatchedTokenException(DRL6Lexer.ID,
                    input);
        }
    }
View Full Code Here

                        builder.toString());
            }

            String value = "true";
            if (input.LA(1) == DRL6Lexer.BOOL) {
                Token bool = match(input,
                        DRL6Lexer.BOOL,
                        null,
                        null,
                        DroolsEditorType.KEYWORD);
                if (state.failed)
                    return null;
                value = bool.getText();
            }
            if (state.backtracking == 0) {
                attribute.value(value);
                attribute.type(AttributeDescr.Type.BOOLEAN);
            }
View Full Code Here

                attribute = helper.start((DescrBuilder<?, ?>) as,
                        AttributeDescrBuilder.class,
                        builder.toString());
            }

            Token value = match(input,
                    DRL6Lexer.STRING,
                    null,
                    null,
                    DroolsEditorType.STRING_CONST);
            if (state.failed)
                return null;
            if (state.backtracking == 0) {
                attribute.value(StringUtils.unescapeJava(safeStripStringDelimiters(value.getText())));
                attribute.type(AttributeDescr.Type.STRING);
            }
        } finally {
            if (attribute != null) {
                helper.end(AttributeDescrBuilder.class,
View Full Code Here

TOP

Related Classes of org.antlr.runtime.Token

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.