bel_parser 1.0.0.alpha.21 → 1.0.0.alpha.22

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: d6a168817ba0f0cede0a3b4c7fdd078514a8ee6f
4
- data.tar.gz: 84bb8cded6070abe5f02e93703c149cbb3adfd88
3
+ metadata.gz: 2e418c5b2fae45c7d2d04f8d6f6192fff2f1f1d4
4
+ data.tar.gz: 42a84936274b3cdd6eccdb2918b2b5ad37f49551
5
5
  SHA512:
6
- metadata.gz: b6960ba1eb867c53e98ea37be80617c7521773bd8676e348b1165a7ecf598acf9b6d005147423601b449c446638644cc130afec39856714b4ff70ac92b848f5e
7
- data.tar.gz: 516482702677227cfdcb88aa44de29ea0a6ca3f00f1da74ad7e4ca3cfd6773d7df765e715b18e72a5e9a92845e05b1c5a2fdac1e52362d0a374073e75c24eff4
6
+ metadata.gz: 356b39aebd42b4298a29d2a4e7ec1521855a5def19f6c1baa8b5769c81a14866f3bab2f7c28450171682b41bb841f47b11c3cd6a98c05ff52749dff53bc294b4
7
+ data.tar.gz: f9f900d99b8ba8f5adfd72d5a08747a2b3771bee8a475fa0e2408712ac5ae1cc9470eb49d40837687bc83b6ca4b8e2ea31a4b2174ee627dc5fdb69ce18458d26
data/VERSION CHANGED
@@ -1 +1 @@
1
- 1.0.0.alpha.21
1
+ 1.0.0.alpha.22
@@ -6,8 +6,10 @@ module BEL::Translator::Plugins
6
6
  module BelScript
7
7
  class Reader
8
8
  include ::BELParser::Script
9
+
10
+ SyntaxError = ::BELParser::Language::Syntax::SyntaxError
9
11
 
10
- def initialize(io)
12
+ def initialize(io, options = {})
11
13
  @io = io
12
14
  @state = {
13
15
  resource_reader: BELParser::Resource::ResourceURLReader.new(true),
@@ -22,8 +24,11 @@ module BEL::Translator::Plugins
22
24
  Validator.new(
23
25
  StateAggregator.new(
24
26
  FirstNode.new(Filter.new(BELParser::ASTGenerator.new(@io))),
25
- @state))).each do |hash|
26
- yield ::BEL::Model::Evidence.create(hash)
27
+ @state)),
28
+ true,
29
+ false
30
+ ).each do |(num, line, ast_node, nanopub_hash)|
31
+ yield ::BEL::Model::Evidence.create(nanopub_hash)
27
32
  end
28
33
  else
29
34
  enum_for(:each)
@@ -17,22 +17,35 @@ module BELParser
17
17
 
18
18
  DEFINITIONS = [:annotation_definitions, :namespace_definitions]
19
19
 
20
- def initialize(ast_enum)
21
- @ast_enum = ast_enum
20
+ def initialize(ast_enum, omit_on_error = false, omit_on_warning = false)
21
+ @ast_enum = ast_enum
22
+ @omit_on_error = omit_on_error
23
+ @omit_on_warning = omit_on_warning
22
24
  end
23
25
 
24
- def each(&block)
26
+ def each
25
27
  if block_given?
26
- @ast_enum.each do |(line_nunber, line, ast_node, state)|
28
+ @ast_enum.each do |(num, line, ast_node, state)|
27
29
  next unless STATEMENT_TYPES.include?(ast_node.type)
28
- yield nanopub(ast_node, state, &block)
30
+
31
+ errors = errors(ast_node)
32
+ warnings = warnings(ast_node)
33
+
34
+ if (@omit_on_error && !errors.empty?) ||
35
+ (@omit_on_warning && !warnings.empty?)
36
+
37
+ report(num, line, errors, warnings)
38
+ next
39
+ end
40
+
41
+ yield [num, line, ast_node, nanopub(ast_node, state)]
29
42
  end
30
43
  else
31
44
  enum_for(:each)
32
45
  end
33
46
  end
34
47
 
35
- def nanopub(ast_node, state, &block)
48
+ def nanopub(ast_node, state)
36
49
  {
37
50
  bel_statement: serialize(ast_node),
38
51
  citation: citation(state[:citation]),
@@ -43,6 +56,34 @@ module BELParser
43
56
  }
44
57
  end
45
58
 
59
+ def report(num, line, errors, warnings)
60
+ warn "Line #{num}: #{line}"
61
+ errors.each do |err|
62
+ warn " #{err}"
63
+ end
64
+ warnings.each do |warn|
65
+ warn " #{warn}"
66
+ end
67
+ warn
68
+ end
69
+
70
+ def errors(ast_node)
71
+ ast_node
72
+ .syntax_errors
73
+ .select do |err|
74
+ err.is_a?(::BELParser::Language::Syntax::SyntaxError)
75
+ end.each(&:to_s)
76
+ end
77
+
78
+ def warnings(ast_node)
79
+ ast_node
80
+ .syntax_errors
81
+ .select do |warn|
82
+ warn.is_a?(::BELParser::Language::Syntax::SyntaxError) ||
83
+ warn.is_a?(::BELParser::Language::Semantics::SemanticsWarning)
84
+ end.each(&:to_s)
85
+ end
86
+
46
87
  def citation(citation)
47
88
  citation.each do |field, value|
48
89
  citation[field] = unquote(value)
@@ -133,6 +174,6 @@ if __FILE__ == $PROGRAM_NAME
133
174
  Validator.new(
134
175
  StateAggregator.new(
135
176
  FirstNode.new(Filter.new(BELParser::ASTGenerator.new(io))),
136
- initial_state))).each.to_a
177
+ initial_state))).each.map(&:last).to_a
137
178
  puts JSON.dump(nanopubs)
138
179
  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.21
4
+ version: 1.0.0.alpha.22
5
5
  platform: ruby
6
6
  authors:
7
7
  - Anthony Bargnesi