bel_parser 1.0.0.alpha.6 → 1.0.0.alpha.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 31d99776d9e14c8680ec557fcc2e9e94136b90dc
4
- data.tar.gz: 0764321e9c0d762d5a4186301f62c4f21b56431c
3
+ metadata.gz: a34f2b2fcde4d9804cccccca0a470bce0d266956
4
+ data.tar.gz: c3443d26fb7a34c8a65b5ca7275bb77cda43557f
5
5
  SHA512:
6
- metadata.gz: 4d8915205e38ae41098e1c4468b7a54b7d07f23b20f6667d8ab17fbbd7371504402e369122d3e6a91d3adb1148d824578732328f457531956b729402b5401d1f
7
- data.tar.gz: 528a2bad2581e21df25812804b56d7c366d23f1ee18524767aac5cf8e518b4d1d58952c75763e7893d760b66809b3e15d0d92b0091dda4b6a56bf6d28ebf1146
6
+ metadata.gz: 224d93b78ef97b22a0105ffe03188e20fad89096922c806a2a474d043ba6effe33889ba7162d7aa310bdf34a57355cbb81776099c00c037a9a4d3b62570d45e2
7
+ data.tar.gz: 907a17075b1053f6f515e434061d51a49f23167bc5f37bd475124b8f4a6f6ba6cc9364b498ddf428f2172c92ab0aae41b2693657331b1d6cdd9806c2448b9110
data/VERSION CHANGED
@@ -1 +1 @@
1
- 1.0.0.alpha.6
1
+ 1.0.0.alpha.7
@@ -25,3 +25,16 @@ module BELParser
25
25
  end
26
26
  end
27
27
  end
28
+
29
+ if __FILE__ == $PROGRAM_NAME
30
+ require_relative 'ast_generator'
31
+
32
+ types = ARGV.map(&:to_sym)
33
+ ast = BELParser::ASTGenerator.new.each($stdin)
34
+ BELParser::ASTFilter.new(*types).each(ast) do |(line_number, line, results)|
35
+ puts "#{line_number}: #{line}"
36
+ results.each do |ast|
37
+ puts ast.to_s(1)
38
+ end
39
+ end
40
+ end
@@ -34,10 +34,9 @@ module BELParser
34
34
  end
35
35
 
36
36
  if __FILE__ == $PROGRAM_NAME
37
- BELParser::Expression::Parser.new.each($stdin) do |line_result|
38
- line_number, line, ast_results = line_result
37
+ BELParser::Expression::Parser.new.each($stdin) do |(line_number, line, res)|
39
38
  puts "#{line_number}: #{line}"
40
- ast_results.each do |ast|
39
+ res.each do |ast|
41
40
  puts ast.to_s(1)
42
41
  end
43
42
  end
@@ -46,10 +46,8 @@ if __FILE__ == $PROGRAM_NAME
46
46
  USAGE
47
47
  exit 1
48
48
  end
49
- namespaces = Hash[ARGV[1..-1].map { |ns| ns.split('=') }]
50
- BELParser::Expression::Validator.new(ARGV.first, namespaces).each($stdin) do |res|
51
- res.each do |res|
52
- puts res.each_line.map { |l| " #{l}" }.join
53
- end
49
+ ns = Hash[ARGV[1..-1].map { |ns| ns.split('=') }]
50
+ BELParser::Expression::Validator.new(ARGV.first, ns).each($stdin) do |res|
51
+ puts res.map { |r| "#{r}\n" }.join.each_line.map { |l| " #{l}" }.join
54
52
  end
55
53
  end
@@ -24,8 +24,8 @@ module BELParser
24
24
  :observed_term,
25
25
  :simple_statement,
26
26
  :nested_statement,
27
- :define_annotation,
28
- :define_namespace,
27
+ :annotation_definition,
28
+ :namespace_definition,
29
29
  :set,
30
30
  :unset
31
31
  )
@@ -44,10 +44,9 @@ module BELParser
44
44
  end
45
45
 
46
46
  if __FILE__ == $PROGRAM_NAME
47
- BELParser::Parser.new.each($stdin) do |line_result|
48
- line_number, line, ast_results = line_result
47
+ BELParser::Parser.new.each($stdin) do |(line_number, line, results)|
49
48
  puts "#{line_number}: #{line}"
50
- ast_results.each do |ast|
49
+ results.each do |ast|
51
50
  puts ast.to_s(1)
52
51
  end
53
52
  end
@@ -250,7 +250,97 @@ module BELParser
250
250
 
251
251
  # Get the namespace definition's keyword.
252
252
  def keyword
