Module: Hemingway::Math

Includes:
Treetop::Runtime
Included in:
Latex, MathParser
Defined in:
lib/hemingway/math/math.rb

Defined Under Namespace

Modules: Exponent0, Math0

Instance Method Summary collapse

Instance Method Details

#_nt_exponentObject



100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
# File 'lib/hemingway/math/math.rb', line 100

def _nt_exponent
  start_index = index
  if node_cache[:exponent].has_key?(index)
    cached = node_cache[:exponent][index]
    if cached
      cached = SyntaxNode.new(input, index...(index + 1)) if cached == true
      @index = cached.interval.end
    end
    return cached
  end

  i0, s0 = index, []
  if has_terminal?("^{", false, index)
    r1 = instantiate_node(SyntaxNode,input, index...(index + 2))
    @index += 2
  else
    terminal_parse_failure("^{")
    r1 = nil
  end
  s0 << r1
  if r1
    i2 = index
    if has_terminal?("\\circ", false, index)
      r3 = instantiate_node(SyntaxNode,input, index...(index + 5))
      @index += 5
    else
      terminal_parse_failure("\\circ")
      r3 = nil
    end
    if r3
      r2 = r3
    else
      r4 = _nt_text
      if r4
        r2 = r4
      else
        @index = i2
        r2 = nil
      end
    end
    s0 << r2
    if r2
      if has_terminal?("}", false, index)
        r5 = instantiate_node(SyntaxNode,input, index...(index + 1))
        @index += 1
      else
        terminal_parse_failure("}")
        r5 = nil
      end
      s0 << r5
    end
  end
  if s0.last
    r0 = instantiate_node(ExponentNode,input, i0...index, s0)
    r0.extend(Exponent0)
  else
    @index = i0
    r0 = nil
  end

  node_cache[:exponent][start_index] = r0

  r0
end

#_nt_mathObject



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
69
70
71
72
73
# File 'lib/hemingway/math/math.rb', line 28

def _nt_math
  start_index = index
  if node_cache[:math].has_key?(index)
    cached = node_cache[:math][index]
    if cached
      cached = SyntaxNode.new(input, index...(index + 1)) if cached == true
      @index = cached.interval.end
    end
    return cached
  end

  i0, s0 = index, []
  r1 = _nt_math_start
  s0 << r1
  if r1
    i2 = index
    r3 = _nt_symbol
    if r3
      r2 = r3
    else
      r4 = _nt_exponent
      if r4
        r2 = r4
      else
        @index = i2
        r2 = nil
      end
    end
    s0 << r2
    if r2
      r5 = _nt_math_end
      s0 << r5
    end
  end
  if s0.last
    r0 = instantiate_node(MathNode,input, i0...index, s0)
    r0.extend(Math0)
  else
    @index = i0
    r0 = nil
  end

  node_cache[:math][start_index] = r0

  r0
end

#_nt_math_endObject



189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
# File 'lib/hemingway/math/math.rb', line 189

def _nt_math_end
  start_index = index
  if node_cache[:math_end].has_key?(index)
    cached = node_cache[:math_end][index]
    if cached
      cached = SyntaxNode.new(input, index...(index + 1)) if cached == true
      @index = cached.interval.end
    end
    return cached
  end

  if has_terminal?("$", false, index)
    r0 = instantiate_node(SyntaxNode,input, index...(index + 1))
    @index += 1
  else
    terminal_parse_failure("$")
    r0 = nil
  end

  node_cache[:math_end][start_index] = r0

  r0
end

#_nt_math_startObject



165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
# File 'lib/hemingway/math/math.rb', line 165

def _nt_math_start
  start_index = index
  if node_cache[:math_start].has_key?(index)
    cached = node_cache[:math_start][index]
    if cached
      cached = SyntaxNode.new(input, index...(index + 1)) if cached == true
      @index = cached.interval.end
    end
    return cached
  end

  if has_terminal?("$", false, index)
    r0 = instantiate_node(SyntaxNode,input, index...(index + 1))
    @index += 1
  else
    terminal_parse_failure("$")
    r0 = nil
  end

  node_cache[:math_start][start_index] = r0

  r0
end

#_nt_symbolObject



75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
# File 'lib/hemingway/math/math.rb', line 75

def _nt_symbol
  start_index = index
  if node_cache[:symbol].has_key?(index)
    cached = node_cache[:symbol][index]
    if cached
      cached = SyntaxNode.new(input, index...(index + 1)) if cached == true
      @index = cached.interval.end
    end
    return cached
  end

  r0 = _nt_math_symbol

  node_cache[:symbol][start_index] = r0

  r0
end

#rootObject



10
11
12
# File 'lib/hemingway/math/math.rb', line 10

def root
  @root ||= :math
end