use of org.antlr.works.ate.syntax.misc.ATEToken in project antlrworks by antlr.
the class ATEStringTemplateSyntaxParser method resolveReferences.
/**
* Resolves the unresolved references by looking at the set of declared references
*/
private void resolveReferences() {
for (int i = unresolvedReferences.size() - 1; i >= 0; i--) {
ATEToken ref = unresolvedReferences.get(i);
if (declaredReferenceNames.contains(ref.getAttribute())) {
ref.type = ATEStringTemplateSyntaxLexer.TOKEN_REFERENCE;
references.add(new ElementTemplateReference(refsToRules.get(ref), ref));
unresolvedReferences.remove(i);
}
}
}
use of org.antlr.works.ate.syntax.misc.ATEToken in project antlrworks by antlr.
the class ATEStringTemplateSyntaxParser method tryMatchKey.
private boolean tryMatchKey() {
if (matchID(0, "default"))
return true;
if (!isDOUBLE_QUOTE(0))
return false;
ATEToken start = T(0);
start.type = ATESyntaxLexer.TOKEN_DOUBLE_QUOTE_STRING;
nextToken();
while (true) {
ATEToken t = T(0);
if (isDOUBLE_QUOTE(0) || isNewline(0)) {
t.type = ATESyntaxLexer.TOKEN_DOUBLE_QUOTE_STRING;
nextToken();
return true;
}
t.type = ATESyntaxLexer.TOKEN_DOUBLE_QUOTE_STRING;
if (!nextToken())
return false;
}
}
use of org.antlr.works.ate.syntax.misc.ATEToken in project antlrworks by antlr.
the class ATEStringTemplateSyntaxParser method matchLiteral.
private boolean matchLiteral() {
ATEToken t = T(0);
if (t == null)
return false;
t.type = ATEStringTemplateSyntaxLexer.TOKEN_LITERAL;
nextToken();
return true;
}
use of org.antlr.works.ate.syntax.misc.ATEToken in project antlrworks by antlr.
the class ATESyntaxLexer method tokenize.
protected void tokenize() {
while (nextCharacter()) {
ATEToken token = customMatch();
if (token != null) {
// custom match matched something
} else if (c0 == '\'')
token = matchSingleQuoteString();
else if (c0 == '\"')
token = matchDoubleQuoteString();
else if (c0 == '/' && c1 == '/')
token = matchSingleComment();
else if (c0 == '/' && c1 == '*')
token = matchComplexComment();
else if (isLetter())
token = matchID();
else if (c0 == '(')
token = createNewToken(TOKEN_LPAREN);
else if (c0 == ')')
token = createNewToken(TOKEN_RPAREN);
else if (c0 == '{')
token = createNewToken(TOKEN_LCURLY);
else if (c0 == '}')
token = createNewToken(TOKEN_RCURLY);
else if (c0 == '[')
token = createNewToken(TOKEN_LBRACK);
else if (c0 == ']')
token = createNewToken(TOKEN_RBRACK);
else if (c0 == ':')
token = createNewToken(TOKEN_COLON);
else if (c0 == ';')
token = createNewToken(TOKEN_SEMI);
else if (!isWhitespace())
token = createNewToken(TOKEN_CHAR);
addToken(token);
}
}
use of org.antlr.works.ate.syntax.misc.ATEToken in project antlrworks by antlr.
the class GrammarRefactorMenu method replaceLiteralWithTokenLabel.
public void replaceLiteralWithTokenLabel() {
StatisticsAW.shared().recordEvent(StatisticsAW.EVENT_REPLACE_LITERALS);
ATEToken token = window.getCurrentToken();
if (token == null)
return;
if (token.type != ATESyntaxLexer.TOKEN_SINGLE_QUOTE_STRING && token.type != ATESyntaxLexer.TOKEN_DOUBLE_QUOTE_STRING) {
XJAlert.display(window.getJavaContainer(), "Cannot Replace Literal With Token Label", "The current token is not a literal.");
return;
}
window.selectTextRange(token.getStartIndex(), token.getEndIndex());
String s = (String) JOptionPane.showInputDialog(window.getJavaContainer(), "Replace Literal '" + token.getAttribute() + "' with token label:", "Replace Literal With Token Label", JOptionPane.QUESTION_MESSAGE, null, null, "");
if (s != null && !s.equals(token.getAttribute())) {
beginRefactor("Replace Literal With Token Label");
replaceLiteralTokenWithTokenLabel(token, s);
endRefactor();
}
}
Aggregations