public Rule Abbreviation() { Var<AbbreviationNode> node = new Var<AbbreviationNode>(); return NodeSequence( NonindentSpace(), '*', Label(), push(node.setAndGet(new AbbreviationNode(popAsNode()))), Sp(), ':', Sp(), AbbreviationText(node), abbreviations.add(node.get()) ); }
public Rule TableDivider(Var<TableNode> tableNode) { Var<Boolean> pipeSeen = new Var<Boolean>(Boolean.FALSE); return Sequence( Optional('|', pipeSeen.set(Boolean.TRUE)), OneOrMore(TableColumn(tableNode, pipeSeen)), pipeSeen.get() || tableNode.get().hasTwoOrMoreDividers(), Sp(), Newline() ); }
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 TableRow() { Var<Boolean> leadingPipe = new Var<Boolean>(Boolean.FALSE); return NodeSequence( push(new TableRowNode()), Optional('|', leadingPipe.set(Boolean.TRUE)), OneOrMore(TableCell(), addAsChild()), leadingPipe.get() || ((Node) peek()).getChildren().size() > 1 || getContext().getInputBuffer().charAt(matchEnd() - 1) == '|', Sp(), Newline() ); }
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 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()) ); }
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() ); }
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()),
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() {
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() {
Rule fieldFunction() { Var<String> alias = new Var<String>(); return Sequence(field(), push(toElement(match())), Optional(alias(alias)), push(new FunctionFieldValue(alias.get(), pop().toString()))); }
@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())))); }
Rule stringFunction() { Var<String> alias = new Var<String>(); return Sequence(valueText(), Optional(alias(alias)), push(new FunctionValue(alias.get(), ((ConditionValueString)pop()).getValue() ))); }
Rule function() { Var<String> alias = new Var<String>(); return Sequence(OneOrMore(FirstOf(field(), AnyOf("#"))), push(match()), BRACKET_OPEN, push(new LinkedList()), Optional(functionOrFieldOrString(), ZeroOrMore(COMMA, functionOrFieldOrString())), BRACKET_CLOSE, Optional(alias(alias)), push(WikittyQueryFunction.create(pop(1).toString(), alias.get(), (List)pop()))); }
@Label("parameter::hash") Rule hash(final Map<String, Object> hash) { final StringVar name = new StringVar(); final Var<Object> value = new Var<Object>(); return Sequence( qualifiedId(), name.set(match()), spacing(), '=', spacing(), Sequence(param(value), add(hash, name.get(), value.get()))); }
/** * Term definition. * * @return Term definition rule. */ public Rule term() { Var<Character> op = new Var<>(); return Sequence(factor(), ZeroOrMore(ZeroOrMore(whitespace()), FirstOf("*", "/"), op.set(matchedChar()), ZeroOrMore(whitespace()), factor(), push(createMultiplicationOrDivisionRateGenerator(op.get())))); }
/** * Rate generator definition. * * @return rate generator definition rule. */ public Rule rateGenerator() { Var<Character> op = new Var<>(); return Sequence(term(), ZeroOrMore(ZeroOrMore(whitespace()), FirstOf("+", "-"), op.set(matchedChar()), ZeroOrMore(whitespace()), term(), push(createAdditionOrSubtractionRateGenerator(op.get())))); }
/** * Rate generator definition. * * @return rate generator definition rule. */ public Rule rateGenerator() { Var<Character> op = new Var<>(); return Sequence(term(), ZeroOrMore(ZeroOrMore(whitespace()), FirstOf("+", "-"), op.set(matchedChar()), ZeroOrMore(whitespace()), term(), push(createAdditionOrSubtractionRateGenerator(op.get())))); }
/** * Term definition. * * @return Term definition rule. */ public Rule term() { Var<Character> op = new Var<>(); return Sequence(factor(), ZeroOrMore(ZeroOrMore(whitespace()), FirstOf("*", "/"), op.set(matchedChar()), ZeroOrMore(whitespace()), factor(), push(createMultiplicationOrDivisionRateGenerator(op.get())))); }