Class: Luaof::Parser

Inherits:
Object
  • Object
show all
Defined in:
lib/luaof/parser.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeParser

Returns a new instance of Parser.



9
10
11
12
13
# File 'lib/luaof/parser.rb', line 9

def initialize
  @document = []
  @stack = []
  @labels = {}
end

Instance Attribute Details

#documentObject (readonly)

Returns the value of attribute document.



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

def document
  @document
end

Instance Method Details

#parse_api_indicator!Object



82
83
84
# File 'lib/luaof/parser.rb', line 82

def parse_api_indicator!
  @document.each(&:parse_api_indicator!)
end

#parse_section!Object



70
71
72
# File 'lib/luaof/parser.rb', line 70

def parse_section!
  @document.each(&:parse_section!)
end

#push(token) ⇒ Object



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# File 'lib/luaof/parser.rb', line 15

def push(token)
  case token
  in { tag: :sect1 | :sect2 | :sect3 | :sect4 => tag }
    @stack.unshift(Node.new({ **token, tag: :section,
                              level: Integer(tag.to_s.match(/ sect (\d) /x)[1]) }, @labels))
  in { tag: _ } | :leftbrace
    @stack.unshift(Node.new(token, @labels))
  in { pipe: }
    case @stack
    in { label: { tag: (:item | :link | :APIEntry | :LibEntry | :section) } => label,
         children: } => function, *_
      label[:param] and raise
      label[:param] = children
      function.children = []
    else
      @stack.first.children << pipe
    end
  in String | { keyword: _ }
    case @stack
    in Node => node, *_
      node.children << token
    end
  in :closer
    case @stack
    in Node[label: { tag: :C | :Ci }], *_
      @stack.shift
    in Node[label: :leftbrace] => child, Node => parent, *_
      parent.children << @stack.shift
    in [Node => child, Node => parent, *_]
      child.children.pop while child.children.last in :emptyline | :linebreak
      parent.children << @stack.shift
    in [Node[label: { tag: :manual }], *_]
      @document << @stack.shift
    end
  in :emptyline
    case @stack
    in Node[children: [*_, :linebreak | :emptyline]] => node, *_
      node.children[-1] = token
    in Node[children: [] | [*_, Node[label: { tag: :title }]]], *_
    # nop
    in Node => node, *_
      node.children << token
    end
  in :linebreak
    case @stack
    in [Node[label: :leftbrace] => node, *_]
      node.children << token
    in [] | [Node[children: [] | [*_, Node[label: { tag: :title }] | :emptyline]], *_]
    # nop
    in Node => node, *_
      node.children << token
    end
  end
end

#register_mapping!Object



74
75
76
# File 'lib/luaof/parser.rb', line 74

def register_mapping!
  @document.each(&:register_mapping!)
end

#register_refs!Object



78
79
80
# File 'lib/luaof/parser.rb', line 78

def register_refs!
  @document.each(&:register_refs!)
end