bel_parser 1.0.0.alpha.13 → 1.0.0.alpha.14

Sign up to get free protection for your applications and to get access to all the features.
Files changed (31) hide show
  1. checksums.yaml +4 -4
  2. data/VERSION +1 -1
  3. data/lib/bel_parser/language/apply_namespace_encoding.rb +5 -2
  4. data/lib/bel_parser/language/expression_validator.rb +25 -7
  5. data/lib/bel_parser/language/syntax/undefined_namespace_value.rb +5 -6
  6. data/lib/bel_parser/language.rb +8 -0
  7. data/lib/bel_parser/parsers/ast/node.rb +30 -3
  8. data/lib/bel_parser/parsers/bel_script/define_annotation.rb +1732 -1288
  9. data/lib/bel_parser/parsers/bel_script/set.rb +1424 -972
  10. data/lib/bel_parser/parsers/bel_script/set_document.rb +2735 -2100
  11. data/lib/bel_parser/parsers/common/list.rb +708 -462
  12. data/lib/bel_parser/parsers/common/list.rl +6 -4
  13. data/lib/bel_parser/resource/eager_reader.rb +9 -9
  14. data/lib/bel_parser/resource/http_cache.rb +26 -8
  15. data/lib/bel_parser/resource/resource_file_reader.rb +1 -0
  16. data/lib/bel_parser/resource/sparql_reader.rb +1 -0
  17. data/lib/bel_parser/script/state/annotation_definition.rb +62 -0
  18. data/lib/bel_parser/script/state/bel_version.rb +35 -0
  19. data/lib/bel_parser/script/state/document_property.rb +29 -0
  20. data/lib/bel_parser/script/state/namespace_definition.rb +32 -0
  21. data/lib/bel_parser/script/state/set.rb +57 -0
  22. data/lib/bel_parser/script/state/unset.rb +43 -0
  23. data/lib/bel_parser/script/state_function.rb +10 -0
  24. data/lib/bel_parser/script/syntax/expression_validation.rb +46 -0
  25. data/lib/bel_parser/script/syntax/invalid_regex_pattern.rb +49 -0
  26. data/lib/bel_parser/script/syntax/undefined_annotation.rb +60 -0
  27. data/lib/bel_parser/script/syntax/undefined_annotation_value.rb +83 -0
  28. data/lib/bel_parser/script/syntax/unresolvable_namespace.rb +55 -0
  29. data/lib/bel_parser/script/syntax/unsupported_bel_version.rb +58 -0
  30. data/lib/bel_parser/script/validator.rb +153 -0
  31. metadata +15 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: a431be1d3646bca92e1e4df5371f3d8bf8865c3f
4
- data.tar.gz: ca8bd4846cbfb847efff3ba22840df28e2d222d7
3
+ metadata.gz: a93a3b8baa29469eeee1329e06bbc82a886d7d59
4
+ data.tar.gz: 07332e2aff2a9b3ba75e7570c13dd4b5be14d340
5
5
  SHA512:
6
- metadata.gz: 621944ea9d667b47e61b017fdbdf05632355c25dc7d214ec5515ce872faee31ea84e2cf47147daf82c28a278be31c4116d2ce12b1ad87339fb6765621e979b12
7
- data.tar.gz: a2102f77e4bc6419c7d28fdfea8c12005f08588c91b854b6a5b30d9987b70235af5ef0d00df8ec538af3423661e7d92e28c89304a7efee858591f272f5242f85
6
+ metadata.gz: 810411e5492af6670af3ba4a1674d1bf72f1543e4bd432befecd528f466b9f35e03e321861faba4d25a9efe000c0d8b3b0ed9cd809b4df2e4d56256d742a6200
7
+ data.tar.gz: 29cfd9031739f4108975fb8dd618c8051c2ad95cd46ccbdee6840d1768bb7f90d9776e687dc8f816825b7c7aa7a83bf47f9b98f8cf15907c9ac180f6ec0b99f3
data/VERSION CHANGED
@@ -1 +1 @@
1
- 1.0.0.alpha.13
1
+ 1.0.0.alpha.14
@@ -52,15 +52,16 @@ module BELParser
52
52
 
53
53
  def on_parameter(parameter_node)
54
54
  @resolved_dataset = nil
55
+ @prefix = nil
55
56
  process(parameter_node.prefix)
56
57
  process(parameter_node.value)
57
58
  end
58
59
 
59
60
  def on_prefix(prefix_node)
60
61
  return prefix_node unless prefix_node.identifier
61
- prefix = prefix_node.identifier.string_literal
62
62
 
63
- identifier = @identifier_hash[prefix]
63
+ @prefix = prefix_node.identifier.string_literal
64
+ identifier = @identifier_hash[@prefix].identifier
64
65
  return prefix_node unless identifier
65
66
 
66
67
  dataset = @resource_reader.retrieve_resource(identifier)
@@ -80,6 +81,7 @@ module BELParser
80
81
  @resource_reader
81
82
  .retrieve_value_from_resource(identifier, value_literal)
82
83
 
84
+ value_node.prefix = @prefix
83
85
  if value
84
86
  value_node.encoding =
85
87
  value
@@ -90,6 +92,7 @@ module BELParser
90
92
  value_node.encoding = nil
91
93
  value_node.namespace_value = nil
92
94
  end
