bel_parser 1.0.0.alpha.38-java → 1.0.0.alpha.39-java

Sign up to get free protection for your applications and to get access to all the features.
Files changed (47) hide show
  1. checksums.yaml +4 -4
  2. data/VERSION +1 -1
  3. data/lib/bel_parser/ast_filter.rb +6 -2
  4. data/lib/bel_parser/parsers/ast/node.rb +113 -58
  5. data/lib/bel_parser/parsers/bel_script/define_annotation.rb +4175 -3097
  6. data/lib/bel_parser/parsers/bel_script/define_annotation.rl +142 -49
  7. data/lib/bel_parser/parsers/bel_script/define_namespace.rb +980 -461
  8. data/lib/bel_parser/parsers/bel_script/define_namespace.rl +79 -39
  9. data/lib/bel_parser/parsers/bel_script/set.rb +4878 -2743
  10. data/lib/bel_parser/parsers/bel_script/set.rl +114 -32
  11. data/lib/bel_parser/parsers/bel_script/set_document.rb +5839 -5292
  12. data/lib/bel_parser/parsers/bel_script/set_document.rl +130 -27
  13. data/lib/bel_parser/parsers/bel_script/unset.rb +321 -234
  14. data/lib/bel_parser/parsers/bel_script/unset.rl +49 -21
  15. data/lib/bel_parser/parsers/common/blank_line.rb +12 -11
  16. data/lib/bel_parser/parsers/common/blank_line.rl +12 -12
  17. data/lib/bel_parser/parsers/common/comment_line.rb +65 -40
  18. data/lib/bel_parser/parsers/common/comment_line.rl +26 -26
  19. data/lib/bel_parser/parsers/common/common.rl +60 -0
  20. data/lib/bel_parser/parsers/common/function.rb +319 -0
  21. data/lib/bel_parser/parsers/common/function.rl +149 -0
  22. data/lib/bel_parser/parsers/common/identifier.rb +72 -68
  23. data/lib/bel_parser/parsers/common/identifier.rl +73 -29
  24. data/lib/bel_parser/parsers/common/list.rb +1617 -1243
  25. data/lib/bel_parser/parsers/common/list.rl +120 -60
  26. data/lib/bel_parser/parsers/common/string.rb +114 -41
  27. data/lib/bel_parser/parsers/common/string.rl +91 -28
  28. data/lib/bel_parser/parsers/common.rb +1 -0
  29. data/lib/bel_parser/parsers/expression/comment.rb +70 -38
  30. data/lib/bel_parser/parsers/expression/comment.rl +37 -20
  31. data/lib/bel_parser/parsers/expression/nested_statement.rb +63116 -13958
  32. data/lib/bel_parser/parsers/expression/nested_statement.rl +53 -23
  33. data/lib/bel_parser/parsers/expression/observed_term.rb +32497 -5188
  34. data/lib/bel_parser/parsers/expression/observed_term.rl +25 -20
  35. data/lib/bel_parser/parsers/expression/parameter.rb +2861 -847
  36. data/lib/bel_parser/parsers/expression/parameter.rl +178 -21
  37. data/lib/bel_parser/parsers/expression/relationship.rb +73 -55
  38. data/lib/bel_parser/parsers/expression/relationship.rl +41 -23
  39. data/lib/bel_parser/parsers/expression/simple_statement.rb +42895 -7846
  40. data/lib/bel_parser/parsers/expression/simple_statement.rl +41 -24
  41. data/lib/bel_parser/parsers/expression/term.rb +16498 -2602
  42. data/lib/bel_parser/parsers/expression/term.rl +52 -35
  43. data/lib/bel_parser/parsers/line_parser.rb +1 -0
  44. data/lib/bel_parser/parsers/mixin/buffer.rb +4 -0
  45. data/lib/bel_parser/parsers/tracer.rb +19 -0
  46. data/lib/bel_parser/script/state/namespace_definition.rb +1 -0
  47. metadata +10 -7
