Class: BELParser::Language::Semantics::SignatureMapping
- Inherits:
-
Object
- Object
- BELParser::Language::Semantics::SignatureMapping
- Includes:
- SemanticsFunction
- Defined in:
- lib/bel_parser/language/semantics/signature_mapping.rb
Overview
SignatureMapping implements a SemanticsFunction that maps a Parsers::AST::Node to SemanticsResult by checking each signature for the Function.
Class Method Summary collapse
-
.map(term_node, spec, _namespaces) ⇒ Object
Map term to BEL signatures defined by a BELParser::Language::Specification.
- .map_signature(term_node, spec, signature) ⇒ Object
Class Method Details
.map(term_node, spec, _namespaces) ⇒ Object
Map term to BEL signatures defined by a BELParser::Language::Specification. The mapping includes both successful and failed signature matches.
20 21 22 23 24 25 26 27 28 29 |
# File 'lib/bel_parser/language/semantics/signature_mapping.rb', line 20 def self.map(term_node, spec, _namespaces) return nil unless term_node.is_a?(BELParser::Parsers::AST::Term) function_name = term_node.function.identifier.string_literal function = spec.function(function_name.to_sym) return nil unless function mapsig = method(:map_signature).to_proc.curry[term_node][spec] function.signatures.map(&mapsig) end |
.map_signature(term_node, spec, signature) ⇒ Object
31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/bel_parser/language/semantics/signature_mapping.rb', line 31 def self.map_signature(term_node, spec, signature) results = BELParser::Language::Semantics.match( term_node, signature.semantic_ast, spec) if results.all?(&:success?) SignatureMappingSuccess.new(term_node, spec, signature, results) else SignatureMappingWarning.new(term_node, spec, signature, results) end end |