bel_parser 1.0.0.alpha.15 → 1.0.0.alpha.16

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: 5a99bbde75e5c199ecf2dd8be815f1405e9eb5e4
4
- data.tar.gz: c356ebe805e01532cfce41ac8106468cb4f5c385
3
+ metadata.gz: 3e827bc3f99b0c849e302bd2f32debd794abf423
4
+ data.tar.gz: e18d99921f436e6eb6d684230252d3c213d470da
5
5
  SHA512:
6
- metadata.gz: b2106d5573f751b638a5386111ecd43a5278bdb8dcfc2c346f2a7a92b14cee760d53e848ad1f251f7b4430722219309b1c67190e63e6ed05854ee65a6fcbbd57
7
- data.tar.gz: 6876b054cf3ddb09c21471dd787608754fcc09aa31842228d25204464e24f7816464f67f2d02ef9b50a9f2b5d6432aaac44668c6af072e765d229213183a0d15
6
+ metadata.gz: 6c25495a94d389796b6a6f086527fc1c0ce6d6a6850966eaa169a6961d970f853ff03ec201022fd86609011ed0a3dfd76670e88ef4afdd18c749b43a02aa56ab
7
+ data.tar.gz: a3fbb92d0168fe0d7373ba01cc9a986f8127be586aefe31d3a93117ff72506ea406daa073979fbbaa5af5ae98360858ed1edf1289550a485c950fb42736894a4
data/README.md CHANGED
@@ -4,6 +4,17 @@ Parser for BEL expressions and the BEL Script document format.
4
4
 
5
5
  ### Installation
6
6
 
7
+ gem install bel_parser --pre
8
+
7
9
  ### Getting Started
8
10
 
11
+ Two tools are available to try out:
12
+ 1) bel_script_reader - will read a BEL Script with a specified BEL version and not any warning or errors with the script
13
+
14
+ 2) bel2_validator - will read in lines and validate the BEL Statements
15
+
16
+ Example script using bel_parser module
17
+
18
+ examples/upgrade_kinase.rb
19
+
9
20
  ### Design
data/VERSION CHANGED
@@ -1 +1 @@
1
- 1.0.0.alpha.15
1
+ 1.0.0.alpha.16
@@ -2,27 +2,51 @@
2
2
  $LOAD_PATH.unshift(
3
3
  File.join(File.expand_path(File.dirname(__FILE__)), '..', 'lib'))
4
4
 
5
- bel_specification_version, file = ARGV
5
+ require 'optparse'
6
+ require 'bel_parser'
7
+ require 'bel_parser/resource/resource_file_reader'
8
+
9
+ options = {
10
+ spec: BELParser::Language.specification(
11
+ BELParser::Language.latest_supported_version)
12
+ }
13
+ OptionParser.new do |opts|
14
+ opts.banner = <<-USAGE.gsub(/^ {4}/, '')
15
+ Validates BEL Script with support for multiple BEL specifications.
16
+
17
+ Read from a BEL file.
18
+ usage: #$PROGRAM_NAME --file [FILE]
6
19
 
7
- unless bel_specification_version
8
- program = File.basename($PROGRAM_NAME)
9
- $stderr.puts <<-USAGE.gsub(/ {4}/, '')
10
- usage: #{program} [BEL specification version]
20
+ Read from standard input.
21
+ usage: #$PROGRAM_NAME
11
22
  USAGE
12
- exit 1
13
- end
14
23
 
24
+ opts.on('-f', '--file FILE', 'BEL script file to read.') do |bel|
25
+ options[:file] = bel
26
+ end
27
+
28
+ opts.on(
29
+ '-s',
30
+ '--specification VERSION',
31
+ 'BEL specification version (e.g. 1.0, 2.0)') do |spec|
32
+
33
+ unless BELParser::Language.defines_version?(spec)
34
+ $stderr.puts %(Invalid BEL specification "#{spec}")
35
+ exit 1
36
+ end
37
+
38
+ options[:spec] = BELParser::Language.specification(spec)
39
+ end
40
+ end.parse!
41
+
42
+ file, spec = options.values_at(:file, :spec)
15
43
  io =
