use of org.antlr.works.ate.syntax.misc.ATEToken in project antlrworks by antlr.
the class GrammarSyntaxParser 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 = GrammarSyntaxLexer.TOKEN_REFERENCE;
references.add(new ElementReference(refsToRules.get(ref), ref));
unresolvedReferences.remove(i);
}
}
}
use of org.antlr.works.ate.syntax.misc.ATEToken in project antlrworks by antlr.
the class GrammarSyntaxParser method matchAction.
private boolean matchAction() {
if (!isOpenBLOCK(0))
return false;
// Match an action
ATEToken t0 = T(0);
ElementAction action = new ElementAction(this, currentRule, t0);
if (matchBalancedToken(ATESyntaxLexer.TOKEN_LCURLY, ATESyntaxLexer.TOKEN_RCURLY, action, true)) {
t0.type = GrammarSyntaxLexer.TOKEN_BLOCK_LIMIT;
T(-1).type = GrammarSyntaxLexer.TOKEN_BLOCK_LIMIT;
action.end = T(-1);
action.actionNum = actions.size();
action.setScope(currentRule);
actions.add(action);
return true;
} else {
return false;
}
}
use of org.antlr.works.ate.syntax.misc.ATEToken in project antlrworks by antlr.
the class GrammarRefactorMenu method rename.
public void rename() {
StatisticsAW.shared().recordEvent(StatisticsAW.EVENT_RENAME);
ATEToken token = window.getCurrentToken();
if (token == null)
return;
String s = (String) JOptionPane.showInputDialog(window.getJavaContainer(), "Rename '" + token.getAttribute() + "' and its usages to:", "Rename", JOptionPane.QUESTION_MESSAGE, null, null, token.getAttribute());
if (s != null && !s.equals(token.getAttribute())) {
beginRefactor("Rename");
engine.renameToken(token, s);
endRefactor();
}
}
use of org.antlr.works.ate.syntax.misc.ATEToken in project antlrworks by antlr.
the class GrammarRefactorMenu method convertLiteralsToCStyleQuote.
public void convertLiteralsToCStyleQuote() {
StatisticsAW.shared().recordEvent(StatisticsAW.EVENT_CONVERT_LITERALS_TO_CSTYLE);
beginRefactor("Convert Literals To C-style Quote Literals");
List<ATEToken> tokens = window.getTokens();
for (int index = tokens.size() - 1; index > 0; index--) {
ATEToken token = tokens.get(index);
String attribute;
String stripped;
String replaced = null;
if (token.type == ATESyntaxLexer.TOKEN_SINGLE_QUOTE_STRING || token.type == ATESyntaxLexer.TOKEN_DOUBLE_QUOTE_STRING) {
attribute = token.getAttribute();
stripped = attribute.substring(1, attribute.length() - 1);
} else
continue;
if (token.type == ATESyntaxLexer.TOKEN_SINGLE_QUOTE_STRING) {
// Only one character allowed
if (stripped.length() == 1)
continue;
else if (stripped.length() == 2 && stripped.charAt(0) == '\\')
continue;
if (stripped.indexOf('"') != -1 || stripped.indexOf('\'') != -1)
stripped = escapeStringQuote(stripped, '"', '\'');
replaced = '"' + stripped + '"';
} else if (token.type == ATESyntaxLexer.TOKEN_DOUBLE_QUOTE_STRING) {
if (stripped.length() > 1 && stripped.charAt(0) != '\\')
continue;
if (stripped.indexOf('\'') != -1 || stripped.indexOf('"') != -1)
stripped = escapeStringQuote(stripped, '\'', '"');
replaced = '\'' + stripped + '\'';
}
mutator.replace(token.getStartIndex(), token.getEndIndex(), replaced);
}
endRefactor();
}
use of org.antlr.works.ate.syntax.misc.ATEToken in project antlrworks by antlr.
the class EditorRules method findTokensToIgnore.
public static void findTokensToIgnore(List<ElementRule> rules, boolean reset) {
for (ElementRule rule : rules) {
if (reset)
rule.ignored = false;
List<ElementAction> actions = rule.getActions();
if (actions == null || actions.isEmpty())
continue;
for (ElementAction action : actions) {
List<ATEToken> tokens = action.getTokens();
for (int t = 0; t < tokens.size(); t++) {
ATEToken token = tokens.get(t);
/* the 'channel' token can be either an ID or a reference if a rule in the grammar has the name
'channel' */
if ((token.type == ATESyntaxLexer.TOKEN_ID || token.type == GrammarSyntaxLexer.TOKEN_REFERENCE) && token.getAttribute().equals("channel") && t + 3 < tokens.size()) {
ATEToken t1 = tokens.get(t + 1);
ATEToken t2 = tokens.get(t + 2);
if (t1.type != ATESyntaxLexer.TOKEN_CHAR || !t1.getAttribute().equals("="))
continue;
if (t2.type != ATESyntaxLexer.TOKEN_ID || !t2.getAttribute().equals("HIDDEN"))
continue;
rule.ignored = true;
break;
}
if (token.type == GrammarSyntaxLexer.TOKEN_ID && token.getAttribute().equals("skip")) {
// Take skip() into account only if it is the only token in the block
if (tokens.size() == 5 && t == 1) {
rule.ignored = true;
break;
}
}
}
}
}
}
Aggregations