Class: Factbase::Syntax
- Inherits:
-
Object
- Object
- Factbase::Syntax
- Defined in:
- lib/factbase/syntax.rb
Overview
Syntax.
This is an internal class, it is not supposed to be instantiated directly.
However, you can use it directly, if you need a parser of our syntax. You can create your own “Term” class and let this parser make instances of it for every term it meets in the query:
require 'factbase/syntax'
t = Factbase::Syntax.new('(hello world)', MyTerm).to_term
The MyTerm
class should have a constructor with two arguments: the operator and the list of operands (Array).
- Author
-
Yegor Bugayenko ([email protected])
- Copyright
-
Copyright © 2024 Yegor Bugayenko
- License
-
MIT
Instance Method Summary collapse
-
#initialize(query, term: Factbase::Term) ⇒ Syntax
constructor
Ctor.
-
#to_term ⇒ Term
Convert it to a term.
Constructor Details
Instance Method Details
#to_term ⇒ Term
Convert it to a term.
56 57 58 59 60 61 62 63 64 65 66 67 |
# File 'lib/factbase/syntax.rb', line 56 def to_term @to_term ||= begin t = build t = t.simplify if t.respond_to?(:simplify) t end rescue StandardError => e err = "#{e.} in \"#{@query}\"" err = "#{err}, tokens: #{@tokens}" unless @tokens.nil? raise err end |