Search in sources :

Example 86 with IntervalSet

use of org.antlr.v4.runtime.misc.IntervalSet in project antlr4 by antlr.

the class UnicodeDataTemplateController method addEmojiPresentationPropertyCodesToCodePointRanges.

private static void addEmojiPresentationPropertyCodesToCodePointRanges(Map<String, IntervalSet> propertyCodePointRanges) {
    UnicodeSet emojiDefaultUnicodeSet = new UnicodeSet("[[\\p{Emoji=Yes}]&[\\p{Emoji_Presentation=Yes}]]");
    IntervalSet emojiDefaultIntervalSet = new IntervalSet();
    addUnicodeSetToIntervalSet(emojiDefaultUnicodeSet, emojiDefaultIntervalSet);
    propertyCodePointRanges.put("EmojiPresentation=EmojiDefault", emojiDefaultIntervalSet);
    UnicodeSet textDefaultUnicodeSet = new UnicodeSet("[[\\p{Emoji=Yes}]&[\\p{Emoji_Presentation=No}]]");
    IntervalSet textDefaultIntervalSet = new IntervalSet();
    addUnicodeSetToIntervalSet(textDefaultUnicodeSet, textDefaultIntervalSet);
    propertyCodePointRanges.put("EmojiPresentation=TextDefault", textDefaultIntervalSet);
    UnicodeSet textUnicodeSet = new UnicodeSet("[\\p{Emoji=No}]");
    IntervalSet textIntervalSet = new IntervalSet();
    addUnicodeSetToIntervalSet(textUnicodeSet, textIntervalSet);
    propertyCodePointRanges.put("EmojiPresentation=Text", textIntervalSet);
}
Also used : IntervalSet(org.antlr.v4.runtime.misc.IntervalSet) UnicodeSet(com.ibm.icu.text.UnicodeSet)

Example 87 with IntervalSet

use of org.antlr.v4.runtime.misc.IntervalSet in project antlr4 by antlr.

the class CharSupport method getIntervalSetEscapedString.

public static String getIntervalSetEscapedString(IntervalSet intervalSet) {
    StringBuilder buf = new StringBuilder();
    Iterator<Interval> iter = intervalSet.getIntervals().iterator();
    while (iter.hasNext()) {
        Interval interval = iter.next();
        buf.append(getRangeEscapedString(interval.a, interval.b));
        if (iter.hasNext()) {
            buf.append(" | ");
        }
    }
    return buf.toString();
}
Also used : Interval(org.antlr.v4.runtime.misc.Interval)

Example 88 with IntervalSet

use of org.antlr.v4.runtime.misc.IntervalSet in project antlr4 by antlr.

the class CodeGenPipeline method process.