16
44
  if file
17
- File.open(ARGV.first, external_encoding: 'UTF-8')
45
+ File.open(file, external_encoding: 'UTF-8')
18
46
  else
19
47
  $stdin
20
48
  end
21
49
 
22
- require 'bel_parser/language'
23
- require 'bel_parser/script/validator'
24
- require 'bel_parser/resource/resource_file_reader'
25
-
26
50
  def select(list, cls)
27
51
  list.select { |item| item.is_a?(cls) }
28
52
  end
@@ -46,11 +70,19 @@ SYN_ERR = BELParser::Language::Syntax::SyntaxError
46
70
  SYN_WARN = BELParser::Language::Syntax::SyntaxWarning
47
71
  SEM_WARN = BELParser::Language::Semantics::SemanticsWarning
48
72
 
73
+ rr = BELParser::Resource::ResourceFileReader.new
74
+ namespaces = Hash[
75
+ ARGV.map do |ns|
76
+ prefix, identifier = ns.split('=')
77
+ dataset = rr.retrieve_resource(identifier)
78
+ dataset ? [prefix, dataset] : nil
79
+ end.compact
80
+ ]
81
+
49
82
  initial_state = {
50
- resource_reader: BELParser::Resource::ResourceFileReader.new,
51
- specification: BELParser::Language.specification(
52
- bel_specification_version
53
- )
83
+ resource_reader: BELParser::Resource::ResourceFileReader.new,
84
+ specification: spec,
85
+ namespace_definitions: namespaces
54
86
  }
55
87
 
56
88
  BELParser::Script::Validator
@@ -10,7 +10,7 @@ module BELParser
10
10
  class ExpressionValidator
11
11
  def initialize(spec, namespaces, resource_reader)
12
12
  @spec = spec
13
- @namespaces = namespaces
13
+ @namespaces = namespaces || {}
14
14
  @syntax_functions = Syntax.syntax_functions
15
15
  @semantics_functions = Semantics.semantics_functions
16
16
  @transform =
@@ -670,8 +670,13 @@ module BELParser
670
670
  def match(identifier, spec)
671
671
  return success(identifier, spec) if return_types.include?(:*)
672
672
 
673
- fxret = spec.function(identifier.string_literal.to_sym).return_type
674
- if return_types.any? { |rt| fxret <= rt }
673
+ function = spec.function(identifier.string_literal.to_sym)
674
+ return invalid_return_type_warning(
675
+ identifier,
676
+ spec,
677
+ return_types) unless function
678
+
679
+ if return_types.any? { |rt| function.return_type <= rt }
675
680
  success(identifier, spec)
676
681
  else
677
682
  invalid_return_type_warning(identifier, spec, return_types)
@@ -1,4 +1,5 @@
1
1
  require 'bel_parser/parsers/ast/node'
2
+ require 'bel_parser/quoting'
2
3
 
3
4
  module BELParser
4
5
  module Language
@@ -6,6 +7,7 @@ module BELParser
6
7
  # Undefined namespace value finds values that are missing from their
7
8
  # purported namespaces.
8
9
  class UndefinedNamespaceValue
10
+ extend BELParser::Quoting
9
11
  include SyntaxFunction
10
12
 
11
13
  private_class_method :new
@@ -15,7 +17,7 @@ module BELParser
15
17
  return nil unless value_node.namespace
16
18
 
17
19
  unless value_node.namespace_value
18
- value = value_node.children[0].string_literal
20
+ value = unquote(value_node.children[0].string_literal)
19
21
  UndefinedNamespaceValueWarning.new(value_node, spec, value)
20
22
  end
21
23
  end
@@ -0,0 +1,12 @@
1
+ module BELParser
2
+ module Script
3
+ module Keyword
4
+ BEL_VERSION_STRING = 'BELVersion'.freeze
5
+ BEL_VERSION_REGEX = /\A#{BEL_VERSION_STRING}\Z/i
6
+
7
+ def is_bel_version?(string)
8
+ string.to_s.strip =~ BEL_VERSION_REGEX
9
+ end
10
+ end
11
+ end
12
+ end
@@ -2,6 +2,7 @@ require 'bel_parser/language'
2
2
  require 'bel_parser/parsers/ast/node'
3
3
  require 'bel_parser/quoting'
4
4
  require 'concurrent/hash'
5
+ require_relative '../keywords'
5
6
  require_relative '../state_function'
6
7
 
7
8
  module BELParser
@@ -10,16 +11,16 @@ module BELParser
10
11
  class BELVersion
11
12
  extend StateFunction
12
13
  extend BELParser::Quoting
14
+ extend Keyword
13
15
 
14
16
  TARGET_NODE = BELParser::Parsers::AST::DocumentProperty
15
- BEL_VERSION_REGEX = /#{Regexp.escape('bel_version')}/i
16
17
  DEFAULT_BEL_VERSION = '2.0'
17
18
 
18
19
  def self.consume(ast_node, script_context)
19
20
  return unless ast_node.is_a?(TARGET_NODE)
20
21
  name, value = ast_node.children
21
22
  name_string = name.identifier.string_literal
22
- return unless name_string =~ BEL_VERSION_REGEX
23
+ return unless is_bel_version?(name_string)
23
24
 
24
25
  value_string = unquote(value.children[0].string_literal)
25
26
  begin
@@ -4,6 +4,7 @@ require 'bel_parser/language/syntax_error'
4
4
  require 'bel_parser/quoting'
5
5
  require 'bel_parser/parsers/ast/node'
6
6
  require 'concurrent/hash'
7
+ require_relative '../keywords'
7
8
 
8
9
  module BELParser
9
10
  module Script
@@ -11,15 +12,15 @@ module BELParser
11
12
  class UnsupportedBELVersion
12
13
  extend BELParser::Language::Syntax::SyntaxFunction
13
14
  extend BELParser::Quoting
15
+ extend Keyword
14
16
 
15
17
  TARGET_NODE = BELParser::Parsers::AST::DocumentProperty
16
- BEL_VERSION_REGEX = /#{Regexp.escape('bel_version')}/i
17
18
 
18
19
  def self.map(ast_node, script_context)
19
20
  return nil unless ast_node.is_a?(TARGET_NODE)
20
21
  name, value = ast_node.children
21
22
  name_string = name.identifier.string_literal
22
- return nil unless name_string =~ BEL_VERSION_REGEX
23
+ return nil unless is_bel_version?(name_string)
23
24
 
24
25
  value_string = unquote(value.children[0].string_literal)
25
26
  begin
@@ -0,0 +1,5 @@
1
+ require_relative 'script/keywords'
2
+ require_relative 'script/state_function'
3
+
4
+ require_relative 'script/parser'
5
+ require_relative 'script/validator'
data/lib/bel_parser.rb CHANGED
@@ -15,3 +15,6 @@ require 'bel_parser/ast_filter'
15
15
 
16
16
  # Language; version-independent classes
17
17
  require 'bel_parser/language'
18
+
19
+ # BEL Script support
20
+ require 'bel_parser/script'
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.15
4
+ version: 1.0.0.alpha.16
5
5
  platform: ruby
6
6
  authors:
7
7
  - Anthony Bargnesi
@@ -312,6 +312,8 @@ files:
312
312
  - lib/bel_parser/resource/resource_file_reader.rb
313
313
  - lib/bel_parser/resource/sparql_reader.rb
314
314
  - lib/bel_parser/resource/value.rb
315
+ - lib/bel_parser/script.rb
316
+ - lib/bel_parser/script/keywords.rb
315
317
  - lib/bel_parser/script/parser.rb
316
318
  - lib/bel_parser/script/state/annotation_definition.rb
317
319
  - lib/bel_parser/script/state/bel_version.rb