@@ -6,25 +6,50 @@
6
6
  include 'common.rl';
7
7
  include 'identifier.rl';
8
8
 
9
- UNSET = [uU][nN][sS][eE][tT];
10
-
11
- action unset_keyword {
12
- @buffers[:unset] = unset()
9
+ action add_name {
10
+ trace('UNSET add_name')
11
+ key = @buffers.delete(:ident)
12
+ @buffers[:unset_name] = key
13
13
  }
14
14
 
15
- action name {
16
- @buffers[:unset] = @buffers[:unset] << name(@buffers[:ident])
15
+ action unset_end {
16
+ trace('UNSET unset_end')
17
+ name = @buffers.delete(:unset_name)
18
+ unless name.nil?
19
+ unset_node = unset(name, complete: name.complete)
20
+ else
21
+ unset_node = unset(complete: false)
22
+ end
23
+ @buffers[:unset] = unset_node
17
24
  }
18
25
 
19
- action yield_set {
26
+ action yield_unset {
27
+ trace('UNSET yield_unset')
20
28
  yield @buffers[:unset]
21
29
  }
22
30
 
23
- unset :=
24
- UNSET %unset_keyword
31
+ action set_node_eof {
32
+ trace('UNSET set_node_eof')
33
+ }
34
+
35
+ an_unset =
36
+ KW_UNSET
25
37
  SP+
26
- IDENT %name
27
- NL @yield_set;
38
+ an_ident
39
+ %add_name
40
+ @eof(set_node_eof)
41
+ %unset_end
42
+ ;
43
+
44
+ unset_ast_node :=
45
+ KW_UNSET
46
+ SP+?
47
+ an_ident?
48
+ %add_name
49
+ @eof(set_node_eof)
50
+ %unset_end
51
+ %yield_unset
52
+ ;
28
53
  }%%
29
54
  =end
30
55
  # end: ragel
@@ -32,6 +57,7 @@
32
57
  require_relative '../ast/node'
33
58
  require_relative '../mixin/buffer'
34
59
  require_relative '../nonblocking_io_wrapper'
60
+ require_relative '../tracer'
35
61
 
36
62
  module BELParser
37
63
  module Parsers
@@ -57,25 +83,27 @@ module BELParser
57
83
  include Enumerable
58
84
  include BELParser::Parsers::Buffer
59
85
  include BELParser::Parsers::AST::Sexp
86
+ include BELParser::Parsers::Tracer
60
87
 
61
88
  def initialize(content)
62
89
  @content = content
63
- # begin: ragel
90
+ # begin: ragel
64
91
  %% write data;
65
- # end: ragel
92
+ # end: ragel
66
93
  end
67
94
 
68
95
  def each
69
- @buffers = {}
70
- data = @content.unpack('C*')
71
- p = 0
72
- pe = data.length
73
- eof = data.length
74
-
75
- # begin: ragel
96
+ @buffers = {}
97
+ @incomplete = {}
98
+ data = @content.unpack('C*')
99
+ p = 0
100
+ pe = data.length
101
+ eof = data.length
102
+
103
+ # begin: ragel
76
104
  %% write init;
77
105
  %% write exec;
78
- # end: ragel
106
+ # end: ragel
79
107
  end
80
108
  end
81
109
  end
@@ -37,7 +37,7 @@ module BELParser
37
37
 
38
38
  def initialize(content)
39
39
  @content = content
40
- # begin: ragel
40
+ # begin: ragel
41
41
 
42
42
  class << self
43
43
  attr_accessor :_bel_trans_keys
@@ -98,28 +98,29 @@ self.bel_start = 1;
98
98
  class << self
99
99
  attr_accessor :bel_first_final
100
100
  end
101
- self.bel_first_final = 2;
101
+ self.bel_first_final = 1;
102
102
  class << self
103
103
  attr_accessor :bel_error
104
104
  end
105
105
  self.bel_error = 0;
106
106
 
107
107
  class << self
108
- attr_accessor :bel_en_blank
108
+ attr_accessor :bel_en_bl_ast
109
109
  end
110
- self.bel_en_blank = 1;
110
+ self.bel_en_bl_ast = 1;
111
111
 
112
112
 
113
- # end: ragel
113
+ # end: ragel
114
114
  end
115
115
 
116
116
  def each
117
- @buffers = {}
118
- data = @content.unpack('C*')
119
- p = 0
120
- pe = data.length
117
+ @buffers = {}
118
+ @incomplete = {}
119
+ data = @content.unpack('C*')
120
+ p = 0
121
+ pe = data.length
121
122
 
122
- # begin: ragel
123
+ # begin: ragel
123
124
 
124
125
  begin
125
126
  p ||= 0
@@ -191,7 +192,7 @@ begin
191
192
  end
192
193
  end
193
194
 
194
- # end: ragel
195
+ # end: ragel
195
196
  end
196
197
  end
197
198
  end
@@ -5,13 +5,12 @@
5
5
 
6
6
  include 'common.rl';
7
7
 
8
- action yield_blank_line {
8
+ action blank_line_yield {
9
9
  yield blank_line
10
10
  }
11
11
 
12
- BLANK = SP*;
13
-
14
- blank := BLANK %yield_blank_line NL;
12
+ blank = SP*;
13
+ bl_ast := blank NL? @blank_line_yield;
15
14
  }%%
16
15
  =end
17
16
  # end: ragel
@@ -47,21 +46,22 @@ module BELParser
47
46
 
48
47
  def initialize(content)
49
48
  @content = content
50
- # begin: ragel
49
+ # begin: ragel
51
50
  %% write data;
52
- # end: ragel
51
+ # end: ragel
53
52
  end
54
53
 
55
54
  def each
56
- @buffers = {}
57
- data = @content.unpack('C*')
58
- p = 0
59
- pe = data.length
55
+ @buffers = {}
56
+ @incomplete = {}
57
+ data = @content.unpack('C*')
58
+ p = 0
59
+ pe = data.length
60
60
 
61
- # begin: ragel
61
+ # begin: ragel
62
62
  %% write init;
63
63
  %% write exec;
64
- # end: ragel
64
+ # end: ragel
65
65
  end
66
66
  end
67
67
  end
@@ -37,15 +37,16 @@ module BELParser
37
37
 
38
38
  def initialize(content)
39
39
  @content = content
40
- # begin: ragel
40
+ # begin: ragel
41
41
 
42
42
  class << self
43
43
  attr_accessor :_bel_trans_keys
44
44
  private :_bel_trans_keys, :_bel_trans_keys=
45
45
  end
46
46
  self._bel_trans_keys = [
47
- 0, 0, 9, 35, 10, 10,
48
- 10, 10, 0, 0, 0
47
+ 0, 0, 9, 35, 9, 35,
48
+ 9, 32, 10, 10, 0,
49
+ 0, 0
49
50
  ]
50
51
 
51
52
  class << self
@@ -53,7 +54,7 @@ class << self
53
54
  private :_bel_key_spans, :_bel_key_spans=
54
55
  end
55
56
  self._bel_key_spans = [
56
- 0, 27, 1, 1, 0
57
+ 0, 27, 27, 24, 1, 0
57
58
  ]
58
59
 
59
60
  class << self
@@ -61,7 +62,7 @@ class << self
61
62
  private :_bel_index_offsets, :_bel_index_offsets=
62
63
  end
63
64
  self._bel_index_offsets = [
64
- 0, 0, 28, 30, 32
65
+ 0, 0, 28, 56, 81, 83
65
66
  ]
66
67
 
67
68
  class << self
@@ -72,8 +73,14 @@ self._bel_indicies = [
72
73
  0, 1, 1, 1, 1, 1, 1, 1,
73
74
  1, 1, 1, 1, 1, 1, 1, 1,
74
75
  1, 1, 1, 1, 1, 1, 1, 0,
75
- 1, 1, 2, 1, 4, 3, 6, 5,
76
- 1, 0
76
+ 1, 1, 2, 1, 0, 3, 1, 1,
77
+ 1, 1, 1, 1, 1, 1, 1, 1,
78
+ 1, 1, 1, 1, 1, 1, 1, 1,
79
+ 1, 1, 1, 0, 1, 1, 2, 1,
80
+ 5, 6, 4, 4, 4, 4, 4, 4,
81
+ 4, 4, 4, 4, 4, 4, 4, 4,
82
+ 4, 4, 4, 4, 4, 4, 4, 5,
83
+ 4, 3, 7, 1, 0
77
84
  ]
78
85
 
79
86
  class << self
@@ -81,7 +88,7 @@ class << self
81
88
  private :_bel_trans_targs, :_bel_trans_targs=
82
89
  end
83
90
  self._bel_trans_targs = [
84
- 1, 0, 2, 3, 4, 3, 4
91
+ 1, 0, 3, 5, 4, 3, 5, 4
85
92
  ]
86
93
 
87
94
  class << self
@@ -89,38 +96,49 @@ class << self
89
96
  private :_bel_trans_actions, :_bel_trans_actions=
90
97
  end
91
98
  self._bel_trans_actions = [
92
- 0, 0, 0, 1, 2, 3, 4
99
+ 0, 0, 0, 1, 3, 3, 4, 5
100
+ ]
101
+
102
+ class << self
103
+ attr_accessor :_bel_eof_actions
104
+ private :_bel_eof_actions, :_bel_eof_actions=
105
+ end
106
+ self._bel_eof_actions = [
107
+ 0, 0, 0, 2, 0, 0
93
108
  ]
94
109
 
95
110
  class << self
96
111
  attr_accessor :bel_start
97
112
  end
98
- self.bel_start = 1;
113
+ self.bel_start = 2;
99
114
  class << self
100
115
  attr_accessor :bel_first_final
101
116
  end
102
- self.bel_first_final = 4;
117
+ self.bel_first_final = 2;
103
118
  class << self
104
119
  attr_accessor :bel_error
105
120
  end
106
121
  self.bel_error = 0;
107
122
 
108
123
  class << self
109
- attr_accessor :bel_en_comment_line
124
+ attr_accessor :bel_en_main
110
125
  end
111
- self.bel_en_comment_line = 1;
126
+ self.bel_en_main = 2;
112
127
 
113
128
 
114
- # end: ragel
129
+ # end: ragel
115
130
  end
116
131
 
117
132
  def each
118
- @buffers = {}
119
- data = @content.unpack('C*')
120
- p = 0
121
- pe = data.length
122
-
123
- # begin: ragel
133
+ @buffers = {}
134
+ @started = false
135
+ @incomplete = {}
136
+ data = @content.unpack('C*')
137
+ p = 0
138
+ pe = data.length
139
+ eof = data.length
140
+
141
+ # begin: ragel
124
142
 
125
143
  begin
126
144
  p ||= 0
@@ -165,43 +183,39 @@ begin
165
183
  cs = _bel_trans_targs[_trans]
166
184
  if _bel_trans_actions[_trans] != 0
167
185
  case _bel_trans_actions[_trans]
168
- when 3 then
186
+ when 5 then
169
187
  begin
170
188
 
171
- @buffers[:comment_line] << data[p].ord
189
+ @incomplete[:comment_line] << data[p].ord
172
190
  end
173
191
  when 1 then
174
192
  begin
175
193
 
176
- @buffers[:comment_line] = []
177
- end
178
- begin
179
-
180
- @buffers[:comment_line] << data[p].ord
181
- end
182
- when 4 then
183
- begin
184
-
185
- @buffers[:comment_line] = comment_line(
186
- utf8_string(@buffers[:comment_line]))
194
+ cl = @incomplete.delete(:comment_line) || []
195
+ completed = @started
196
+ yield comment_line(utf8_string(cl), complete: completed)
187
197
  end
198
+ when 3 then
188
199
  begin
189
200
 
190
- yield @buffers[:comment_line]
201
+ @incomplete[:comment_line] = []
202
+ @started = true
191
203
  end
192
- when 2 then
193
204
  begin
194
205
 
195
- @buffers[:comment_line] = []
206
+ @incomplete[:comment_line] << data[p].ord
196
207
  end
208
+ when 4 then
197
209
  begin
198
210
 
199
- @buffers[:comment_line] = comment_line(
200
- utf8_string(@buffers[:comment_line]))
211
+ @incomplete[:comment_line] = []
212
+ @started = true
201
213
  end
202
214
  begin
203
215
 
204
- yield @buffers[:comment_line]
216
+ cl = @incomplete.delete(:comment_line) || []
217
+ completed = @started
218
+ yield comment_line(utf8_string(cl), complete: completed)
205
219
  end
206
220
  end
207
221
  end
@@ -218,6 +232,17 @@ begin
218
232
  end
219
233
  end
220
234
  if _goto_level <= _test_eof
235
+ if p == eof
236
+ case _bel_eof_actions[cs]
237
+ when 2 then
238
+ begin
239
+
240
+ @incomplete[:comment_line] = []
241
+ @started = true
242
+ end
243
+ end
244
+ end
245
+
221
246
  end
222
247
  if _goto_level <= _out
223
248
  break
@@ -225,7 +250,7 @@ begin
225
250
  end
226
251
  end
227
252
 
228
- # end: ragel
253
+ # end: ragel
229
254
  end
230
255
  end
231
256
  end
@@ -5,29 +5,26 @@
5
5
 
6
6
  include 'common.rl';
7
7
 
8
- action start_comment_line {
9
- @buffers[:comment_line] = []
8
+ action comment_line_start {
9
+ @incomplete[:comment_line] = []
10
+ @started = true
10
11
  }
11
12
 
12
- action append_comment_line {
13
- @buffers[:comment_line] << fc
13
+ action comment_line_more {
14
+ @incomplete[:comment_line] << fc
14
15
  }
15
16
 
16
- action finish_comment_line {
17
- @buffers[:comment_line] = comment_line(
18
- utf8_string(@buffers[:comment_line]))
17
+ action comment_line_yield {
18
+ cl = @incomplete.delete(:comment_line) || []
19
+ completed = @started
20
+ yield comment_line(utf8_string(cl), complete: completed)
19
21
  }
20
22
 
21
- action yield_comment_line {
22
- yield @buffers[:comment_line]
23
- }
24
-
25
- COMMENT_LINE =
26
- SP*
27
- NUMBER_SIGN
28
- (any - NL)* >start_comment_line $append_comment_line %finish_comment_line;
29
-
30
- comment_line := COMMENT_LINE %yield_comment_line NL;
23
+ comment_start = SP* NUMBER_SIGN SP*;
24
+ comment = comment_start (any - NL)*
25
+ >comment_line_start
26
+ $comment_line_more;
27
+ main := comment? NL? @comment_line_yield;
31
28
  }%%
32
29
  =end
33
30
  # end: ragel
@@ -63,21 +60,24 @@ module BELParser
63
60
 
64
61
  def initialize(content)
65
62
  @content = content
66
- # begin: ragel
63
+ # begin: ragel
67
64
  %% write data;
68
- # end: ragel
65
+ # end: ragel
69
66
  end
70
67
 
71
68
  def each
72
- @buffers = {}
73
- data = @content.unpack('C*')
74
- p = 0
75
- pe = data.length
76
-
77
- # begin: ragel
69
+ @buffers = {}
70
+ @started = false
71
+ @incomplete = {}
72
+ data = @content.unpack('C*')
73
+ p = 0
74
+ pe = data.length
75
+ eof = data.length
76
+
77
+ # begin: ragel
78
78
  %% write init;
79
79
  %% write exec;
80
- # end: ragel
80
+ # end: ragel
81
81
  end
82
82
  end
83
83
  end
@@ -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: