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
@@ -7,26 +7,176 @@
7
7
  include 'identifier.rl';
8
8
  include 'string.rl';
9
9
 
10
- action prefix {
11
- @buffers[:parameter] = parameter(prefix(@buffers[:ident]))
10
+ action add_ident_param_value {
11
+ trace('PARAMETER add_ident_param_value')
12
+ ident = @buffers.delete(:ident)
13
+ value_node = value(ident, complete: ident.complete)
14
+ @buffers[:param_value] = value_node
12
15
  }
13
16
 
14
- action string {
15
- @buffers[:parameter] ||= parameter(prefix(nil))
16
- @buffers[:parameter] = @buffers[:parameter] << value(@buffers[:string])
17
+ action add_string_param_value {
18
+ trace('PARAMETER add_string_param_value')
19
+ string_node = @buffers.delete(:string)
20
+ value_node = value(string_node, complete: string_node.complete)
21
+ @buffers[:param_value] = value_node
17
22
  }
18
23
 
19
- action ident {
20
- @buffers[:parameter] ||= parameter(prefix(nil))
21
- @buffers[:parameter] = @buffers[:parameter] << value(@buffers[:ident])
24
+ action parameter_end {
25
+ trace('PARAMETER parameter_end')
26
+ param_node = parameter()
27
+ completed = true
28
+ prefix_node = @buffers.delete(:param_prefix)
29
+ unless prefix_node.nil?
30
+ param_node <<= prefix_node
31
+ unless prefix_node.complete
32
+ trace('PN incomplete')
33
+ completed = false
34
+ end
35
+ end
36
+
37
+ value_node = @buffers.delete(:param_value)
38
+ unless value_node.nil?
39
+ param_node <<= value_node
40
+ unless value_node.complete
41
+ trace('VN incomplete')
42
+ completed = false
43
+ end
44
+ else
45
+ completed = false
46
+ end
47
+
48
+ param_node.complete = completed
49
+ @buffers[:parameter] = param_node
22
50
  }
23
51
 
24
- action yield_parameter_ast {
52
+ action add_prefix {
53
+ trace('PARAMETER add_prefix')
54
+ ident = @buffers.delete(:ident)
55
+ prefix_node = prefix(ident, complete: ident.complete)
56
+ @buffers[:param_prefix] = prefix_node
57
+ }
58
+
59
+ action a_parameter_eof {
60
+ trace("PARAMETER a_parameter_eof")
61
+ param_node = parameter()
62
+ completed = true
63
+ prefix_node = @buffers.delete(:param_prefix)
64
+ unless prefix_node.nil?
65
+ param_node <<= prefix_node
66
+ unless prefix_node.complete
67
+ completed = false
68
+ end
69
+ end
70
+
71
+ string_value_node = @buffers.delete(:string)
72
+ unless string_value_node.nil?
73
+ param_node <<= string_value_node
74
+ unless string_value_node.complete
75
+ completed = false
76
+ end
77
+ else
78
+ completed = false
79
+ end
80
+
81
+ param_node.complete = completed
82
+ @buffers[:parameter] = param_node
83
+ }
84
+
85
+ action parameter_node_eof {
86
+ trace("PARAMETER parameter_node_eof")
87
+ param_node = parameter()
88
+ completed = true
89
+ prefix_node = @buffers.delete(:param_prefix)
90
+ unless prefix_node.nil?
91
+ param_node <<= prefix_node
92
+ unless prefix_node.complete
93
+ completed = false
94
+ end
95
+ end
96
+
97
+ string_value_node = @buffers.delete(:string)
98
+ unless string_value_node.nil?
99
+ param_node <<= string_value_node
100
+ unless string_value_node.complete
101
+ completed = false
102
+ end
103
+ else
104
+ completed = false
105
+ end
106
+
107
+ param_node.complete = completed
108
+ yield param_node
109
+ }
110
+
111
+ action yield_parameter {
112
+ trace('PARAMETER yield_parameter')
25
113
  yield @buffers[:parameter]
26
114
  }
27
115
 
28
- BEL_PARAMETER = (IDENT ':')? @prefix SP* (STRING %string | IDENT %ident);
29
- bel_parameter := BEL_PARAMETER %yield_parameter_ast NL;
116
+ prefix =
117
+ an_ident
118
+ COLON
119
+ ;
120
+
121
+ ident_value =
122
+ an_ident
123
+ %add_ident_param_value
124
+ ;
125
+
126
+ string_value =
127
+ a_string
128
+ %add_string_param_value
129
+ ;
130
+
131
+ value =
132
+ ident_value |
133
+ string_value
134
+ ;
135
+
136
+ parameter_prefix_value =
137
+ prefix
138
+ %add_prefix
139
+ SP*
140
+ value
141
+ ;
142
+
143
+ parameter_prefix_maybe_value =
144
+ prefix
145
+ %add_prefix
146
+ SP*
147
+ value?
148
+ ;
149
+
150
+ parameter_value =
151
+ SP*
152
+ value
153
+ ;
154
+
155
+ a_parameter =
156
+ (
157
+ parameter_prefix_value |
158
+ parameter_value |
159
+ parameter_prefix_maybe_value
160
+ )
161
+
162
+ @eof(a_parameter_eof)
163
+ %parameter_end
164
+ ;
165
+
166
+ parameter_node :=
167
+ (
168
+ parameter_prefix_value |
169
+ parameter_value |
170
+ parameter_prefix_maybe_value
171
+ )
172
+ @eof(parameter_node_eof)
173
+ %parameter_end
174
+ %yield_parameter
175
+ NL?
176
+ ;
177
+
178
+ #BEL_PARAMETER = (an_ident ':')? @prefix SP* (a_string %string | an_ident %ident);
179
+ #bel_parameter := BEL_PARAMETER %yield_parameter_ast NL;
30
180
  }%%
31
181
  =end
32
182
  # end: ragel
@@ -34,6 +184,7 @@
34
184
  require_relative '../ast/node'
35
185
  require_relative '../mixin/buffer'
36
186
  require_relative '../nonblocking_io_wrapper'
187
+ require_relative '../tracer'
37
188
 
38
189
  module BELParser
39
190
  module Parsers
@@ -59,25 +210,31 @@ module BELParser
59
210
  include Enumerable
60
211
  include BELParser::Parsers::Buffer
61
212
  include BELParser::Parsers::AST::Sexp
213
+ include BELParser::Parsers::Tracer
62
214
 
63
215
  def initialize(content)
64
216
  @content = content
65
- # begin: ragel
217
+ # begin: ragel
66
218
  %% write data;
67
- # end: ragel
219
+ # end: ragel
68
220
  end
69
221
 
70
222
  def each
71
- @buffers = {}
72
- data = @content.unpack('C*')
73
- p = 0
74
- pe = data.length
75
- eof = data.length
76
-
77
- # begin: ragel
223
+ @buffers = {}
224
+ @incomplete = {}
225
+ data = @content.unpack('C*')
226
+ p = 0
227
+ pe = data.length
228
+ p_start = 0
229
+ p_end = 0
230
+ id_start = 0
231
+ id_end = 0
232
+ eof = data.length
233
+
234
+ # begin: ragel
78
235
  %% write init;
79
236
  %% write exec;
80
- # end: ragel
237
+ # end: ragel
81
238
  end
82
239
  end
83
240
  end
@@ -9,6 +9,7 @@
9
9
  require_relative '../ast/node'
10
10
  require_relative '../mixin/buffer'
11
11
  require_relative '../nonblocking_io_wrapper'
12
+ require_relative '../tracer'
12
13
 
13
14
  module BELParser
14
15
  module Parsers
@@ -34,18 +35,19 @@ module BELParser
34
35
  include Enumerable
35
36
  include BELParser::Parsers::Buffer
36
37
  include BELParser::Parsers::AST::Sexp
38
+ include BELParser::Parsers::Tracer
37
39
 
38
40
  def initialize(content)
39
41
  @content = content
40
- # begin: ragel
42
+ # begin: ragel
41
43
 
42
44
  class << self
43
45
  attr_accessor :_bel_trans_keys
44
46
  private :_bel_trans_keys, :_bel_trans_keys=
45
47
  end
46
48
  self._bel_trans_keys = [
47
- 0, 0, 33, 126, 10, 126,
48
- 0, 0, 0
49
+ 0, 0, 33, 126, 33, 126,
50
+ 0
49
51
  ]
50
52
 
51
53
  class << self
@@ -53,7 +55,7 @@ class << self
53
55
  private :_bel_key_spans, :_bel_key_spans=
54
56
  end
55
57
  self._bel_key_spans = [
56
- 0, 94, 117, 0
58
+ 0, 94, 94
57
59
  ]
58
60
 
59
61
  class << self
@@ -61,7 +63,7 @@ class << self
61
63
  private :_bel_index_offsets, :_bel_index_offsets=
62
64
  end
63
65
  self._bel_index_offsets = [
64
- 0, 0, 95, 213
66
+ 0, 0, 95
65
67
  ]
66
68
 
67
69
  class << self
@@ -81,21 +83,18 @@ self._bel_indicies = [
81
83
  0, 0, 0, 0, 0, 0, 0, 0,
82
84
  0, 0, 0, 0, 0, 0, 0, 0,
83
85
  0, 0, 0, 0, 0, 0, 1, 2,
84
- 1, 1, 1, 1, 1, 1, 1, 1,
85
- 1, 1, 1, 1, 1, 1, 1, 1,
86
- 1, 1, 1, 1, 1, 1, 3, 3,
87
- 3, 3, 3, 3, 3, 3, 3, 3,
88
- 3, 3, 3, 3, 3, 3, 3, 3,
89
- 3, 3, 3, 3, 3, 3, 3, 3,
90
- 3, 3, 3, 3, 3, 3, 3, 3,
91
- 3, 3, 3, 3, 3, 3, 3, 3,
92
- 3, 3, 3, 3, 3, 3, 3, 3,
93
- 3, 3, 3, 3, 3, 3, 3, 3,
94
- 3, 3, 3, 3, 3, 3, 3, 3,
95
- 3, 3, 3, 3, 3, 3, 3, 3,
96
- 3, 3, 3, 3, 3, 3, 3, 3,
97
- 3, 3, 3, 3, 3, 3, 3, 3,
98
- 3, 3, 3, 3, 1, 1, 0
86
+ 2, 2, 2, 2, 2, 2, 2, 2,
87
+ 2, 2, 2, 2, 2, 2, 2, 2,
88
+ 2, 2, 2, 2, 2, 2, 2, 2,
89
+ 2, 2, 2, 2, 2, 2, 2, 2,
90
+ 2, 2, 2, 2, 2, 2, 2, 2,
91
+ 2, 2, 2, 2, 2, 2, 2, 2,
92
+ 2, 2, 2, 2, 2, 2, 2, 2,
93
+ 2, 2, 2, 2, 2, 2, 2, 2,
94
+ 2, 2, 2, 2, 2, 2, 2, 2,
95
+ 2, 2, 2, 2, 2, 2, 2, 2,
96
+ 2, 2, 2, 2, 2, 2, 2, 2,
97
+ 2, 2, 2, 2, 2, 1, 0
99
98
  ]
100
99
 
101
100
  class << self
@@ -103,7 +102,7 @@ class << self
103
102
  private :_bel_trans_targs, :_bel_trans_targs=
104
103
  end
105
104
  self._bel_trans_targs = [
106
- 2, 0, 3, 2
105
+ 2, 0, 2
107
106
  ]
108
107
 
109
108
  class << self
@@ -111,7 +110,15 @@ class << self
111
110
  private :_bel_trans_actions, :_bel_trans_actions=
112
111
  end
113
112
  self._bel_trans_actions = [
114
- 1, 0, 2, 3
113
+ 1, 0, 0
114
+ ]
115
+
116
+ class << self
117
+ attr_accessor :_bel_eof_actions
118
+ private :_bel_eof_actions, :_bel_eof_actions=
119
+ end
120
+ self._bel_eof_actions = [
121
+ 0, 0, 2
115
122
  ]
116
123
 
117
124
  class << self
@@ -121,29 +128,33 @@ self.bel_start = 1;
121
128
  class << self
122
129
  attr_accessor :bel_first_final
123
130
  end
124
- self.bel_first_final = 3;
131
+ self.bel_first_final = 2;
125
132
  class << self
126
133
  attr_accessor :bel_error
127
134
  end
128
135
  self.bel_error = 0;
129
136
 
130
137
  class << self
131
- attr_accessor :bel_en_relationship
138
+ attr_accessor :bel_en_relationship_node
132
139
  end
133
- self.bel_en_relationship = 1;
140
+ self.bel_en_relationship_node = 1;
134
141
 
135
142
 
136
- # end: ragel
143
+ # end: ragel
137
144
  end
138
145
 
139
146
  def each
140
- @buffers = {}
141
- stack = []
142
- data = @content.unpack('C*')
143
- p = 0
144
- pe = data.length
145
-
146
- # begin: ragel
147
+ @buffers = {}
148
+ @incomplete = {}
149
+ stack = []
150
+ data = @content.unpack('C*')
151
+ p = 0
152
+ p_start = 0
153
+ p_end = 0
154
+ pe = data.length
155
+ eof = data.length
156
+
157
+ # begin: ragel
147
158
 
148
159
  begin
149
160
  p ||= 0
@@ -188,29 +199,11 @@ begin
188
199
  cs = _bel_trans_targs[_trans]
189
200
  if _bel_trans_actions[_trans] != 0
190
201
  case _bel_trans_actions[_trans]
191
- when 3 then
192
- begin
193
-
194
- @buffers[:relationship] << data[p].ord
195
- end
196
202
  when 1 then
197
203
  begin
198
204
 
199
- @buffers[:relationship] = []
200
- end
201
- begin
202
-
203
- @buffers[:relationship] << data[p].ord
204
- end
205
- when 2 then
206
- begin
207
-
208
- @buffers[:relationship] = relationship(
209
- utf8_string(@buffers[:relationship]))
210
- end
211
- begin
212
-
213
- yield @buffers[:relationship]
205
+ trace('RELATIONSHIP start_relationship')
206
+ p_start = p;
214
207
  end
215
208
  end
216
209
  end
@@ -227,6 +220,31 @@ begin
227
220
  end
228
221
  end
229
222
  if _goto_level <= _test_eof
223
+ if p == eof
224
+ case _bel_eof_actions[cs]
225
+ when 2 then
226
+ begin
227
+
228
+ trace('RELATIONSHIP stop_relationship')
229
+ # It's not you, it's me. You're a p and I'm a non-protein coding r. It
230
+ # would never work, I just can't reach you.
231
+ p_end = p;
232
+ end
233
+ begin
234
+
235
+ trace('RELATIONSHIP relationship_end')
236
+ chars = data[p_start...p_end]
237
+ completed = !chars.empty?
238
+ ast_node = relationship(utf8_string(chars), complete: completed)
239
+ @buffers[:relationship] = ast_node
240
+ end
241
+ begin
242
+
243
+ yield @buffers[:relationship]
244
+ end
245
+ end
246
+ end
247
+
230
248
  end
231
249
  if _goto_level <= _out
232
250
  break
@@ -234,7 +252,7 @@ begin
234
252
  end
235
253
  end
236
254
 
237
- # end: ragel
255
+ # end: ragel
238
256
  end
239
257
  end
240
258
  end
@@ -244,7 +262,7 @@ end
244
262
 
245
263
  if __FILE__ == $0
246
264
  $stdin.each_line do |line|
247
- BELParser::Parsers::Expression::Relationship.parse(line) { |obj|
265
+ BELParser::Parsers::Expression::Relationship.parse(line.strip) { |obj|
248
266
  puts obj.inspect
249
267
  }
250
268
  end