Class: BELParser::Language::Semantics::SemanticEncodingOf

Inherits:
SemanticASTNode show all
Defined in:
lib/bel_parser/language/semantics_ast.rb

Overview

AST node for EncodingOf is a semantic AST.

Instance Attribute Summary

Attributes inherited from AST::Node

#children, #hash, #type

Instance Method Summary collapse

Methods inherited from SemanticASTNode

#terminal?

Methods inherited from AST::Node

#==, #append, #concat, #dup, #eql?, #inspect, #to_a, #to_ast, #to_sexp, #updated

Constructor Details

#initialize(encodings, **properties) ⇒ SemanticEncodingOf

Returns a new instance of SemanticEncodingOf.



610
611
612
# File 'lib/bel_parser/language/semantics_ast.rb', line 610

def initialize(encodings, **properties)
  super(:encoding_of, encodings, properties)
end

Instance Method Details

#match(value_node, spec) ⇒ Object



618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
# File 'lib/bel_parser/language/semantics_ast.rb', line 618

def match(value_node, spec)
  unless value_node.respond_to?(:encoding) && value_node.encoding
    return invalid_encoding_warning(value_node, spec, match_encoding)
  end

  input     = value_node.encoding
  match     = match_encoding
  enc_match = input.product(match).any? do |(value_enc, match_enc)|
    value_enc.subtype_of?(match_enc)
  end

  if enc_match
    success(value_node, spec)
  else
    invalid_encoding_warning(value_node, spec, match_encoding)
  end
end

#match_encodingObject



614
615
616
# File 'lib/bel_parser/language/semantics_ast.rb', line 614

def match_encoding
  children
end