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_sexp, #updated

Constructor Details

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

Returns a new instance of SemanticTerm.



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

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

Instance Method Details

#argumentsObject



274
275
276
# File 'lib/bel_parser/language/semantics_ast.rb', line 274

def arguments
  children[1..-1]
end

#functionObject



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

def function
  children[0]
end

#match(parse_node, spec) ⇒ Object



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

def match(parse_node, spec)
  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

  # Return success if semantic AST does not supply argument patterns.
  if arguments.empty? || variadic_arguments?
    success(parse_node, spec)
  # Or, check argument length.
  elsif arguments.length == parse_node.arguments.length
    success(parse_node, spec)
  else
    argument_length_warning(
      parse_node,
      spec,
      self,
      parse_node)
  end
end

#variadic_arguments?Boolean

Returns:

  • (Boolean)


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

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