use of org.antlr.works.ate.syntax.misc.ATEToken in project antlrworks by antlr.
the class GrammarSyntaxParser method matchAssignment.
private boolean matchAssignment(LabelTable labels) {
mark();
ATEToken label = T(0);
if (matchID(0)) {
if (matchChar(0, "=")) {
label.type = GrammarSyntaxLexer.TOKEN_LABEL;
labels.add(label.getAttribute());
return true;
} else if (isChar(0, "+") && isChar(1, "=")) {
label.type = GrammarSyntaxLexer.TOKEN_LABEL;
labels.add(label.getAttribute());
skip(2);
return true;
}
}
rewind();
return false;
}
use of org.antlr.works.ate.syntax.misc.ATEToken in project antlrworks by antlr.
the class GrammarSyntaxParser method resolveReferencesWithExternalNames.
/**
* Resolves the unresolved references by using externally provided names. For example,
* reading a file of token using the option tokenVocab will invoke this method to solve
* any remaining references that are still unresolved.
*
* @param externalNames A list of string representing the external declared reference names
*/
public void resolveReferencesWithExternalNames(Set<String> externalNames) {
for (int i = unresolvedReferences.size() - 1; i >= 0; i--) {
ATEToken ref = unresolvedReferences.get(i);
if (externalNames.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 FindMenu method findUsage.
public void findUsage() {
StatisticsAW.shared().recordEvent(StatisticsAW.EVENT_FIND_USAGES);
ATEToken token = delegate.getCurrentToken();
if (token == null)
return;
Usages usage = new Usages(delegate, token);
delegate.addUsagesTab(usage);
for (ATEToken ateToken : delegate.getTokens()) {
if (ateToken.getAttribute().equals(token.getAttribute())) {
ElementRule matchedRule = delegate.getEditorRules().getEnclosingRuleAtPosition(ateToken.getStartIndex());
if (matchedRule != null)
usage.addMatch(matchedRule, ateToken);
}
}
}
use of org.antlr.works.ate.syntax.misc.ATEToken in project antlrworks by antlr.
the class GrammarMenu method ungroup.
public void ungroup() {
StatisticsAW.shared().recordEvent(StatisticsAW.EVENT_RULE_UNGROUP);
ElementGroup openGroup = window.editorRules.getSelectedGroup();
if (openGroup == null) {
// No open group selected in the tree. Try to find the closest open group
// by moving backward
openGroup = window.editorRules.findOpenGroupClosestToLocation(window.getTextPane().getSelectionStart());
if (openGroup == null) {
// Still no open group ? Give up
XJAlert.display(window.getJavaContainer(), "Ungroup", "Cannot ungroup because no enclosing group has been found.");
return;
}
}
ElementGroup closingGroup = window.editorRules.findClosingGroupForGroup(openGroup);
window.beginGroupChange("Ungroup");
if (closingGroup != null) {
// End of file is considered as a closing group but no group really exists
// for that purpose
ATEToken t = closingGroup.token;
window.replaceText(t.getStartIndex() - 1, t.getEndIndex(), "");
}
ATEToken t = openGroup.token;
window.replaceText(t.getStartIndex() - 1, t.getEndIndex(), "");
window.endGroupChange();
}
use of org.antlr.works.ate.syntax.misc.ATEToken in project antlrworks by antlr.
the class GrammarRefactorMenu method convertLiteralsToSpecifiedQuote.
protected void convertLiteralsToSpecifiedQuote(int tokenType, char quote, char unescapeQuote) {
List<ATEToken> tokens = window.getTokens();
for (int index = tokens.size() - 1; index > 0; index--) {
ATEToken token = tokens.get(index);
if (token.type != tokenType)
continue;
// FIX AW-56
if (RefactorEngine.ignoreScopeForDoubleQuoteLiteral(token.scope))
continue;
String attribute = token.getAttribute();
String stripped = attribute.substring(1, attribute.length() - 1);
if (stripped.indexOf(quote) != -1 || stripped.indexOf(unescapeQuote) != -1)
stripped = escapeStringQuote(stripped, quote, unescapeQuote);
mutator.replace(token.getStartIndex(), token.getEndIndex(), quote + stripped + quote);
}
}
Aggregations