Class: Factbase::Syntax

Inherits:
Object
  • Object
show all
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

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.

Parameters:

  • query (String)

    The query, for example “(eq id 42)”


30
31
32
# File 'lib/factbase/syntax.rb', line 30

def initialize(query)
  @query = query
end

Instance Method Details

#to_termTerm

Convert it to a term.

Returns:

  • (Term)

    The term detected


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.message} (#{Backtrace.new(e)}) in \"#{@query}\""
  err = "#{err}, tokens: #{@tokens}" unless @tokens.nil?
  raise Broken, err
end