Class: ParamsTree::Parser

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeParser

Returns a new instance of Parser.



11
12
13
14
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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
# File 'lib/params_tree/parser.rb', line 11

def initialize
  
# line 14 "/Users/razum2um/Code/params_tree/lib/params_tree/parser.rb"
class << self
  attr_accessor :_params_tree_actions
  private :_params_tree_actions, :_params_tree_actions=
end
self._params_tree_actions = [
  0, 2, 1, 7, 2, 1, 8, 3, 
  0, 1, 7, 3, 0, 1, 8, 5, 
  0, 1, 5, 2, 9, 6, 0, 1, 
  5, 2, 4, 10, 6, 0, 1, 6, 
  2, 3, 11
]

class << self
  attr_accessor :_params_tree_key_offsets
  private :_params_tree_key_offsets, :_params_tree_key_offsets=
end
self._params_tree_key_offsets = [
  0, 0, 3, 6
]

class << self
  attr_accessor :_params_tree_trans_keys
  private :_params_tree_trans_keys, :_params_tree_trans_keys=
end
self._params_tree_trans_keys = [
  40, 41, 44, 44, 40, 41, 40, 41, 
  44, 0
]

class << self
  attr_accessor :_params_tree_single_lengths
  private :_params_tree_single_lengths, :_params_tree_single_lengths=
end
self._params_tree_single_lengths = [
  0, 3, 1, 3
]

class << self
  attr_accessor :_params_tree_range_lengths
  private :_params_tree_range_lengths, :_params_tree_range_lengths=
end
self._params_tree_range_lengths = [
  0, 0, 1, 0
]

class << self
  attr_accessor :_params_tree_index_offsets
  private :_params_tree_index_offsets, :_params_tree_index_offsets=
end
self._params_tree_index_offsets = [
  0, 0, 4, 7
]

class << self
  attr_accessor :_params_tree_trans_targs
  private :_params_tree_trans_targs, :_params_tree_trans_targs=
end
self._params_tree_trans_targs = [
  2, 3, 2, 1, 0, 0, 1, 0, 
  3, 2, 1, 0
]

class << self
  attr_accessor :_params_tree_trans_actions
  private :_params_tree_trans_actions, :_params_tree_trans_actions=
end
self._params_tree_trans_actions = [
  28, 7, 15, 4, 0, 0, 11, 0, 
  1, 21, 11, 0
]

class << self
  attr_accessor :params_tree_start
end
self.params_tree_start = 2;
class << self
  attr_accessor :params_tree_first_final
end
self.params_tree_first_final = 2;
class << self
  attr_accessor :params_tree_error
end
self.params_tree_error = 0;

class << self
  attr_accessor :params_tree_en_main
end
self.params_tree_en_main = 2;


# line 30 "/Users/razum2um/Code/params_tree/lib/params_tree/parser.rl"
end

Instance Attribute Details

#dataObject

Returns the value of attribute data.



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

def data
  @data
end

Class Method Details

.parse(string) ⇒ Object



338
339
340
# File 'lib/params_tree/parser.rb', line 338

def self.parse(string)
  self.new.parse(string)
end

Instance Method Details

#charsObject



306
307
308
# File 'lib/params_tree/parser.rb', line 306

def chars
  @data[@head..@tail]
end

#inject_keyObject



326
327
328
# File 'lib/params_tree/parser.rb', line 326

def inject_key
  @hash[key] = {}
end

#keyObject



322
323
324
# File 'lib/params_tree/parser.rb', line 322

def key
  @key.pack('c*')
end

#log(token) ⇒ Object



314
315
316
# File 'lib/params_tree/parser.rb', line 314

def log(token)
  @log << { token => strokes }
end

#memo_keyObject



318
319
320
# File 'lib/params_tree/parser.rb', line 318

def memo_key
  @key = chars
end

#parse(input) ⇒ Object



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
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
# File 'lib/params_tree/parser.rb', line 107

def parse(input)
  input = input.to_s.gsub(/\s*/, '')
  return {} if input.size == 0
  @data = input.unpack('c*')
  stack = []

  @log = []
  @hash = {}
  @hash_stack = []
  @key = nil

  
# line 120 "/Users/razum2um/Code/params_tree/lib/params_tree/parser.rb"
begin
  p ||= 0
  pe ||= data.length
  cs = params_tree_start
  top = 0
end

# line 44 "/Users/razum2um/Code/params_tree/lib/params_tree/parser.rl"
  
