use of org.antlr.works.ate.syntax.misc.ATEToken in project antlrworks by antlr.
the class GrammarRefactorMenu method replaceLiteralTokenWithTokenLabel.
public void replaceLiteralTokenWithTokenLabel(ATEToken t, String name) {
// First insert the rule at the end of the grammar
mutator.insert(window.getText().length(), "\n\n" + name + "\n\t:\t" + t.getAttribute() + "\n\t;");
// Then rename all strings token
List<ATEToken> tokens = window.getTokens();
String attr = t.getAttribute();
for (int index = tokens.size() - 1; index > 0; index--) {
ATEToken token = tokens.get(index);
if (token.type != ATESyntaxLexer.TOKEN_SINGLE_QUOTE_STRING && token.type != ATESyntaxLexer.TOKEN_DOUBLE_QUOTE_STRING)
continue;
if (!token.getAttribute().equals(attr))
continue;
mutator.replace(token.getStartIndex(), token.getEndIndex(), name);
}
}
use of org.antlr.works.ate.syntax.misc.ATEToken in project antlrworks by antlr.
the class STRefactorMenu 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");
renameToken(token, s);
endRefactor();
}
}
use of org.antlr.works.ate.syntax.misc.ATEToken in project antlrworks by antlr.
the class STRefactorMenu method renameToken.
public boolean renameToken(ATEToken t, String name) {
String attr = t.getAttribute();
List<ATEToken> tokens = window.getTokens();
boolean isArg = t.type == ATEStringTemplateSyntaxLexer.TOKEN_ARG_DECL || t.type == ATEStringTemplateSyntaxLexer.TOKEN_ARG_REFERENCE;
boolean renameRefRule = t.type == ATEStringTemplateSyntaxLexer.TOKEN_REFERENCE || t.type == ATEStringTemplateSyntaxLexer.TOKEN_DECL;
if (renameRefRule) {
for (int index = tokens.size() - 1; index > 0; index--) {
ATEToken token = tokens.get(index);
if (!token.getAttribute().equals(attr))
continue;
if (token.type == ATEStringTemplateSyntaxLexer.TOKEN_REFERENCE || token.type == ATEStringTemplateSyntaxLexer.TOKEN_DECL) {
mutator.replace(token.getStartIndex(), token.getEndIndex(), name);
}
}
} else if (isArg) {
ElementTemplateRule rule = getRuleAtPosition(window.getCaretPosition());
for (int index = tokens.size() - 1; index > 0; index--) {
ATEToken token = tokens.get(index);
if (!token.getAttribute().equals(attr))
continue;
if (rule.containsIndex(token.start)) {
if (token.type == ATEStringTemplateSyntaxLexer.TOKEN_ARG_DECL || token.type == ATEStringTemplateSyntaxLexer.TOKEN_ARG_REFERENCE) {
mutator.replace(token.getStartIndex(), token.getEndIndex(), name);
}
}
}
} else {
mutator.replace(t.getStartIndex(), t.getEndIndex(), name);
}
return true;
}
use of org.antlr.works.ate.syntax.misc.ATEToken in project antlrworks by antlr.
the class ATEStringTemplateSyntaxParser method tryMatchName.
private boolean tryMatchName() {
ATEToken start = T(0);
if (!matchID(0, "group"))
return false;
// After the 'group' comes the name of the template
ATEToken name = T(0);
if (!nextToken())
return false;
// match the optional super group
matchSuperGroup();
// match the optional interface/s
matchInterface();
// The next token must be a semi colon
if (!matchSEMI(0))
return false;
this.name = new ElementTemplateName(name, start, T(-1));
return true;
}
use of org.antlr.works.ate.syntax.misc.ATEToken in project antlrworks by antlr.
the class ATEStringTemplateSyntaxParser method tryMapDefinition.
private boolean tryMapDefinition() {
ATEToken start = T(0);
if (start == null)
return false;
String name = start.getAttribute();
if (!matchID(0))
return false;
// should be '::=' right after id
if (isDEFINED_TO_BE(0)) {
// When a defineToBe is matched, we are at the beginning of the content of the template map
nextToken();
} else {
// Invalid template map matching
return false;
}
final ATEToken definedToBeToken = T(-1);
currentTemplateMap = new ElementTemplateMapDefinition(name, start, definedToBeToken, null);
// loop through all new lines
while (matchNewline(0)) ;
if (!tryMatchMapDefinitionBody(start))
return false;
return true;
}
Aggregations