Module: Yadriggy::AstHelper

Overview

Helper module

Instance Method Summary collapse

Instance Method Details

#has_tag?(s, tag) ⇒ Array

Returns the S-expression if it starts with the tag. Otherwise, raise an error.

Parameters:

  • s (Array)

    an S-expression.

  • tag (Symbol)

Returns:

  • (Array)

    the S-expression if it starts with the tag. Otherwise, raise an error.



304
305
306
307
# File 'lib/yadriggy/ast.rb', line 304

def has_tag?(s, tag)
  raise "s-exp is not :#{tag.to_s}. #{s}" if !s.nil? && s[0] != tag
  s
end

#to_node(s) ⇒ ASTnode

Returns an AST.

Parameters:

  • s (Array)

    an S-expression.

Returns:



291
# File 'lib/yadriggy/ast.rb', line 291

def to_node(s) ASTree.to_node(s) end

#to_nodes(s) ⇒ Array<ASTnode>

Returns ASTs.

Parameters:

  • s (Array)

    an array of S-expression.

Returns:



295
296
297
298
# File 'lib/yadriggy/ast.rb', line 295

def to_nodes(s)
  raise "not an array: #{s}" unless s.class == Array
  s.map {|e| ASTree.to_node(e) }
end