/** * Copyright 2011 Oliver Buchtala * * This file is part of ndogen. * * ndogen is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * ndogen is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with ndogen. If not, see <http://www.gnu.org/licenses/>. */ package org.ndogen.markdown; import org.antlr.runtime.CharStream; import org.antlr.runtime.CommonToken; import org.antlr.runtime.RecognizerSharedState; public class Scavenger extends CommonToken { private static final long serialVersionUID = 3198794931215932757L; public Scavenger(int type, CharStream input, RecognizerSharedState state) { this(type, input, state.tokenStartCharIndex, state.tokenStartLine, state.tokenStartCharPositionInLine); } public Scavenger(int type, CharStream input, int start, int line, int col) { super(input, type, DEFAULT_CHANNEL, start, start); super.line = line; super.charPositionInLine = col; } @Override public String getText() { // HACK: somehow this gets filled once to often return super.input.substring(super.start, super.stop-1); } public void append(int c) { // TODO: find out why this is called one time to often (i.e., with char that belongs to next token) super.stop++; } boolean isActive() { int index = input.index(); return (index-1==getStopIndex()); } }