public void process() {
    if (!CodeGenerator.targetExists(g.getOptionString("language")))
        return;
    CodeGenerator gen = new CodeGenerator(g);
    IntervalSet idTypes = new IntervalSet();
    idTypes.add(ANTLRParser.ID);
    idTypes.add(ANTLRParser.RULE_REF);
    idTypes.add(ANTLRParser.TOKEN_REF);
    List<GrammarAST> idNodes = g.ast.getNodesWithType(idTypes);
    for (GrammarAST idNode : idNodes) {
        if (gen.getTarget().grammarSymbolCausesIssueInGeneratedCode(idNode)) {
            g.tool.errMgr.grammarError(ErrorType.USE_OF_BAD_WORD, g.fileName, idNode.getToken(), idNode.getText());
        }
    }
    // all templates are generated in memory to report the most complete
    // error information possible, but actually writing output files stops
    // after the first error is reported
    int errorCount = g.tool.errMgr.getNumErrors();
    if (g.isLexer()) {
        if (gen.getTarget().needsHeader()) {
            // Header file if needed.
            ST lexer = gen.generateLexer(true);
            if (g.tool.errMgr.getNumErrors() == errorCount) {
                writeRecognizer(lexer, gen, true);
            }
        }
        ST lexer = gen.generateLexer(false);
        if (g.tool.errMgr.getNumErrors() == errorCount) {
            writeRecognizer(lexer, gen, false);
        }
    } else {
        if (gen.getTarget().needsHeader()) {
            ST parser = gen.generateParser(true);
            if (g.tool.errMgr.getNumErrors() == errorCount) {
                writeRecognizer(parser, gen, true);
            }
        }
        ST parser = gen.generateParser(false);
        if (g.tool.errMgr.getNumErrors() == errorCount) {
            writeRecognizer(parser, gen, false);
        }
        if (g.tool.gen_listener) {
            if (gen.getTarget().needsHeader()) {
                ST listener = gen.generateListener(true);
                if (g.tool.errMgr.getNumErrors() == errorCount) {
                    gen.writeListener(listener, true);
                }
            }
            ST listener = gen.generateListener(false);
            if (g.tool.errMgr.getNumErrors() == errorCount) {
                gen.writeListener(listener, false);
            }
            if (gen.getTarget().needsHeader()) {
                ST baseListener = gen.generateBaseListener(true);
                if (g.tool.errMgr.getNumErrors() == errorCount) {
                    gen.writeBaseListener(baseListener, true);
                }
            }
            if (gen.getTarget().wantsBaseListener()) {
                ST baseListener = gen.generateBaseListener(false);
                if (g.tool.errMgr.getNumErrors() == errorCount) {
                    gen.writeBaseListener(baseListener, false);
                }
            }
        }
        if (g.tool.gen_visitor) {
            if (gen.getTarget().needsHeader()) {
                ST visitor = gen.generateVisitor(true);
                if (g.tool.errMgr.getNumErrors() == errorCount) {
                    gen.writeVisitor(visitor, true);
                }
            }
            ST visitor = gen.generateVisitor(false);
            if (g.tool.errMgr.getNumErrors() == errorCount) {
                gen.writeVisitor(visitor, false);
            }
            if (gen.getTarget().needsHeader()) {
                ST baseVisitor = gen.generateBaseVisitor(true);
                if (g.tool.errMgr.getNumErrors() == errorCount) {
                    gen.writeBaseVisitor(baseVisitor, true);
                }
            }
            if (gen.getTarget().wantsBaseVisitor()) {
                ST baseVisitor = gen.generateBaseVisitor(false);
                if (g.tool.errMgr.getNumErrors() == errorCount) {
                    gen.writeBaseVisitor(baseVisitor, false);
                }
            }
        }
    }
    gen.writeVocabFile();
}
Also used : ST(org.stringtemplate.v4.ST) GrammarAST(org.antlr.v4.tool.ast.GrammarAST) IntervalSet(org.antlr.v4.runtime.misc.IntervalSet) GrammarAST(org.antlr.v4.tool.ast.GrammarAST)

Aggregations

IntervalSet (org.antlr.v4.runtime.misc.IntervalSet)84 Test (org.junit.Test)48 ATNState (org.antlr.v4.runtime.atn.ATNState)11 GrammarAST (org.antlr.v4.tool.ast.GrammarAST)10 ATN (org.antlr.v4.runtime.atn.ATN)8 ArrayList (java.util.ArrayList)7 Grammar (org.antlr.v4.tool.Grammar)7 Interval (org.antlr.v4.runtime.misc.Interval)6 SetTransition (org.antlr.v4.runtime.atn.SetTransition)5 UnicodeSet (com.ibm.icu.text.UnicodeSet)4 HashMap (java.util.HashMap)4 Token (org.antlr.runtime.Token)4 NotSetTransition (org.antlr.v4.runtime.atn.NotSetTransition)4 BaseJavaTest (org.antlr.v4.test.runtime.java.BaseJavaTest)4 LinkedHashMap (java.util.LinkedHashMap)3 ParserRuleContext (org.antlr.v4.runtime.ParserRuleContext)3 AtomTransition (org.antlr.v4.runtime.atn.AtomTransition)3 DecisionState (org.antlr.v4.runtime.atn.DecisionState)3 RuleTransition (org.antlr.v4.runtime.atn.RuleTransition)3 Transition (org.antlr.v4.runtime.atn.Transition)3