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), ), 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( FirstOf(Sequence(Test(BlankLine()), tight.set(false)), tight.set(true)), ListItemIndentedBlocks(block), (tight.get() ? push(parseListBlock(block)) : ((!ext(FORCELISTITEMPARA)) || tightFirstItem.isNotSet() || wrapFirstItemInPara(tightFirstItem.get())) && push(wrapFirstSubItemInPara((SuperNode) parseListBlock(block.appended('\n')))) ) && addAsChild()
@Cached public Rule CodeFence(Var<Integer> markerLength) { return Sequence( FirstOf(NOrMore('~', 3), NOrMore('`', 3)), (markerLength.isSet() && matchLength() == markerLength.get()) || (markerLength.isNotSet() && markerLength.set(matchLength())), Sp(), ZeroOrMore(TestNot(Newline()), ANY), // GFM code type identifier push(match()), Newline() ); }
Rule containsAll() { Var<List<ConditionValue>> elems = new Var<List<ConditionValue>>(new LinkedList<ConditionValue>()); return Sequence(field(), push(match()), space(), EQUALS, space(), SQUARE_BRACKET_OPEN, space(), value(), elems.get().add((ConditionValue)pop()), space(), ZeroOrMore(COMMA, space(), value(), elems.get().add((ConditionValue)pop()), space()), SQUARE_BRACKET_CLOSE, push(new ContainsAll(toElement(pop().toString()), elems.get()))); } Rule containsOne() {
public Rule RefSrcContent(Var<ReferenceNode> ref) { return Sequence(OneOrMore(TestNot('>'), Nonspacechar()), ref.get().setUrl(match())); }
/** * Exits a frame previously entered with {@link #enterFrame()}. * Normally you do not have to call this method manually as parboiled provides for automatic Var frame management. * * @return true */ public boolean exitFrame() { if (--level > 0) { set(stack.removeLast()); } return true; }
/** * Provides a new frame for the variable. * Potentially existing previous frames are saved. * Normally you do not have to call this method manually as parboiled provides for automatic Var frame management. * * @return true */ public boolean enterFrame() { if (level++ > 0) { if (stack == null) stack = new LinkedList<T>(); stack.add(get()); } return set(initialValueFactory.create()); }
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() ); }
public <V> boolean match(MatcherContext<V> context) { for (Var var : variables) { var.enterFrame(); } boolean matched = inner.match(context); for (Var var : variables) { var.exitFrame(); } return matched; }
Rule containsOne() { Var<List<ConditionValue>> elems = new Var<List<ConditionValue>>(new LinkedList<ConditionValue>()); return Sequence(field(), push(match()), space(), EQUALS, space(), CURLY_BRACKET_OPEN, space(), value(), elems.get().add((ConditionValue)pop()), space(), ZeroOrMore(COMMA, space(), value(), elems.get().add((ConditionValue)pop()), space()), CURLY_BRACKET_CLOSE, push(new ContainsOne(toElement(pop().toString()), elems.get()))); } Rule select() {
public Rule ReferenceNoEOL() { Var<ReferenceNode> ref = new Var<ReferenceNode>(); return NodeSequence( NonindentSpace(), Label(), push(ref.setAndGet(new ReferenceNode(popAsNode()))), ':', Spn1(), RefSrc(ref), Sp(), Optional(RefTitle(ref)), Sp(), // make range not include the EOL Test(Newline()), references.add(ref.get()) ); }
public Rule RefTitle(char open, char close, Var<ReferenceNode> ref) { return Sequence( open, ZeroOrMore(TestNot(close, Sp(), Newline()), NotNewline(), ANY), ref.get().setTitle(match()), close ); }
@Label("string") Rule string(final Var<Object> value) { return Sequence(stringLiteral(), value.set(match().replace("\\\"", "\""))); }
@Label("parameter::hash") Rule paramOrHash(final List<Object> params, final Map<String, Object> hash) { final Var<Object> var = new Var<Object>(); return ZeroOrMore(FirstOf( Sequence(hash(hash), spacing()), Sequence(param(var), spacing(), new Action<BaseTemplate>() { @Override public boolean run(final Context<BaseTemplate> context) { if (!hash.isEmpty()) { noffset = var.get().toString().length(); throw new ActionException("'" + var.get() + "' is out of order, a 'hash' was found previously"); } return true; } }, add(params, var.get())))); }
public Rule TableColumn(Var<TableNode> tableNode, Var<Boolean> pipeSeen) { Var<TableColumnNode> node = new Var<TableColumnNode>(new TableColumnNode()); return Sequence( NodeSequence( push(node.get()), Sp(), Optional(':', node.get().markLeftAligned()), Sp(), OneOrMore('-'), Sp(), Optional(':', node.get().markRightAligned()), Sp(), Optional('|', pipeSeen.set(Boolean.TRUE)) ), tableNode.get().addColumn((TableColumnNode) pop()) ); }
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( ), tight.get() ? push(tightFirstItem.setAndGet(itemNodeCreator.create(parseListBlock(block)))) : fixFirstItem((SuperNode) peek(1)) && push(itemNodeCreator.create(parseListBlock(block.appended('\n')))), FirstOf(Sequence(Test(BlankLine()), tight.set(false)), tight.set(true)), ListItemIndentedBlocks(block), (tight.get() ? push(parseListBlock(block)) : ((!ext(FORCELISTITEMPARA)) || tightFirstItem.isNotSet() || wrapFirstItemInPara(tightFirstItem.get())) && push(wrapFirstSubItemInPara((SuperNode) parseListBlock(block.appended('\n')))) ) && addAsChild()
public Rule Table() { Var<TableNode> node = new Var<TableNode>(); return NodeSequence( push(node.setAndGet(new TableNode())), Optional( NodeSequence( TableRow(), push(1, new TableHeaderNode()) && addAsChild(), ZeroOrMore(TableRow(), addAsChild()) ), addAsChild() // add the TableHeaderNode to the TableNode ), TableDivider(node), Optional( NodeSequence( TableRow(), push(1, new TableBodyNode()) && addAsChild(), ZeroOrMore(TableRow(), addAsChild()) ), addAsChild() // add the TableHeaderNode to the TableNode ), // only accept as table if we have at least one header or at least one body Optional(TableCaption(), addAsChild()), !node.get().getChildren().isEmpty() ); }
public Rule AbbreviationText(Var<AbbreviationNode> node) { return Sequence( NodeSequence( push(new SuperNode()), ZeroOrMore(NotNewline(), Inline(), addAsChild()) ), node.get().setExpansion(popAsNode()) ); }