bel_parser 1.0.0.alpha.7 → 1.0.0.alpha.8

Sign up to get free protection for your applications and to get access to all the features.
Files changed (153) hide show
  1. checksums.yaml +4 -4
  2. data/.gemspec +1 -1
  3. data/VERSION +1 -1
  4. data/bin/bel2_validator +7 -4
  5. data/lib/bel_parser/ast_filter.rb +2 -2
  6. data/lib/bel_parser/ast_generator.rb +11 -18
  7. data/lib/bel_parser/language/expression_validator.rb +8 -0
  8. data/lib/bel_parser/language/quoting.rb +19 -22
  9. data/lib/bel_parser/language/semantics/deeply_nested_statement.rb +65 -0
  10. data/lib/bel_parser/language/semantics/function_deprecation.rb +36 -0
  11. data/lib/bel_parser/language/semantics/list_function_subject.rb +45 -0
  12. data/lib/bel_parser/language/semantics/relationship_deprecation.rb +36 -0
  13. data/lib/bel_parser/language/semantics/signature_mapping.rb +30 -16
  14. data/lib/bel_parser/language/semantics.rb +7 -2
  15. data/lib/bel_parser/language/semantics_ast.rb +22 -12
  16. data/lib/bel_parser/language/semantics_function.rb +4 -1
  17. data/lib/bel_parser/language/semantics_result.rb +1 -0
  18. data/lib/bel_parser/language/semantics_warning.rb +2 -0
  19. data/lib/bel_parser/language/signature.rb +3 -3
  20. data/lib/bel_parser/language/syntax/invalid_function.rb +2 -2
  21. data/lib/bel_parser/language/syntax/invalid_relationship.rb +2 -2
  22. data/lib/bel_parser/language/syntax/undefined_namespace.rb +0 -1
  23. data/lib/bel_parser/language/syntax.rb +7 -2
  24. data/lib/bel_parser/language/syntax_error.rb +2 -0
  25. data/lib/bel_parser/language/syntax_function.rb +4 -1
  26. data/lib/bel_parser/language/syntax_result.rb +1 -0
  27. data/lib/bel_parser/language/syntax_warning.rb +2 -0
  28. data/lib/bel_parser/language/version1_0/functions/abundance.rb +14 -15
  29. data/lib/bel_parser/language/version1_0/functions/biological_process.rb +14 -15
  30. data/lib/bel_parser/language/version1_0/functions/catalytic_activity.rb +25 -21
  31. data/lib/bel_parser/language/version1_0/functions/cell_secretion.rb +15 -12
  32. data/lib/bel_parser/language/version1_0/functions/cell_surface_expression.rb +15 -12
  33. data/lib/bel_parser/language/version1_0/functions/chaperone_activity.rb +25 -21
  34. data/lib/bel_parser/language/version1_0/functions/complex_abundance.rb +26 -25
  35. data/lib/bel_parser/language/version1_0/functions/composite_abundance.rb +13 -12
  36. data/lib/bel_parser/language/version1_0/functions/degradation.rb +15 -12
  37. data/lib/bel_parser/language/version1_0/functions/fusion.rb +135 -129
  38. data/lib/bel_parser/language/version1_0/functions/gene_abundance.rb +34 -34
  39. data/lib/bel_parser/language/version1_0/functions/gtp_bound_activity.rb +24 -21
  40. data/lib/bel_parser/language/version1_0/functions/kinase_activity.rb +25 -21
  41. data/lib/bel_parser/language/version1_0/functions/list.rb +24 -24
  42. data/lib/bel_parser/language/version1_0/functions/micro_rna_abundance.rb +18 -17
  43. data/lib/bel_parser/language/version1_0/functions/molecular_activity.rb +14 -12
  44. data/lib/bel_parser/language/version1_0/functions/pathology.rb +14 -15
  45. data/lib/bel_parser/language/version1_0/functions/peptidase_activity.rb +23 -21
  46. data/lib/bel_parser/language/version1_0/functions/phosphatase_activity.rb +23 -21
  47. data/lib/bel_parser/language/version1_0/functions/products.rb +9 -10
  48. data/lib/bel_parser/language/version1_0/functions/protein_abundance.rb +94 -91
  49. data/lib/bel_parser/language/version1_0/functions/protein_modification.rb +60 -57
  50. data/lib/bel_parser/language/version1_0/functions/reactants.rb +9 -10
  51. data/lib/bel_parser/language/version1_0/functions/reaction.rb +18 -17
  52. data/lib/bel_parser/language/version1_0/functions/ribosylation_activity.rb +25 -21
  53. data/lib/bel_parser/language/version1_0/functions/rna_abundance.rb +34 -34
  54. data/lib/bel_parser/language/version1_0/functions/substitution.rb +29 -28
  55. data/lib/bel_parser/language/version1_0/functions/transcriptional_activity.rb +25 -21
  56. data/lib/bel_parser/language/version1_0/functions/translocation.rb +33 -32
  57. data/lib/bel_parser/language/version1_0/functions/transport_activity.rb +26 -21
  58. data/lib/bel_parser/language/version1_0/functions/truncation.rb +15 -14
  59. data/lib/bel_parser/language/version1_0/relationships/acts_in.rb +16 -2
  60. data/lib/bel_parser/language/version1_0/relationships/analogous.rb +8 -2
  61. data/lib/bel_parser/language/version1_0/relationships/association.rb +13 -2
  62. data/lib/bel_parser/language/version1_0/relationships/biomarker_for.rb +9 -2
  63. data/lib/bel_parser/language/version1_0/relationships/causes_no_change.rb +13 -2
  64. data/lib/bel_parser/language/version1_0/relationships/decreases.rb +22 -2
  65. data/lib/bel_parser/language/version1_0/relationships/directly_decreases.rb +11 -2
  66. data/lib/bel_parser/language/version1_0/relationships/directly_increases.rb +11 -2
  67. data/lib/bel_parser/language/version1_0/relationships/has_component.rb +25 -2
  68. data/lib/bel_parser/language/version1_0/relationships/has_components.rb +20 -2
  69. data/lib/bel_parser/language/version1_0/relationships/has_member.rb +15 -2
  70. data/lib/bel_parser/language/version1_0/relationships/has_members.rb +20 -2
  71. data/lib/bel_parser/language/version1_0/relationships/has_modification.rb +13 -2
  72. data/lib/bel_parser/language/version1_0/relationships/has_product.rb +15 -2
  73. data/lib/bel_parser/language/version1_0/relationships/has_variant.rb +13 -2
  74. data/lib/bel_parser/language/version1_0/relationships/includes.rb +18 -2
  75. data/lib/bel_parser/language/version1_0/relationships/increases.rb +22 -2
  76. data/lib/bel_parser/language/version1_0/relationships/is_a.rb +15 -2
  77. data/lib/bel_parser/language/version1_0/relationships/negative_correlation.rb +13 -2
  78. data/lib/bel_parser/language/version1_0/relationships/orthologous.rb +15 -2
  79. data/lib/bel_parser/language/version1_0/relationships/positive_correlation.rb +9 -2
  80. data/lib/bel_parser/language/version1_0/relationships/prognostic_biomarker_for.rb +11 -2
  81. data/lib/bel_parser/language/version1_0/relationships/rate_limiting_step_of.rb +16 -2
  82. data/lib/bel_parser/language/version1_0/relationships/reactant_in.rb +15 -2
  83. data/lib/bel_parser/language/version1_0/relationships/sub_process_of.rb +22 -2
  84. data/lib/bel_parser/language/version1_0/relationships/transcribed_to.rb +12 -2
  85. data/lib/bel_parser/language/version1_0/relationships/translated_to.rb +13 -2
  86. data/lib/bel_parser/language/version1_0/relationships/translocates.rb +16 -2
  87. data/lib/bel_parser/language/version1_0/syntax/function.rb +0 -1
  88. data/lib/bel_parser/language/version1_0.rb +13 -2
  89. data/lib/bel_parser/language/version2_0/functions/abundance.rb +54 -53
  90. data/lib/bel_parser/language/version2_0/functions/activity.rb +8 -5
  91. data/lib/bel_parser/language/version2_0/functions/biological_process.rb +16 -16
  92. data/lib/bel_parser/language/version2_0/functions/cell_secretion.rb +15 -12
  93. data/lib/bel_parser/language/version2_0/functions/cell_surface_expression.rb +15 -12
  94. data/lib/bel_parser/language/version2_0/functions/complex_abundance.rb +61 -58
  95. data/lib/bel_parser/language/version2_0/functions/composite_abundance.rb +13 -12
  96. data/lib/bel_parser/language/version2_0/functions/degradation.rb +15 -12
  97. data/lib/bel_parser/language/version2_0/functions/fragment.rb +8 -6
  98. data/lib/bel_parser/language/version2_0/functions/from_location.rb +18 -17
  99. data/lib/bel_parser/language/version2_0/functions/fusion.rb +120 -117
  100. data/lib/bel_parser/language/version2_0/functions/gene_abundance.rb +64 -62
  101. data/lib/bel_parser/language/version2_0/functions/list.rb +24 -24
  102. data/lib/bel_parser/language/version2_0/functions/location.rb +14 -15
  103. data/lib/bel_parser/language/version2_0/functions/micro_rna_abundance.rb +58 -55
  104. data/lib/bel_parser/language/version2_0/functions/molecular_activity.rb +16 -14
  105. data/lib/bel_parser/language/version2_0/functions/pathology.rb +14 -15
  106. data/lib/bel_parser/language/version2_0/functions/products.rb +9 -10
  107. data/lib/bel_parser/language/version2_0/functions/protein_abundance.rb +96 -92
  108. data/lib/bel_parser/language/version2_0/functions/protein_modification.rb +57 -54
  109. data/lib/bel_parser/language/version2_0/functions/reactants.rb +9 -10
  110. data/lib/bel_parser/language/version2_0/functions/reaction.rb +18 -17
  111. data/lib/bel_parser/language/version2_0/functions/rna_abundance.rb +64 -62
  112. data/lib/bel_parser/language/version2_0/functions/to_location.rb +16 -16
  113. data/lib/bel_parser/language/version2_0/functions/translocation.rb +23 -22
  114. data/lib/bel_parser/language/version2_0/functions/variant.rb +13 -13
  115. data/lib/bel_parser/language/version2_0/relationships/acts_in.rb +16 -2
  116. data/lib/bel_parser/language/version2_0/relationships/analogous.rb +8 -2
  117. data/lib/bel_parser/language/version2_0/relationships/association.rb +13 -2
  118. data/lib/bel_parser/language/version2_0/relationships/biomarker_for.rb +9 -2
  119. data/lib/bel_parser/language/version2_0/relationships/causes_no_change.rb +13 -2
  120. data/lib/bel_parser/language/version2_0/relationships/decreases.rb +22 -2
  121. data/lib/bel_parser/language/version2_0/relationships/directly_decreases.rb +11 -2
  122. data/lib/bel_parser/language/version2_0/relationships/directly_increases.rb +11 -2
  123. data/lib/bel_parser/language/version2_0/relationships/has_component.rb +25 -2
  124. data/lib/bel_parser/language/version2_0/relationships/has_components.rb +20 -2
  125. data/lib/bel_parser/language/version2_0/relationships/has_member.rb +15 -2
  126. data/lib/bel_parser/language/version2_0/relationships/has_members.rb +20 -2
  127. data/lib/bel_parser/language/version2_0/relationships/has_modification.rb +13 -2
  128. data/lib/bel_parser/language/version2_0/relationships/has_product.rb +15 -2
  129. data/lib/bel_parser/language/version2_0/relationships/has_variant.rb +13 -2
  130. data/lib/bel_parser/language/version2_0/relationships/includes.rb +18 -2
  131. data/lib/bel_parser/language/version2_0/relationships/increases.rb +22 -2
  132. data/lib/bel_parser/language/version2_0/relationships/is_a.rb +15 -2
  133. data/lib/bel_parser/language/version2_0/relationships/negative_correlation.rb +13 -2
  134. data/lib/bel_parser/language/version2_0/relationships/orthologous.rb +15 -2
  135. data/lib/bel_parser/language/version2_0/relationships/positive_correlation.rb +9 -2
  136. data/lib/bel_parser/language/version2_0/relationships/prognostic_biomarker_for.rb +11 -2
  137. data/lib/bel_parser/language/version2_0/relationships/rate_limiting_step_of.rb +16 -2
  138. data/lib/bel_parser/language/version2_0/relationships/reactant_in.rb +15 -2
  139. data/lib/bel_parser/language/version2_0/relationships/regulates.rb +14 -2
  140. data/lib/bel_parser/language/version2_0/relationships/sub_process_of.rb +22 -2
  141. data/lib/bel_parser/language/version2_0/relationships/transcribed_to.rb +12 -2
  142. data/lib/bel_parser/language/version2_0/relationships/translated_to.rb +13 -2
  143. data/lib/bel_parser/language/version2_0/relationships/translocates.rb +16 -2
  144. data/lib/bel_parser/language.rb +18 -8
  145. data/lib/bel_parser/parser.rb +1 -0
  146. data/lib/bel_parser/parsers/ast/node.rb +112 -74
  147. data/lib/bel_parser/parsers/bel_script/set.rl +1 -1
  148. data/lib/bel_parser/parsers/bel_script/set_document.rb +7087 -0
  149. data/lib/bel_parser/parsers/bel_script/set_document.rl +97 -0
  150. data/lib/bel_parser/parsers/bel_script.rb +1 -0
  151. data/lib/bel_parser/parsers/common/common.rl +1 -1
  152. data/lib/bel_parser/script/parser.rb +1 -0
  153. metadata +8 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: a34f2b2fcde4d9804cccccca0a470bce0d266956
