Class: ARST::Parser

Inherits:
Parslet::Parser
  • Object
show all
Defined in:
lib/arst/parser.rb

Overview

The parser for ARST.

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.parse(input, options = {}) ⇒ Object



9
10
11
# File 'lib/arst/parser.rb', line 9

def self.parse(input, options={})
  new.parse(input, options)
end

Instance Method Details

#indent(depth) ⇒ Object



19
20
21
# File 'lib/arst/parser.rb', line 19

def indent(depth)
  str('  ' * depth)
end

#node(depth) ⇒ Object



48
49
50
51
52
53
54
55
56
# File 'lib/arst/parser.rb', line 48

def node(depth)
  indent(depth) >> 
  (
    ( class_keyword | module_keyword ) >> newline.maybe >>
    dynamic { |soutce, context| node(depth+1).repeat(0) }.as(:children) |
    ( include_keyword | extend_keyword ) >> newline.maybe |
    newline
  )
end

#parse(input, options = {}) ⇒ Object



13
14
15
16
17
# File 'lib/arst/parser.rb', line 13

def parse(input, options={})
  tree = super(input)
  
  options[:raw] ? tree : Node::Root.new(tree)
end