Search in sources :

Example 36 with ATEToken

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++;
        }
    }
}
Also used : ATEToken(org.antlr.works.ate.syntax.misc.ATEToken)

Example 37 with ATEToken

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();
}
Also used : ATEToken(org.antlr.works.ate.syntax.misc.ATEToken)

Example 38 with ATEToken

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;
}
Also used : ATESyntaxParser(org.antlr.works.ate.syntax.generic.ATESyntaxParser) GrammarSyntaxLexer(org.antlr.works.grammar.syntax.GrammarSyntaxLexer) ATEToken(org.antlr.works.ate.syntax.misc.ATEToken)

Example 39 with ATEToken

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);
    }
}
Also used : ATEToken(org.antlr.works.ate.syntax.misc.ATEToken)

Example 40 with ATEToken

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;
}
Also used : ElementGroup(org.antlr.works.grammar.element.ElementGroup) ATEToken(org.antlr.works.ate.syntax.misc.ATEToken)

Aggregations

ATEToken (org.antlr.works.ate.syntax.misc.ATEToken)42 ElementGroup (org.antlr.works.grammar.element.ElementGroup)2 ElementRule (org.antlr.works.grammar.element.ElementRule)2 ArrayList (java.util.ArrayList)1 HashSet (java.util.HashSet)1 List (java.util.List)1 BadLocationException (javax.swing.text.BadLocationException)1 ATESyntaxEngine (org.antlr.works.ate.syntax.generic.ATESyntaxEngine)1 ATESyntaxParser (org.antlr.works.ate.syntax.generic.ATESyntaxParser)1 Usages (org.antlr.works.find.Usages)1 ElementAction (org.antlr.works.grammar.element.ElementAction)1 ElementBlock (org.antlr.works.grammar.element.ElementBlock)1 GrammarSyntaxLexer (org.antlr.works.grammar.syntax.GrammarSyntaxLexer)1 ElementTemplateRule (org.antlr.works.stringtemplate.element.ElementTemplateRule)1