bel_parser 1.0.0.alpha.7 → 1.0.0.alpha.8
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/.gemspec +1 -1
- data/VERSION +1 -1
- data/bin/bel2_validator +7 -4
- data/lib/bel_parser/ast_filter.rb +2 -2
- data/lib/bel_parser/ast_generator.rb +11 -18
- data/lib/bel_parser/language/expression_validator.rb +8 -0
- data/lib/bel_parser/language/quoting.rb +19 -22
- data/lib/bel_parser/language/semantics/deeply_nested_statement.rb +65 -0
- data/lib/bel_parser/language/semantics/function_deprecation.rb +36 -0
- data/lib/bel_parser/language/semantics/list_function_subject.rb +45 -0
- data/lib/bel_parser/language/semantics/relationship_deprecation.rb +36 -0
- data/lib/bel_parser/language/semantics/signature_mapping.rb +30 -16
- data/lib/bel_parser/language/semantics.rb +7 -2
- data/lib/bel_parser/language/semantics_ast.rb +22 -12
- data/lib/bel_parser/language/semantics_function.rb +4 -1
- data/lib/bel_parser/language/semantics_result.rb +1 -0
- data/lib/bel_parser/language/semantics_warning.rb +2 -0
- data/lib/bel_parser/language/signature.rb +3 -3
- data/lib/bel_parser/language/syntax/invalid_function.rb +2 -2
- data/lib/bel_parser/language/syntax/invalid_relationship.rb +2 -2
- data/lib/bel_parser/language/syntax/undefined_namespace.rb +0 -1
- data/lib/bel_parser/language/syntax.rb +7 -2
- data/lib/bel_parser/language/syntax_error.rb +2 -0
- data/lib/bel_parser/language/syntax_function.rb +4 -1
- data/lib/bel_parser/language/syntax_result.rb +1 -0
- data/lib/bel_parser/language/syntax_warning.rb +2 -0
- data/lib/bel_parser/language/version1_0/functions/abundance.rb +14 -15
- data/lib/bel_parser/language/version1_0/functions/biological_process.rb +14 -15
- data/lib/bel_parser/language/version1_0/functions/catalytic_activity.rb +25 -21
- data/lib/bel_parser/language/version1_0/functions/cell_secretion.rb +15 -12
- data/lib/bel_parser/language/version1_0/functions/cell_surface_expression.rb +15 -12
- data/lib/bel_parser/language/version1_0/functions/chaperone_activity.rb +25 -21
- data/lib/bel_parser/language/version1_0/functions/complex_abundance.rb +26 -25
- data/lib/bel_parser/language/version1_0/functions/composite_abundance.rb +13 -12
- data/lib/bel_parser/language/version1_0/functions/degradation.rb +15 -12
- data/lib/bel_parser/language/version1_0/functions/fusion.rb +135 -129
- data/lib/bel_parser/language/version1_0/functions/gene_abundance.rb +34 -34
- data/lib/bel_parser/language/version1_0/functions/gtp_bound_activity.rb +24 -21
- data/lib/bel_parser/language/version1_0/functions/kinase_activity.rb +25 -21
- data/lib/bel_parser/language/version1_0/functions/list.rb +24 -24
- data/lib/bel_parser/language/version1_0/functions/micro_rna_abundance.rb +18 -17
- data/lib/bel_parser/language/version1_0/functions/molecular_activity.rb +14 -12
- data/lib/bel_parser/language/version1_0/functions/pathology.rb +14 -15
- data/lib/bel_parser/language/version1_0/functions/peptidase_activity.rb +23 -21
- data/lib/bel_parser/language/version1_0/functions/phosphatase_activity.rb +23 -21
- data/lib/bel_parser/language/version1_0/functions/products.rb +9 -10
- data/lib/bel_parser/language/version1_0/functions/protein_abundance.rb +94 -91
- data/lib/bel_parser/language/version1_0/functions/protein_modification.rb +60 -57
- data/lib/bel_parser/language/version1_0/functions/reactants.rb +9 -10
- data/lib/bel_parser/language/version1_0/functions/reaction.rb +18 -17
- data/lib/bel_parser/language/version1_0/functions/ribosylation_activity.rb +25 -21
- data/lib/bel_parser/language/version1_0/functions/rna_abundance.rb +34 -34
- data/lib/bel_parser/language/version1_0/functions/substitution.rb +29 -28
- data/lib/bel_parser/language/version1_0/functions/transcriptional_activity.rb +25 -21
- data/lib/bel_parser/language/version1_0/functions/translocation.rb +33 -32
- data/lib/bel_parser/language/version1_0/functions/transport_activity.rb +26 -21
- data/lib/bel_parser/language/version1_0/functions/truncation.rb +15 -14
- data/lib/bel_parser/language/version1_0/relationships/acts_in.rb +16 -2
- data/lib/bel_parser/language/version1_0/relationships/analogous.rb +8 -2
- data/lib/bel_parser/language/version1_0/relationships/association.rb +13 -2
- data/lib/bel_parser/language/version1_0/relationships/biomarker_for.rb +9 -2
- data/lib/bel_parser/language/version1_0/relationships/causes_no_change.rb +13 -2
- data/lib/bel_parser/language/version1_0/relationships/decreases.rb +22 -2
- data/lib/bel_parser/language/version1_0/relationships/directly_decreases.rb +11 -2
- data/lib/bel_parser/language/version1_0/relationships/directly_increases.rb +11 -2
- data/lib/bel_parser/language/version1_0/relationships/has_component.rb +25 -2
- data/lib/bel_parser/language/version1_0/relationships/has_components.rb +20 -2
- data/lib/bel_parser/language/version1_0/relationships/has_member.rb +15 -2
- data/lib/bel_parser/language/version1_0/relationships/has_members.rb +20 -2
- data/lib/bel_parser/language/version1_0/relationships/has_modification.rb +13 -2
- data/lib/bel_parser/language/version1_0/relationships/has_product.rb +15 -2
- data/lib/bel_parser/language/version1_0/relationships/has_variant.rb +13 -2
- data/lib/bel_parser/language/version1_0/relationships/includes.rb +18 -2
- data/lib/bel_parser/language/version1_0/relationships/increases.rb +22 -2
- data/lib/bel_parser/language/version1_0/relationships/is_a.rb +15 -2
- data/lib/bel_parser/language/version1_0/relationships/negative_correlation.rb +13 -2
- data/lib/bel_parser/language/version1_0/relationships/orthologous.rb +15 -2
- data/lib/bel_parser/language/version1_0/relationships/positive_correlation.rb +9 -2
- data/lib/bel_parser/language/version1_0/relationships/prognostic_biomarker_for.rb +11 -2
- data/lib/bel_parser/language/version1_0/relationships/rate_limiting_step_of.rb +16 -2
- data/lib/bel_parser/language/version1_0/relationships/reactant_in.rb +15 -2
- data/lib/bel_parser/language/version1_0/relationships/sub_process_of.rb +22 -2
- data/lib/bel_parser/language/version1_0/relationships/transcribed_to.rb +12 -2
- data/lib/bel_parser/language/version1_0/relationships/translated_to.rb +13 -2
- data/lib/bel_parser/language/version1_0/relationships/translocates.rb +16 -2
- data/lib/bel_parser/language/version1_0/syntax/function.rb +0 -1
- data/lib/bel_parser/language/version1_0.rb +13 -2
- data/lib/bel_parser/language/version2_0/functions/abundance.rb +54 -53
- data/lib/bel_parser/language/version2_0/functions/activity.rb +8 -5
- data/lib/bel_parser/language/version2_0/functions/biological_process.rb +16 -16
- data/lib/bel_parser/language/version2_0/functions/cell_secretion.rb +15 -12
- data/lib/bel_parser/language/version2_0/functions/cell_surface_expression.rb +15 -12
- data/lib/bel_parser/language/version2_0/functions/complex_abundance.rb +61 -58
- data/lib/bel_parser/language/version2_0/functions/composite_abundance.rb +13 -12
- data/lib/bel_parser/language/version2_0/functions/degradation.rb +15 -12
- data/lib/bel_parser/language/version2_0/functions/fragment.rb +8 -6
- data/lib/bel_parser/language/version2_0/functions/from_location.rb +18 -17
- data/lib/bel_parser/language/version2_0/functions/fusion.rb +120 -117
- data/lib/bel_parser/language/version2_0/functions/gene_abundance.rb +64 -62
- data/lib/bel_parser/language/version2_0/functions/list.rb +24 -24
- data/lib/bel_parser/language/version2_0/functions/location.rb +14 -15
- data/lib/bel_parser/language/version2_0/functions/micro_rna_abundance.rb +58 -55
- data/lib/bel_parser/language/version2_0/functions/molecular_activity.rb +16 -14
- data/lib/bel_parser/language/version2_0/functions/pathology.rb +14 -15
- data/lib/bel_parser/language/version2_0/functions/products.rb +9 -10
- data/lib/bel_parser/language/version2_0/functions/protein_abundance.rb +96 -92
- data/lib/bel_parser/language/version2_0/functions/protein_modification.rb +57 -54
- data/lib/bel_parser/language/version2_0/functions/reactants.rb +9 -10
- data/lib/bel_parser/language/version2_0/functions/reaction.rb +18 -17
- data/lib/bel_parser/language/version2_0/functions/rna_abundance.rb +64 -62
- data/lib/bel_parser/language/version2_0/functions/to_location.rb +16 -16
- data/lib/bel_parser/language/version2_0/functions/translocation.rb +23 -22
- data/lib/bel_parser/language/version2_0/functions/variant.rb +13 -13
- data/lib/bel_parser/language/version2_0/relationships/acts_in.rb +16 -2
- data/lib/bel_parser/language/version2_0/relationships/analogous.rb +8 -2
- data/lib/bel_parser/language/version2_0/relationships/association.rb +13 -2
- data/lib/bel_parser/language/version2_0/relationships/biomarker_for.rb +9 -2
- data/lib/bel_parser/language/version2_0/relationships/causes_no_change.rb +13 -2
- data/lib/bel_parser/language/version2_0/relationships/decreases.rb +22 -2
- data/lib/bel_parser/language/version2_0/relationships/directly_decreases.rb +11 -2
- data/lib/bel_parser/language/version2_0/relationships/directly_increases.rb +11 -2
- data/lib/bel_parser/language/version2_0/relationships/has_component.rb +25 -2
- data/lib/bel_parser/language/version2_0/relationships/has_components.rb +20 -2
- data/lib/bel_parser/language/version2_0/relationships/has_member.rb +15 -2
- data/lib/bel_parser/language/version2_0/relationships/has_members.rb +20 -2
- data/lib/bel_parser/language/version2_0/relationships/has_modification.rb +13 -2
- data/lib/bel_parser/language/version2_0/relationships/has_product.rb +15 -2
- data/lib/bel_parser/language/version2_0/relationships/has_variant.rb +13 -2
- data/lib/bel_parser/language/version2_0/relationships/includes.rb +18 -2
- data/lib/bel_parser/language/version2_0/relationships/increases.rb +22 -2
- data/lib/bel_parser/language/version2_0/relationships/is_a.rb +15 -2
- data/lib/bel_parser/language/version2_0/relationships/negative_correlation.rb +13 -2
- data/lib/bel_parser/language/version2_0/relationships/orthologous.rb +15 -2
- data/lib/bel_parser/language/version2_0/relationships/positive_correlation.rb +9 -2
- data/lib/bel_parser/language/version2_0/relationships/prognostic_biomarker_for.rb +11 -2
- data/lib/bel_parser/language/version2_0/relationships/rate_limiting_step_of.rb +16 -2
- data/lib/bel_parser/language/version2_0/relationships/reactant_in.rb +15 -2
- data/lib/bel_parser/language/version2_0/relationships/regulates.rb +14 -2
- data/lib/bel_parser/language/version2_0/relationships/sub_process_of.rb +22 -2
- data/lib/bel_parser/language/version2_0/relationships/transcribed_to.rb +12 -2
- data/lib/bel_parser/language/version2_0/relationships/translated_to.rb +13 -2
- data/lib/bel_parser/language/version2_0/relationships/translocates.rb +16 -2
- data/lib/bel_parser/language.rb +18 -8
- data/lib/bel_parser/parser.rb +1 -0
- data/lib/bel_parser/parsers/ast/node.rb +112 -74
- data/lib/bel_parser/parsers/bel_script/set.rl +1 -1
- data/lib/bel_parser/parsers/bel_script/set_document.rb +7087 -0
- data/lib/bel_parser/parsers/bel_script/set_document.rl +97 -0
- data/lib/bel_parser/parsers/bel_script.rb +1 -0
- data/lib/bel_parser/parsers/common/common.rl +1 -1
- data/lib/bel_parser/script/parser.rb +1 -0
- metadata +8 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA1:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: db955e27ca9e82bf06bbd0b3a01d4e7c9f4a00d3
|
|
4
|
+
data.tar.gz: a4621fb03673bba08e748328d3087cb6b98c2881
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 42721d3f23244e42a9ea26399964d359bfe334a927ae622fead2255fb33758748aac4e3259cee34e2d4a53ebd5305ec18dd2571be657e86eca3872704c7373e7
|
|
7
|
+
data.tar.gz: 55a9fd90bb9807075bc240afd9a4fc513c656d638ffb9fb27055d8431746323d7870ad1501de0607f4b84072986233534e82a6a40ad2bfa54096602c17727b81
|
data/.gemspec
CHANGED
data/VERSION
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
1.0.0.alpha.
|
|
1
|
+
1.0.0.alpha.8
|
data/bin/bel2_validator
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
#!/usr/bin/env ruby
|
|
2
|
-
|
|
2
|
+
$LOAD_PATH.unshift(
|
|
3
|
+
File.join(File.expand_path(File.dirname(__FILE__)), '..', 'lib'))
|
|
3
4
|
|
|
4
5
|
unless ARGV.first
|
|
5
6
|
program = File.basename($PROGRAM_NAME)
|
|
@@ -12,6 +13,8 @@ namespaces = Hash[ARGV[1..-1].map { |ns| ns.split('=') }]
|
|
|
12
13
|
|
|
13
14
|
require 'bel_parser'
|
|
14
15
|
require 'bel_parser/expression/validator'
|
|
15
|
-
BELParser::Expression::Validator
|
|
16
|
-
|
|
17
|
-
|
|
16
|
+
BELParser::Expression::Validator
|
|
17
|
+
.new(ARGV.first, namespaces)
|
|
18
|
+
.each($stdin) do |res|
|
|
19
|
+
puts res.map { |r| "#{r}\n" }.join.each_line.map { |l| " #{l}" }.join
|
|
20
|
+
end
|
|
@@ -33,8 +33,8 @@ if __FILE__ == $PROGRAM_NAME
|
|
|
33
33
|
ast = BELParser::ASTGenerator.new.each($stdin)
|
|
34
34
|
BELParser::ASTFilter.new(*types).each(ast) do |(line_number, line, results)|
|
|
35
35
|
puts "#{line_number}: #{line}"
|
|
36
|
-
results.each do |
|
|
37
|
-
puts
|
|
36
|
+
results.each do |result_ast|
|
|
37
|
+
puts result_ast.to_s(1)
|
|
38
38
|
end
|
|
39
39
|
end
|
|
40
40
|
end
|
|
@@ -21,34 +21,27 @@ module BELParser
|
|
|
21
21
|
# Yields AST results for each line of the IO.
|
|
22
22
|
#
|
|
23
23
|
# @example Receive AST results in given block.
|
|
24
|
-
# # doctest setup
|
|
25
|
-
# require 'bel_parser'
|
|
26
|
-
# self.class.include AST::Sexp
|
|
24
|
+
# # doctest setup require 'bel_parser' self.class.include AST::Sexp
|
|
27
25
|
#
|
|
28
|
-
# # example usage
|
|
29
|
-
#
|
|
30
|
-
# line
|
|
31
|
-
# ast_res = nil
|
|
32
|
-
# ::BELParser::ASTGenerator.new.each(line_io) { |(line_number, line, results)|
|
|
26
|
+
# # example usage line_io = StringIO.new("\"AKT1\"\n") line =
|
|
27
|
+
# nil ast_res = nil ::BELParser::ASTGenerator.new.each(line_io)
|
|
28
|
+
# { |(line_number, line, results)|
|
|
33
29
|
# # do something
|
|
34
30
|
# }
|
|
35
31
|
#
|
|
36
32
|
# @example Receive AST results as an enumerator.
|
|
37
|
-
# # doctest setup
|
|
38
|
-
# require 'bel_parser'
|
|
39
|
-
# self.class.include AST::Sexp
|
|
33
|
+
# # doctest setup require 'bel_parser' self.class.include AST::Sexp
|
|
40
34
|
#
|
|
41
|
-
# # example usage
|
|
42
|
-
#
|
|
43
|
-
# line, ast_res = ::BELParser::ASTGenerator.new.each(line_io).first.to_a
|
|
35
|
+
# # example usage line_io = StringIO.new("\"AKT1\"\n") line,
|
|
36
|
+
# ast_res = ::BELParser::ASTGenerator.new.each(line_io).first.to_a
|
|
44
37
|
#
|
|
45
|
-
# @param [IO] io the IO-object to read each line from
|
|
46
|
-
#
|
|
38
|
+
# @param [IO] io the IO-object to read each line from @yield
|
|
39
|
+
# [[Integer, String, Array<AST::Node>]] yields line number, line,
|
|
47
40
|
# and AST results as an {Array}
|
|
48
41
|
# @return [IO, #<Enumerator: #<BELParser::ASTGenerator#each>] the {IO}
|
|
49
42
|
# object is returned if a block is given, otherwise an
|
|
50
|
-
# {Enumerator} object is returned that can be iterated
|
|
51
|
-
#
|
|
43
|
+
# {Enumerator} object is returned that can be iterated with
|
|
44
|
+
# {Enumerator#each}
|
|
52
45
|
def each(io) # rubocop:disable MethodLength
|
|
53
46
|
if block_given?
|
|
54
47
|
line_enumerator = map_lines(io.each_line.lazy)
|
|
@@ -3,6 +3,9 @@ require_relative 'semantics'
|
|
|
3
3
|
|
|
4
4
|
module BELParser
|
|
5
5
|
module Language
|
|
6
|
+
# ExpressionValidator validates the syntax and semantics of BEL expressions
|
|
7
|
+
# when supplied a {BELParser::Language::Specification} and Hash of
|
|
8
|
+
# namespaces.
|
|
6
9
|
class ExpressionValidator
|
|
7
10
|
def initialize(spec, namespaces)
|
|
8
11
|
@spec = spec
|
|
@@ -11,6 +14,11 @@ module BELParser
|
|
|
11
14
|
@semantics_functions = Semantics.semantics_functions
|
|
12
15
|
end
|
|
13
16
|
|
|
17
|
+
# Validate the syntax and semantics of
|
|
18
|
+
# {BELParser::Parsers::AST::Node expression_node}.
|
|
19
|
+
#
|
|
20
|
+
# @param [BELParser::Parsers::AST::Node] expression_node to validate
|
|
21
|
+
# @return [BELParser::Language::Syntax::SyntaxResult] syntax results
|
|
14
22
|
def validate(expression_node)
|
|
15
23
|
results = syntax(expression_node)
|
|
16
24
|
if results.empty?
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
module BELParser
|
|
2
|
-
|
|
3
2
|
# The Quoting module implements quoting rules consistent with BEL
|
|
4
3
|
# and BEL Script. Double quotes are used to group a string together
|
|
5
4
|
# which may contain whitespace or special characters.
|
|
@@ -16,10 +15,9 @@ module BELParser
|
|
|
16
15
|
# BEL Script: BEL parameters, document property values, and annotation
|
|
17
16
|
# values must be an identifier or string value.
|
|
18
17
|
module Quoting
|
|
19
|
-
|
|
20
18
|
# Declares BEL Script keywords that cause problems with the OpenBEL
|
|
21
19
|
# Framework parser.
|
|
22
|
-
Keywords = %w(SET DEFINE a g p r m)
|
|
20
|
+
Keywords = %w(SET DEFINE a g p r m).freeze
|
|
23
21
|
|
|
24
22
|
# Regular expression that matches one of {Quoting::Keywords}.
|
|
25
23
|
KeywordMatcher = Regexp.compile(/^(#{Keywords.join('|')})$/)
|
|
@@ -54,8 +52,8 @@ module BELParser
|
|
|
54
52
|
def quote(value)
|
|
55
53
|
string = value.to_s
|
|
56
54
|
unquoted = unquote(string)
|
|
57
|
-
escaped = unquoted.gsub(QuoteNotEscapedMatcher, "
|
|
58
|
-
%
|
|
55
|
+
escaped = unquoted.gsub(QuoteNotEscapedMatcher, '\\"')
|
|
56
|
+
%("#{escaped}")
|
|
59
57
|
end
|
|
60
58
|
|
|
61
59
|
# Returns +value+ with surrounded quotes removed.
|
|
@@ -150,9 +148,9 @@ module BELParser
|
|
|
150
148
|
# +false+ if +value+ is not an identifier
|
|
151
149
|
def identifier_value?(value)
|
|
152
150
|
string = value.to_s
|
|
153
|
-
[NonWordMatcher, KeywordMatcher].none?
|
|
151
|
+
[NonWordMatcher, KeywordMatcher].none? do |matcher|
|
|
154
152
|
matcher.match string
|
|
155
|
-
|
|
153
|
+
end
|
|
156
154
|
end
|
|
157
155
|
|
|
158
156
|
# Returns whether the +value+ represents a string value. A string
|
|
@@ -171,21 +169,21 @@ module BELParser
|
|
|
171
169
|
# +false+ if +value+ is not a string value
|
|
172
170
|
def string_value?(value)
|
|
173
171
|
string = value.to_s
|
|
174
|
-
[NonWordMatcher, KeywordMatcher].any?
|
|
172
|
+
[NonWordMatcher, KeywordMatcher].any? do |matcher|
|
|
175
173
|
matcher.match string
|
|
176
|
-
|
|
174
|
+
end
|
|
177
175
|
end
|
|
178
176
|
|
|
179
177
|
## Deprecated, remove in [0.6.0].
|
|
180
178
|
|
|
181
179
|
# @deprecated Use {#quote_if_needed} instead. Will be removed in a
|
|
182
180
|
# future release.
|
|
183
|
-
def ensure_quotes
|
|
181
|
+
def ensure_quotes(identifier)
|
|
184
182
|
warn <<-DOC.gsub(/^\s+/, '')
|
|
185
183
|
Deprecation Warning
|
|
186
184
|
-------------------
|
|
187
185
|
The BEL::Quoting::ensure_quotes method is deprecated and
|
|
188
|
-
will be removed in a future
|
|
186
|
+
will be removed in a future release.
|
|
189
187
|
Call module method BEL::Quoting.quote_if_needed instead.
|
|
190
188
|
DOC
|
|
191
189
|
quote_if_needed(identifier)
|
|
@@ -193,12 +191,12 @@ module BELParser
|
|
|
193
191
|
|
|
194
192
|
# @deprecated Use {#unquote} instead. Will be removed in a
|
|
195
193
|
# future release.
|
|
196
|
-
def remove_quotes
|
|
194
|
+
def remove_quotes(identifier)
|
|
197
195
|
warn <<-DOC.gsub(/^\s+/, '')
|
|
198
196
|
Deprecation Warning
|
|
199
197
|
-------------------
|
|
200
198
|
The BEL::Quoting::remove_quotes method is deprecated and
|
|
201
|
-
will be removed in a future
|
|
199
|
+
will be removed in a future release.
|
|
202
200
|
Call module method BEL::Quoting.unquote instead.
|
|
203
201
|
DOC
|
|
204
202
|
unquote(identifier)
|
|
@@ -206,12 +204,12 @@ module BELParser
|
|
|
206
204
|
|
|
207
205
|
# @deprecated Use {#quote} instead. Will be removed in a
|
|
208
206
|
# future release.
|
|
209
|
-
def always_quote
|
|
207
|
+
def always_quote(identifier)
|
|
210
208
|
warn <<-DOC.gsub(/^\s+/, '')
|
|
211
209
|
Deprecation Warning
|
|
212
210
|
-------------------
|
|
213
211
|
The BEL::Quoting::always_quote method is deprecated and
|
|
214
|
-
will be removed in a future
|
|
212
|
+
will be removed in a future release.
|
|
215
213
|
Call module method BEL::Quoting.quote instead.
|
|
216
214
|
DOC
|
|
217
215
|
quote(identifier)
|
|
@@ -219,18 +217,17 @@ module BELParser
|
|
|
219
217
|
|
|
220
218
|
# @deprecated Use {#quoted?} or {#unquoted?} instead. Will be removed
|
|
221
219
|
# in a future release.
|
|
222
|
-
def quotes_required?
|
|
220
|
+
def quotes_required?(identifier)
|
|
223
221
|
warn <<-DOC.gsub(/^\s+/, '')
|
|
224
222
|
Deprecation Warning
|
|
225
223
|
-------------------
|
|
226
|
-
The BEL::Quoting::quotes_required? method is deprecated and
|
|
227
|
-
will be removed in a future
|
|
228
|
-
|
|
229
|
-
going forward.
|
|
224
|
+
The BEL::Quoting::quotes_required? method is deprecated and
|
|
225
|
+
will be removed in a future release. Use BEL::Quoting.quoted? and
|
|
226
|
+
BEL::Quoting.unquoted?.
|
|
230
227
|
DOC
|
|
231
|
-
[NonWordMatcher, KeywordMatcher].any?
|
|
228
|
+
[NonWordMatcher, KeywordMatcher].any? do |m|
|
|
232
229
|
m.match identifier.to_s
|
|
233
|
-
|
|
230
|
+
end
|
|
234
231
|
end
|
|
235
232
|
end
|
|
236
233
|
end
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
require 'bel_parser/parsers/ast/node'
|
|
2
|
+
|
|
3
|
+
module BELParser
|
|
4
|
+
module Language
|
|
5
|
+
module Semantics
|
|
6
|
+
# DeeplyNestedStatement implements a {SemanticsFunction} that maps a
|
|
7
|
+
# {BELParser::Parsers::AST::NestedStatement} to {SemanticsWarning} if
|
|
8
|
+
# the number of nested statements exceeds
|
|
9
|
+
# {DeeplyNestedStatement::NESTING_THRESHOLD}.
|
|
10
|
+
#
|
|
11
|
+
# @see DeeplyNestedStatement::NESTING_THRESHOLD
|
|
12
|
+
class DeeplyNestedStatement
|
|
13
|
+
include SemanticsFunction
|
|
14
|
+
|
|
15
|
+
# Represents how many nested statments must be exceeded before a
|
|
16
|
+
# {SemanticsWarning} results.
|
|
17
|
+
NESTING_THRESHOLD = 1
|
|
18
|
+
|
|
19
|
+
private_class_method :new
|
|
20
|
+
|
|
21
|
+
def self.map(node, spec, _namespaces)
|
|
22
|
+
return nil unless node.is_a?(BELParser::Parsers::AST::NestedStatement)
|
|
23
|
+
|
|
24
|
+
nested_number = count_nested_statements(node)
|
|
25
|
+
DeeplyNestedStatementWarning.new(
|
|
26
|
+
node,
|
|
27
|
+
spec,
|
|
28
|
+
NESTING_THRESHOLD,
|
|
29
|
+
nested_number) if nested_number > NESTING_THRESHOLD
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
def self.count_nested_statements(node)
|
|
33
|
+
node
|
|
34
|
+
.traverse
|
|
35
|
+
.select { |n| n.is_a?(BELParser::Parsers::AST::Object) }
|
|
36
|
+
.reduce(0) do |sum, object|
|
|
37
|
+
sum += 1 if object.statement?
|
|
38
|
+
sum
|
|
39
|
+
end
|
|
40
|
+
end
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
# DeeplyNestedStatementWarning defines a {SemanticsWarning} that
|
|
44
|
+
# indicates the nested statement threshold was exceeded.
|
|
45
|
+
#
|
|
46
|
+
# @see DeeplyNestedStatement::NESTING_THRESHOLD
|
|
47
|
+
class DeeplyNestedStatementWarning < SemanticsWarning
|
|
48
|
+
attr_reader :nested_threshold, :nested_number
|
|
49
|
+
|
|
50
|
+
def initialize(stmt_node, spec, nested_threshold, nested_number)
|
|
51
|
+
super(stmt_node, spec)
|
|
52
|
+
@nested_number = nested_number
|
|
53
|
+
@nested_threshold = nested_threshold
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
def to_s
|
|
57
|
+
<<-MSG.gsub(/ {12}/, '').delete("\n")
|
|
58
|
+
Statement contains more than #{nested_threshold} nested statements
|
|
59
|
+
(#{nested_number} nested statements).
|
|
60
|
+
MSG
|
|
61
|
+
end
|
|
62
|
+
end
|
|
63
|
+
end
|
|
64
|
+
end
|
|
65
|
+
end
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
require 'bel_parser/parsers/ast/node'
|
|
2
|
+
|
|
3
|
+
module BELParser
|
|
4
|
+
module Language
|
|
5
|
+
module Semantics
|
|
6
|
+
class FunctionDeprecation
|
|
7
|
+
include SemanticsFunction
|
|
8
|
+
|
|
9
|
+
private_class_method :new
|
|
10
|
+
|
|
11
|
+
def self.map(node, spec, _namespaces)
|
|
12
|
+
return nil unless node.is_a?(BELParser::Parsers::AST::Function)
|
|
13
|
+
|
|
14
|
+
function_name = node.identifier.string_literal
|
|
15
|
+
func = spec.function(function_name.to_sym)
|
|
16
|
+
return nil unless func
|
|
17
|
+
|
|
18
|
+
FunctionDeprecationWarning.new(node, spec, func) if func.deprecated?
|
|
19
|
+
end
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
class FunctionDeprecationWarning < SemanticsWarning
|
|
23
|
+
attr_reader :deprecated_function
|
|
24
|
+
|
|
25
|
+
def initialize(function_node, spec, deprecated_function)
|
|
26
|
+
super(function_node, spec)
|
|
27
|
+
@deprecated_function = deprecated_function
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
def to_s
|
|
31
|
+
%Q{Function "#{deprecated_function}" is deprecated.}
|
|
32
|
+
end
|
|
33
|
+
end
|
|
34
|
+
end
|
|
35
|
+
end
|
|
36
|
+
end
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
require 'bel_parser/parsers/ast/node'
|
|
2
|
+
|
|
3
|
+
module BELParser
|
|
4
|
+
module Language
|
|
5
|
+
module Semantics
|
|
6
|
+
# ListFunctionSubject implements a {SemanticsFunction} that maps a
|
|
7
|
+
# {BELParser::Parsers::AST::Subject} to {SemanticsWarning} if a _list_
|
|
8
|
+
# {BELParser::Parsers::AST::Term} is used as the
|
|
9
|
+
# {BELParser::Parsers::AST::Subject} of a
|
|
10
|
+
# {BELParser::Parsers::AST::Statement}.
|
|
11
|
+
class ListFunctionSubject
|
|
12
|
+
include SemanticsFunction
|
|
13
|
+
|
|
14
|
+
private_class_method :new
|
|
15
|
+
|
|
16
|
+
def self.map(node, spec, _namespaces)
|
|
17
|
+
return nil unless node.is_a?(BELParser::Parsers::AST::Subject)
|
|
18
|
+
|
|
19
|
+
list_func = spec.function(:list)
|
|
20
|
+
return nil unless list_func
|
|
21
|
+
|
|
22
|
+
func_name = node.term.function.identifier.string_literal
|
|
23
|
+
sub_func = spec.function(func_name.to_sym)
|
|
24
|
+
ListFunctionSubjectWarning.new(node, spec) if sub_func == list_func
|
|
25
|
+
end
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
# ListFunctionSubjectWarning defines a {SemanticsWarning} that indicates
|
|
29
|
+
# that a _list_ {BELParser::Parsers::AST::Term} was used as the
|
|
30
|
+
# {BELParser::Parsers::AST::Subject} of a
|
|
31
|
+
# {BELParser::Parsers::AST::Statement}.
|
|
32
|
+
class ListFunctionSubjectWarning < SemanticsWarning
|
|
33
|
+
def initialize(subject_node, spec)
|
|
34
|
+
super(subject_node, spec)
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
def to_s
|
|
38
|
+
<<-MSG.gsub(/ {12}/, '').delete("\n")
|
|
39
|
+
List term is only valid in the Object of a Statement.
|
|
40
|
+
MSG
|
|
41
|
+
end
|
|
42
|
+
end
|
|
43
|
+
end
|
|
44
|
+
end
|
|
45
|
+
end
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
require 'bel_parser/parsers/ast/node'
|
|
2
|
+
|
|
3
|
+
module BELParser
|
|
4
|
+
module Language
|
|
5
|
+
module Semantics
|
|
6
|
+
class RelationshipDeprecation
|
|
7
|
+
include SemanticsFunction
|
|
8
|
+
|
|
9
|
+
private_class_method :new
|
|
10
|
+
|
|
11
|
+
def self.map(node, spec, _namespaces)
|
|
12
|
+
return nil unless node.is_a?(BELParser::Parsers::AST::Relationship)
|
|
13
|
+
|
|
14
|
+
relationship_name = node.string_literal
|
|
15
|
+
rel = spec.relationship(relationship_name.to_sym)
|
|
16
|
+
return nil unless rel
|
|
17
|
+
|
|
18
|
+
RelationshipDeprecationWarning.new(node, spec, rel) if rel.deprecated?
|
|
19
|
+
end
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
class RelationshipDeprecationWarning < SemanticsWarning
|
|
23
|
+
attr_reader :deprecated_relationship
|
|
24
|
+
|
|
25
|
+
def initialize(relationship_node, spec, deprecated_relationship)
|
|
26
|
+
super(relationship_node, spec)
|
|
27
|
+
@deprecated_relationship = deprecated_relationship
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
def to_s
|
|
31
|
+
%Q{Relationship "#{deprecated_relationship}" is deprecated.}
|
|
32
|
+
end
|
|
33
|
+
end
|
|
34
|
+
end
|
|
35
|
+
end
|
|
36
|
+
end
|
|
@@ -3,24 +3,24 @@ require 'bel_parser/parsers/ast/node'
|
|
|
3
3
|
module BELParser
|
|
4
4
|
module Language
|
|
5
5
|
module Semantics
|
|
6
|
+
# SignatureMapping implements a {SemanticsFunction} that maps
|
|
7
|
+
# a {BELParser::Parsers::AST::Node} to {SemanticsResult} by
|
|
8
|
+
# checking each {BELParser::Language::Signature signature} for
|
|
9
|
+
# the {BELParser::Language::Function}.
|
|
10
|
+
#
|
|
11
|
+
# @see BELParser::Language::Function#signatures
|
|
6
12
|
class SignatureMapping
|
|
7
13
|
include SemanticsFunction
|
|
8
14
|
|
|
9
15
|
private_class_method :new
|
|
10
16
|
|
|
11
|
-
# Map {BELParser::Parsers::AST::Term term} to BEL signatures
|
|
12
|
-
# by a {BELParser::Language::Specification}. The mapping
|
|
13
|
-
# successful and failed signature matches.
|
|
14
|
-
def self.map(term_node, spec,
|
|
17
|
+
# Map {BELParser::Parsers::AST::Term term} to BEL signatures
|
|
18
|
+
# defined by a {BELParser::Language::Specification}. The mapping
|
|
19
|
+
# includes both successful and failed signature matches.
|
|
20
|
+
def self.map(term_node, spec, _namespaces)
|
|
15
21
|
return nil unless term_node.is_a?(BELParser::Parsers::AST::Term)
|
|
16
22
|
|
|
17
|
-
|
|
18
|
-
function = spec.function(function_name.to_sym)
|
|
19
|
-
match = BELParser::Language::Semantics.method(:match)
|
|
20
|
-
|
|
21
|
-
successes, failures = function.signatures
|
|
22
|
-
.map { |sig| [sig, match.call(term_node, sig.semantic_ast, spec)] }
|
|
23
|
-
.partition { |(sig, results)| results.all?(&:success?) }
|
|
23
|
+
successes, failures = map_signatures(term_node, spec)
|
|
24
24
|
|
|
25
25
|
if successes.empty?
|
|
26
26
|
SignatureMappingWarning.new(term_node, spec, failures)
|
|
@@ -28,8 +28,20 @@ module BELParser
|
|
|
28
28
|
SignatureMappingSuccess.new(term_node, spec, successes, failures)
|
|
29
29
|
end
|
|
30
30
|
end
|
|
31
|
+
|
|
32
|
+
def self.map_signatures(term_node, spec)
|
|
33
|
+
function_name = term_node.function.identifier.string_literal
|
|
34
|
+
function = spec.function(function_name.to_sym)
|
|
35
|
+
match = BELParser::Language::Semantics.method(:match)
|
|
36
|
+
function
|
|
37
|
+
.signatures
|
|
38
|
+
.map { |sig| [sig, match.call(term_node, sig.semantic_ast, spec)] }
|
|
39
|
+
.partition { |(_sig, results)| results.all?(&:success?) }
|
|
40
|
+
end
|
|
31
41
|
end
|
|
32
42
|
|
|
43
|
+
# SignatureMappingSuccess defines a {SemanticsResult} that indicates
|
|
44
|
+
# a successful signature match.
|
|
33
45
|
class SignatureMappingSuccess < SemanticsResult
|
|
34
46
|
attr_reader :success_signatures
|
|
35
47
|
attr_reader :failure_signatures
|
|
@@ -37,13 +49,13 @@ module BELParser
|
|
|
37
49
|
def initialize(term_node, spec, successes, failures)
|
|
38
50
|
super(term_node, spec)
|
|
39
51
|
@success_signatures = successes
|
|
40
|
-
@failure_signatures
|
|
52
|
+
@failure_signatures = failures
|
|
41
53
|
end
|
|
42
54
|
|
|
43
55
|
def to_s
|
|
44
56
|
sig_list = success_signatures
|
|
45
|
-
|
|
46
|
-
|
|
57
|
+
.map { |(sig, _results)| sig.string_form }
|
|
58
|
+
.join("\n ")
|
|
47
59
|
<<-MSG.gsub(/ {12}/, '').gsub(/\n$/, '')
|
|
48
60
|
Term matches function signatures:
|
|
49
61
|
#{sig_list}
|
|
@@ -51,6 +63,8 @@ module BELParser
|
|
|
51
63
|
end
|
|
52
64
|
end
|
|
53
65
|
|
|
66
|
+
# SignatureMappingWarning defines a {SemanticsWarning} that indicates
|
|
67
|
+
# an unsuccessful signature match.
|
|
54
68
|
class SignatureMappingWarning < SemanticsWarning
|
|
55
69
|
attr_reader :failure_signatures
|
|
56
70
|
|
|
@@ -61,8 +75,8 @@ module BELParser
|
|
|
61
75
|
|
|
62
76
|
def to_s
|
|
63
77
|
sig_list = failure_signatures
|
|
64
|
-
|
|
65
|
-
|
|
78
|
+
.map { |(sig, _results)| sig.string_form }
|
|
79
|
+
.join("\n ")
|
|
66
80
|
<<-MSG.gsub(/ {12}/, '').gsub(/\n$/, '')
|
|
67
81
|
Term did not conform to function signatures:
|
|
68
82
|
#{sig_list}
|
|
@@ -6,16 +6,21 @@ require_relative 'semantics_function'
|
|
|
6
6
|
|
|
7
7
|
module BELParser
|
|
8
8
|
module Language
|
|
9
|
+
# Semantics module aggregates the generic {SemanticsFunction}
|
|
10
|
+
# implementations that apply to all
|
|
11
|
+
# {BELParser::Language::Specification BEL specifications}.
|
|
9
12
|
module Semantics
|
|
10
13
|
def self.semantics_functions
|
|
11
|
-
|
|
12
|
-
const =
|
|
14
|
+
constants.collect do |symbol|
|
|
15
|
+
const = const_get(symbol)
|
|
13
16
|
const if
|
|
14
17
|
const.respond_to?(:include?) &&
|
|
15
18
|
const.include?(SemanticsFunction)
|
|
16
19
|
end.compact
|
|
17
20
|
end
|
|
18
21
|
|
|
22
|
+
# Valid defines a {SemanticsResult} that indicates successful semantic
|
|
23
|
+
# validation.
|
|
19
24
|
class Valid < SemanticsResult
|
|
20
25
|
def msg
|
|
21
26
|
'Semantics are valid.'
|
|
@@ -4,8 +4,8 @@ require_relative '../parsers/ast/node'
|
|
|
4
4
|
|
|
5
5
|
module BELParser
|
|
6
6
|
module Language
|
|
7
|
-
# Semantics capture BEL version-independent semantics for terms
|
|
8
|
-
# statements.
|
|
7
|
+
# Semantics capture BEL version-independent semantics for terms
|
|
8
|
+
# and statements.
|
|
9
9
|
module Semantics
|
|
10
10
|
# rubocop:disable Metrics/MethodLength
|
|
11
11
|
# rubocop:disable Metrics/AbcSize
|
|
@@ -15,16 +15,23 @@ module BELParser
|
|
|
15
15
|
if res.flatten.all?(&:success?) && !semantic_ast.terminal?
|
|
16
16
|
return match_results if semantic_ast.children.empty?
|
|
17
17
|
|
|
18
|
-
var_test = semantic_ast.children.any?
|
|
18
|
+
var_test = semantic_ast.children.any? do |x|
|
|
19
|
+
x.is_a?(SemanticVariadicArguments)
|
|
20
|
+
end
|
|
19
21
|
if var_test
|
|
20
|
-
test_pairs =
|
|
21
|
-
|
|
22
|
-
|
|
22
|
+
test_pairs =
|
|
23
|
+
input_ast
|
|
24
|
+
.children
|
|
25
|
+
.zip(semantic_ast.children)
|
|
26
|
+
.select do |pair|
|
|
27
|
+
!pair.include?(nil)
|
|
28
|
+
end
|
|
23
29
|
|
|
24
30
|
test_pairs.each do |(input_child, semantic_child)|
|
|
25
31
|
if semantic_child.is_a?(SemanticVariadicArguments)
|
|
26
32
|
input_children = input_ast.children
|
|
27
|
-
input_arguments =
|
|
33
|
+
input_arguments =
|
|
34
|
+
input_children[input_children.index(input_child)..-1]
|
|
28
35
|
argument_pattern = semantic_child.children.first
|
|
29
36
|
input_arguments.each do |argument_child|
|
|
30
37
|
res = semantic_child.match(argument_child, spec)
|
|
@@ -323,10 +330,7 @@ module BELParser
|
|
|
323
330
|
return failure(nil) if identifier.nil?
|
|
324
331
|
return failure(identifier) if type != identifier.type
|
|
325
332
|
|
|
326
|
-
value_results
|
|
327
|
-
pattern.match(identifier, spec)
|
|
328
|
-
end
|
|
329
|
-
|
|
333
|
+
value_results = match_value_patterns(identifier, spec)
|
|
330
334
|
failure_result = value_results.flatten.find(&:failure?)
|
|
331
335
|
|
|
332
336
|
if failure_result
|
|
@@ -335,6 +339,12 @@ module BELParser
|
|
|
335
339
|
value_results.unshift(success(identifier))
|
|
336
340
|
end
|
|
337
341
|
end
|
|
342
|
+
|
|
343
|
+
private
|
|
344
|
+
|
|
345
|
+
def match_value_patterns(identifier, spec)
|
|
346
|
+
value_patterns.map { |pattern| pattern.match(identifier, spec) }
|
|
347
|
+
end
|
|
338
348
|
end
|
|
339
349
|
|
|
340
350
|
# AST node for Any is a semantic AST.
|
|
@@ -559,7 +569,7 @@ module BELParser
|
|
|
559
569
|
class SemanticIsAminoAcidRange < SemanticASTNode
|
|
560
570
|
START_STOP = /[1-9][0-9]*_[1-9][0-9]*/
|
|
561
571
|
UNDETERMINED = /[1?]_[?*]/
|
|
562
|
-
UNKNOWN_START_STOP =
|
|
572
|
+
UNKNOWN_START_STOP = '?'.freeze
|
|
563
573
|
|
|
564
574
|
include BELParser::Quoting
|
|
565
575
|
|
|
@@ -1,10 +1,13 @@
|
|
|
1
1
|
module BELParser
|
|
2
2
|
module Language
|
|
3
3
|
module Semantics
|
|
4
|
+
# SemanticsFunction provides a {#map} function that maps a
|
|
5
|
+
# {BELParser::Parsers::AST::Node} to one or more
|
|
6
|
+
# {SemanticsResult semantics results}.
|
|
4
7
|
module SemanticsFunction
|
|
5
8
|
# @abstract Include {SemanticsFunction} and override {#map} to check
|
|
6
9
|
# term semantics (e.g. signatures).
|
|
7
|
-
def self.map(
|
|
10
|
+
def self.map(_term_ast, _spec, _namespaces)
|
|
8
11
|
raise NotImplementedError, "#{__method__} is not implemented."
|
|
9
12
|
end
|
|
10
13
|
end
|
|
@@ -3,6 +3,8 @@ require_relative 'semantics_result'
|
|
|
3
3
|
module BELParser
|
|
4
4
|
module Language
|
|
5
5
|
module Semantics
|
|
6
|
+
# SemanticsWarning defines a {SemanticsResult} that should be regarded as
|
|
7
|
+
# a warning with the expression.
|
|
6
8
|
class SemanticsWarning < SemanticsResult
|
|
7
9
|
def initialize(expression_node, specification)
|
|
8
10
|
super(expression_node, specification)
|