4
- data.tar.gz: c3443d26fb7a34c8a65b5ca7275bb77cda43557f
3
+ metadata.gz: db955e27ca9e82bf06bbd0b3a01d4e7c9f4a00d3
4
+ data.tar.gz: a4621fb03673bba08e748328d3087cb6b98c2881
5
5
  SHA512:
6
- metadata.gz: 224d93b78ef97b22a0105ffe03188e20fad89096922c806a2a474d043ba6effe33889ba7162d7aa310bdf34a57355cbb81776099c00c037a9a4d3b62570d45e2
7
- data.tar.gz: 907a17075b1053f6f515e434061d51a49f23167bc5f37bd475124b8f4a6f6ba6cc9364b498ddf428f2172c92ab0aae41b2693657331b1d6cdd9806c2448b9110
6
+ metadata.gz: 42721d3f23244e42a9ea26399964d359bfe334a927ae622fead2255fb33758748aac4e3259cee34e2d4a53ebd5305ec18dd2571be657e86eca3872704c7373e7
7
+ data.tar.gz: 55a9fd90bb9807075bc240afd9a4fc513c656d638ffb9fb27055d8431746323d7870ad1501de0607f4b84072986233534e82a6a40ad2bfa54096602c17727b81
data/.gemspec CHANGED
@@ -11,7 +11,7 @@ Gem::Specification.new do |spec|
11
11
  'Anthony Bargnesi',
