Class: Janeway::AST::Function
- Inherits:
-
Expression
- Object
- Expression
- Janeway::AST::Function
- Defined in:
- lib/janeway/ast/function.rb
Overview
Represents a JSONPath built-in function.
This is pure structure: name + parameters. The body / literal_return metadata lives in Functions::REGISTRY (looked up by name), so AST nodes don't drag closures over the parser's binding.
Instance Attribute Summary collapse
-
#parameters ⇒ Object
readonly
Returns the value of attribute parameters.
Attributes inherited from Expression
Instance Method Summary collapse
-
#initialize(name, parameters) ⇒ Function
constructor
A new instance of Function.
-
#literal? ⇒ Boolean
True if the function's return value is a literal.
-
#singular_query? ⇒ Boolean
True if this is the root of a singular-query.
- #to_s ⇒ Object
- #tree(level) ⇒ Array
Methods inherited from Expression
#chain_of?, #indented, #type, type_name
Constructor Details
#initialize(name, parameters) ⇒ Function
Returns a new instance of Function.
17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/janeway/ast/function.rb', line 17 def initialize(name, parameters) raise ArgumentError, "expect string, got #{name.inspect}" unless name.is_a?(String) spec = Functions::REGISTRY[name] raise ArgumentError, "unknown function #{name.inspect}" unless spec unless spec[:arity] == parameters.size raise ArgumentError, "function #{name.inspect}: declared arity #{spec[:arity]} does not " \ "match parameter count #{parameters.size}" end super(name) @parameters = parameters end |
Instance Attribute Details
#parameters ⇒ Object (readonly)
Returns the value of attribute parameters.
15 16 17 |
# File 'lib/janeway/ast/function.rb', line 15 def parameters @parameters end |
Instance Method Details
#literal? ⇒ Boolean
True if the function's return value is a literal
51 52 53 |
# File 'lib/janeway/ast/function.rb', line 51 def literal? Functions::REGISTRY.fetch(name)[:literal_return] end |
#singular_query? ⇒ Boolean
True if this is the root of a singular-query.
46 47 48 |
# File 'lib/janeway/ast/function.rb', line 46 def singular_query? true end |
#to_s ⇒ Object
32 33 34 |
# File 'lib/janeway/ast/function.rb', line 32 def to_s "#{name}(#{@parameters.join(',')})" end |
#tree(level) ⇒ Array
38 39 40 |
# File 'lib/janeway/ast/function.rb', line 38 def tree(level) [indented(level, to_s)] end |