bel_parser 1.0.0.alpha.10 → 1.0.0.alpha.11

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 56e97fd6f3c7806fa34aea964a08dbceb7c03d91
4
- data.tar.gz: 79712252a5ee0abbb4c92ccbfe1291b3e5dd657a
3
+ metadata.gz: 102eb6c434bb351a77b6c48cb79819b4bbd6c02d
4
+ data.tar.gz: a018453c3f5a83b1ec952460c58462f9086b05c5
5
5
  SHA512:
6
- metadata.gz: 90cd6d95eb8a80079dda7d53f99e0a883390ab1a7a40125de67a397c91bf453778a5f31ac7c9b018fd299c798eb3d82e7c24299fba6f233a75048a3a86f9b86b
7
- data.tar.gz: 7cdb7c9cc960b319e960bebeea568c74742434b6831d73b27f9a648e6684476611521863018693c17f7bce8ddc55ba86a75c4e2eaae26ad3303ccb04c9fcdd21
6
+ metadata.gz: fe0528010d3ad24d9afa719bf8509965b5f9ee447049d67a27ca412b96d5781a8ba54de98d100a710648e60120a3195e2d7531ac0d332f7aa7d0a6d2d8d3b658
7
+ data.tar.gz: d85096c8ffacc3b2887b43907949c36c155d26a925f7fa41e0ccee3138c902858be4898e9689d67c4db3c18e2e4d84b5d5b90df6cdb379718d7358571d7382f3
data/VERSION CHANGED
@@ -1 +1 @@
1
- 1.0.0.alpha.10
1
+ 1.0.0.alpha.11
data/bin/bel2_validator CHANGED
@@ -15,6 +15,13 @@ require 'bel_parser'
15
15
  require 'bel_parser/expression/validator'
16
16
  BELParser::Expression::Validator
17
17
  .new(ARGV.first, namespaces)
18
- .each($stdin) do |res|
19
- puts res.map { |r| "#{r}\n" }.join.each_line.map { |l| " #{l}" }.join
18
+ .each($stdin) do |(line_number, line, ast, messages)|
19
+ puts "#{line_number}: #{line}"
20
+ puts " AST Type: #{ast.type}"
21
+ puts messages
22
+ .map { |r| "#{r}\n" }
23
+ .join
24
+ .each_line
25
+ .map { |l| " #{l}" }
26
+ .join
20
27
  end
@@ -55,7 +55,7 @@ module BELParser
55
55
  PARSERS.map do |parser|
56
56
  parser.parse(line) { |ast| ast_results << ast }
57
57
  end
58
- yield([line_number, line, ast_results])
58
+ yield [line_number, line, ast_results]
59
59
  line_number += 1
60
60
  rescue StopIteration
61
61
  return
@@ -20,15 +20,17 @@ module BELParser
20
20
 
21
21
  def initialize(specification_version, namespaces)
22
22
  @spec = BELParser::Language.specification(specification_version)
23
- @validator = BELParser::Language::ExpressionValidator.new(@spec, namespaces)
23
+ @validator = BELParser::Language::ExpressionValidator.new(
24
+ @spec, namespaces)
24
25
  end
25
26
 
26
27
  def each(io)
27
28
  if block_given?
28
29
  filtered_ast = FILTER.each(BELParser::ASTGenerator.new.each(io))
29
- filtered_ast.each do |results|
30
- term = results.last.first
31
- yield @validator.validate(term)
30
+ filtered_ast.each do |(line_number, line, ast_results)|
31
+ ast_results.each do |ast|
32
+ yield [line_number, line, ast, @validator.validate(ast)]
33
+ end
32
34
  end
33
35
  else
34
36
  enum_for(:each, io)
@@ -46,8 +48,17 @@ if __FILE__ == $PROGRAM_NAME
46
48
  USAGE
47
49
  exit 1
48
50
  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
52
- end
51
+ namespaces = Hash[ARGV[1..-1].map { |ns| ns.split('=') }]
52
+ BELParser::Expression::Validator
53
+ .new(ARGV.first, namespaces)
54
+ .each($stdin) do |(line_number, line, ast, messages)|
55
+ puts "#{line_number}: #{line}"
56
+ puts " AST Type: #{ast.type}"
57
+ puts messages
58
+ .map { |r| "#{r}\n" }
59
+ .join
60
+ .each_line
61
+ .map { |l| " #{l}" }
62
+ .join
63
+ end
53
64
  end
@@ -54,11 +54,11 @@ module BELParser
54
54
  )
55
55
  end
56
56
  @hash.freeze
57
- end
57
+ end
58
58
 
59
59
  unless defined? @names
60
60
  @names = constants.map(&method(:const_get)).map(&:first).sort.freeze
61
- end
61
+ end
62
62
 
63
63
  unless defined? @values
64
64
  @values = constants.map(&method(:const_get)).map(&:to_a).flatten.freeze
@@ -13,7 +13,7 @@ module BELParser
13
13
 
14
14
  def self.map(stmt_node, spec, _namespaces)
15
15
  return nil unless stmt_node.is_a?(BELParser::Parsers::AST::Statement)
16
- return nil unless stmt_node.relationship?
16
+ return nil if stmt_node.relationship.string_literal.nil?
17
17
  rel = spec.relationship(stmt_node.relationship.string_literal.to_sym)
18
18
  return nil unless rel.listable?
19
19
 
@@ -44,7 +44,7 @@ module BELParser
44
44
  end
45
45
 
46
46
  def to_s
47
- <<-MSG.gsub(/ {12}/, '').gsub(/\n/, '')
47
+ <<-MSG.gsub(/ {12}/, '').delete("\n")
48
48
  A "#{@rel.long}" statement cannot use the subject term as an
49
49
  object list() argument.
