Class: Yarr::AST

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/yarr/ast.rb

Overview

The parsed user input

Instance Method Summary collapse

Constructor Details

#initialize(hash) ⇒ AST

Constructs an AST from a hash produced by the parser

Parameters:

  • hash (Hash)

    parslet output


10
11
12
# File 'lib/yarr/ast.rb', line 10

def initialize(hash)
  @hash = stringify_hash_values(hash)
end

Instance Method Details

#[]Object

Accesses an immediate AST sub node by key


20
# File 'lib/yarr/ast.rb', line 20

def_delegator :@hash, :[]

#dig_deep(key) ⇒ Object|nil

Looks up a key traversing the AST recursively

Parameters:

  • key (Symbol)

    AST key

Returns:

  • (Object|nil)

    AST node stored under key if any


28
29
30
# File 'lib/yarr/ast.rb', line 28

def dig_deep(key)
  self.class.send(:dig_deep, @hash, key)
end

#key?(sym) ⇒ Object

Is the given symbol at the top level of the AST

Parameters:

  • sym (Symbol)

    ast key


20
# File 'lib/yarr/ast.rb', line 20

def_delegator :@hash, :[]