Package org.parboiled.support

Examples of org.parboiled.support.StringBuilderVar


            close
        );
    }

    public Rule FencedCodeBlock() {
        StringBuilderVar text = new StringBuilderVar();
        Var<Integer> markerLength = new Var<>();
        return NodeSequence(
            CodeFence(markerLength),
            TestNot(CodeFence(markerLength)), // prevent empty matches
            ZeroOrMore(BlankLine(), text.append('\n')),
            OneOrMore(TestNot(Newline(), CodeFence(markerLength)), ANY, text.append(matchedChar())),
            Newline(),
            push(new GaidenVerbatimNode(text.appended('\n').getString(), (SpecialAttributesNode) pop())),
            CodeFence(markerLength), drop()
        );
    }
View Full Code Here


        );
    }

    @Cached
    public Rule LinkSource() {
        StringBuilderVar url = new StringBuilderVar();
        return FirstOf(
                Sequence('(', LinkSource(), ')'),
                Sequence('<', LinkSource(), '>'),
                Sequence(
                        OneOrMore(
                                FirstOf(
                                        Sequence('\\', AnyOf("()"), url.append(matchedChar())),
                                        Sequence(TestNot(AnyOf("()>")), Nonspacechar(), url.append(matchedChar()))
                                )
                        ),
                        push(url.getString())
                ),
                push("")
        );
    }
View Full Code Here

    public Rule[] inlinePluginRules() {
        return new Rule[] {InlinePlugin()};
    }

    public Rule InlinePlugin() {
        StringBuilderVar text = new StringBuilderVar();
        return NodeSequence(
                Ch('%'),
                OneOrMore(TestNot(Ch('%')), BaseParser.ANY, text.append(matchedChar())),
                push(new InlinePluginNode(text.getString())),
                Ch('%')
        );
    }
View Full Code Here

                Ch('%')
        );
    }

    public Rule BlockPlugin() {
        StringBuilderVar text = new StringBuilderVar();
        return NodeSequence(
                BlockPluginMarker(),
                OneOrMore(TestNot(Newline(), BlockPluginMarker()), BaseParser.ANY, text.append(matchedChar())),
                Newline(),
                push(new BlockPluginNode(text.appended('\n').getString())),
                BlockPluginMarker()
        );
    }
View Full Code Here

                NonindentSpace(), Inlines(), push(new ParaNode(popAsNode())), OneOrMore(BlankLine())
        );
    }

    public Rule BlockQuote() {
        StringBuilderVar inner = new StringBuilderVar();
        return NodeSequence(
                OneOrMore(
                        CrossedOut(Sequence('>', Optional(' ')), inner), Line(inner),
                        ZeroOrMore(
                                TestNot('>'),
                                TestNot(BlankLine()),
                                Line(inner)
                        ),
                        ZeroOrMore(BlankLine(), inner.append(match()))
                ),
                // trigger a recursive parsing run on the inner source we just built
                // and attach the root of the inner parses AST
                push(new BlockQuoteNode(withIndicesShifted(parseInternal(inner), (Integer)peek()).getChildren()))
        );
View Full Code Here

                push(new BlockQuoteNode(withIndicesShifted(parseInternal(inner), (Integer)peek()).getChildren()))
        );
    }

    public Rule Verbatim() {
        StringBuilderVar text = new StringBuilderVar();
        StringBuilderVar line = new StringBuilderVar();
        return NodeSequence(
                OneOrMore(
                        ZeroOrMore(BlankLine(), line.append("\n")),
                        Indent(), push(currentIndex()),
                        OneOrMore(
                                FirstOf(
                                        Sequence('\t', line.append(repeat(' ', 4-(currentIndex()-1-(Integer)peek())%4))),
                                        Sequence(NotNewline(), ANY, line.append(matchedChar()))
                                )
                        ),
                        Newline(),
                        text.appended(line.getString()).append('\n') && line.clearContents() && drop()
                ),
                push(new VerbatimNode(text.getString()))
        );
    }
View Full Code Here

                push(new VerbatimNode(text.getString()))
        );
    }
   
    public Rule FencedCodeBlock() {
        StringBuilderVar text = new StringBuilderVar();
        Var<Integer> markerLength = new Var<Integer>();
        return NodeSequence(
                CodeFence(markerLength),
                TestNot(CodeFence(markerLength)), // prevent empty matches
                ZeroOrMore(BlankLine(), text.append('\n')),
                OneOrMore(TestNot(Newline(), CodeFence(markerLength)), ANY, text.append(matchedChar())),
                Newline(),
                push(new VerbatimNode(text.appended('\n').getString(), popAsString())),
                CodeFence(markerLength), drop()
        );
    }
View Full Code Here

    @Cached
    public Rule ListItem(Rule itemStart, SuperNodeCreator itemNodeCreator) {
        // for a simpler parser design we use a recursive parsing strategy for list items:
        // we collect a number of markdown source blocks for an item, run complete parsing cycle on these and attach
        // the roots of the inner parsing results AST to the outer AST tree
        StringBuilderVar block = new StringBuilderVar();
        StringBuilderVar temp = new StringBuilderVar();
        Var<Boolean> tight = new Var<Boolean>(false);
        Var<SuperNode> tightFirstItem = new Var<SuperNode>();
        return Sequence(
                push(getContext().getCurrentIndex()),
                FirstOf(CrossedOut(BlankLine(), block), tight.set(true)),
                CrossedOut(itemStart, block), Line(block),
                ZeroOrMore(
                        Optional(CrossedOut(Indent(), temp)),
                        NotItem(),
                        Line(temp),
                        block.append(temp.getString()) && temp.clearContents()
                ),
                tight.get() ? push(tightFirstItem.setAndGet(itemNodeCreator.create(parseListBlock(block)))) :
                        fixFirstItem((SuperNode) peek(1)) &&
                                push(itemNodeCreator.create(parseListBlock(block.appended("\n\n")))),
                ZeroOrMore(
View Full Code Here

    public Rule CrossedOut(Rule rule, StringBuilderVar block) {
        return Sequence(rule, appendCrossed(block));
    }
   
    public Rule DoubleIndentedBlocks(StringBuilderVar block) {
        StringBuilderVar line = new StringBuilderVar();
        return Sequence(
                Indent(), TestNot(BlankLine()), block.append("    "), Line(block),
                ZeroOrMore(
                        ZeroOrMore(BlankLine(), line.append(match())),
                        CrossedOut(Indent(), line), Indent(), line.append("    "), Line(line),
                        block.append(line.getString()) && line.clearContents()
                )
        );
    }
View Full Code Here

TOP

Related Classes of org.parboiled.support.StringBuilderVar

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.