bel_parser 1.0.0.alpha.21 → 1.0.0.alpha.22
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 +4 -4
- data/VERSION +1 -1
- data/lib/bel/translator/plugins/bel_script/reader.rb +8 -3
- data/lib/bel_parser/script/nanopub_mapper.rb +48 -7
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2e418c5b2fae45c7d2d04f8d6f6192fff2f1f1d4
|
4
|
+
data.tar.gz: 42a84936274b3cdd6eccdb2918b2b5ad37f49551
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 356b39aebd42b4298a29d2a4e7ec1521855a5def19f6c1baa8b5769c81a14866f3bab2f7c28450171682b41bb841f47b11c3cd6a98c05ff52749dff53bc294b4
|
7
|
+
data.tar.gz: f9f900d99b8ba8f5adfd72d5a08747a2b3771bee8a475fa0e2408712ac5ae1cc9470eb49d40837687bc83b6ca4b8e2ea31a4b2174ee627dc5fdb69ce18458d26
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
1.0.0.alpha.
|
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))
|
26
|
-
|
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
|
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
|
26
|
+
def each
|
25
27
|
if block_given?
|
26
|
-
@ast_enum.each do |(
|
28
|
+
@ast_enum.each do |(num, line, ast_node, state)|
|
27
29
|
next unless STATEMENT_TYPES.include?(ast_node.type)
|
28
|
-
|
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
|
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
|