List of usage examples for org.antlr.v4.runtime CommonToken getStartIndex
@Override public int getStartIndex()
From source file:nl.lxtreme.libtdl.TdlHelper.java
License:Apache License
/** * @param input//ww w .j ava 2s. c om * the text to split into tokens. * @return a list of {@link TdlToken}s, never <code>null</code>. */ protected List<TdlToken> tokenize(CharStream input) { setInput(input); reset(); List<TdlToken> tokens = new ArrayList<TdlToken>(); Token token; while ((token = m_lexer.nextToken()).getType() != EOF) { CommonToken ctoken = (CommonToken) token; int startIdx = ctoken.getStartIndex(); int stopIdx = ctoken.getStopIndex(); int offset = startIdx; int length = (stopIdx + 1) - startIdx; TdlTokenType type = TdlTokenFactory.convertTokenType(m_config, ctoken.getType()); tokens.add(new TdlTokenImpl(type, offset, length, ctoken.getText())); } return tokens; }
From source file:org.eclipse.titan.common.parsers.TitanListener.java
License:Open Source License
@Override public void syntaxError(@NotNull final Recognizer<?, ?> recognizer, @Nullable final Object offendingSymbol, final int line, final int charPositionInLine, @NotNull final String msg, @Nullable final RecognitionException e) { SyntacticErrorStorage errorStorage;/* w w w. ja v a2s . c om*/ if (offendingSymbol instanceof CommonToken) { final CommonToken token = (CommonToken) offendingSymbol; errorStorage = new SyntacticErrorStorage(line, token.getStartIndex(), token.getStopIndex() + 1, msg, e); } else { errorStorage = new SyntacticErrorStorage(line, charPositionInLine, charPositionInLine + 1, msg, e); } errorsStored.add(errorStorage); }