bel_parser 1.0.0.alpha.38 → 1.0.0.alpha.39

Sign up to get free protection for your applications and to get access to all the features.
Files changed (48) hide show
  1. checksums.yaml +4 -4
  2. data/.gemspec +1 -1
  3. data/VERSION +1 -1
  4. data/lib/bel_parser/ast_filter.rb +6 -2
  5. data/lib/bel_parser/parsers/ast/node.rb +113 -58
  6. data/lib/bel_parser/parsers/bel_script/define_annotation.rb +4175 -3097
  7. data/lib/bel_parser/parsers/bel_script/define_annotation.rl +142 -49
  8. data/lib/bel_parser/parsers/bel_script/define_namespace.rb +980 -461
  9. data/lib/bel_parser/parsers/bel_script/define_namespace.rl +79 -39
  10. data/lib/bel_parser/parsers/bel_script/set.rb +4878 -2743
  11. data/lib/bel_parser/parsers/bel_script/set.rl +114 -32
  12. data/lib/bel_parser/parsers/bel_script/set_document.rb +5839 -5292
  13. data/lib/bel_parser/parsers/bel_script/set_document.rl +130 -27
  14. data/lib/bel_parser/parsers/bel_script/unset.rb +321 -234
  15. data/lib/bel_parser/parsers/bel_script/unset.rl +49 -21
  16. data/lib/bel_parser/parsers/common.rb +1 -0
  17. data/lib/bel_parser/parsers/common/blank_line.rb +12 -11
  18. data/lib/bel_parser/parsers/common/blank_line.rl +12 -12
  19. data/lib/bel_parser/parsers/common/comment_line.rb +65 -40
  20. data/lib/bel_parser/parsers/common/comment_line.rl +26 -26
  21. data/lib/bel_parser/parsers/common/common.rl +60 -0
  22. data/lib/bel_parser/parsers/common/function.rb +319 -0
  23. data/lib/bel_parser/parsers/common/function.rl +149 -0
  24. data/lib/bel_parser/parsers/common/identifier.rb +72 -68
  25. data/lib/bel_parser/parsers/common/identifier.rl +73 -29
  26. data/lib/bel_parser/parsers/common/list.rb +1617 -1243
  27. data/lib/bel_parser/parsers/common/list.rl +120 -60
  28. data/lib/bel_parser/parsers/common/string.rb +114 -41
  29. data/lib/bel_parser/parsers/common/string.rl +91 -28
  30. data/lib/bel_parser/parsers/expression/comment.rb +70 -38
  31. data/lib/bel_parser/parsers/expression/comment.rl +37 -20
  32. data/lib/bel_parser/parsers/expression/nested_statement.rb +63116 -13958
  33. data/lib/bel_parser/parsers/expression/nested_statement.rl +53 -23
  34. data/lib/bel_parser/parsers/expression/observed_term.rb +32497 -5188
  35. data/lib/bel_parser/parsers/expression/observed_term.rl +25 -20
  36. data/lib/bel_parser/parsers/expression/parameter.rb +2861 -847
  37. data/lib/bel_parser/parsers/expression/parameter.rl +178 -21
  38. data/lib/bel_parser/parsers/expression/relationship.rb +73 -55
  39. data/lib/bel_parser/parsers/expression/relationship.rl +41 -23
  40. data/lib/bel_parser/parsers/expression/simple_statement.rb +42895 -7846
  41. data/lib/bel_parser/parsers/expression/simple_statement.rl +41 -24
  42. data/lib/bel_parser/parsers/expression/term.rb +16498 -2602
  43. data/lib/bel_parser/parsers/expression/term.rl +52 -35
  44. data/lib/bel_parser/parsers/line_parser.rb +1 -0
  45. data/lib/bel_parser/parsers/mixin/buffer.rb +4 -0
  46. data/lib/bel_parser/parsers/tracer.rb +19 -0
  47. data/lib/bel_parser/script/state/namespace_definition.rb +1 -0
  48. metadata +13 -9
