Class: Smartdown::Parser::Rules

Inherits:
Base
  • Object
show all
Defined in:
lib/smartdown/parser/rules.rb

Instance Method Summary collapse

Instance Method Details

#childrenObject



15
16
17
18
19
20
# 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) ⇒ Object



22
23
24
# File 'lib/smartdown/parser/rules.rb', line 22

def condition_with_children(depth)
  conditional_line(depth) >> children
end

#condition_with_children_or_rule(depth) ⇒ Object



36
37
38
# 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) ⇒ Object



11
12
13
# 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) ⇒ Object



7
8
9
# File 'lib/smartdown/parser/rules.rb', line 7

def indent(depth)
  str(' ').repeat(depth).capture(:indent)
end

#rule(depth) ⇒ Object



26
27
28
29
30
31
32
33
34
# 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