# line 130 "/Users/razum2um/Code/params_tree/lib/params_tree/parser.rb"
begin
  _klen, _trans, _keys, _acts, _nacts = nil
  _goto_level = 0
  _resume = 10
  _eof_trans = 15
  _again = 20
  _test_eof = 30
  _out = 40
  while true
  _trigger_goto = false
  if _goto_level <= 0
  if p == pe
    _goto_level = _test_eof
    next
  end
  if cs == 0
    _goto_level = _out
    next
  end
  end
  if _goto_level <= _resume
  _keys = _params_tree_key_offsets[cs]
  _trans = _params_tree_index_offsets[cs]
  _klen = _params_tree_single_lengths[cs]
  _break_match = false
  
  begin
    if _klen > 0
  _lower = _keys
  _upper = _keys + _klen - 1

  loop do
     break if _upper < _lower
     _mid = _lower + ( (_upper - _lower) >> 1 )

     if data[p].ord < _params_tree_trans_keys[_mid]
        _upper = _mid - 1
     elsif data[p].ord > _params_tree_trans_keys[_mid]
        _lower = _mid + 1
     else
        _trans += (_mid - _keys)
        _break_match = true
        break
     end
  end # loop
  break if _break_match
  _keys += _klen
  _trans += _klen
    end
    _klen = _params_tree_range_lengths[cs]
    if _klen > 0
  _lower = _keys
  _upper = _keys + (_klen << 1) - 2
  loop do
     break if _upper < _lower
     _mid = _lower + (((_upper-_lower) >> 1) & ~1)
     if data[p].ord < _params_tree_trans_keys[_mid]
       _upper = _mid - 2
     elsif data[p].ord > _params_tree_trans_keys[_mid+1]
       _lower = _mid + 2
     else
       _trans += ((_mid - _keys) >> 1)
       _break_match = true
       break
     end
  end # loop
  break if _break_match
  _trans += _klen
    end
  end while false
  cs = _params_tree_trans_targs[_trans]
  if _params_tree_trans_actions[_trans] != 0
    _acts = _params_tree_trans_actions[_trans]
    _nacts = _params_tree_actions[_acts]
    _acts += 1
    while _nacts > 0
      _nacts -= 1
      _acts += 1
      case _params_tree_actions[_acts - 1]
when 0 then
# line 3 "/Users/razum2um/Code/params_tree/lib/params_tree/parser.rl"
    begin
 @head = p    end
when 1 then
# line 4 "/Users/razum2um/Code/params_tree/lib/params_tree/parser.rl"
    begin
 @tail = p    end
when 2 then
# line 5 "/Users/razum2um/Code/params_tree/lib/params_tree/parser.rl"
    begin
 inject_key     end
when 3 then
# line 6 "/Users/razum2um/Code/params_tree/lib/params_tree/parser.rl"
    begin
 push     end
when 4 then
# line 7 "/Users/razum2um/Code/params_tree/lib/params_tree/parser.rl"
    begin
 pop    end
when 5 then
# line 9 "/Users/razum2um/Code/params_tree/lib/params_tree/parser.rl"
    begin
 log(:delimiter)    end
when 6 then
# line 10 "/Users/razum2um/Code/params_tree/lib/params_tree/parser.rl"
    begin
 log(:level)    end
when 7 then
# line 11 "/Users/razum2um/Code/params_tree/lib/params_tree/parser.rl"
    begin
 log(:end_level);     end
when 8 then
# line 12 "/Users/razum2um/Code/params_tree/lib/params_tree/parser.rl"
    begin
 log(:input); memo_key;     end
when 9 then
# line 17 "/Users/razum2um/Code/params_tree/lib/params_tree/parser.rl"
    begin
 cs = 2;    end
when 10 then
# line 18 "/Users/razum2um/Code/params_tree/lib/params_tree/parser.rl"
    begin
  begin
    top -= 1
    cs = stack[top]
    _trigger_goto = true
    _goto_level = _again
    break
  end
    end
when 11 then
# line 19 "/Users/razum2um/Code/params_tree/lib/params_tree/parser.rl"
    begin
  begin
    stack[top] = cs
    top+= 1
    cs = 2
    _trigger_goto = true
    _goto_level = _again
    break
  end
    end
# line 273 "/Users/razum2um/Code/params_tree/lib/params_tree/parser.rb"
      end # action switch
    end
  end
  if _trigger_goto
    next
  end
  end
  if _goto_level <= _again
  if cs == 0
    _goto_level = _out
    next
  end
  p += 1
  if p != pe
    _goto_level = _resume
    next
  end
  end
  if _goto_level <= _test_eof
  end
  if _goto_level <= _out
    break
  end
  end
  end

# line 45 "/Users/razum2um/Code/params_tree/lib/params_tree/parser.rl"

  inject_key # FIXME

  @hash_stack.first || @hash
end

#popObject



334
335
336
# File 'lib/params_tree/parser.rb', line 334

def pop
  @hash = @hash_stack.pop
end

#pushObject



330
331
332
# File 'lib/params_tree/parser.rb', line 330

def push
  @hash_stack.push @hash; @hash = @hash[key]
end

#strokesObject



310
311
312
# File 'lib/params_tree/parser.rb', line 310

def strokes
  chars.pack('c*')
end