50
50
  MSG
@@ -13,7 +13,7 @@ module BELParser
13
13
 
14
14
  def self.map(stmt_node, spec, _namespaces)
15
15
  return nil unless stmt_node.is_a?(BELParser::Parsers::AST::Statement)
16
- return nil unless stmt_node.relationship?
16
+ return nil if stmt_node.relationship.string_literal.nil?
17
17
 
18
18
  list_func = spec.function(:list)
19
19
  return nil unless list_func
@@ -14,6 +14,7 @@ module BELParser
14
14
 
15
15
  def self.map(node, spec, _namespaces)
16
16
  return nil unless node.is_a?(BELParser::Parsers::AST::Relationship)
17
+ return nil if node.string_literal.nil?
17
18
 
18
19
  relationship_name = node.string_literal
19
20
  rel = spec.relationship(relationship_name.to_sym)
@@ -166,6 +166,10 @@ module BELParser
166
166
  SemanticIsAminoAcidRange.new(**properties)
167
167
  end
168
168
 
169
+ def is_sequence_position(**properties)
170
+ SemanticIsSequencePosition.new(**properties)
171
+ end
172
+
169
173
  def variadic_arguments(*params_or_terms, **properties)
170
174
  SemanticVariadicArguments.new(params_or_terms, **properties)
171
175
  end
@@ -229,13 +233,11 @@ module BELParser
229
233
  # Return success if semantic AST does not supply argument patterns.
230
234
  if arguments.empty? || variadic_arguments?
231
235
  success(parse_node)
236
+ # Or, check argument length.
237
+ elsif arguments.length == parse_node.arguments.length
238
+ success(parse_node)
232
239
  else
233
- # Otherwise, check argument length.
234
- if arguments.length == parse_node.arguments.length
235
- success(parse_node)
236
- else
237
- failure(parse_node)
238
- end
240
+ failure(parse_node)
239
241
  end
240
242
  end
241
243
  end
@@ -612,6 +614,30 @@ module BELParser
612
614
  end
613
615
  end
614
616
  end
617
+
618
+ # AST node for IsSequencePosition is a semantic AST.
619
+ class SemanticIsSequencePosition < SemanticASTNode
620
+ include BELParser::Quoting
621
+
622
+ def initialize(**properties)
623
+ super(:is_sequence_position, [], properties)
624
+ end
625
+
626
+ def match(value_type, _)
627
+ string_literal = unquote(value_type.string_literal)
628
+ integer_position =
629
+ begin
630
+ Integer(string_literal)
631
+ rescue
632
+ nil
633
+ end
634
+ if integer_position && integer_position > 0
635
+ success(value_type)
636
+ else
637
+ failure(value_type)
638
+ end
639
+ end
640
+ end
615
641
  end
616
642
  end
617
643
  end
@@ -66,14 +66,14 @@ module BELParser
66
66
  any),
67
67
  value(
68
68
  value_type(
69
- encoding_of(:*))))),
69
+ is_sequence_position)))),
70
70
  argument(
71
71
  parameter(
72
72
  prefix(
73
73
  any),
74
74
  value(
75
75
  value_type(
76
- encoding_of(:*))))))
76
+ is_sequence_position)))))
77
77
  end
78
78
  private_constant :AST
79
79
 
@@ -152,14 +152,14 @@ module BELParser
152
152
  any),
153
153
  value(
154
154
  value_type(
155
- encoding_of(:*))))),
155
+ is_sequence_position)))),
156
156
  argument(
157
157
  parameter(
158
158
  prefix(
159
159
  any),
160
160
  value(
161
161
  value_type(
162
- encoding_of(:*))))))
162
+ is_sequence_position)))))
163
163
  end
164
164
  private_constant :AST
165
165
 
@@ -238,14 +238,14 @@ module BELParser
238
238
  any),
239
239
  value(
240
240
  value_type(
241
- encoding_of(:*))))),
241
+ is_sequence_position)))),
242
242
  argument(
243
243
  parameter(
244
244
  prefix(
245
245
  any),
246
246
  value(
247
247
  value_type(
248
- encoding_of(:*))))))
248
+ is_sequence_position)))))
249
249
  end
250
250
  private_constant :AST
251
251
 
@@ -71,7 +71,7 @@ module BELParser
71
71
  any),
72
72
  value(
73
73
  value_type(
74
- encoding_of(:*))))))
74
+ is_sequence_position)))))
75
75
  end
76
76
  private_constant :AST
77
77
 
@@ -63,7 +63,7 @@ module BELParser
63
63
  any),
64
64
  value(
65
65
  value_type(
66
- encoding_of(:*))))),
66
+ is_sequence_position)))),
67
67
  argument(
68
68
  parameter(
69
69
  prefix(
@@ -56,7 +56,7 @@ module BELParser
56
56
  any),
57
57
  value(
58
58
  value_type(
59
- encoding_of(:*))))))
59
+ is_sequence_position)))))
60
60
  end
61
61
  private_constant :AST
62
62
 
@@ -149,7 +149,7 @@ module BELParser
149
149
  prefix(any),
150
150
  value(
151
151
  value_type(
152
- encoding_of(:*))))))
152
+ is_sequence_position)))))
153
153
  end
154
154
  private_constant :AST
155
155
 
@@ -911,6 +911,10 @@ module BELParser
911
911
  Set.new(children)
912
912
  end
913
913
 
914
+ def unset(*children)
915
+ Unset.new(children)
916
+ end
917
+
914
918
  def document_property(*children)
915
919
  DocumentProperty.new(children)
916
920
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bel_parser
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0.alpha.10
4
+ version: 1.0.0.alpha.11
5
5
  platform: ruby
6
6
  authors:
7
7
  - Anthony Bargnesi