253
- # TODO: access children for content
253
+ children[0]
254
+ end
255
+
256
+ # Get the namespace definition's domain.
257
+ def domain
258
+ children[1]
259
+ end
260
+ end
261
+
262
+ # AST node representing a keyword (e.g. definitions).
263
+ class Keyword < Node
264
+ # AST node type
265
+ @ast_type = :keyword
266
+ # Keywords have semantic meaning
267
+ @has_semantics = true
268
+
269
+ # New Keyword AST node.
270
+ #
271
+ # @see Node#initialize Node class for basic properties
272
+ def initialize(children = [], properties = {})
273
+ super(Keyword.ast_type, children, properties)
274
+ end
275
+
276
+ # Get the keyword's identifier.
277
+ def identifier
278
+ children[0]
279
+ end
280
+ end
281
+
282
+ # AST node representing a domain (e.g. Url, Uri, List, Pattern).
283
+ class Domain < Node
284
+ # AST node type
285
+ @ast_type = :domain
286
+ # Domains have semantic meaning
287
+ @has_semantics = true
288
+
289
+ # New Domain AST node.
290
+ #
291
+ # @see Node#initialize Node class for basic properties
292
+ def initialize(children = [], properties = {})
293
+ super(Domain.ast_type, children, properties)
294
+ end
295
+
296
+ # Determine if this is a URL domain.
297
+ def has_url?
298
+ children[0] && children[0].is_a?(Url)
299
+ end
300
+
301
+ # Get the domain's Url.
302
+ def url
303
+ has_url? ? children[0] : nil
304
+ end
305
+ end
306
+
307
+ # AST node representing a URL.
308
+ class Url < Node
309
+ # AST node type
310
+ @ast_type = :url
311
+ # Urls have semantic meaning
312
+ @has_semantics = true
313
+
314
+ # New Url AST node.
315
+ #
316
+ # @see Node#initialize Node class for basic properties
317
+ def initialize(children = [], properties = {})
318
+ super(Url.ast_type, children, properties)
319
+ end
320
+
321
+ # Get the url's string.
322
+ def string
323
+ children[0]
324
+ end
325
+ end
326
+
327
+ # AST node representing a Pattern.
328
+ class Pattern < Node
329
+ # AST node type
330
+ @ast_type = :pattern
331
+ # Patterns have semantic meaning
332
+ @has_semantics = true
333
+
334
+ # New Pattern AST node.
335
+ #
336
+ # @see Node#initialize Node class for basic properties
337
+ def initialize(children = [], properties = {})
338
+ super(Pattern.ast_type, children, properties)
339
+ end
340
+
341
+ # Get the pattern's string.
342
+ def string
343
+ children[0]
254
344
  end
255
345
  end
256
346
 
@@ -289,6 +379,21 @@ module BELParser
289
379
  end
290
380
  end
291
381
 
382
+ # AST node representing a list item.
383
+ class ListItem < Node
384
+ # AST node type
385
+ @ast_type = :list_item
386
+ # List items have semantics (content is meaningful)
387
+ @has_semantics = true
388
+
389
+ # New ListItem AST node.
390
+ #
391
+ # @see Node#initialize Node class for basic properties
392
+ def initialize(children = [], properties = {})
393
+ super(ListItem.ast_type, children, properties)
394
+ end
395
+ end
396
+
292
397
  # AST node representing an argument.
293
398
  class Argument < Node
294
399
  # AST node type
@@ -750,6 +855,10 @@ module BELParser
750
855
  List.new(children)
751
856
  end
752
857
 
858
+ def list_item(*children)
859
+ ListItem.new(children)
860
+ end
861
+
753
862
  def comment(*children)
754
863
  Comment.new(children)
755
864
  end
@@ -758,6 +867,10 @@ module BELParser
758
867
  CommentLine.new(children)
759
868
  end
760
869
 
870
+ def blank_line
871
+ BlankLine.new
872
+ end
873
+
761
874
  def annotation_definition(*children)
762
875
  AnnotationDefinition.new(children)
763
876
  end
@@ -765,6 +878,22 @@ module BELParser
765
878
  def namespace_definition(*children)
766
879
  NamespaceDefinition.new(children)
767
880
  end
881
+
882
+ def keyword(*children)
883
+ Keyword.new(children)
884
+ end
885
+
886
+ def domain(*children)
887
+ Domain.new(children)
888
+ end
889
+
890
+ def url(*children)
891
+ Url.new(children)
892
+ end
893
+
894
+ def pattern(*children)
895
+ Pattern.new(children)
896
+ end
768
897
  end
769
898
  end
770
899
  end