Search in sources :

Example 1 with StringBuilderVar

use of org.parboiled.support.StringBuilderVar in project zeppelin by apache.

the class PegdownWebSequencelPlugin method BlockRule.

Rule BlockRule() {
    StringBuilderVar style = new StringBuilderVar();
    StringBuilderVar body = new StringBuilderVar();
    return NodeSequence(StartMarker(), Optional(String("style="), Sequence(OneOrMore(Letter()), style.append(match()), Spn1())), Sequence(Body(), body.append(match())), EndMarker(), push(new ExpImageNode("title", createWebsequenceUrl(style.getString(), body.getString()), new TextNode(""))));
}
Also used : StringBuilderVar(org.parboiled.support.StringBuilderVar) TextNode(org.pegdown.ast.TextNode) ExpImageNode(org.pegdown.ast.ExpImageNode)

Example 2 with StringBuilderVar

use of org.parboiled.support.StringBuilderVar in project zeppelin by apache.

the class PegdownYumlPlugin method BlockRule.

Rule BlockRule() {
    ParamVar<String, String> params = new ParamVar<String, String>();
    StringBuilderVar name = new StringBuilderVar();
    StringBuilderVar value = new StringBuilderVar();
    StringBuilderVar body = new StringBuilderVar();
    return NodeSequence(StartMarker(), ZeroOrMore(Sequence(ParameterName(), name.append(match()), String("="), OneOrMore(Alphanumeric()), value.append(match())), Sp(), params.put(name.getString(), value.getString()), name.clear(), value.clear()), Body(), body.append(match()), EndMarker(), push(new ExpImageNode("title", createYumlUrl(params.get(), body.getString()), new TextNode(""))));
}
Also used : StringBuilderVar(org.parboiled.support.StringBuilderVar) TextNode(org.pegdown.ast.TextNode) StringUtils.defaultString(org.apache.commons.lang3.StringUtils.defaultString) ExpImageNode(org.pegdown.ast.ExpImageNode)

Example 3 with StringBuilderVar

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

the class Parser method TaskListItem.

// vsch: #185 This handles the optional extension TASKLISTITEMS to parse and generate GFM task list styled items. These are
// bullet items: * [ ] or * [x] , the space after the ] is not optional.
@Cached
public Rule TaskListItem(Rule itemStart, SuperNodeTaskItemCreator 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 taskListMarker = new StringBuilderVar();
    StringBuilderVar temp = new StringBuilderVar();
    Var<Boolean> tight = new Var<Boolean>(false);
    Var<Integer> taskType = new Var<Integer>(0);
    Var<SuperNode> tightFirstItem = new Var<SuperNode>();
    return Sequence(push(getContext().getCurrentIndex()), FirstOf(CrossedOut(BlankLine(), block), tight.set(true)), CrossedOut(itemStart, block), Optional(CrossedOut(Sequence(FirstOf(Sequence("[ ]", taskType.set(1)), Sequence(FirstOf("[x]", "[X]"), taskType.set(2))), OneOrMore(Spacechar())), taskListMarker)), block.append(taskListMarker.getString()), Line(block), //                debugMsg("have a " + taskType.get() + " task list body", block.getString()),
    ZeroOrMore(Optional(CrossedOut(Indent(), temp)), TestNotItem(), Line(temp), block.append(temp.getString()) && temp.clearContents()), tight.get() ? push(tightFirstItem.setAndGet(itemNodeCreator.create(parseListBlock(block), taskType.get(), taskListMarker.getString()))) && taskListMarker.clearContents() : fixFirstItem((SuperNode) peek(1)) && push(itemNodeCreator.create(parseListBlock(block.appended('\n')), taskType.get(), taskListMarker.getString())) && taskListMarker.clearContents(), 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 4 with StringBuilderVar

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

the class Parser method BlockQuote.

// vsch: #184 modified to only include trailing blank lines if there are more blocks for the blockquote following
// otherwise don't include the blank lines, they are not part of the block quote
public Rule BlockQuote() {
    StringBuilderVar inner = new StringBuilderVar();
    StringBuilderVar optional = new StringBuilderVar();
    return NodeSequence(OneOrMore(CrossedOut(Sequence('>', Optional(' ')), inner), Line(inner), ZeroOrMore(TestNot('>'), TestNot(BlankLine()), Line(inner)), //                        ZeroOrMore(BlankLine()), inner.append(match())
    Optional(Sequence(OneOrMore(BlankLine()), optional.append(match()), Test('>')), inner.append(optional.getString()) && optional.clearContents())), // take care of that possibility, now that we don't include blank lines after a block quote we add one extra
    inner.append("\n\n"), // and attach the root of the inner parses AST
    push(new BlockQuoteNode(withIndicesShifted(parseInternal(inner), (Integer) peek()).getChildren())));
}
Also used : StringBuilderVar(org.parboiled.support.StringBuilderVar)

Example 5 with StringBuilderVar

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

the class Parser method Verbatim.

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())));
}
Also used : 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