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
@@ -4,9 +4,69 @@ machine bel;
4
4
 
5
5
  NL = '\n';
6
6
  SP = ' ' | '\t';
7
+ WS = space;
7
8
  EQL = '=';
8
9
  NUMBER_SIGN = '#';
10
+ SQ = "'";
11
+ DQ = '"';
12
+ COLON = ':';
13
+ ESCAPED = /\\./;
14
+ NOT_SQESC = [^'\\];
15
+ NOT_DQESC = [^"\\];
16
+ COMMA_DELIM = SP* ',' SP*;
17
+ SS = '//';
18
+ ID_CHARS = [a-zA-Z0-9_]+;
19
+ LP = '(';
20
+ RP = ')';
9
21
 
22
+ KW_SET = /SET/i;
23
+ KW_UNSET = /UNSET/i;
24
+ KW_DEFINE = /DEFINE/i;
25
+ KW_ANNOTATION = /ANNOTATION/i;
26
+ KW_NAMESPACE = /NAMESPACE/i;
27
+ KW_AS = /AS/i;
28
+ KW_LIST = /LIST/i;
29
+ KW_PATTERN = /PATTERN/i;
30
+ KW_URL = /URL/i;
31
+ KW_DOCUMENT = /DOCUMENT/i;
32
+ KW_AUTHORS = /Authors/i;
33
+ KW_CONTACT_INFO = /ContactInfo/i;
34
+ KW_COPYRIGHT = /Copyright/i;
35
+ KW_DESCRIPTION = /Description/i;
36
+ KW_LICENSES = /Licenses/i;
37
+ KW_NAME = /Name/i;
38
+ KW_VERSION = /Version/i;
39
+
40
+ DOCUMENT_PROPERTY =
41
+ KW_AUTHORS |
42
+ KW_CONTACT_INFO |
43
+ KW_COPYRIGHT |
44
+ KW_DESCRIPTION |
45
+ KW_LICENSES |
46
+ KW_NAME |
47
+ KW_VERSION
48
+ ;
49
+
50
+ DEFINE_ANNOTATION =
51
+ KW_DEFINE
52
+ SP+
53
+ KW_ANNOTATION
54
+ ;
55
+
56
+ DEFINE_NAMESPACE =
57
+ KW_DEFINE
58
+ SP+
59
+ KW_NAMESPACE
60
+ ;
61
+
62
+ RELATIONSHIP =
63
+ # ASCII range '!' to '~'
64
+ (33..126)+
65
+ ;
66
+
67
+ FUNCTION =
68
+ (print - (' ' | "'" | '"' | '('))+
69
+ ;
10
70
  }%%
11
71
  =end
12
72
  # vim: ts=2 sw=2 ft=ragel:
@@ -0,0 +1,319 @@
1
+
2
+ # begin: ragel
3
+ =begin
4
+
5
+
6
+ =end
7
+ # end: ragel
8
+
9
+ require_relative '../ast/node'
10
+ require_relative '../mixin/buffer'
11
+ require_relative '../nonblocking_io_wrapper'
12
+ require_relative '../tracer'
13
+
14
+ module BELParser
15
+ module Parsers
16
+ module Common
17
+ module Function
18
+
19
+ class << self
20
+
21
+ MAX_LENGTH = 1024 * 128 # 128K
22
+
23
+ def parse(content)
24
+ return nil unless content
25
+
26
+ Parser.new(content).each do |obj|
27
+ yield obj
28
+ end
29
+ end
30
+ end
31
+
32
+ private
33
+
34
+ class Parser
35
+ include Enumerable
36
+ include BELParser::Parsers::Buffer
37
+ include BELParser::Parsers::AST::Sexp
38
+ include BELParser::Parsers::Tracer
39
+
40
+ def initialize(content)
41
+ @content = content
42
+ # begin: ragel
43
+
44
+ class << self
45
+ attr_accessor :_bel_trans_keys
46
+ private :_bel_trans_keys, :_bel_trans_keys=
47
+ end
48
+ self._bel_trans_keys = [
49
+ 0, 0, 33, 126, 10, 126,
50
+ 0, 0, 0
51
+ ]
52
+
53
+ class << self
54
+ attr_accessor :_bel_key_spans
55
+ private :_bel_key_spans, :_bel_key_spans=
56
+ end
57
+ self._bel_key_spans = [
58
+ 0, 94, 117, 0
59
+ ]
60
+
61
+ class << self
62
+ attr_accessor :_bel_index_offsets
63
+ private :_bel_index_offsets, :_bel_index_offsets=
64
+ end
65
+ self._bel_index_offsets = [
66
+ 0, 0, 95, 213
67
+ ]
68
+
69
+ class << self
70
+ attr_accessor :_bel_indicies
71
+ private :_bel_indicies, :_bel_indicies=
72
+ end
73
+ self._bel_indicies = [
74
+ 1, 0, 1, 1, 1, 1, 0, 0,
75
+ 1, 1, 1, 1, 1, 1, 1, 1,
76
+ 1, 1, 1, 1, 1, 1, 1, 1,
77
+ 1, 1, 1, 1, 1, 1, 1, 1,
78
+ 1, 1, 1, 1, 1, 1, 1, 1,
79
+ 1, 1, 1, 1, 1, 1, 1, 1,
80
+ 1, 1, 1, 1, 1, 1, 1, 1,
81
+ 1, 1, 1, 1, 1, 1, 1, 1,
82
+ 1, 1, 1, 1, 1, 1, 1, 1,
83
+ 1, 1, 1, 1, 1, 1, 1, 1,
84
+ 1, 1, 1, 1, 1, 1, 1, 1,
85
+ 1, 1, 1, 1, 1, 1, 0, 2,
86
+ 0, 0, 0, 0, 0, 0, 0, 0,
87
+ 0, 0, 0, 0, 0, 0, 0, 0,
88
+ 0, 0, 0, 0, 0, 0, 3, 0,
89
+ 3, 3, 3, 3, 0, 0, 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, 3, 3, 3, 3,
99
+ 3, 3, 3, 3, 3, 3, 3, 3,
100
+ 3, 3, 3, 3, 0, 4, 0
101
+ ]
102
+
103
+ class << self
104
+ attr_accessor :_bel_trans_targs
105
+ private :_bel_trans_targs, :_bel_trans_targs=
106
+ end
107
+ self._bel_trans_targs = [
108
+ 0, 2, 3, 2, 0
109
+ ]
110
+
111
+ class << self
112
+ attr_accessor :_bel_trans_actions
113
+ private :_bel_trans_actions, :_bel_trans_actions=
114
+ end
115
+ self._bel_trans_actions = [
116
+ 1, 2, 4, 0, 0
117
+ ]
118
+
119
+ class << self
120
+ attr_accessor :_bel_eof_actions
121
+ private :_bel_eof_actions, :_bel_eof_actions=
122
+ end
123
+ self._bel_eof_actions = [
124
+ 0, 1, 3, 5
125
+ ]
126
+
127
+ class << self
128
+ attr_accessor :bel_start
129
+ end
130
+ self.bel_start = 1;
131
+ class << self
132
+ attr_accessor :bel_first_final
133
+ end
134
+ self.bel_first_final = 2;
135
+ class << self
136
+ attr_accessor :bel_error
137
+ end
138
+ self.bel_error = 0;
139
+
140
+ class << self
141
+ attr_accessor :bel_en_function_node
142
+ end
143
+ self.bel_en_function_node = 1;
144
+
145
+
146
+ # end: ragel
147
+ end
148
+
149
+ def each
150
+ @buffers = {}
151
+ @incomplete = {}
152
+ data = @content.unpack('C*')
153
+ p = 0
154
+ p_start = 0
155
+ p_end = 0
156
+ pe = data.length
157
+ eof = data.length
158
+ @function_started = false
159
+
160
+ # begin: ragel
161
+
162
+ begin
163
+ p ||= 0
164
+ pe ||= data.length
165
+ cs = bel_start
166
+ end
167
+
168
+
169
+ begin
170
+ testEof = false
171
+ _slen, _trans, _keys, _inds, _acts, _nacts = nil
172
+ _goto_level = 0
173
+ _resume = 10
174
+ _eof_trans = 15
175
+ _again = 20
176
+ _test_eof = 30
177
+ _out = 40
178
+ while true
179
+ if _goto_level <= 0
180
+ if p == pe
181
+ _goto_level = _test_eof
182
+ next
183
+ end
184
+ if cs == 0
185
+ _goto_level = _out
186
+ next
187
+ end
188
+ end
189
+ if _goto_level <= _resume
190
+ _keys = cs << 1
191
+ _inds = _bel_index_offsets[cs]
192
+ _slen = _bel_key_spans[cs]
193
+ _wide = data[p].ord
194
+ _trans = if ( _slen > 0 &&
195
+ _bel_trans_keys[_keys] <= _wide &&
196
+ _wide <= _bel_trans_keys[_keys + 1]
197
+ ) then
198
+ _bel_indicies[ _inds + _wide - _bel_trans_keys[_keys] ]
199
+ else
200
+ _bel_indicies[ _inds + _slen ]
201
+ end
202
+ cs = _bel_trans_targs[_trans]
203
+ if _bel_trans_actions[_trans] != 0
204
+ case _bel_trans_actions[_trans]
205
+ when 2 then
206
+ begin
207
+
208
+ trace('FUNCTION start_function')
209
+ @function_started = true
210
+ p_start = p;
211
+ end
212
+ when 4 then
213
+ begin
214
+
215
+ trace('FUNCTION end_function')
216
+ p_end = p
217
+ chars = data[p_start...p_end]
218
+ completed = !chars.empty?
219
+ ident_node = identifier(utf8_string(chars), complete: completed)
220
+ fx_node = function(ident_node, complete: ident_node.complete)
221
+ @buffers[:function] = fx_node
222
+ end
223
+ when 1 then
224
+ begin
225
+
226
+ trace('FUNCTION function_node_err')
227
+ if @function_started
228
+ # hit invalid char, include it in the identifier that results
229
+ p_end = p + 1
230
+ chars = data[p_start...p_end]
231
+ completed = !chars.empty?
232
+ ident_node = identifier(utf8_string(chars), complete: completed)
233
+ fx_node = function(ident_node, complete: false)
234
+ @buffers[:function] = fx_node
235
+ yield @buffers[:function]
236
+ end
237
+ end
238
+ end
239
+ end
240
+ end
241
+ if _goto_level <= _again
242
+ if cs == 0
243
+ _goto_level = _out
244
+ next
245
+ end
246
+ p += 1
247
+ if p != pe
248
+ _goto_level = _resume
249
+ next
250
+ end
251
+ end
252
+ if _goto_level <= _test_eof
253
+ if p == eof
254
+ case _bel_eof_actions[cs]
255
+ when 1 then
256
+ begin
257
+
258
+ trace('FUNCTION function_node_err')
259
+ if @function_started
260
+ # hit invalid char, include it in the identifier that results
261
+ p_end = p + 1
262
+ chars = data[p_start...p_end]
263
+ completed = !chars.empty?
264
+ ident_node = identifier(utf8_string(chars), complete: completed)
265
+ fx_node = function(ident_node, complete: false)
266
+ @buffers[:function] = fx_node
267
+ yield @buffers[:function]
268
+ end
269
+ end
270
+ when 5 then
271
+ begin
272
+
273
+ trace('FUNCTION yield_function')
274
+ yield @buffers[:function]
275
+ end
276
+ when 3 then
277
+ begin
278
+
279
+ trace('FUNCTION end_function')
280
+ p_end = p
281
+ chars = data[p_start...p_end]
282
+ completed = !chars.empty?
283
+ ident_node = identifier(utf8_string(chars), complete: completed)
284
+ fx_node = function(ident_node, complete: ident_node.complete)
285
+ @buffers[:function] = fx_node
286
+ end
287
+ begin
288
+
289
+ trace('FUNCTION yield_function')
290
+ yield @buffers[:function]
291
+ end
292
+ end
293
+ end
294
+
295
+ end
296
+ if _goto_level <= _out
297
+ break
298
+ end
299
+ end
300
+ end
301
+
302
+ # end: ragel
303
+ end
304
+ end
305
+ end
306
+ end
307
+ end
308
+ end
309
+
310
+ if __FILE__ == $0
311
+ $stdin.each_line do |line|
312
+ BELParser::Parsers::Common::Function.parse(line) { |obj|
313
+ puts obj.inspect
314
+ }
315
+ end
316
+ end
317
+
318
+ # vim: ft=ruby ts=2 sw=2:
319
+ # encoding: utf-8
@@ -0,0 +1,149 @@
1
+ # begin: ragel
2
+ =begin
3
+ %%{
4
+ machine bel;
5
+
6
+ include 'common.rl';
7
+
8
+ action start_function {
9
+ trace('FUNCTION start_function')
10
+ @function_started = true
11
+ p_start = p;
12
+ }
13
+
14
+ action end_function {
15
+ trace('FUNCTION end_function')
16
+ p_end = p
17
+ chars = data[p_start...p_end]
18
+ completed = !chars.empty?
19
+ ident_node = identifier(utf8_string(chars), complete: completed)
20
+ fx_node = function(ident_node, complete: ident_node.complete)
21
+ @buffers[:function] = fx_node
22
+ }
23
+
24
+ action a_function_eof {
25
+ trace('FUNCTION a_function_eof')
26
+ if @function_started
27
+ p_end = p
28
+ chars = data[p_start...p_end]
29
+ completed = !chars.empty?
30
+ ident_node = identifier(utf8_string(chars), complete: completed)
31
+ fx_node = function(ident_node, complete: ident_node.complete)
32
+ @buffers[:function] = fx_node
33
+ end
34
+ }
35
+
36
+ action function_node_err {
37
+ trace('FUNCTION function_node_err')
38
+ if @function_started
39
+ # hit invalid char, include it in the identifier that results
40
+ p_end = p + 1
41
+ chars = data[p_start...p_end]
42
+ completed = !chars.empty?
43
+ ident_node = identifier(utf8_string(chars), complete: completed)
44
+ fx_node = function(ident_node, complete: false)
45
+ @buffers[:function] = fx_node
46
+ yield @buffers[:function]
47
+ end
48
+ }
49
+
50
+ action yield_function {
51
+ trace('FUNCTION yield_function')
52
+ yield @buffers[:function]
53
+ }
54
+
55
+ function =
56
+ FUNCTION
57
+ >start_function
58
+ %end_function
59
+ ;
60
+
61
+ maybe_function =
62
+ function?
63
+ ;
64
+
65
+ a_function =
66
+ function
67
+ $eof(a_function_eof)
68
+ ;
69
+
70
+ function_node :=
71
+ function
72
+ $err(function_node_err)
73
+ NL?
74
+ %yield_function
75
+ ;
76
+ }%%
77
+ =end
78
+ # end: ragel
79
+
80
+ require_relative '../ast/node'
81
+ require_relative '../mixin/buffer'
82
+ require_relative '../nonblocking_io_wrapper'
83
+ require_relative '../tracer'
84
+
85
+ module BELParser
86
+ module Parsers
87
+ module Common
88
+ module Function
89
+
90
+ class << self
91
+
92
+ MAX_LENGTH = 1024 * 128 # 128K
93
+
94
+ def parse(content)
95
+ return nil unless content
96
+
97
+ Parser.new(content).each do |obj|
98
+ yield obj
99
+ end
100
+ end
101
+ end
102
+
103
+ private
104
+
105
+ class Parser
106
+ include Enumerable
107
+ include BELParser::Parsers::Buffer
108
+ include BELParser::Parsers::AST::Sexp
109
+ include BELParser::Parsers::Tracer
110
+
111
+ def initialize(content)
112
+ @content = content
113
+ # begin: ragel
114
+ %% write data;
115
+ # end: ragel
116
+ end
117
+
118
+ def each
119
+ @buffers = {}
120
+ @incomplete = {}
121
+ data = @content.unpack('C*')
122
+ p = 0
123
+ p_start = 0
124
+ p_end = 0
125
+ pe = data.length
126
+ eof = data.length
127
+ @function_started = false
128
+
129
+ # begin: ragel
130
+ %% write init;
131
+ %% write exec;
132
+ # end: ragel
133
+ end
134
+ end
135
+ end
136
+ end
137
+ end
138
+ end
139
+
140
+ if __FILE__ == $0
141
+ $stdin.each_line do |line|
142
+ BELParser::Parsers::Common::Function.parse(line) { |obj|
143
+ puts obj.inspect
144
+ }
145
+ end
146
+ end
147
+
148
+ # vim: ft=ruby ts=2 sw=2:
149
+ # encoding: utf-8