Class: BELParser::Language::Semantics::SemanticTerm

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

Overview

AST node for Term 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_bel, #to_s, #to_sexp, #updated

Methods included from Parsers

#serialize

Constructor Details

#initialize(children = [], **properties) ⇒ SemanticTerm

Returns a new instance of SemanticTerm.



257
258
259
# File 'lib/bel_parser/language/semantics_ast.rb', line 257

def initialize(children = [], **properties)
  super(:term, children, properties)
end

Instance Method Details

#argumentsObject



269
270
271
# File 'lib/bel_parser/language/semantics_ast.rb', line 269

def arguments
  children[1..-1]
end

#functionObject



261
262
263
# File 'lib/bel_parser/language/semantics_ast.rb', line 261

def function
  children[0]
end

#match(parse_node, spec, will_match_partial = false) ⇒ Object



273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
# File 'lib/bel_parser/language/semantics_ast.rb', line 273

def match(parse_node, spec, will_match_partial = false)
  return nil_node_warning(
    parse_node,
    spec,
    BELParser::Parsers::AST::Term) if parse_node.nil?
  return type_warning(
    parse_node,
    spec,
    BELParser::Parsers::AST::Term,
    parse_node) if parse_node.type != type

  # Allowed empty.
  if arguments.empty? || variadic_arguments?
    success(parse_node, spec)
  # Partial match on arity.
  elsif will_match_partial && parse_node.arguments.length < arguments.length
    success(parse_node, spec)
  # Or, check full arity
  elsif arguments.length == parse_node.arguments.length
    success(parse_node, spec)
  # Mismatch, warning
  else
    argument_length_warning(
      parse_node,
      spec,
      self,
      parse_node)
  end
end

#variadic_arguments?Boolean

Returns:

  • (Boolean)


265
266
267
# File 'lib/bel_parser/language/semantics_ast.rb', line 265

def variadic_arguments?
  children[1].type == :variadic_arguments
end