Class: SyntaxTree::Database::Pattern
- Inherits:
-
Object
- Object
- SyntaxTree::Database::Pattern
- 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
-
#query ⇒ Object
readonly
Returns the value of attribute query.
Instance Method Summary collapse
- #compile ⇒ Object
-
#initialize(query) ⇒ Pattern
constructor
A new instance of Pattern.
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
#query ⇒ Object (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
#compile ⇒ Object
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 |