Package org.antlr.v4.runtime

Examples of org.antlr.v4.runtime.Token


        protected boolean sync(int i) {
            if (!super.sync(i)) {
        return false;
      }

      Token t = get(i);
      if ( hide.contains(t.getType()) ) {
        ((WritableToken)t).setChannel(Token.HIDDEN_CHANNEL);
      }

      return true;
        }
View Full Code Here


      }
      else {
        TextChunk textChunk = (TextChunk)chunk;
        ANTLRInputStream in = new ANTLRInputStream(textChunk.getText());
        lexer.setInputStream(in);
        Token t = lexer.nextToken();
        while ( t.getType()!=Token.EOF ) {
          tokens.add(t);
          t = lexer.nextToken();
        }
      }
    }
View Full Code Here

    List<XPathElement> elements = new ArrayList<XPathElement>();
    int n = tokens.size();
    int i=0;
loop:
    while ( i<n ) {
      Token el = tokens.get(i);
      Token next = null;
      switch ( el.getType() ) {
        case XPathLexer.ROOT :
        case XPathLexer.ANYWHERE :
          boolean anywhere = el.getType() == XPathLexer.ANYWHERE;
          i++;
          next = tokens.get(i);
          boolean invert = next.getType()==XPathLexer.BANG;
          if ( invert ) {
            i++;
            next = tokens.get(i);
          }
          XPathElement pathElement = getXPathElement(next, anywhere);
View Full Code Here

            private void bail(Parser recognizer, Exception exc, String additionalHint)
                        throws ParseCancellationException
            {
                RecognitionException re = (RecognitionException)exc.getCause();
                int offendingState = re.getOffendingState();
                Token offendingToken = re.getOffendingToken();
                int offendingTokenType = offendingToken.getType();

                String msg = getErrorMessage(offendingState, offendingTokenType);

                StringBuilder sb = new StringBuilder();
                sb.append(introductionLine());
                sb.append("\n");
                // TODO add line, column
                if (msg != null) {
                    sb.append("Possible issue: ");
                    sb.append(msg);
                    sb.append("\n");
                }

                sb.append(additionalHint);
                underlineError(sb, recognizer, offendingToken);

                throw new ParseCancellationException(
                        sb.toString(),
                        exc.getCause()
                    );
            }

            @Override public void recover(Parser recognizer, RecognitionException e)
                        throws ParseCancellationException
            {
                try {
                    super.recover(recognizer, e);
                    checkState(false);
                } catch (Exception exc) {
                    bail(recognizer, exc, "");
                }
            }

            @Override public Token recoverInline(Parser recognizer)
                        throws ParseCancellationException
            {
                String additionalHint = "";
               // per {@link DefaultErrorStrategy#singleTokenDeletion}, {@link BailErrorStrategy#recoverInline}:
                Token currentSymbol = recognizer.getCurrentToken();
                int nextTokenType = recognizer.getInputStream().LA(2);
                IntervalSet expecting = getExpectedTokens(recognizer);
                if ( expecting.contains(nextTokenType) ) {
                    String s = currentSymbol.getType() == -1 ? "EOF" : ruleNames()[currentSymbol.getType()-1];
                    additionalHint += String.format("Maybe the token %s should be removed.\n", s);
                }
                // attempt to conjure a token, {@link DefaultErrorStrategy#getMissingSymbol}
                int missingTokenType = expecting.getSingleElement();
                if (missingTokenType != Token.INVALID_TYPE && missingTokenType != -1) {
View Full Code Here

  private List<TerminalNode> parseTree(final ParseTree tree) {
    final List<TerminalNode> tokens = new ArrayList<TerminalNode>();
    if (tree instanceof TerminalNode) {
      final TerminalNode terminalNode = (TerminalNode) tree;
      final Token symbol = terminalNode.getSymbol();
      final int type = symbol.getType();
      if (Token.EOF != type) {
        tokens.add(terminalNode);
      }
      return tokens;
    }
View Full Code Here

public final class EquationGrammerListener extends EquationGrammarBaseListener {

  @Override
  public void exitFunction(final FunctionContext ctx) {
    final Token start = ctx.getStart();
    final String[] split = start.getText().split("\\(");
    final String functionName = split[0];
    if (!FunctionFactory.containsFunction(functionName)) {
      throw new ParseCancellationException(String.format("%s is not a valid function", functionName));
    }
  }
View Full Code Here

      }
      else if (t instanceof ErrorNode) {
        return "<" + t.toString() + ">";
      }
      else if (t instanceof TerminalNode) {
        Token symbol = ((TerminalNode) t).getSymbol();
        if (symbol != null) {
          String s = symbol.getText();
          return "'" + s + "'";
        }
      }
    }
    // no recog for rule names
View Full Code Here

                Recognizer<?, ?> aRecognizer, Object aOffendingSymbol,
                int aLine, int aCharPositionInLine,
                String aMsg, RecognitionException aEx)
        {
            final int lineNumber = mOffset + aLine;
            final Token token = (Token) aOffendingSymbol;

            if (JAVADOC_MISSED_HTML_CLOSE.equals(aMsg)) {
                log(lineNumber, JAVADOC_MISSED_HTML_CLOSE, token.getText());
                throw new ParseCancellationException();
            }
            else if (JAVADOC_WRONG_SINGLETON_TAG.equals(aMsg)) {
                log(lineNumber, JAVADOC_WRONG_SINGLETON_TAG, token.getText());
                throw new ParseCancellationException();
            }
            else {
                final RuleContext ruleContext = aEx.getCtx();
                if (ruleContext != null) {
View Full Code Here

        tokens.fill();
        List tokenList = tokens.getTokens();

        for (int i = 0; i < tokenList.size(); i++)
        {
            Token token = (Token) tokenList.get(i);
            if ((token == null) || token.getText() == null)
            {
                break;
            }
            String text = token.getText().toLowerCase().trim();
            if (text.equals("where"))
            {
                whereIndex = token.getCharPositionInLine() + 1;
            }
            if (text.equals("group"))
            {
                groupbyIndex = token.getCharPositionInLine() + 1;
            }
            if (text.equals("having"))
            {
                havingIndex = token.getCharPositionInLine() + 1;
            }
            if (text.equals("order"))
            {
                orderByIndex = token.getCharPositionInLine() + 1;
            }
            if (text.equals("union"))
            {
                unionIndexes.add(token.getCharPositionInLine() + 1);
            }
        }

        // If we have a union, break string into subselects and process each
        if (unionIndexes.size() != 0)
View Full Code Here

            StringWriter writer = new StringWriter();
            PrintWriter printer = new PrintWriter(writer);
            for (int i = 0; i < tokens.size(); i++)
            {
                Token t = (Token) tokenList.get(i);
                String text = t.getText();
                if (text.trim().length() == 0)
                {
                    printer.print("'" + text + "'");
                }
                else
                {
                    printer.print(text);
                }
                printer.print('[');
                printer.print(t.getType());
                printer.print(']');
                printer.print(" ");
            }
            printer.println();
            log.debug("Tokens: " + writer.toString());
View Full Code Here

TOP

Related Classes of org.antlr.v4.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.