Class: SyntaxTree::Database::Pattern

Inherits:
Object
  • Object
show all
Defined in:
lib/syntax_tree/database.rb

Overview

A pattern matching expression that will be compiled into a query.

Defined Under Namespace

Classes: CompilationError

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(query) ⇒ Pattern

Returns a new instance of Pattern.



172
173
174
# File 'lib/syntax_tree/database.rb', line 172

def initialize(query)
  @query = query
end

Instance Attribute Details

#queryObject (readonly)

Returns the value of attribute query.



170
171
172
# File 'lib/syntax_tree/database.rb', line 170

def query
  @query
end

Instance Method Details

#compileObject



176
177
178
179
180
181
182
183
184
185
# File 'lib/syntax_tree/database.rb', line 176

def compile
  program =
    begin
      SyntaxTree.parse("case nil\nin #{query}\nend")
    rescue Parser::ParseError
      raise CompilationError, query
    end

  compile_node(program.statements.body.first.consequent.pattern)
end