95
+ value_node
93
96
  end
94
97
  end
95
98
  end
@@ -25,10 +25,8 @@ module BELParser
25
25
  def validate(expression_node)
26
26
  @transform.process(expression_node)
27
27
  results = syntax(expression_node)
28
- if results.empty?
29
- results << Syntax::Valid.new(expression_node, @spec)
30
- results.concat(semantics(expression_node))
31
- end
28
+ results << Syntax::Valid.new(expression_node, @spec) if results.empty?
29
+ results.concat(semantics(expression_node))
32
30
  results
33
31
  end
34
32
 
@@ -41,9 +39,29 @@ module BELParser
41
39
  end
42
40
 
43
41
  def semantics(expression_node)
44
- expression_node.traverse.flat_map do |node|
45
- @semantics_functions.flat_map { |func| func.map(node, @spec, @namespaces) }
46
- end.compact
42
+ semantic_results =
43
+ expression_node.traverse.flat_map do |node|
44
+ @semantics_functions.flat_map { |func| func.map(node, @spec, @namespaces) }
45
+ end.compact
46
+ sigmap_results, other_results =
47
+ semantic_results.partition do |result|
48
+ result.is_a?(Semantics::SignatureMappingSuccess) ||
49
+ result.is_a?(Semantics::SignatureMappingWarning)
50
+ end
51
+ expression_node
52
+ .traverse
53
+ .select do |node|
54
+ node.is_a?(BELParser::Parsers::AST::Term)
55
+ end
56
+ .map do |term_node|
57
+ sigmap_term =
58
+ sigmap_results
59
+ .select { |res| res.expression_node == term_node }
60
+ unless sigmap_term.any?(&:success?)
61
+ other_results.concat(sigmap_term)
62
+ end
63
+ end
64
+ other_results
47
65
  end
48
66
  end
49
67
  end
@@ -27,15 +27,14 @@ module BELParser
27
27
  # Gets the undefined value.
28
28
  attr_reader :undefined_value
29
29
 
30
- def initialize(prefix_node, spec, undefined_value)
31
- super(prefix_node, spec)
32
- @undefined_value = undefined_value
30
+ def initialize(value_node, spec, value)
31
+ super(value_node, spec)
32
+ @value = value
33
33
  end
34
34
 
35
35
  def msg
36
- <<-MSG.gsub(/ {10}/, '')
37
- Undefined namespace value "#{undefined_value}".
38
- MSG
36
+ prefix = @expression_node.prefix
37
+ %(Undefined namespace value "#@value" for namespace "#{prefix}".)
39
38
  end
40
39
  end
41
40
  end
@@ -52,6 +52,14 @@ module BELParser
52
52
  end.sort
53
53
  end
54
54
 
55
+ # Returns the latest supported version string according to the
56
+ # _MAJOR.MINOR_ pattern.
57
+ #
58
+ # @return [String] latest supported version
59
+ def self.latest_supported_version
60
+ versions.max_by { |version| version.to_f }
61
+ end
62
+
55
63
  # Returns all language {Specification specifications}.
56
64
  #
57
65
  # @return [Array<Specification>] BEL specifications
@@ -209,6 +209,16 @@ module BELParser
209
209
  def initialize(children = [], properties = {})
210
210
  super(AnnotationDefinition.ast_type, children, properties)
211
211
  end
212
+
213
+ # Get the annotation definition's keyword.
214
+ def keyword
215
+ children[0]
216
+ end
217
+
218
+ # Get the annotation definition's domain.
219
+ def domain
220
+ children[1]
221
+ end
212
222
  end
213
223
 
214
224
  # AST node representing the function of a BEL term.
@@ -296,14 +306,24 @@ module BELParser
296
306
  super(Domain.ast_type, children, properties)
297
307
  end
298
308
 
309
+ # Determine if this is a LIST domain.
310
+ def list?
311
+ children[0] && children[0].is_a?(List)
312
+ end
313
+
314
+ # Determine if this is a PATTERN domain.
315
+ def pattern?
316
+ children[0] && children[0].is_a?(Pattern)
317
+ end
318
+
299
319
  # Determine if this is a URL domain.
300
320
  def url?
301
321
  children[0] && children[0].is_a?(Url)
302
322
  end
303
323
 
304
324
  # Get the domain's Url.
305
- def url
306
- url? ? children[0] : nil
325
+ def child
326
+ children[0]
307
327
  end
308
328
  end
309
329
 
@@ -380,6 +400,10 @@ module BELParser
380
400
  def initialize(children = [], properties = {})
381
401
  super(List.ast_type, children, properties)
382
402
  end
403
+
404
+ def list_items
405
+ children
406
+ end
383
407
  end
384
408
 
385
409
  # AST node representing a list item.
@@ -780,7 +804,7 @@ module BELParser
780
804
 
781
805
  # Get what is being unset.
782
806
  def name
783
- # TODO: access children for content
807
+ children[0]
784
808
  end
785
809
  end
786
810
 
@@ -820,6 +844,9 @@ module BELParser
820
844
  super(Value.ast_type, children, properties)
821
845
  end
822
846
 
847
+ # Get/Set the namespace prefix.
848
+ attr_accessor :prefix
849
+
823
850
  # Get/Set the value's encoding.
824
851
  attr_accessor :encoding
825
852