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 +4 -4
- data/lib/factbase/syntax.rb +16 -1
- data/lib/factbase.rb +1 -1
- data/test/factbase/test_syntax.rb +3 -3
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 48e3aa4baba1a3e241c30002133a56627b43e9ef5ce903c46fbafe2873a8625f
|
4
|
+
data.tar.gz: f6fe14cbed445d1bd07e743f4b29f4eca2b65c3b46438a73c4654644626f8ae3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0b9900e9aefabc39c5a84af552c34011fa54cffaa9828f3eb84aa677ec2f006ee6a32028cb74be5d04a65a7e68e7d516f072d7b78dd89aa91a04168c67fdd561
|
7
|
+
data.tar.gz: 915d162e0b9ff8f533ef3f34f9b39cca0593fd1823a14918acb99f0f1f9d88aaf08016d85d5fdfd892410ebe701392a16322f8c4dc8cb16fc93e064287b29d01
|
data/lib/factbase/syntax.rb
CHANGED
@@ -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
|
-
|
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.
|
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
|
|