Class: Factbase::Syntax
- Inherits:
-
Object
- Object
- Factbase::Syntax
- Defined in:
- lib/factbase/syntax.rb
Overview
Syntax parser.
This is an internal class, it is not supposed to be instantiated directly.
- Author
-
Yegor Bugayenko (yegor256@gmail.com)
- Copyright
-
Copyright © 2024-2025 Yegor Bugayenko
- License
-
MIT
Defined Under Namespace
Classes: Broken
Instance Method Summary collapse
-
#initialize(query) ⇒ Syntax
constructor
Ctor.
-
#to_term ⇒ Term
Convert it to a term.
Constructor Details
#initialize(query) ⇒ Syntax
Ctor.
The class provided as the term
argument must have a constructor that accepts an operator, operands array, and a keyword argument fb. Also, it must be a child of Factbase::Term
.
30 31 32 |
# File 'lib/factbase/syntax.rb', line 30 def initialize(query) @query = query end |
Instance Method Details
#to_term ⇒ Term
Convert it to a term.
36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/factbase/syntax.rb', line 36 def to_term @to_term ||= begin t = build t = t.simplify if t.respond_to?(:simplify) t end rescue StandardError => e err = "#{e.} (#{Backtrace.new(e)}) in \"#{@query}\"" err = "#{err}, tokens: #{@tokens}" unless @tokens.nil? raise Broken, err end |