Search in sources :

Example 6 with StringBuilderVar

use of org.parboiled.support.StringBuilderVar in project pegdown by sirthias.

the class Parser method ListItem.

@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)), TestNotItem(), 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')))), ZeroOrMore(//                        debugMsg("have a " + (tight.get() ? "tight" : "loose") + " list body at " + getContext().getCurrentIndex(), block.getString()),
    push(getContext().getCurrentIndex()), // it must be left for it to determine its own looseness. Much safer to just test for it but not consume it.
    FirstOf(Sequence(Test(BlankLine()), tight.set(false)), tight.set(true)), ListItemIndentedBlocks(block), // in a ParaNode to have its looseness properly reflected.
    (tight.get() ? push(parseListBlock(block)) : ((!ext(FORCELISTITEMPARA)) || tightFirstItem.isNotSet() || wrapFirstItemInPara(tightFirstItem.get())) && push(wrapFirstSubItemInPara((SuperNode) parseListBlock(block.appended('\n'))))) && addAsChild()), setListItemIndices());
}
Also used : StringBuilderVar(org.parboiled.support.StringBuilderVar) Var(org.parboiled.support.Var) StringVar(org.parboiled.support.StringVar) StringBuilderVar(org.parboiled.support.StringBuilderVar)

Example 7 with StringBuilderVar

use of org.parboiled.support.StringBuilderVar in project pegdown by sirthias.

the class Parser method FencedCodeBlock.

public Rule FencedCodeBlock() {
    StringBuilderVar text = new StringBuilderVar();
    Var<Integer> markerLength = new Var<Integer>();
    return NodeSequence(CodeFence(markerLength), // prevent empty matches
    TestNot(CodeFence(markerLength)), 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());
}
Also used : StringBuilderVar(org.parboiled.support.StringBuilderVar) Var(org.parboiled.support.Var) StringVar(org.parboiled.support.StringVar) StringBuilderVar(org.parboiled.support.StringBuilderVar)

Aggregations

StringBuilderVar (org.parboiled.support.StringBuilderVar)7 StringVar (org.parboiled.support.StringVar)3 Var (org.parboiled.support.Var)3 ExpImageNode (org.pegdown.ast.ExpImageNode)2 TextNode (org.pegdown.ast.TextNode)2 StringUtils.defaultString (org.apache.commons.lang3.StringUtils.defaultString)1