factbase 0.0.37 → 0.0.38
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/.rubocop.yml +1 -1
- data/README.md +1 -1
- data/lib/factbase/syntax.rb +8 -2
- data/lib/factbase/term.rb +1 -1
- data/lib/factbase.rb +1 -1
- data/test/factbase/test_query.rb +1 -1
- data/test/factbase/test_syntax.rb +8 -7
- data/test/factbase/test_term.rb +2 -2
- 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: f3c7e0abf7bec6e53f050b4eeaeddd2b9954ee77b2a5f9a0332394c995d91ba9
|
4
|
+
data.tar.gz: 5da4b8574d7b1a93fd67f3d833bf51952eb5b3d9c303b9e20a084dc5953d71bc
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f472603e32966c098979c2a461d94cd60f1f6213c4cea4abae225694d59ae88df252bbd42dcfb3292efb97352618cfa35fe56bef86bf87310dc74b4dbce65a20
|
7
|
+
data.tar.gz: fb91b271a5d57c59268dd386f8960e1c3c3c1577ea80e5c9bc3b623eaa6c559b15ce326f23ec9035e795d08ce647af353f4ae12aef5a34a124286f41fdf79130
|
data/.rubocop.yml
CHANGED
data/README.md
CHANGED
@@ -71,7 +71,7 @@ There are some terms available in a query:
|
|
71
71
|
* `(many a)` return true if there are many values in the `a` property
|
72
72
|
* `(one a)` returns true if there is only one value in the `a` property
|
73
73
|
* `(at i a)` returns the `i`-th value of the `a` property
|
74
|
-
* `(
|
74
|
+
* `(either a b)` returns `b` if `a` is `nil`
|
75
75
|
* `(matches a re)` returns true when `a` matches regular expression `re`
|
76
76
|
* `(defn foo "self.to_s")` defines a new term using Ruby syntax and returns true
|
77
77
|
|
data/lib/factbase/syntax.rb
CHANGED
@@ -44,7 +44,9 @@ class Factbase::Syntax
|
|
44
44
|
def to_term
|
45
45
|
build.simplify
|
46
46
|
rescue StandardError => e
|
47
|
-
|
47
|
+
err = "#{e.message} in #{@query}"
|
48
|
+
err = "#{err}, tokens: #{@tokens}" unless @tokens.nil?
|
49
|
+
raise err
|
48
50
|
end
|
49
51
|
|
50
52
|
private
|
@@ -95,7 +97,11 @@ class Factbase::Syntax
|
|
95
97
|
list = []
|
96
98
|
acc = ''
|
97
99
|
string = false
|
98
|
-
|
100
|
+
comment = false
|
101
|
+
@query.to_s.chars.each do |c|
|
102
|
+
comment = true if !string && c == '#'
|
103
|
+
comment = false if comment && c == "\n"
|
104
|
+
next if comment
|
99
105
|
if ['\'', '"'].include?(c)
|
100
106
|
if string && acc[acc.length - 1] == '\\'
|
101
107
|
acc = acc[0..-2]
|
data/lib/factbase/term.rb
CHANGED
data/lib/factbase.rb
CHANGED
data/test/factbase/test_query.rb
CHANGED
@@ -59,7 +59,7 @@ class TestQuery < Minitest::Test
|
|
59
59
|
'(when (eq num 0) (exists time))' => 2,
|
60
60
|
'(many num)' => 1,
|
61
61
|
'(one num)' => 2,
|
62
|
-
'(gt num (minus 1 (
|
62
|
+
'(gt num (minus 1 (either (at 0 (prev num)) 0)))' => 3,
|
63
63
|
'(and (not (many num)) (eq num (plus 21 +21)))' => 1,
|
64
64
|
'(and (not (many num)) (eq num (minus -100 -142)))' => 1,
|
65
65
|
'(and (one num) (eq num (times 7 6)))' => 1,
|
@@ -42,10 +42,12 @@ class TestSyntax < Minitest::Test
|
|
42
42
|
def test_simple_parsing
|
43
43
|
[
|
44
44
|
'(foo)',
|
45
|
-
'(foo (bar) (zz 77) )',
|
45
|
+
'(foo (bar) (zz 77) ) # hey',
|
46
|
+
"# hello\n\n\n(foo (bar))",
|
46
47
|
"(eq foo \n\n 'Hello, world!'\n)\n",
|
47
48
|
"(eq x 'Hello, \\' \n) \\' ( world!')",
|
48
49
|
"# this is a comment\n(eq foo # test\n 42)\n\n# another comment\n",
|
50
|
+
"(foo 'Hello,\n\nworld!\r\t\n')\n",
|
49
51
|
"(or ( a 4) (b 5) (always) (and (always) (c 5) \t\t(r 7 w8s w8is 'Foo')))"
|
50
52
|
].each do |q|
|
51
53
|
Factbase::Syntax.new(q).to_term
|
@@ -60,7 +62,7 @@ class TestSyntax < Minitest::Test
|
|
60
62
|
"(r 'Dude\\'s Friend')",
|
61
63
|
"(r 'I\\'m \\\"good\\\"')",
|
62
64
|
'(foo x y z)',
|
63
|
-
"(foo x y z t f 42 'Hi
|
65
|
+
"(foo x y z t f 42 'Hi!# you' 33)",
|
64
66
|
'(foo (x) y z)',
|
65
67
|
'(eq t 2024-05-25T19:43:48Z)',
|
66
68
|
'(eq t 2024-05-25T19:43:48Z)',
|
@@ -106,11 +108,10 @@ class TestSyntax < Minitest::Test
|
|
106
108
|
')',
|
107
109
|
'"'
|
108
110
|
].each do |q|
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
)
|
111
|
+
msg = assert_raises(q) do
|
112
|
+
Factbase::Syntax.new(q).to_term
|
113
|
+
end.message
|
114
|
+
assert(msg.include?(q), msg)
|
114
115
|
end
|
115
116
|
end
|
116
117
|
|
data/test/factbase/test_term.rb
CHANGED
@@ -178,8 +178,8 @@ class TestTerm < Minitest::Test
|
|
178
178
|
assert_equal(5, t.evaluate(fact('foo' => [4, 5]), []))
|
179
179
|
end
|
180
180
|
|
181
|
-
def
|
182
|
-
t = Factbase::Term.new(:
|
181
|
+
def test_either
|
182
|
+
t = Factbase::Term.new(:either, [Factbase::Term.new(:at, [5, :foo]), 42])
|
183
183
|
assert_equal([42], t.evaluate(fact('foo' => 4), []))
|
184
184
|
end
|
185
185
|
|