Search in sources :

Example 6 with FrequencySet

use of org.antlr.v4.misc.FrequencySet in project antlr4 by tunnelvisionlabs.

the class RuleFunction method getElementFrequenciesForAlt.

/**
 * Given list of X and r refs in alt, compute how many of each there are
 */
protected Tuple2<FrequencySet<String>, FrequencySet<String>> getElementFrequenciesForAlt(AltAST ast) {
    try {
        ElementFrequenciesVisitor visitor = new ElementFrequenciesVisitor(rule.g, new CommonTreeNodeStream(new GrammarASTAdaptor(), ast));
        visitor.outerAlternative();
        if (visitor.frequencies.size() != 1) {
            factory.getGrammar().tool.errMgr.toolError(ErrorType.INTERNAL_ERROR);
            return Tuple.create(new FrequencySet<String>(), new FrequencySet<String>());
        }
        return Tuple.create(visitor.getMinFrequencies(), visitor.frequencies.peek());
    } catch (RecognitionException ex) {
        factory.getGrammar().tool.errMgr.toolError(ErrorType.INTERNAL_ERROR, ex);
        return Tuple.create(new FrequencySet<String>(), new FrequencySet<String>());
    }
}
Also used : GrammarASTAdaptor(org.antlr.v4.parse.GrammarASTAdaptor) RecognitionException(org.antlr.runtime.RecognitionException) FrequencySet(org.antlr.v4.misc.FrequencySet) CommonTreeNodeStream(org.antlr.runtime.tree.CommonTreeNodeStream)

Aggregations

FrequencySet (org.antlr.v4.misc.FrequencySet)4 ArrayList (java.util.ArrayList)2 HashSet (java.util.HashSet)2 LinkedHashSet (java.util.LinkedHashSet)2 Map (java.util.Map)2 RecognitionException (org.antlr.runtime.RecognitionException)2 CommonTreeNodeStream (org.antlr.runtime.tree.CommonTreeNodeStream)2 AltLabelStructDecl (org.antlr.v4.codegen.model.decl.AltLabelStructDecl)2 AttributeDecl (org.antlr.v4.codegen.model.decl.AttributeDecl)2 ContextRuleGetterDecl (org.antlr.v4.codegen.model.decl.ContextRuleGetterDecl)2 ContextRuleListGetterDecl (org.antlr.v4.codegen.model.decl.ContextRuleListGetterDecl)2 ContextRuleListIndexedGetterDecl (org.antlr.v4.codegen.model.decl.ContextRuleListIndexedGetterDecl)2 ContextTokenGetterDecl (org.antlr.v4.codegen.model.decl.ContextTokenGetterDecl)2 ContextTokenListGetterDecl (org.antlr.v4.codegen.model.decl.ContextTokenListGetterDecl)2 ContextTokenListIndexedGetterDecl (org.antlr.v4.codegen.model.decl.ContextTokenListIndexedGetterDecl)2 Decl (org.antlr.v4.codegen.model.decl.Decl)2 StructDecl (org.antlr.v4.codegen.model.decl.StructDecl)2 MutableInt (org.antlr.v4.misc.MutableInt)2 GrammarASTAdaptor (org.antlr.v4.parse.GrammarASTAdaptor)2 IntervalSet (org.antlr.v4.runtime.misc.IntervalSet)2