@@ -3,30 +3,128 @@
3
3
  %%{
4
4
  machine bel;
5
5
 
6
- include 'set.rl';
6
+ include 'common.rl';
7
+ include 'identifier.rl';
8
+ include 'string.rl';
9
+ include 'list.rl';
10
+
11
+ action add_property {
12
+ trace('SET_DOCUMENT add_property')
13
+ key = @buffers.delete(:ident)
14
+ @buffers[:set_document_name] = key
15
+ }
7
16
 
8
- DOCUMENT_KW = [dD][oO][cC][uU][mM][eE][nN][tT];
17
+ action add_ident_value {
18
+ trace('SET_DOCUMENT add_ident_value')
19
+ ident = @buffers.delete(:ident)
20
+ @buffers[:set_document_value] = ident
21
+ }
9
22
 
10
- action yield_document_property {
11
- yield(
12
- document_property(
13
- *@buffers[:set].children))
23
+ action add_string_value {
24
+ trace('SET_DOCUMENT add_string_value')
25
+ string = @buffers.delete(:string)
26
+ @buffers[:set_document_value] = string
14
27
  }
15
28
 
16
- set_document :=
17
- SET_KW %set_keyword
18
- SP+
19
- DOCUMENT_KW
29
+ action add_list_value {
30
+ trace('SET_DOCUMENT add_list_value')
31
+ list = @buffers.delete(:list)
32
+ @buffers[:set_document_value] = list
33
+ }
34
+
35
+ action set_document_end {
36
+ trace('SET_DOCUMENT set_document_end')
37
+ set_document_node = document_property()
38
+ completed = true
39
+
40
+ name = @buffers.delete(:set_document_name)
41
+ unless name.nil?
42
+ set_document_node <<= name
43
+ end
44
+
45
+ value = @buffers.delete(:set_document_value)
46
+ unless value.nil?
47
+ set_document_node <<= value
48
+ end
49
+
50
+ completed = false
51
+ unless name.nil? || value.nil?
52
+ completed = name.complete && value.complete
53
+ end
54
+
55
+ set_document_node.complete = completed
56
+ @buffers[:set_document] = set_document_node
57
+ }
58
+
59
+ action yield_set_document {
60
+ trace('SET_DOCUMENT yield_set')
61
+ yield @buffers[:set_document]
62
+ }
63
+
64
+ action set_document_node_eof {
65
+ trace('SET_DOCUMENT set_document_node_eof')
66
+ name = @buffers.delete(:set_document_name)
67
+ set_document_node = set(name)
68
+ completed = name.complete
69
+ if @buffers.key?(:string)
70
+ value = @buffers.delete(:string)
71
+ set_document_node <<= value
72
+ completed = completed && value.complete
73
+ elsif @buffers.key?(:ident)
74
+ value = @buffers.delete(:ident)
75
+ set_document_node <<= value
76
+ completed = completed && value.complete
77
+ elsif @buffers.key?(:list)
78
+ value = @buffers.delete(:list)
79
+ set_document_node <<= value
80
+ completed = completed && value.complete
81
+ end
82
+ set_document_node.complete = completed
83
+ yield set_document_node
84
+ }
85
+
86
+ document_property =
87
+ an_ident &
88
+ DOCUMENT_PROPERTY
89
+ ;
90
+
91
+ ident_value =
92
+ an_ident
93
+ %add_ident_value
94
+ ;
95
+
96
+ string_value =
97
+ a_string
98
+ %add_string_value
99
+ ;
100
+
101
+ list_value =
102
+ a_list
103
+ %add_list_value
104
+ ;
105
+
106
+ value =
107
+ ident_value |
108
+ string_value |
109
+ list_value
110
+ ;
111
+
112
+ set_document_node :=
113
+ KW_SET
20
114
  SP+
21
- IDENT %name
115
+ KW_DOCUMENT
22
116
  SP+
23
- EQL
117
+ document_property
118
+ %add_property
119
+ @eof(set_document_node_eof)
24
120
  SP+
25
- (
26
- STRING %string_value |
27
- LIST %list_value |
28
- IDENT %ident_value
29
- ) NL @yield_document_property;
121
+ EQL?
122
+ SP+?
123
+ value?
124
+ @eof(set_document_node_eof)
125
+ %set_document_end
126
+ %yield_set_document
127
+ ;
30
128
  }%%
31
129
  =end
32
130
  # end: ragel
@@ -34,6 +132,7 @@
34
132
  require_relative '../ast/node'
35
133
  require_relative '../mixin/buffer'
36
134
  require_relative '../nonblocking_io_wrapper'
135
+ require_relative '../tracer'
37
136
 
38
137
  module BELParser
39
138
  module Parsers
@@ -59,25 +158,29 @@ module BELParser
59
158
  include Enumerable
60
159
  include BELParser::Parsers::Buffer
61
160
  include BELParser::Parsers::AST::Sexp
161
+ include BELParser::Parsers::Tracer
62
162
 
63
163
  def initialize(content)
64
164
  @content = content
65
- # begin: ragel
165
+ # begin: ragel
66
166
  %% write data;
67
- # end: ragel
167
+ # end: ragel
68
168
  end
69
169
 
70
170
  def each
71
- @buffers = {}
72
- data = @content.unpack('C*')
73
- p = 0
74
- pe = data.length
75
- eof = data.length
76
-
77
- # begin: ragel
171
+ @buffers = {}
172
+ @incomplete = {}
173
+ data = @content.unpack('C*')
174
+ p = 0
175
+ pe = data.length
176
+ eof = data.length
177
+ id_start = 0
178
+ id_end = 0
179
+
180
+ # begin: ragel
78
181
  %% write init;
79
182
  %% write exec;
80
- # end: ragel
183
+ # end: ragel
81
184
  end
82
185
  end
83
186
  end
@@ -9,9 +9,9 @@ end
9
9
  self._bel_trans_keys = [
10
10
  0, 0, 85, 117, 78, 110,
11
11
  83, 115, 69, 101, 84,
12
- 116, 9, 32, 9, 122,
13
- 10, 122, 48, 122, 10, 122,
14
- 0, 0, 0, 0, 0
12
+ 116, 48, 122, 9, 122,
13
+ 48, 122, 10, 122, 0, 0,
14
+ 0
15
15
  ]
16
16
 
17
17
  class << self
@@ -19,8 +19,8 @@ class << self
19
19
  private :_bel_key_spans, :_bel_key_spans=
20
20
  end
21
21
  self._bel_key_spans = [
22
- 0, 33, 33, 33, 33, 33, 24, 114,
23
- 113, 75, 113, 0, 0
22
+ 0, 33, 33, 33, 33, 33, 75, 114,
23
+ 75, 113, 0
24
24
  ]
25
25
 
26
26
  class << self
@@ -28,8 +28,8 @@ class << self
28
28
  private :_bel_index_offsets, :_bel_index_offsets=
29
29
  end
30
30
  self._bel_index_offsets = [
31
- 0, 0, 34, 68, 102, 136, 170, 195,
32
- 310, 424, 500, 614, 615
31
+ 0, 0, 34, 68, 102, 136, 170, 246,
32
+ 361, 437, 551
33
33
  ]
34
34
 
35
35
  class << self
@@ -58,62 +58,54 @@ self._bel_indicies = [
58
58
  1, 1, 1, 1, 1, 1, 1, 1,
59
59
  1, 1, 1, 1, 1, 1, 1, 1,
60
60
  1, 1, 1, 1, 1, 1, 1, 1,
61
- 5, 1, 6, 1, 1, 1, 1, 1,
62
- 1, 1, 1, 1, 1, 1, 1, 1,
63
- 1, 1, 1, 1, 1, 1, 1, 1,
64
- 1, 6, 1, 8, 7, 7, 7, 7,
61
+ 5, 1, 6, 6, 6, 6, 6, 6,
62
+ 6, 6, 6, 6, 1, 1, 1, 1,
63
+ 1, 1, 1, 6, 6, 6, 6, 6,
64
+ 6, 6, 6, 6, 6, 6, 6, 6,
65
+ 6, 6, 6, 6, 6, 6, 6, 6,
66
+ 6, 6, 6, 6, 6, 1, 1, 1,
67
+ 1, 6, 1, 6, 6, 6, 6, 6,
68
+ 6, 6, 6, 6, 6, 6, 6, 6,
69
+ 6, 6, 6, 6, 6, 6, 6, 6,
70
+ 6, 6, 6, 6, 6, 1, 5, 7,
65
71
  7, 7, 7, 7, 7, 7, 7, 7,
66
72
  7, 7, 7, 7, 7, 7, 7, 7,
67
- 7, 7, 8, 7, 7, 7, 7, 7,
73
+ 7, 7, 7, 7, 7, 5, 7, 7,
68
74
  7, 7, 7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, 11, 11, 11, 11, 11, 11,
91
- 11, 11, 11, 11, 11, 11, 11, 11,
92
- 11, 11, 11, 11, 11, 11, 11, 7,
93
- 13, 13, 13, 13, 13, 13, 13, 13,
94
- 13, 13, 12, 12, 12, 12, 12, 12,
95
- 12, 13, 13, 13, 13, 13, 13, 13,
96
- 13, 13, 13, 13, 13, 13, 13, 13,
97
- 13, 13, 13, 13, 13, 13, 13, 13,
98
- 13, 13, 13, 12, 12, 12, 12, 13,
99
- 12, 13, 13, 13, 13, 13, 13, 13,
100
- 13, 13, 13, 13, 13, 13, 13, 13,
101
- 13, 13, 13, 13, 13, 13, 13, 13,
102
- 13, 13, 13, 12, 14, 12, 12, 12,
94
+ 9, 9, 9, 9, 7, 11, 10, 10,
95
+ 10, 10, 10, 10, 10, 10, 10, 10,
96
+ 10, 10, 10, 10, 10, 10, 10, 10,
97
+ 10, 10, 10, 10, 10, 10, 10, 10,
98
+ 10, 10, 10, 10, 10, 10, 10, 10,
99
+ 10, 10, 10, 12, 12, 12, 12, 12,
100
+ 12, 12, 12, 12, 12, 10, 10, 10,
101
+ 10, 10, 10, 10, 12, 12, 12, 12,
103
102
  12, 12, 12, 12, 12, 12, 12, 12,
104
103
  12, 12, 12, 12, 12, 12, 12, 12,
104
+ 12, 12, 12, 12, 12, 12, 10, 10,
105
+ 10, 10, 12, 10, 12, 12, 12, 12,
105
106
  12, 12, 12, 12, 12, 12, 12, 12,
106
107
  12, 12, 12, 12, 12, 12, 12, 12,
107
- 12, 12, 15, 15, 15, 15, 15, 15,
108
- 15, 15, 15, 15, 12, 12, 12, 12,
109
- 12, 12, 12, 15, 15, 15, 15, 15,
110
- 15, 15, 15, 15, 15, 15, 15, 15,
111
- 15, 15, 15, 15, 15, 15, 15, 15,
112
- 15, 15, 15, 15, 15, 12, 12, 12,
113
- 12, 15, 12, 15, 15, 15, 15, 15,
114
- 15, 15, 15, 15, 15, 15, 15, 15,
115
- 15, 15, 15, 15, 15, 15, 15, 15,
116
- 15, 15, 15, 15, 15, 12, 1, 1,
108
+ 12, 12, 12, 12, 12, 12, 10, 10,
117
109
  0
118
110
  ]
119
111
 
@@ -122,8 +114,8 @@ class << self
122
114
  private :_bel_trans_targs, :_bel_trans_targs=
123
115
  end
124
116
  self._bel_trans_targs = [
125
- 2, 0, 3, 4, 5, 6, 7, 0,
126
- 7, 8, 11, 8, 0, 10, 12, 10
117
+ 2, 0, 3, 4, 5, 7, 9, 0,
118
+ 8, 8, 0, 10, 9
127
119
  ]
128
120
 
129
121
  class << self
@@ -131,8 +123,8 @@ class << self
131
123
  private :_bel_trans_actions, :_bel_trans_actions=
132
124
  end
133
125
  self._bel_trans_actions = [
134
- 0, 0, 0, 0, 0, 0, 1, 2,
135
- 0, 3, 4, 5, 6, 3, 7, 5
126
+ 0, 0, 0, 0, 0, 0, 1, 3,
127
+ 1, 0, 6, 7, 0
136
128
  ]
137
129
 
138
130
  class << self
@@ -141,7 +133,7 @@ class << self
141
133
  end
142
134
  self._bel_eof_actions = [
143
135
  0, 0, 0, 0, 0, 0, 0, 2,
144
- 2, 6, 6, 0, 0
136
+ 4, 5, 8
145
137
  ]
146
138
 
147
139
  class << self
@@ -151,20 +143,20 @@ self.bel_start = 1;
151
143
  class << self
152
144
  attr_accessor :bel_first_final
153
145
  end
154
- self.bel_first_final = 11;
146
+ self.bel_first_final = 7;
155
147
  class << self
156
148
  attr_accessor :bel_error
157
149
  end
158
150
  self.bel_error = 0;
159
151
 
160
152
  class << self
161
- attr_accessor :bel_en_ident
153
+ attr_accessor :bel_en_ident_node
162
154
  end
163
- self.bel_en_ident = 9;
155
+ self.bel_en_ident_node = 6;
164
156
  class << self
165
- attr_accessor :bel_en_unset
157
+ attr_accessor :bel_en_unset_ast_node
166
158
  end
167
- self.bel_en_unset = 1;
159
+ self.bel_en_unset_ast_node = 1;
168
160
 
169
161
 
170
162
  begin
@@ -209,105 +201,155 @@ begin
209
201
  cs = _bel_trans_targs[_trans]
210
202
  if _bel_trans_actions[_trans] != 0
211
203
  case _bel_trans_actions[_trans]
212
- when 5 then
204
+ when 1 then
213
205
  begin
214
206
 
215
- (@buffers[:ident] ||= []) << data[p].ord
207
+ trace('IDENTIFIER start_identifier')
208
+ @identifier_started = true
209
+ id_start = p;
216
210
  end
217
- when 2 then
211
+ when 7 then
218
212
  begin
219
213
 
220
- unless @buffers[:ident].is_a?(::AST::Node)
221
- @buffers[:ident] ||= []
222
- @buffers[:ident] = identifier(utf8_string(@buffers[:ident]).sub(/\n$/, ''))
223
- end
214
+ trace('IDENTIFIER end_identifier')
215
+ id_end = p
216
+ chars = data[id_start...id_end]
217
+ completed = !chars.empty?
218
+ ast_node = identifier(utf8_string(chars), complete: completed)
219
+ @buffers[:ident] = ast_node
224
220
  end
225
- when 1 then
221
+ when 3 then
226
222
  begin
227
223
 
228
- @buffers[:unset] = unset()
224
+ trace('IDENTIFIER an_ident_err')
225
+ id_end = p
226
+ chars = data[id_start...id_end]
227
+ ast_node = identifier(utf8_string(chars), complete: false)
228
+ @buffers[:ident] = ast_node
229
229
  end
230
- when 3 then
230
+ when 6 then
231
231
  begin
232
232
 
233
- @buffers[:ident] = []
233
+ trace('IDENTIFIER ident_node_err')
234
+ id_end = p
235
+ chars = data[id_start...id_end]
236
+ ast_node = identifier(utf8_string(chars), complete: false)
237
+ yield ast_node
234
238
  end
239
+ end
240
+ end
241
+ end
242
+ if _goto_level <= _again
243
+ if cs == 0
244
+ _goto_level = _out
245
+ next
246
+ end
247
+ p += 1
248
+ if p != pe
249
+ _goto_level = _resume
250
+ next
251
+ end
252
+ end
253
+ if _goto_level <= _test_eof
254
+ if p == eof
255
+ case _bel_eof_actions[cs]
256
+ when 8 then
235
257
  begin
236
258
 
237
- (@buffers[:ident] ||= []) << data[p].ord
259
+ trace('IDENTIFIER yield_identifier')
260
+ yield @buffers[:ident]
238
261
  end
239
- when 7 then
262
+ when 5 then
240
263
  begin
241
264
 
242
- @buffers[:ident] = identifier(utf8_string(@buffers[:ident]))
265
+ trace('IDENTIFIER end_identifier')
266
+ id_end = p
267
+ chars = data[id_start...id_end]
268
+ completed = !chars.empty?
269
+ ast_node = identifier(utf8_string(chars), complete: completed)
270
+ @buffers[:ident] = ast_node
243
271
  end
244
272
  begin
245
273
 
274
+ trace('IDENTIFIER yield_identifier')
246
275
  yield @buffers[:ident]
247
276
  end
248
- when 6 then
277
+ when 2 then
249
278
  begin
250
279
 
251
- unless @buffers[:ident].is_a?(::AST::Node)
252
- @buffers[:ident] ||= []
253
- @buffers[:ident] = identifier(utf8_string(@buffers[:ident]).sub(/\n$/, ''))
280
+ trace('IDENTIFIER an_ident_eof')
281
+ if @identifier_started
282
+ id_end = p
283
+ chars = data[id_start...id_end]
284
+ completed = !chars.empty?
285
+ ast_node = identifier(utf8_string(chars), complete: completed)
286
+ @buffers[:ident] = ast_node
254
287
  end
255
288
  end
256
289
  begin
257
290
 
258
- @buffers[:ident] ||= []
259
- yield @buffers[:ident]
291
+ trace('UNSET add_name')
292
+ key = @buffers.delete(:ident)
293
+ @buffers[:unset_name] = key
260
294
  end
261
- when 4 then
262
295
  begin
263
296
 
264
- @buffers[:ident] = identifier(utf8_string(@buffers[:ident]))
297
+ trace('UNSET unset_end')
298
+ name = @buffers.delete(:unset_name)
299
+ unless name.nil?
300
+ unset_node = unset(name, complete: name.complete)
301
+ else
302
+ unset_node = unset(complete: false)
303
+ end
304
+ @buffers[:unset] = unset_node
265
305
  end
266
306
  begin
267
307
 
268
- @buffers[:unset] = @buffers[:unset] << name(@buffers[:ident])
308
+ trace('UNSET yield_unset')
309
+ yield @buffers[:unset]
269
310
  end
311
+ when 4 then
270
312
  begin
271
313
 
272
- yield @buffers[:unset]
314
+ trace('IDENTIFIER end_identifier')
315
+ id_end = p
316
+ chars = data[id_start...id_end]
317
+ completed = !chars.empty?
318
+ ast_node = identifier(utf8_string(chars), complete: completed)
319
+ @buffers[:ident] = ast_node
273
320
  end
274
- end
275
- end
276
- end
277
- if _goto_level <= _again
278
- if cs == 0
279
- _goto_level = _out
280
- next
281
- end
282
- p += 1
283
- if p != pe
284
- _goto_level = _resume
285
- next
286
- end
287
- end
288
- if _goto_level <= _test_eof
289
- if p == eof
290
- case _bel_eof_actions[cs]
291
- when 2 then
292
321
  begin
293
322
 
294
- unless @buffers[:ident].is_a?(::AST::Node)
295
- @buffers[:ident] ||= []
296
- @buffers[:ident] = identifier(utf8_string(@buffers[:ident]).sub(/\n$/, ''))
323
+ trace('IDENTIFIER an_ident_eof')
324
+ if @identifier_started
325
+ id_end = p
326
+ chars = data[id_start...id_end]
327
+ completed = !chars.empty?
328
+ ast_node = identifier(utf8_string(chars), complete: completed)
329
+ @buffers[:ident] = ast_node
297
330
  end
298
331
  end
299
- when 6 then
300
332
  begin
301
333
 
302
- unless @buffers[:ident].is_a?(::AST::Node)
303
- @buffers[:ident] ||= []
304
- @buffers[:ident] = identifier(utf8_string(@buffers[:ident]).sub(/\n$/, ''))
334
+ trace('UNSET add_name')
335
+ key = @buffers.delete(:ident)
336
+ @buffers[:unset_name] = key
337
+ end
338
+ begin
339
+
340
+ trace('UNSET unset_end')
341
+ name = @buffers.delete(:unset_name)
342
+ unless name.nil?
343
+ unset_node = unset(name, complete: name.complete)
344
+ else
345
+ unset_node = unset(complete: false)
305
346
  end
347
+ @buffers[:unset] = unset_node
306
348
  end
307
349
  begin
308
350
 
309
- @buffers[:ident] ||= []
310
- yield @buffers[:ident]
351
+ trace('UNSET yield_unset')
352
+ yield @buffers[:unset]
311
353
  end
312
354
  end
313
355
  end
@@ -326,6 +368,7 @@ end
326
368
  require_relative '../ast/node'
327
369
  require_relative '../mixin/buffer'
328
370
  require_relative '../nonblocking_io_wrapper'
371
+ require_relative '../tracer'
329
372
 
330
373
  module BELParser
331
374
  module Parsers
@@ -351,10 +394,11 @@ module BELParser
351
394
  include Enumerable
352
395
  include BELParser::Parsers::Buffer
353
396
  include BELParser::Parsers::AST::Sexp
397
+ include BELParser::Parsers::Tracer
354
398
 
355
399
  def initialize(content)
356
400
  @content = content
357
- # begin: ragel
401
+ # begin: ragel
358
402
 
359
403
  class << self
360
404
  attr_accessor :_bel_trans_keys
@@ -363,9 +407,9 @@ end
363
407
  self._bel_trans_keys = [
364
408
  0, 0, 85, 117, 78, 110,
365
409
  83, 115, 69, 101, 84,
366
- 116, 9, 32, 9, 122,
367
- 10, 122, 48, 122, 10, 122,
368
- 0, 0, 0, 0, 0
410
+ 116, 48, 122, 9, 122,
411
+ 48, 122, 10, 122, 0, 0,
412
+ 0
369
413
  ]
370
414
 
371
415
  class << self
@@ -373,8 +417,8 @@ class << self
373
417
  private :_bel_key_spans, :_bel_key_spans=
374
418
  end
375
419
  self._bel_key_spans = [
376
- 0, 33, 33, 33, 33, 33, 24, 114,
377
- 113, 75, 113, 0, 0
420
+ 0, 33, 33, 33, 33, 33, 75, 114,
421
+ 75, 113, 0
378
422
  ]
379
423
 
380
424
  class << self
@@ -382,8 +426,8 @@ class << self
382
426
  private :_bel_index_offsets, :_bel_index_offsets=
383
427
  end
384
428
  self._bel_index_offsets = [
385
- 0, 0, 34, 68, 102, 136, 170, 195,
386
- 310, 424, 500, 614, 615
429
+ 0, 0, 34, 68, 102, 136, 170, 246,
430
+ 361, 437, 551
387
431
  ]
388
432
 
389
433
  class << self
@@ -412,62 +456,54 @@ self._bel_indicies = [
412
456
  1, 1, 1, 1, 1, 1, 1, 1,
413
457
  1, 1, 1, 1, 1, 1, 1, 1,
414
458
  1, 1, 1, 1, 1, 1, 1, 1,
415
- 5, 1, 6, 1, 1, 1, 1, 1,
416
- 1, 1, 1, 1, 1, 1, 1, 1,
417
- 1, 1, 1, 1, 1, 1, 1, 1,
418
- 1, 6, 1, 8, 7, 7, 7, 7,
459
+ 5, 1, 6, 6, 6, 6, 6, 6,
460
+ 6, 6, 6, 6, 1, 1, 1, 1,
461
+ 1, 1, 1, 6, 6, 6, 6, 6,
462
+ 6, 6, 6, 6, 6, 6, 6, 6,
463
+ 6, 6, 6, 6, 6, 6, 6, 6,
464
+ 6, 6, 6, 6, 6, 1, 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, 7, 7, 7, 7, 7,
436
- 7, 7, 7, 7, 7, 7, 7, 7,
437
- 7, 7, 7, 7, 11, 11, 11, 11,
438
- 11, 11, 11, 11, 11, 11, 7, 7,
439
- 7, 7, 7, 7, 7, 11, 11, 11,
440
- 11, 11, 11, 11, 11, 11, 11, 11,
441
- 11, 11, 11, 11, 11, 11, 11, 11,
442
- 11, 11, 11, 11, 11, 11, 11, 7,
443
- 7, 7, 7, 11, 7, 11, 11, 11,
444
- 11, 11, 11, 11, 11, 11, 11, 11,
445
- 11, 11, 11, 11, 11, 11, 11, 11,
446
- 11, 11, 11, 11, 11, 11, 11, 7,
447
- 13, 13, 13, 13, 13, 13, 13, 13,
448
- 13, 13, 12, 12, 12, 12, 12, 12,
449
- 12, 13, 13, 13, 13, 13, 13, 13,
450
- 13, 13, 13, 13, 13, 13, 13, 13,
451
- 13, 13, 13, 13, 13, 13, 13, 13,
452
- 13, 13, 13, 12, 12, 12, 12, 13,
453
- 12, 13, 13, 13, 13, 13, 13, 13,
454
- 13, 13, 13, 13, 13, 13, 13, 13,
455
- 13, 13, 13, 13, 13, 13, 13, 13,
456
- 13, 13, 13, 12, 14, 12, 12, 12,
492
+ 9, 9, 9, 9, 7, 11, 10, 10,
493
+ 10, 10, 10, 10, 10, 10, 10, 10,
494
+ 10, 10, 10, 10, 10, 10, 10, 10,
495
+ 10, 10, 10, 10, 10, 10, 10, 10,
496
+ 10, 10, 10, 10, 10, 10, 10, 10,
497
+ 10, 10, 10, 12, 12, 12, 12, 12,
498
+ 12, 12, 12, 12, 12, 10, 10, 10,
499
+ 10, 10, 10, 10, 12, 12, 12, 12,
457
500
  12, 12, 12, 12, 12, 12, 12, 12,
458
501
  12, 12, 12, 12, 12, 12, 12, 12,
502
+ 12, 12, 12, 12, 12, 12, 10, 10,
503
+ 10, 10, 12, 10, 12, 12, 12, 12,
459
504
  12, 12, 12, 12, 12, 12, 12, 12,
460
505
  12, 12, 12, 12, 12, 12, 12, 12,
461
- 12, 12, 15, 15, 15, 15, 15, 15,
462
- 15, 15, 15, 15, 12, 12, 12, 12,
463
- 12, 12, 12, 15, 15, 15, 15, 15,
464
- 15, 15, 15, 15, 15, 15, 15, 15,
465
- 15, 15, 15, 15, 15, 15, 15, 15,
466
- 15, 15, 15, 15, 15, 12, 12, 12,
467
- 12, 15, 12, 15, 15, 15, 15, 15,
468
- 15, 15, 15, 15, 15, 15, 15, 15,
469
- 15, 15, 15, 15, 15, 15, 15, 15,
470
- 15, 15, 15, 15, 15, 12, 1, 1,
506
+ 12, 12, 12, 12, 12, 12, 10, 10,
471
507
  0
472
508
  ]
473
509
 
@@ -476,8 +512,8 @@ class << self
476
512
  private :_bel_trans_targs, :_bel_trans_targs=
477
513
  end
478
514
  self._bel_trans_targs = [
479
- 2, 0, 3, 4, 5, 6, 7, 0,
480
- 7, 8, 11, 8, 0, 10, 12, 10
515
+ 2, 0, 3, 4, 5, 7, 9, 0,
516
+ 8, 8, 0, 10, 9
481
517
  ]
482
518
 
483
519
  class << self
@@ -485,8 +521,8 @@ class << self
485
521
  private :_bel_trans_actions, :_bel_trans_actions=
486
522
  end
487
523
  self._bel_trans_actions = [
488
- 0, 0, 0, 0, 0, 0, 1, 2,
489
- 0, 3, 4, 5, 6, 3, 7, 5
524
+ 0, 0, 0, 0, 0, 0, 1, 3,
525
+ 1, 0, 6, 7, 0
490
526
  ]
491
527
 
492
528
  class << self
@@ -495,7 +531,7 @@ class << self
495
531
  end
496
532
  self._bel_eof_actions = [
497
533
  0, 0, 0, 0, 0, 0, 0, 2,
498
- 2, 6, 6, 0, 0
534
+ 4, 5, 8
499
535
  ]
500
536
 
501
537
  class << self
@@ -505,33 +541,34 @@ self.bel_start = 1;
505
541
  class << self
506
542
  attr_accessor :bel_first_final
507
543
  end
508
- self.bel_first_final = 11;
544
+ self.bel_first_final = 7;
509
545
  class << self
510
546
  attr_accessor :bel_error
511
547
  end
512
548
  self.bel_error = 0;
513
549
 
514
550
  class << self
515
- attr_accessor :bel_en_ident
551
+ attr_accessor :bel_en_ident_node
516
552
  end
517
- self.bel_en_ident = 9;
553
+ self.bel_en_ident_node = 6;
518
554
  class << self
519
- attr_accessor :bel_en_unset
555
+ attr_accessor :bel_en_unset_ast_node
520
556
  end
521
- self.bel_en_unset = 1;
557
+ self.bel_en_unset_ast_node = 1;
522
558
 
523
559
 
524
- # end: ragel
560
+ # end: ragel
525
561
  end
526
562
 
527
563
  def each
528
- @buffers = {}
529
- data = @content.unpack('C*')
530
- p = 0
531
- pe = data.length
532
- eof = data.length
533
-
534
- # begin: ragel
564
+ @buffers = {}
565
+ @incomplete = {}
566
+ data = @content.unpack('C*')
567
+ p = 0
568
+ pe = data.length
569
+ eof = data.length
570
+
571
+ # begin: ragel
535
572
 
536
573
  begin
537
574
  p ||= 0
@@ -576,105 +613,155 @@ begin
576
613
  cs = _bel_trans_targs[_trans]
577
614
  if _bel_trans_actions[_trans] != 0
578
615
  case _bel_trans_actions[_trans]
579
- when 5 then
616
+ when 1 then
580
617
  begin
581
618
 
582
- (@buffers[:ident] ||= []) << data[p].ord
619
+ trace('IDENTIFIER start_identifier')
620
+ @identifier_started = true
621
+ id_start = p;
583
622
  end
584
- when 2 then
623
+ when 7 then
585
624
  begin
586
625
 
587
- unless @buffers[:ident].is_a?(::AST::Node)
588
- @buffers[:ident] ||= []
589
- @buffers[:ident] = identifier(utf8_string(@buffers[:ident]).sub(/\n$/, ''))
590
- end
626
+ trace('IDENTIFIER end_identifier')
627
+ id_end = p
628
+ chars = data[id_start...id_end]
629
+ completed = !chars.empty?
630
+ ast_node = identifier(utf8_string(chars), complete: completed)
631
+ @buffers[:ident] = ast_node
591
632
  end
592
- when 1 then
633
+ when 3 then
593
634
  begin
594
635
 
595
- @buffers[:unset] = unset()
636
+ trace('IDENTIFIER an_ident_err')
637
+ id_end = p
638
+ chars = data[id_start...id_end]
639
+ ast_node = identifier(utf8_string(chars), complete: false)
640
+ @buffers[:ident] = ast_node
596
641
  end
597
- when 3 then
642
+ when 6 then
598
643
  begin
599
644
 
600
- @buffers[:ident] = []
645
+ trace('IDENTIFIER ident_node_err')
646
+ id_end = p
647
+ chars = data[id_start...id_end]
648
+ ast_node = identifier(utf8_string(chars), complete: false)
649
+ yield ast_node
601
650
  end
651
+ end
652
+ end
653
+ end
654
+ if _goto_level <= _again
655
+ if cs == 0
656
+ _goto_level = _out
657
+ next
658
+ end
659
+ p += 1
660
+ if p != pe
661
+ _goto_level = _resume
662
+ next
663
+ end
664
+ end
665
+ if _goto_level <= _test_eof
666
+ if p == eof
667
+ case _bel_eof_actions[cs]
668
+ when 8 then
602
669
  begin
603
670
 
604
- (@buffers[:ident] ||= []) << data[p].ord
671
+ trace('IDENTIFIER yield_identifier')
672
+ yield @buffers[:ident]
605
673
  end
606
- when 7 then
674
+ when 5 then
607
675
  begin
608
676
 
609
- @buffers[:ident] = identifier(utf8_string(@buffers[:ident]))
677
+ trace('IDENTIFIER end_identifier')
678
+ id_end = p
679
+ chars = data[id_start...id_end]
680
+ completed = !chars.empty?
681
+ ast_node = identifier(utf8_string(chars), complete: completed)
682
+ @buffers[:ident] = ast_node
610
683
  end
611
684
  begin
612
685
 
686
+ trace('IDENTIFIER yield_identifier')
613
687
  yield @buffers[:ident]
614
688
  end
615
- when 6 then
689
+ when 2 then
616
690
  begin
617
691
 
618
- unless @buffers[:ident].is_a?(::AST::Node)
619
- @buffers[:ident] ||= []
620
- @buffers[:ident] = identifier(utf8_string(@buffers[:ident]).sub(/\n$/, ''))
692
+ trace('IDENTIFIER an_ident_eof')
693
+ if @identifier_started
694
+ id_end = p
695
+ chars = data[id_start...id_end]
696
+ completed = !chars.empty?
697
+ ast_node = identifier(utf8_string(chars), complete: completed)
698
+ @buffers[:ident] = ast_node
621
699
  end
622
700
  end
623
701
  begin
624
702
 
625
- @buffers[:ident] ||= []
626
- yield @buffers[:ident]
703
+ trace('UNSET add_name')
704
+ key = @buffers.delete(:ident)
705
+ @buffers[:unset_name] = key
627
706
  end
628
- when 4 then
629
707
  begin
630
708
 
631
- @buffers[:ident] = identifier(utf8_string(@buffers[:ident]))
709
+ trace('UNSET unset_end')
710
+ name = @buffers.delete(:unset_name)
711
+ unless name.nil?
712
+ unset_node = unset(name, complete: name.complete)
713
+ else
714
+ unset_node = unset(complete: false)
715
+ end
716
+ @buffers[:unset] = unset_node
632
717
  end
633
718
  begin
634
719
 
635
- @buffers[:unset] = @buffers[:unset] << name(@buffers[:ident])
720
+ trace('UNSET yield_unset')
721
+ yield @buffers[:unset]
636
722
  end
723
+ when 4 then
637
724
  begin
638
725
 
639
- yield @buffers[:unset]
726
+ trace('IDENTIFIER end_identifier')
727
+ id_end = p
728
+ chars = data[id_start...id_end]
729
+ completed = !chars.empty?
730
+ ast_node = identifier(utf8_string(chars), complete: completed)
731
+ @buffers[:ident] = ast_node
640
732
  end
641
- end
642
- end
643
- end
644
- if _goto_level <= _again
645
- if cs == 0
646
- _goto_level = _out
647
- next
648
- end
649
- p += 1
650
- if p != pe
651
- _goto_level = _resume
652
- next
653
- end
654
- end
655
- if _goto_level <= _test_eof
656
- if p == eof
657
- case _bel_eof_actions[cs]
658
- when 2 then
659
733
  begin
660
734
 
661
- unless @buffers[:ident].is_a?(::AST::Node)
662
- @buffers[:ident] ||= []
663
- @buffers[:ident] = identifier(utf8_string(@buffers[:ident]).sub(/\n$/, ''))
735
+ trace('IDENTIFIER an_ident_eof')
736
+ if @identifier_started
737
+ id_end = p
738
+ chars = data[id_start...id_end]
739
+ completed = !chars.empty?
740
+ ast_node = identifier(utf8_string(chars), complete: completed)
741
+ @buffers[:ident] = ast_node
664
742
  end
665
743
  end
666
- when 6 then
667
744
  begin
668
745
 
669
- unless @buffers[:ident].is_a?(::AST::Node)
670
- @buffers[:ident] ||= []
671
- @buffers[:ident] = identifier(utf8_string(@buffers[:ident]).sub(/\n$/, ''))
746
+ trace('UNSET add_name')
747
+ key = @buffers.delete(:ident)
748
+ @buffers[:unset_name] = key
749
+ end
750
+ begin
751
+
752
+ trace('UNSET unset_end')
753
+ name = @buffers.delete(:unset_name)
754
+ unless name.nil?
755
+ unset_node = unset(name, complete: name.complete)
756
+ else
757
+ unset_node = unset(complete: false)
672
758
  end
759
+ @buffers[:unset] = unset_node
673
760
  end
674
761
  begin
675
762
 
676
- @buffers[:ident] ||= []
677
- yield @buffers[:ident]
763
+ trace('UNSET yield_unset')
764
+ yield @buffers[:unset]
678
765
  end
679
766
  end
680
767
  end
@@ -686,7 +773,7 @@ begin
686
773
  end
687
774
  end
688
775
 
689
- # end: ragel
776
+ # end: ragel
690
777
  end
691
778
  end
692
779
  end