bel_parser 1.0.0.alpha.5 → 1.0.0.alpha.6
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/bin/bel2_validator +2 -2
- data/lib/bel_parser/expression/parser.rb +1 -1
- data/lib/bel_parser/expression/{term_validator.rb → validator.rb} +8 -3
- data/lib/bel_parser/language/expression_validator.rb +12 -36
- data/lib/bel_parser/language/semantics/signature_mapping.rb +10 -14
- data/lib/bel_parser/language/syntax/invalid_function.rb +11 -10
- data/lib/bel_parser/language/syntax/invalid_relationship.rb +42 -0
- data/lib/bel_parser/language/syntax/undefined_namespace.rb +12 -18
- data/lib/bel_parser/language/version1_0/return_types/molecular_activity.rb +1 -1
- data/lib/bel_parser/language/version2_0/functions/protein_abundance.rb +9 -19
- data/lib/bel_parser/parser.rb +1 -1
- data/lib/bel_parser/parsers/ast/node.rb +53 -7
- data/lib/bel_parser/parsers/expression/{statement_nested.rb → nested_statement.rb} +58 -58
- data/lib/bel_parser/parsers/expression/{statement_nested.rl → nested_statement.rl} +6 -6
- data/lib/bel_parser/parsers/expression/{statement_observed_term.rb → observed_term.rb} +14 -14
- data/lib/bel_parser/parsers/expression/{statement_observed_term.rl → observed_term.rl} +5 -5
- data/lib/bel_parser/parsers/expression/{statement_simple.rb → simple_statement.rb} +37 -37
- data/lib/bel_parser/parsers/expression/{statement_simple.rl → simple_statement.rl} +6 -6
- data/lib/bel_parser/parsers/expression.rb +3 -3
- data/lib/bel_parser/parsers/line_parser.rb +3 -3
- data/lib/bel_parser/script/parser.rb +1 -1
- metadata +9 -8
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 31d99776d9e14c8680ec557fcc2e9e94136b90dc
|
4
|
+
data.tar.gz: 0764321e9c0d762d5a4186301f62c4f21b56431c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4d8915205e38ae41098e1c4468b7a54b7d07f23b20f6667d8ab17fbbd7371504402e369122d3e6a91d3adb1148d824578732328f457531956b729402b5401d1f
|
7
|
+
data.tar.gz: 528a2bad2581e21df25812804b56d7c366d23f1ee18524767aac5cf8e518b4d1d58952c75763e7893d760b66809b3e15d0d92b0091dda4b6a56bf6d28ebf1146
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
1.0.0.alpha.
|
1
|
+
1.0.0.alpha.6
|
data/bin/bel2_validator
CHANGED
@@ -11,7 +11,7 @@ end
|
|
11
11
|
namespaces = Hash[ARGV[1..-1].map { |ns| ns.split('=') }]
|
12
12
|
|
13
13
|
require 'bel_parser'
|
14
|
-
require 'bel_parser/expression/
|
15
|
-
BELParser::Expression::
|
14
|
+
require 'bel_parser/expression/validator'
|
15
|
+
BELParser::Expression::Validator.new(ARGV.first, namespaces).each($stdin) do |res|
|
16
16
|
puts res.map { |r| "#{r}\n" }.join.each_line.map { |l| " #{l}" }.join
|
17
17
|
end
|
@@ -7,11 +7,16 @@ require_relative '../language/expression_validator'
|
|
7
7
|
module BELParser
|
8
8
|
module Expression
|
9
9
|
# Parser for BEL Expression.
|
10
|
-
class
|
10
|
+
class Validator
|
11
11
|
include BELParser::Parsers::Common
|
12
12
|
include BELParser::Parsers::Expression
|
13
13
|
|
14
|
-
FILTER = BELParser::ASTFilter.new(
|
14
|
+
FILTER = BELParser::ASTFilter.new(
|
15
|
+
:parameter,
|
16
|
+
:term,
|
17
|
+
:observed_term,
|
18
|
+
:simple_statement,
|
19
|
+
:nested_statement)
|
15
20
|
|
16
21
|
def initialize(specification_version, namespaces)
|
17
22
|
@spec = BELParser::Language.specification(specification_version)
|
@@ -42,7 +47,7 @@ if __FILE__ == $PROGRAM_NAME
|
|
42
47
|
exit 1
|
43
48
|
end
|
44
49
|
namespaces = Hash[ARGV[1..-1].map { |ns| ns.split('=') }]
|
45
|
-
BELParser::Expression::
|
50
|
+
BELParser::Expression::Validator.new(ARGV.first, namespaces).each($stdin) do |res|
|
46
51
|
res.each do |res|
|
47
52
|
puts res.each_line.map { |l| " #{l}" }.join
|
48
53
|
end
|
@@ -11,51 +11,27 @@ module BELParser
|
|
11
11
|
@semantics_functions = Semantics.semantics_functions
|
12
12
|
end
|
13
13
|
|
14
|
-
def validate(
|
15
|
-
results = syntax(
|
14
|
+
def validate(expression_node)
|
15
|
+
results = syntax(expression_node)
|
16
16
|
if results.empty?
|
17
|
-
results << Syntax::Valid.new(
|
18
|
-
results.concat(semantics(
|
17
|
+
results << Syntax::Valid.new(expression_node, @spec)
|
18
|
+
results.concat(semantics(expression_node))
|
19
19
|
end
|
20
20
|
results
|
21
21
|
end
|
22
22
|
|
23
23
|
private
|
24
24
|
|
25
|
-
def syntax(
|
26
|
-
|
25
|
+
def syntax(expression_node)
|
26
|
+
expression_node.traverse.flat_map do |node|
|
27
|
+
@syntax_functions.map { |func| func.map(node, @spec, @namespaces) }
|
28
|
+
end.compact
|
27
29
|
end
|
28
30
|
|
29
|
-
def semantics(
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
def syntax_term(term_ast)
|
34
|
-
syntax_results = @syntax_functions.flat_map do |syntax_func|
|
35
|
-
syntax_func.map(term_ast, @spec, @namespaces)
|
36
|
-
end
|
37
|
-
|
38
|
-
term_ast.arguments
|
39
|
-
.select(&:has_term?)
|
40
|
-
.map(&:child)
|
41
|
-
.each do |child_term|
|
42
|
-
syntax_results.concat(syntax_term(child_term))
|
43
|
-
end
|
44
|
-
syntax_results
|
45
|
-
end
|
46
|
-
|
47
|
-
def semantics_term(term_ast)
|
48
|
-
semantics_results = @semantics_functions.flat_map do |semantics_func|
|
49
|
-
semantics_func.map(term_ast, @spec, @namespaces)
|
50
|
-
end
|
51
|
-
|
52
|
-
term_ast.arguments
|
53
|
-
.select(&:has_term?)
|
54
|
-
.map(&:child)
|
55
|
-
.each do |child_term|
|
56
|
-
semantics_results.concat(semantics_term(child_term))
|
57
|
-
end
|
58
|
-
semantics_results
|
31
|
+
def semantics(expression_node)
|
32
|
+
expression_node.traverse.flat_map do |node|
|
33
|
+
@semantics_functions.map { |func| func.map(node, @spec, @namespaces) }
|
34
|
+
end.compact
|
59
35
|
end
|
60
36
|
end
|
61
37
|
end
|
@@ -11,25 +11,21 @@ module BELParser
|
|
11
11
|
# Map {BELParser::Parsers::AST::Term term} to BEL signatures defined
|
12
12
|
# by a {BELParser::Language::Specification}. The mapping includes both
|
13
13
|
# successful and failed signature matches.
|
14
|
-
def self.map(
|
15
|
-
unless
|
16
|
-
raise(
|
17
|
-
ArgumentError,
|
18
|
-
"term_ast: expected BELParser::Parsers::AST::Term")
|
19
|
-
end
|
14
|
+
def self.map(term_node, spec, namespaces)
|
15
|
+
return nil unless term_node.is_a?(BELParser::Parsers::AST::Term)
|
20
16
|
|
21
|
-
function_name =
|
17
|
+
function_name = term_node.function.identifier.string_literal
|
22
18
|
function = spec.function(function_name.to_sym)
|
23
19
|
match = BELParser::Language::Semantics.method(:match)
|
24
20
|
|
25
21
|
successes, failures = function.signatures
|
26
|
-
.map { |sig| [sig, match.call(
|
22
|
+
.map { |sig| [sig, match.call(term_node, sig.semantic_ast, spec)] }
|
27
23
|
.partition { |(sig, results)| results.all?(&:success?) }
|
28
24
|
|
29
25
|
if successes.empty?
|
30
|
-
SignatureMappingWarning.new(
|
26
|
+
SignatureMappingWarning.new(term_node, spec, failures)
|
31
27
|
else
|
32
|
-
SignatureMappingSuccess.new(
|
28
|
+
SignatureMappingSuccess.new(term_node, spec, successes, failures)
|
33
29
|
end
|
34
30
|
end
|
35
31
|
end
|
@@ -38,8 +34,8 @@ module BELParser
|
|
38
34
|
attr_reader :success_signatures
|
39
35
|
attr_reader :failure_signatures
|
40
36
|
|
41
|
-
def initialize(
|
42
|
-
super(
|
37
|
+
def initialize(term_node, spec, successes, failures)
|
38
|
+
super(term_node, spec)
|
43
39
|
@success_signatures = successes
|
44
40
|
@failure_signatures = failures
|
45
41
|
end
|
@@ -58,8 +54,8 @@ module BELParser
|
|
58
54
|
class SignatureMappingWarning < SemanticsWarning
|
59
55
|
attr_reader :failure_signatures
|
60
56
|
|
61
|
-
def initialize(
|
62
|
-
super(
|
57
|
+
def initialize(term_node, spec, failure_signatures)
|
58
|
+
super(term_node, spec)
|
63
59
|
@failure_signatures = failure_signatures
|
64
60
|
end
|
65
61
|
|
@@ -10,27 +10,28 @@ module BELParser
|
|
10
10
|
|
11
11
|
private_class_method :new
|
12
12
|
|
13
|
-
def self.map(
|
14
|
-
|
13
|
+
def self.map(func_node, spec, namespaces)
|
14
|
+
return nil unless func_node.is_a?(BELParser::Parsers::AST::Function)
|
15
|
+
|
16
|
+
function_name = func_node.identifier.string_literal
|
15
17
|
unless spec.function(function_name.to_sym)
|
16
|
-
InvalidFunctionSyntaxError.new(
|
18
|
+
InvalidFunctionSyntaxError.new(func_node, spec, function_name)
|
17
19
|
end
|
18
20
|
end
|
19
21
|
end
|
20
22
|
|
21
23
|
# InvalidFunctionSyntaxError indicates a function name was invalid.
|
22
24
|
class InvalidFunctionSyntaxError < SyntaxError
|
23
|
-
# Gets the function literal
|
24
|
-
|
25
|
-
attr_reader :function
|
25
|
+
# Gets the invalid function literal.
|
26
|
+
attr_reader :invalid_function
|
26
27
|
|
27
|
-
def initialize(
|
28
|
-
super(
|
29
|
-
@
|
28
|
+
def initialize(function, spec, invalid_function)
|
29
|
+
super(function, spec)
|
30
|
+
@invalid_function = invalid_function
|
30
31
|
end
|
31
32
|
|
32
33
|
def msg
|
33
|
-
%Q{Invalid function "#{
|
34
|
+
%Q{Invalid function "#{invalid_function}".}
|
34
35
|
end
|
35
36
|
end
|
36
37
|
end
|
@@ -0,0 +1,42 @@
|
|
1
|
+
require 'bel_parser/parsers/ast/node'
|
2
|
+
|
3
|
+
module BELParser
|
4
|
+
module Language
|
5
|
+
module Syntax
|
6
|
+
# InvalidRelationship represents a syntax error with invalid
|
7
|
+
# relationship according to a BEL specification.
|
8
|
+
class InvalidRelationship
|
9
|
+
include SyntaxFunction
|
10
|
+
|
11
|
+
private_class_method :new
|
12
|
+
|
13
|
+
def self.map(stmt_node, spec, namespaces)
|
14
|
+
return nil unless stmt_node.is_a?(BELParser::Parsers::AST::Statement)
|
15
|
+
|
16
|
+
rel_name = stmt_node.relationship.string_literal
|
17
|
+
return nil if rel_name.nil?
|
18
|
+
|
19
|
+
unless spec.relationship(rel_name.to_sym)
|
20
|
+
InvalidRelationshipSyntaxError.new(stmt_node, spec, rel_name)
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
# InvalidRelationshipSyntaxError indicates a relationship was invalid.
|
26
|
+
class InvalidRelationshipSyntaxError < SyntaxError
|
27
|
+
# Gets the relationship literal that was invalid according to a
|
28
|
+
# BEL specification.
|
29
|
+
attr_reader :relationship
|
30
|
+
|
31
|
+
def initialize(stmt_node, spec, relationship)
|
32
|
+
super(stmt_node, spec)
|
33
|
+
@relationship = relationship
|
34
|
+
end
|
35
|
+
|
36
|
+
def msg
|
37
|
+
%Q{Invalid relationship "#{relationship}".}
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
@@ -10,22 +10,16 @@ module BELParser
|
|
10
10
|
|
11
11
|
private_class_method :new
|
12
12
|
|
13
|
-
def self.map(
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
unless namespaces[namespace_prefix]
|
24
|
-
syntax_results << UndefinedNamespaceError.new(
|
25
|
-
term_node, spec, namespace_prefix, namespaces)
|
26
|
-
end
|
27
|
-
end
|
28
|
-
syntax_results
|
13
|
+
def self.map(prefix_node, spec, namespaces)
|
14
|
+
return nil unless prefix_node.is_a?(BELParser::Parsers::AST::Prefix)
|
15
|
+
|
16
|
+
prefix_identifier = prefix_node.identifier
|
17
|
+
return nil if prefix_identifier.nil?
|
18
|
+
|
19
|
+
prefix = prefix_identifier.string_literal
|
20
|
+
unless namespaces[prefix]
|
21
|
+
UndefinedNamespaceError.new(prefix_node, spec, prefix, namespaces)
|
22
|
+
end
|
29
23
|
end
|
30
24
|
end
|
31
25
|
|
@@ -37,8 +31,8 @@ module BELParser
|
|
37
31
|
# Gets the defined namespaces.
|
38
32
|
attr_reader :defined_namespaces
|
39
33
|
|
40
|
-
def initialize(
|
41
|
-
super(
|
34
|
+
def initialize(prefix_node, spec, invalid_prefix, defined_namespaces)
|
35
|
+
super(prefix_node, spec)
|
42
36
|
@invalid_prefix = invalid_prefix
|
43
37
|
@defined_namespaces = defined_namespaces.dup
|
44
38
|
end
|
@@ -120,28 +120,18 @@ module BELParser
|
|
120
120
|
|
121
121
|
AST = BELParser::Language::Semantics::Builder.build do
|
122
122
|
term(
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
namespace_of(:*))),
|
132
|
-
value(
|
133
|
-
value_type(
|
134
|
-
has_encoding,
|
135
|
-
encoding_of(:ProteinAbundance))))),
|
136
|
-
argument(
|
137
|
-
term(
|
138
|
-
function(
|
139
|
-
identifier(
|
140
|
-
return_type_of(BELParser::Language::Version2_0::ReturnTypes::Fusion))))))
|
123
|
+
function(
|
124
|
+
identifier(
|
125
|
+
function_of(ProteinAbundance))),
|
126
|
+
argument(
|
127
|
+
term(
|
128
|
+
function(
|
129
|
+
identifier(
|
130
|
+
return_type_of(BELParser::Language::Version2_0::ReturnTypes::Fusion))))))
|
141
131
|
end
|
142
132
|
private_constant :AST
|
143
133
|
|
144
|
-
STRING_FORM = 'proteinAbundance(
|
134
|
+
STRING_FORM = 'proteinAbundance(F:fusion)proteinAbundance'.freeze
|
145
135
|
private_constant :STRING_FORM
|
146
136
|
|
147
137
|
def self.semantic_ast
|
data/lib/bel_parser/parser.rb
CHANGED
@@ -377,6 +377,11 @@ module BELParser
|
|
377
377
|
def initialize(children = [], properties = {})
|
378
378
|
super(Relationship.ast_type, children, properties)
|
379
379
|
end
|
380
|
+
|
381
|
+
# Get the string literal.
|
382
|
+
def string_literal
|
383
|
+
children[0]
|
384
|
+
end
|
380
385
|
end
|
381
386
|
|
382
387
|
# AST node representing a set.
|
@@ -420,7 +425,33 @@ module BELParser
|
|
420
425
|
|
421
426
|
# Get the subject of the statement.
|
422
427
|
def subject
|
423
|
-
|
428
|
+
children[0]
|
429
|
+
end
|
430
|
+
|
431
|
+
def has_relationship?
|
432
|
+
children[1] && children[1].is_a?(Relationship)
|
433
|
+
end
|
434
|
+
|
435
|
+
# Get the relationship of the nested statement.
|
436
|
+
def relationship
|
437
|
+
has_relationship? ? children[1] : nil
|
438
|
+
end
|
439
|
+
|
440
|
+
def has_object?
|
441
|
+
children[2] && children[2].is_a?(Object)
|
442
|
+
end
|
443
|
+
|
444
|
+
# Get the object of the nested statement.
|
445
|
+
def object
|
446
|
+
has_object? ? children[2] : nil
|
447
|
+
end
|
448
|
+
|
449
|
+
def has_comment?
|
450
|
+
children[-1] && children[-1].is_a?(Comment)
|
451
|
+
end
|
452
|
+
|
453
|
+
def comment
|
454
|
+
has_comment? ? children[-1] : nil
|
424
455
|
end
|
425
456
|
end
|
426
457
|
|
@@ -438,14 +469,19 @@ module BELParser
|
|
438
469
|
super(NestedStatement.ast_type, children, properties)
|
439
470
|
end
|
440
471
|
|
472
|
+
# Get the subject of the statement.
|
473
|
+
def subject
|
474
|
+
children[0]
|
475
|
+
end
|
476
|
+
|
441
477
|
# Get the relationship of the nested statement.
|
442
|
-
def
|
443
|
-
|
478
|
+
def relationship
|
479
|
+
children[1]
|
444
480
|
end
|
445
481
|
|
446
482
|
# Get the object of the nested statement.
|
447
483
|
def object
|
448
|
-
|
484
|
+
children[2]
|
449
485
|
end
|
450
486
|
end
|
451
487
|
|
@@ -462,6 +498,11 @@ module BELParser
|
|
462
498
|
def initialize(children = [], properties = {})
|
463
499
|
super(ObservedTerm.ast_type, children, properties)
|
464
500
|
end
|
501
|
+
|
502
|
+
# Get the subject of the statement.
|
503
|
+
def subject
|
504
|
+
children[0]
|
505
|
+
end
|
465
506
|
end
|
466
507
|
|
467
508
|
# AST node representing a simple statement.
|
@@ -478,14 +519,19 @@ module BELParser
|
|
478
519
|
super(SimpleStatement.ast_type, children, properties)
|
479
520
|
end
|
480
521
|
|
522
|
+
# Get the subject of the statement.
|
523
|
+
def subject
|
524
|
+
children[0]
|
525
|
+
end
|
526
|
+
|
481
527
|
# Get the relationship of the nested statement.
|
482
|
-
def
|
483
|
-
|
528
|
+
def relationship
|
529
|
+
children[1]
|
484
530
|
end
|
485
531
|
|
486
532
|
# Get the object of the nested statement.
|
487
533
|
def object
|
488
|
-
|
534
|
+
children[2]
|
489
535
|
end
|
490
536
|
end
|
491
537
|
|