use of org.antlr.works.ate.syntax.misc.ATEToken in project antlrworks by antlr.
the class ATERenderingView method findStartingTokenIndex.
/** This method finds the first token that is located in the line index p0
*
* @param p0
* @param low
* @param high
* @param candidate
* @return The index of the first token on line p0
*/
private int findStartingTokenIndex(int p0, int low, int high, int candidate) {
if (Math.abs(high - low) <= 1)
return Math.min(candidate, low);
final int middle = low + (high - low) / 2;
final ATEToken t = tokens.get(middle);
if (p0 >= t.startLineIndex && p0 <= t.endLineIndex) {
return findStartingTokenIndex(p0, low, middle, middle);
} else {
if (t.startLineIndex < p0)
return findStartingTokenIndex(p0, middle, high, candidate);
else
return findStartingTokenIndex(p0, low, middle, candidate);
}
}
use of org.antlr.works.ate.syntax.misc.ATEToken in project antlrworks by antlr.
the class ATERenderingView method renderText.
/**
* This method renders the text using the token information to set up the display attribute
* of each token.
*
*/
protected int renderText(TextOperation action, Graphics g, int x, int y, int p0, int p1) throws BadLocationException {
if (p0 == p1)
return x;
if (!textEditor.isSyntaxColoring()) {
return super.drawUnselectedText(g, x, y, p0, p1);
}
// Note: the tokens are not contiguous (e.g. white spaces are ignored)
final Document doc = getDocument();
final ATESyntaxEngine engine = textEditor.getParserEngine();
tokens = engine.getTokens();
int p = p0;
final int start = findStartingTokenIndex(p0, 0, tokens.size(), 0);
for (int i = start; i < tokens.size(); i++) {
ATEToken t = tokens.get(i);
AttributeSet attribute = engine.getAttributeForToken(t);
if (t.start >= p0 && t.start <= p1) {
// Fill any non-contiguous token with default color
if (t.start > p) {
x = action.renderTextPortion(g, x, y, p, t.start, p1, doc, null);
}
x = action.renderTextPortion(g, x, y, t.start, t.end, p1, doc, attribute);
p = t.end;
} else if (t.end >= p0 && t.start < p0) {
x = action.renderTextPortion(g, x, y, p0, t.end, p1, doc, attribute);
p = t.end;
} else if (t.start > p1) {
break;
}
}
// Fill any remaining range with default color
if (p < p1) {
x = action.renderTextPortion(g, x, y, p, p1, p1, doc, null);
}
return x;
}
use of org.antlr.works.ate.syntax.misc.ATEToken in project antlrworks by antlr.
the class RefactorEngine method renameToken.
public boolean renameToken(ATEToken t, String name) {
String attr = t.getAttribute();
boolean renameRefRule = t.type == GrammarSyntaxLexer.TOKEN_REFERENCE || t.type == GrammarSyntaxLexer.TOKEN_DECL;
for (int index = tokens.size() - 1; index > 0; index--) {
ATEToken token = tokens.get(index);
if (!token.getAttribute().equals(attr))
continue;
if (token.type == t.type || renameRefRule && (token.type == GrammarSyntaxLexer.TOKEN_REFERENCE || token.type == GrammarSyntaxLexer.TOKEN_DECL)) {
mutator.replace(token.getStartIndex(), token.getEndIndex(), name);
}
}
return true;
}
use of org.antlr.works.ate.syntax.misc.ATEToken in project antlrworks by antlr.
the class EditorInspector method discoverInvalidCharLiteralTokens.
protected void discoverInvalidCharLiteralTokens(List<EditorInspectorItem> items) {
List<ATEToken> tokens = engine.getTokens();
if (tokens == null)
return;
for (ATEToken t : tokens) {
if (t.type == ATESyntaxLexer.TOKEN_DOUBLE_QUOTE_STRING) {
if (RefactorEngine.ignoreScopeForDoubleQuoteLiteral(t.scope))
continue;
EditorInspectorItem item = new ItemInvalidCharLiteral();
item.setAttributes(t, t.getStartIndex(), t.getEndIndex(), t.startLineNumber, Color.red, "Invalid character literal '" + t.getAttribute() + "' - must use single quote");
items.add(item);
}
}
}
use of org.antlr.works.ate.syntax.misc.ATEToken in project antlrworks by antlr.
the class ElementBlock method parseForTokenVocab.
/**
* Parses for the tokenVocab key/value pair of a block of type 'options'
*/
private void parseForTokenVocab() {
for (int index = 0; index < internalTokens.size(); index++) {
ATEToken t = internalTokens.get(index);
if (t.getAttribute().equals("tokenVocab") && index + 2 < internalTokens.size()) {
t = internalTokens.get(index + 2);
tokenVocab = t.getAttribute();
}
}
}
Aggregations