factbase 0.1.0 → 0.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 190cce930c1b89f0b8f9a3f5bfd1c186b0fcb44b237056c89c0844d3ded39102
4
- data.tar.gz: 900c8db8d5d4b6494c409d9df9b0acf9e484a4e680dce67df31ab754e0c1ddc6
3
+ metadata.gz: 48e3aa4baba1a3e241c30002133a56627b43e9ef5ce903c46fbafe2873a8625f
4
+ data.tar.gz: f6fe14cbed445d1bd07e743f4b29f4eca2b65c3b46438a73c4654644626f8ae3
5
5
  SHA512:
6
- metadata.gz: b78e198034d25412f97a07273c3005bf0f10b14e5889370f48e7ac687f16e3bb708393d10bebe00289db0f1f478d9de2eb7f2be2d58a6d5dcedbda1438444a8a
7
- data.tar.gz: 5d66f9d6d94c48ad3de475d7bf478b6cd133c15598d1a8a17bf53a8467e03631737e4ae345826972d6158df4f2f315102a7743453ba031a3d6d64110de6ef1da
6
+ metadata.gz: 0b9900e9aefabc39c5a84af552c34011fa54cffaa9828f3eb84aa677ec2f006ee6a32028cb74be5d04a65a7e68e7d516f072d7b78dd89aa91a04168c67fdd561
7
+ data.tar.gz: 915d162e0b9ff8f533ef3f34f9b39cca0593fd1823a14918acb99f0f1f9d88aaf08016d85d5fdfd892410ebe701392a16322f8c4dc8cb16fc93e064287b29d01
@@ -29,6 +29,16 @@ require_relative 'term'
29
29
  #
30
30
  # This is an internal class, it is not supposed to be instantiated directly.
31
31
  #
32
+ # However, you can use it directly, if you need a parser of our syntax. You can
33
+ # create your own "Term" class and let this parser make instances of it for
34
+ # every term it meets in the query:
35
+ #
36
+ # require 'factbase/syntax'
37
+ # t = Factbase::Syntax.new('(hello world)', MyTerm).to_term
38
+ #
39
+ # The +MyTerm+ class should have a constructor with two arguments:
40
+ # the operator and the list of operands (Array).
41
+ #
32
42
  # Author:: Yegor Bugayenko (yegor256@gmail.com)
33
43
  # Copyright:: Copyright (c) 2024 Yegor Bugayenko
34
44
  # License:: MIT
@@ -44,7 +54,12 @@ class Factbase::Syntax
44
54
  # Convert it to a term.
45
55
  # @return [Term] The term detected
46
56
  def to_term
47
- build.simplify
57
+ @to_term ||=
58
+ begin
59
+ t = build
60
+ t = t.simplify if t.respond_to?(:simplify)
61
+ t
62
+ end
48
63
  rescue StandardError => e
49
64
  err = "#{e.message} in \"#{@query}\""
50
65
  err = "#{err}, tokens: #{@tokens}" unless @tokens.nil?
data/lib/factbase.rb CHANGED
@@ -81,7 +81,7 @@ require 'yaml'
81
81
  # License:: MIT
82
82
  class Factbase
83
83
  # Current version of the gem (changed by .rultor.yml on every release)
84
- VERSION = '0.1.0'
84
+ VERSION = '0.1.1'
85
85
 
86
86
  # An exception that may be thrown in a transaction, to roll it back.
87
87
  class Rollback < StandardError; end
@@ -35,7 +35,7 @@ class TestSyntax < Minitest::Test
35
35
  "(foo 'one two three ')",
36
36
  "(foo 'one two three ' 'tail tail')"
37
37
  ].each do |q|
38
- assert_equal(q, Factbase::Syntax.new(q).to_term.to_s)
38
+ assert_equal(q, Factbase::Syntax.new(q).to_term.to_s, q)
39
39
  end
40
40
  end
41
41
 
@@ -50,7 +50,7 @@ class TestSyntax < Minitest::Test
50
50
  "(foo 'Hello,\n\nworld!\r\t\n')\n",
51
51
  "(or ( a 4) (b 5) (always) (and (always) (c 5) \t\t(r 7 w8s w8is 'Foo')))"
52
52
  ].each do |q|
53
- Factbase::Syntax.new(q).to_term
53
+ assert(!Factbase::Syntax.new(q).to_term.nil?)
54
54
  end
55
55
  end
56
56
 
@@ -70,7 +70,7 @@ class TestSyntax < Minitest::Test
70
70
  '(eq t 3.0e+21)',
71
71
  "(foo (x (f (t (y 42 'Hey you'))) (never) (r 3)) y z)"
72
72
  ].each do |q|
73
- assert_equal(q, Factbase::Syntax.new(q).to_term.to_s)
73
+ assert_equal(q, Factbase::Syntax.new(q).to_term.to_s, q)
74
74
  end
75
75
  end
76
76
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: factbase
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Yegor Bugayenko