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
@@ -5,45 +5,102 @@
5
5
 
6
6
  include 'common.rl';
7
7
 
8
- action start_string {
9
- @buffers[:string] = []
8
+ action string_end {
9
+ trace('STRING string_end')
10
+ completed = @string_opened && @string_closed
11
+ chars = data[p_start...p_end]
12
+ ast_node = string(utf8_string(chars), complete: true)
13
+ @buffers[:string] = ast_node
10
14
  }
11
15
 
12
- action append_string {
13
- (@buffers[:string] ||= []) << fc
16
+ action yield_string {
17
+ trace('STRING yield_string')
18
+ yield @buffers[:string]
14
19
  }
15
20
 
16
- action finish_string {
17
- @buffers[:string] = string(utf8_string(@buffers[:string]))
21
+ action start_string {
22
+ trace('STRING start_string')
23
+ @string_opened = true
24
+ p_start = p
18
25
  }
19
26
 
20
- action error_string {
21
- @buffers[:string] ||= []
22
- @buffers[:string] = string(utf8_string(@buffers[:string]).sub(/\n$/, ''))
27
+ action stop_string {
28
+ trace('STRING stop_string')
29
+ @string_closed = true
30
+ p_end = p
23
31
  }
24
32
 
25
- action yield_complete_string {
26
- yield @buffers[:string]
33
+ action eof_string {
34
+ trace('STRING eof_string')
35
+ p_end = p
36
+ chars = data[p_start...p_end]
37
+ ast_node = string(utf8_string(chars), complete: false)
38
+ @buffers[:string] = ast_node
27
39
  }
28
40
 
29
- action yield_error_string {
30
- @buffers[:string] ||= []
41
+ action string_node_eof {
42
+ trace('STRING string_node_eof')
31
43
  yield @buffers[:string]
32
44
  }
33
45
 
34
- STRING =
35
- ('"' ('\\\"' | [^"])** '"') >start_string $append_string %finish_string $err(error_string);
46
+ action a_string_err {
47
+ trace('STRING a_string_err')
48
+ p_end = p
49
+ chars = data[p_start...p_end]
50
+ ast_node = string(utf8_string(chars), complete: false)
51
+ @buffers[:string] = ast_node
52
+ }
53
+
54
+ action string_node_err {
55
+ trace('STRING string_node_err')
56
+ p_end = p
57
+ chars = data[p_start...p_end]
58
+ ast_node = string(utf8_string(chars), complete: false)
59
+ yield ast_node
60
+ }
36
61
 
37
- string :=
38
- STRING $err(yield_error_string) %yield_complete_string
39
- NL;
62
+ #single =
63
+ # WS* SQ (NOT_SQESC | ESCAPED)*
64
+ # >start_string
65
+ # $eof(eof_string)
66
+ # %stop_string
67
+ # %string_end
68
+ # SQ
69
+ # ;
70
+
71
+ double =
72
+ WS* DQ (NOT_DQESC | ESCAPED)*
73
+ >start_string
74
+ $eof(eof_string)
75
+ %stop_string
76
+ %string_end
77
+ DQ
78
+ ;
79
+
80
+ a_string =
81
+ #(single | double)
82
+ double
83
+ $err(a_string_err)
84
+ ;
85
+
86
+ string_node :=
87
+ (
88
+ #single |
89
+ double
90
+ )
91
+ $err(string_node_err)
92
+ @eof(string_node_eof)
93
+ @yield_string
94
+ ;
40
95
  }%%
41
96
  =end
42
97
  # end: ragel
98
+ # ('\"' | ^(0 .. 31 | 34))* ^'\\"'
43
99
 
44
100
  require_relative '../ast/node'
45
101
  require_relative '../mixin/buffer'
46
102
  require_relative '../nonblocking_io_wrapper'
103
+ require_relative '../tracer'
47
104
 
48
105
  module BELParser
49
106
  module Parsers
@@ -69,25 +126,31 @@ module BELParser
69
126
  include Enumerable
70
127
  include BELParser::Parsers::Buffer
71
128
  include BELParser::Parsers::AST::Sexp
129
+ include BELParser::Parsers::Tracer
72
130
 
73
131
  def initialize(content)
74
132
  @content = content
75
- # begin: ragel
133
+ # begin: ragel
76
134
  %% write data;
77
- # end: ragel
135
+ # end: ragel
78
136
  end
79
137
 
80
138
  def each
81
- @buffers = {}
82
- data = @content.unpack('C*')
83
- p = 0
84
- pe = data.length
85
- eof = data.length
86
-
87
- # begin: ragel
139
+ @buffers = {}
140
+ @incomplete = {}
141
+ @string_opened = false
142
+ @string_closed = false
143
+ data = @content.unpack('C*')
144
+ p_start = 0
145
+ p_end = 0
146
+ p = 0
147
+ pe = data.length
148
+ eof = data.length
149
+
150
+ # begin: ragel
88
151
  %% write init;
89
152
  %% write exec;
90
- # end: ragel
153
+ # end: ragel
91
154
  end
92
155
  end
93
156
  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,17 +35,18 @@ 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, 10, 47, 47, 47,
49
+ 0, 0, 47, 47, 47, 47,
48
50
  10, 10, 10, 10, 0,
49
51
  0, 0
50
52
  ]
@@ -54,7 +56,7 @@ class << self
54
56
  private :_bel_key_spans, :_bel_key_spans=
55
57
  end
56
58
  self._bel_key_spans = [
57
- 0, 38, 1, 1, 1, 0
59
+ 0, 1, 1, 1, 1, 0
58
60
  ]
59
61
 
60
62
  class << self
@@ -62,7 +64,7 @@ class << self
62
64
  private :_bel_index_offsets, :_bel_index_offsets=
63
65
  end
64
66
  self._bel_index_offsets = [
65
- 0, 0, 39, 41, 43, 45
67
+ 0, 0, 2, 4, 6, 8
66
68
  ]
67
69
 
68
70
  class << self
@@ -70,12 +72,8 @@ class << self
70
72
  private :_bel_indicies, :_bel_indicies=
71
73
  end
72
74
  self._bel_indicies = [
73
- 0, 1, 1, 1, 1, 1, 1, 1,
74
- 1, 1, 1, 1, 1, 1, 1, 1,
75
- 1, 1, 1, 1, 1, 1, 1, 1,
76
- 1, 1, 1, 1, 1, 1, 1, 1,
77
- 1, 1, 1, 1, 1, 2, 1, 3,
78
- 1, 1, 4, 6, 5, 1, 0
75
+ 0, 1, 2, 1, 1, 3, 5, 4,
76
+ 1, 0
79
77
  ]
80
78
 
81
79
  class << self
@@ -83,7 +81,7 @@ class << self
83
81
  private :_bel_trans_targs, :_bel_trans_targs=
84
82
  end
85
83
  self._bel_trans_targs = [
86
- 5, 0, 2, 3, 4, 4, 5
84
+ 2, 0, 3, 4, 4, 5
87
85
  ]
88
86
 
89
87
  class << self
@@ -91,7 +89,15 @@ class << self
91
89
  private :_bel_trans_actions, :_bel_trans_actions=
92
90
  end
93
91
  self._bel_trans_actions = [
94
- 1, 0, 0, 0, 2, 3, 4
92
+ 0, 0, 0, 1, 0, 2
93
+ ]
94
+
95
+ class << self
96
+ attr_accessor :_bel_eof_actions
97
+ private :_bel_eof_actions, :_bel_eof_actions=
98
+ end
99
+ self._bel_eof_actions = [
100
+ 0, 0, 0, 0, 2, 0
95
101
  ]
96
102
 
97
103
  class << self
@@ -101,29 +107,33 @@ self.bel_start = 1;
101
107
  class << self
102
108
  attr_accessor :bel_first_final
103
109
  end
104
- self.bel_first_final = 5;
110
+ self.bel_first_final = 4;
105
111
  class << self
106
112
  attr_accessor :bel_error
107
113
  end
108
114
  self.bel_error = 0;
109
115
 
110
116
  class << self
111
- attr_accessor :bel_en_comment
117
+ attr_accessor :bel_en_comment_node
112
118
  end
113
- self.bel_en_comment = 1;
119
+ self.bel_en_comment_node = 1;
114
120
 
115
121
 
116
- # end: ragel
122
+ # end: ragel
117
123
  end
118
124
 
119
125
  def each
120
- @buffers = {}
121
- stack = []
122
- data = @content.unpack('C*')
123
- p = 0
124
- pe = data.length
125
-
126
- # begin: ragel
126
+ @buffers = {}
127
+ @incomplete = {}
128
+ stack = []
129
+ data = @content.unpack('C*')
130
+ p = 0
131
+ p_start = 0
132
+ p_end = 0
133
+ pe = data.length
134
+ eof = data.length
135
+
136
+ # begin: ragel
127
137
 
128
138
  begin
129
139
  p ||= 0
@@ -168,33 +178,30 @@ begin
168
178
  cs = _bel_trans_targs[_trans]
169
179
  if _bel_trans_actions[_trans] != 0
170
180
  case _bel_trans_actions[_trans]
171
- when 3 then
172
- begin
173
-
174
- @buffers[:comment] << data[p].ord
175
- end
176
181
  when 1 then
177
182
  begin
178
183
 
179
- yield @buffers[:comment] || comment(nil)
184
+ trace('COMMENT start_comment')
185
+ p_start = p;
180
186
  end
181
187
  when 2 then
182
188
  begin
183
189
 
184
- @buffers[:comment] = []
185
- end
186
- begin
187
-
188
- @buffers[:comment] << data[p].ord
190
+ trace('COMMENT stop_comment')
191
+ p_end = p;
189
192
  end
190
- when 4 then
191
193
  begin
192
194
 
193
- @buffers[:comment] = comment(
194
- utf8_string(@buffers[:comment]))
195
+ trace('COMMENT comment_end')
196
+ p_end = p
197
+ chars = data[p_start...p_end]
198
+ completed = !chars.empty?
199
+ ast_node = comment(utf8_string(chars), complete: completed)
200
+ @buffers[:comment] = ast_node
195
201
  end
196
202
  begin
197
203
 
204
+ trace('COMMENT yield_comment')
198
205
  yield @buffers[:comment] || comment(nil)
199
206
  end
200
207
  end
@@ -212,6 +219,31 @@ begin
212
219
  end
213
220
  end
214
221
  if _goto_level <= _test_eof
222
+ if p == eof
223
+ case _bel_eof_actions[cs]
224
+ when 2 then
225
+ begin
226
+
227
+ trace('COMMENT stop_comment')
228
+ p_end = p;
229
+ end
230
+ begin
231
+
232
+ trace('COMMENT comment_end')
233
+ p_end = p
234
+ chars = data[p_start...p_end]
235
+ completed = !chars.empty?
236
+ ast_node = comment(utf8_string(chars), complete: completed)
237
+ @buffers[:comment] = ast_node
238
+ end
239
+ begin
240
+
241
+ trace('COMMENT yield_comment')
242
+ yield @buffers[:comment] || comment(nil)
243
+ end
244
+ end
245
+ end
246
+
215
247
  end
216
248
  if _goto_level <= _out
217
249
  break
@@ -219,7 +251,7 @@ begin
219
251
  end
220
252
  end
221
253
 
222
- # end: ragel
254
+ # end: ragel
223
255
  end
224
256
  end
225
257
  end
@@ -6,27 +6,38 @@
6
6
  include 'common.rl';
7
7
 
8
8
  action start_comment {
9
- @buffers[:comment] = []
9
+ trace('COMMENT start_comment')
10
+ p_start = p;
10
11
  }
11
12
 
12
- action append_comment {
13
- @buffers[:comment] << fc
13
+ action stop_comment {
14
+ trace('COMMENT stop_comment')
15
+ p_end = p;
14
16
  }
15
17
 
16
- action finish_comment {
17
- @buffers[:comment] = comment(
18
- utf8_string(@buffers[:comment]))
18
+ action comment_end {
19
+ trace('COMMENT comment_end')
20
+ p_end = p
21
+ chars = data[p_start...p_end]
22
+ completed = !chars.empty?
23
+ ast_node = comment(utf8_string(chars), complete: completed)
24
+ @buffers[:comment] = ast_node
19
25
  }
20
26
 
21
27
  action yield_comment {
28
+ trace('COMMENT yield_comment')
22
29
  yield @buffers[:comment] || comment(nil)
23
30
  }
24
31
 
25
- COMMENT = '//' ^NL+ >start_comment $append_comment %finish_comment;
32
+ comment =
33
+ SS
34
+ ^NL+ >start_comment %stop_comment %comment_end
35
+ ;
26
36
 
27
- comment :=
28
- COMMENT? %yield_comment
29
- NL;
37
+ comment_node :=
38
+ comment %yield_comment
39
+ NL?
40
+ ;
30
41
  }%%
31
42
  =end
32
43
  # end: ragel
@@ -34,6 +45,7 @@
34
45
  require_relative '../ast/node'
35
46
  require_relative '../mixin/buffer'
36
47
  require_relative '../nonblocking_io_wrapper'
48
+ require_relative '../tracer'
37
49
 
38
50
  module BELParser
39
51
  module Parsers
@@ -59,25 +71,30 @@ module BELParser
59
71
  include Enumerable
60
72
  include BELParser::Parsers::Buffer
61
73
  include BELParser::Parsers::AST::Sexp
74
+ include BELParser::Parsers::Tracer
62
75
 
63
76
  def initialize(content)
64
77
  @content = content
65
- # begin: ragel
78
+ # begin: ragel
66
79
  %% write data;
67
- # end: ragel
80
+ # end: ragel
68
81
  end
69
82
 
70
83
  def each
71
- @buffers = {}
72
- stack = []
73
- data = @content.unpack('C*')
74
- p = 0
75
- pe = data.length
76
-
77
- # begin: ragel
84
+ @buffers = {}
85
+ @incomplete = {}
86
+ stack = []
87
+ data = @content.unpack('C*')
88
+ p = 0
89
+ p_start = 0
90
+ p_end = 0
91
+ pe = data.length
92
+ eof = data.length
93
+
94
+ # begin: ragel
78
95
  %% write init;
79
96
  %% write exec;
80
- # end: ragel
97
+ # end: ragel
81
98
  end
82
99
  end
83
100
  end