12
12
  'Nick Bargnesi',
13
13
  ]
14
- spec.date = %q{2016-04-11}
14
+ spec.date = %q{2016-04-13}
15
15
  spec.email = %q{abargnesi@selventa.com}
16
16
  spec.files = [
17
17
  Dir.glob('lib/**/*.{rb,rl}'),
data/VERSION CHANGED
@@ -1 +1 @@
1
- 1.0.0.alpha.7
1
+ 1.0.0.alpha.8
data/bin/bel2_validator CHANGED
@@ -1,5 +1,6 @@
1
1
  #!/usr/bin/env ruby
2
- $:.unshift(File.join(File.expand_path(File.dirname(__FILE__)), '..', 'lib'))
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.new(ARGV.first, namespaces).each($stdin) do |res|
16
- puts res.map { |r| "#{r}\n" }.join.each_line.map { |l| " #{l}" }.join
17
- end
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 |ast|
37
- puts ast.to_s(1)
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
- # line_io = StringIO.new("\"AKT1\"\n")
30
- # line = nil
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
- # line_io = StringIO.new("\"AKT1\"\n")
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
- # @yield [[Integer, String, Array<AST::Node>]] yields line number, line,
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
- # with {Enumerator#each}
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
- %Q{"#{escaped}"}
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? { |matcher|
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? { |matcher|
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 identifier
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 relase.
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 identifier
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 relase.
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 identifier
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 relase.
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? identifier
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 relase.
228
- You can use BEL::Quoting.quoted? and BEL::Quoting.unquoted?
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? { |m|
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 defined
12
- # by a {BELParser::Language::Specification}. The mapping includes both
13
- # successful and failed signature matches.
14
- def self.map(term_node, spec, namespaces)
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
- function_name = term_node.function.identifier.string_literal
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 = failures
52
+ @failure_signatures = failures
41
53
  end
42
54
 
43
55
  def to_s
44
56
  sig_list = success_signatures
45
- .map { |(sig, results)| sig.string_form }
46
- .join("\n ")
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
- .map { |(sig, results)| sig.string_form }
65
- .join("\n ")
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
- self.constants.collect do |symbol|
12
- const = self.const_get(symbol)
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 and
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? { |x| x.is_a?(SemanticVariadicArguments) }
18
+ var_test = semantic_ast.children.any? do |x|
19
+ x.is_a?(SemanticVariadicArguments)
20
+ end
19
21
  if var_test
20
- test_pairs = input_ast.children.zip(semantic_ast.children).select do |pair|
21
- !pair.include?(nil)
22
- end
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 = input_children[input_children.index(input_child)..-1]
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 = value_patterns.map do |pattern|
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(term_ast, spec, namespaces)
10
+ def self.map(_term_ast, _spec, _namespaces)
8
11
  raise NotImplementedError, "#{__method__} is not implemented."
9
12
  end
10
13
  end
@@ -1,6 +1,7 @@
1
1
  module BELParser
2
2
  module Language
3
3
  module Semantics
4
+ # SemanticsResult represents the result of running a {SemanticsFunction}.
4
5
  class SemanticsResult
5
6
  attr_reader :expression_node, :specification
6
7
 
@@ -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)