class Smartdown::Parser::Rules

Public Instance Methods

children() click to toggle source
# File lib/smartdown/parser/rules.rb, line 15
def children
  dynamic do |s,c|
    current_indent = c.captures[:indent].size
    condition_with_children_or_rule(current_indent + 1).repeat(1)
  end.as(:child_rules)
end
condition_with_children(depth) click to toggle source
# File lib/smartdown/parser/rules.rb, line 22
def condition_with_children(depth)
  conditional_line(depth) >> children
end
condition_with_children_or_rule(depth) click to toggle source
# File lib/smartdown/parser/rules.rb, line 36
def condition_with_children_or_rule(depth)
  condition_with_children(depth).as(:nested_rule) | rule(depth)
end
conditional_line(depth) click to toggle source
# File lib/smartdown/parser/rules.rb, line 11
def conditional_line(depth)
  indent(depth) >> bullet >> optional_space >> Smartdown::Parser::Predicates.new.as(:predicate) >> optional_space >> line_ending
end
indent(depth) click to toggle source
# File lib/smartdown/parser/rules.rb, line 7
def indent(depth)
  str(' ').repeat(depth).capture(:indent)
end
rule(depth) click to toggle source
# File lib/smartdown/parser/rules.rb, line 26
def rule(depth)
  (
    indent(depth) >> bullet >> optional_space >>
    Smartdown::Parser::Predicates.new.as(:predicate) >> optional_space >>
    str("=>") >> optional_space >>
    question_identifier.as(:outcome) >>
    optional_space >> line_ending
  ).as(:rule)
end