use of org.antlr.works.ate.syntax.misc.ATEToken in project antlrworks by antlr.
the class ElementBlock method parseForTokens.
/**
* Parses the internal tokens of a block of type 'tokens'.
*
* The tokens are considered as the following:
* TOKEN_A="value";
* TOKEN_B;
* ...
*/
private void parseForTokens() {
declaredTokens = new ArrayList<ATEToken>();
for (int index = 0; index < internalTokens.size(); index++) {
ATEToken t = internalTokens.get(index);
if (t.getAttribute().equals("=")) {
declaredTokens.add(internalTokens.get(index - 1));
// skip the value and the semi
index += 2;
} else if (t.getAttribute().equals(";")) {
declaredTokens.add(internalTokens.get(index - 1));
// skip the semi
index++;
}
}
}
use of org.antlr.works.ate.syntax.misc.ATEToken in project antlrworks by antlr.
the class ElementRule method getTextRuleAfterRemovingLeftRecursion.
public String getTextRuleAfterRemovingLeftRecursion() {
StringBuilder head = new StringBuilder();
StringBuilder star = new StringBuilder();
for (List<ATEToken> alts : getAlternatives()) {
ATEToken firstTokenInAlt = alts.get(0);
if (firstTokenInAlt.getAttribute().equals(name)) {
if (alts.size() > 1) {
if (star.length() > 0)
star.append(" | ");
int start = (alts.get(1)).getStartIndex();
int end = (alts.get(alts.size() - 1)).getEndIndex();
star.append(firstTokenInAlt.getText().substring(start, end));
}
} else {
if (head.length() > 0)
head.append(" | ");
int start = firstTokenInAlt.getStartIndex();
int end = (alts.get(alts.size() - 1)).getEndIndex();
head.append(firstTokenInAlt.getText().substring(start, end));
}
}
StringBuilder sb = new StringBuilder();
sb.append("(");
sb.append(head);
sb.append(")");
if (star.length() > 0) {
sb.append(" (");
sb.append(star);
sb.append(")*");
}
return sb.toString();
}
use of org.antlr.works.ate.syntax.misc.ATEToken in project antlrworks by antlr.
the class GrammarPropertiesImpl method parsePropertiesString.
private static List<ATEToken> parsePropertiesString(final String content) {
class ParseProperties extends ATESyntaxParser {
public List<ATEToken> propertiesTokens;
public void parseTokens() {
propertiesTokens = new ArrayList<ATEToken>();
while (nextToken()) {
if (T(0).type == ATESyntaxLexer.TOKEN_ID) {
if (isChar(1, "=") || isChar(1, "\n"))
propertiesTokens.add(T(0));
}
}
}
}
GrammarSyntaxLexer lexer = new GrammarSyntaxLexer();
lexer.tokenize(content);
ParseProperties parser = new ParseProperties();
parser.parse(lexer.getTokens());
return parser.propertiesTokens;
}
use of org.antlr.works.ate.syntax.misc.ATEToken in project antlrworks by antlr.
the class EditorInspector method discoverInvalidGrammarName.
protected void discoverInvalidGrammarName(List<EditorInspectorItem> items) {
ElementGrammarName n = getGrammarName();
String grammarFileName = getGrammarNameFromFile();
if (n != null && grammarFileName != null && !grammarFileName.equals(n.getName())) {
ATEToken t = n.name;
EditorInspectorItem item = new ItemInvalidGrammarName();
item.setAttributes(t, t.getStartIndex(), t.getEndIndex(), t.startLineNumber, Color.red, "Invalid grammar name '" + t.getAttribute() + "'");
items.add(item);
}
}
use of org.antlr.works.ate.syntax.misc.ATEToken in project antlrworks by antlr.
the class EditorRules method findOpenGroupClosestToLocation.
public ElementGroup findOpenGroupClosestToLocation(int location) {
// Look backward into the list of groups
List<ElementGroup> groups = getGrammarEngine().getGroups();
if (groups == null || groups.isEmpty())
return null;
ElementGroup previous = null;
for (ElementGroup group : groups) {
if (!group.openGroup)
continue;
ATEToken t = group.token;
if (t.getStartIndex() > location)
break;
previous = group;
}
return previous;
}
Aggregations