factbase 0.0.2 → 0.0.3

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: 870d9d422444751180a6e69d1be17c9f89ac46e168d7fc1023e7df22829f9134
4
- data.tar.gz: 21e5886fc43c7f297a5f0dd4070d738efb4d6b2ff1f1b9d261d0007bf9ce483d
3
+ metadata.gz: 270354d428517846946f93bec8e2e5b4c134306ca2c2136d5d99eae6add60b65
4
+ data.tar.gz: 170078b593a186785869f33fdb41e5152d8d34d5b7a47eb65a9b5756939592a0
5
5
  SHA512:
6
- metadata.gz: 91992d0fe70646084d7da8091ca5659a3f1aa64c474cfbf328278d40b0e5bc56233abb3b316435660ca3522afd3af275c29291b4f178136ef0544cf173a6d243
7
- data.tar.gz: 97c605569af192e7f6960c0bac50777134acb917aa2085b6195d89be95687cde606084569db351025c7c0d4472247feb5f394af1e346a9f14c6af7d5422c2242
6
+ metadata.gz: afecc5884796f2e67c8f95bab613c6b82f92291c424adbea1c883a19c7c3816475ea14897ea4079434da71e1a382ee40aa4e7e62347702116f999ea40de6d24a
7
+ data.tar.gz: d14d86d5ea751d540dd3ed5d52b3aba747f70b6db9ec295717abdcb30af2d57793b2d2b0cc2607eb4e90d509a53f0a6d336865afddcbce658ed2fd7e9a3f07b0
@@ -20,7 +20,6 @@
20
20
  # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
21
  # SOFTWARE.
22
22
 
23
- require 'cgi'
24
23
  require_relative 'fact'
25
24
  require_relative 'term'
26
25
 
@@ -70,7 +69,13 @@ class Factbase::Syntax
70
69
  def to_tokens
71
70
  list = []
72
71
  acc = ''
72
+ string = false
73
73
  @query.to_s.chars.each do |c|
74
+ string = !string if ['\'', '"'].include?(c)
75
+ if string
76
+ acc += c
77
+ next
78
+ end
74
79
  if !acc.empty? && [' ', ')'].include?(c)
75
80
  list << acc
76
81
  acc = ''
@@ -89,8 +94,8 @@ class Factbase::Syntax
89
94
  list.map do |t|
90
95
  if t.is_a?(Symbol)
91
96
  t
92
- elsif t.start_with?('\'')
93
- CGI.unescapeHTML(t[1..-2])
97
+ elsif t.start_with?('\'', '"')
98
+ t[1..-2]
94
99
  elsif t.match?(/^[0-9]+$/)
95
100
  t.to_i
96
101
  else
data/lib/factbase.rb CHANGED
@@ -26,7 +26,7 @@
26
26
  # License:: MIT
27
27
  class Factbase
28
28
  # Current version of the library and of this class.
29
- VERSION = '0.0.2'
29
+ VERSION = '0.0.3'
30
30
 
31
31
  # Constructor.
32
32
  def initialize
@@ -48,15 +48,14 @@ class Factbase
48
48
 
49
49
  # Create a query capable of iterating.
50
50
  #
51
- # There is a Lisp-like syntax, for example (all string literals
52
- # must be HTML-escaped):
51
+ # There is a Lisp-like syntax, for example:
53
52
  #
54
- # (eq title 'Object&#20;Thinking')
53
+ # (eq title 'Object Thinking')
55
54
  # (gt time '2024-03-23T03:21:43')
56
55
  # (gt cost 42)
57
56
  # (exists seenBy)
58
57
  # (and
59
- # (eq foo '42')
58
+ # (eq foo 42)
60
59
  # (or
61
60
  # (gt bar 200)
62
61
  # (absent zzz)))
@@ -29,12 +29,23 @@ require_relative '../../lib/factbase/syntax'
29
29
  # Copyright:: Copyright (c) 2024 Yegor Bugayenko
30
30
  # License:: MIT
31
31
  class TestSyntax < Minitest::Test
32
+ def test_parses_string_right
33
+ [
34
+ "(foo 'abc')",
35
+ "(foo 'one two')",
36
+ "(foo 'one two three ')",
37
+ "(foo 'one two three ' 'tail tail')"
38
+ ].each do |q|
39
+ assert_equal(q, Factbase::Syntax.new(q).to_term.to_s)
40
+ end
41
+ end
42
+
32
43
  def test_simple_parsing
33
44
  [
34
45
  '()',
35
46
  '(foo)',
36
47
  '(foo (bar) (zz 77) )',
37
- "(eq foo 'Hello,&#x20;world!')",
48
+ "(eq foo 'Hello, world!')",
38
49
  "(or ( a 4) (b 5) () (and () (c 5) (r 7 8s 8is 'Foo')))"
39
50
  ].each do |q|
40
51
  Factbase::Syntax.new(q).to_term
@@ -49,7 +60,7 @@ class TestSyntax < Minitest::Test
49
60
  '(foo x y z)',
50
61
  "(foo x y z t f 42 'Hi!' 33)",
51
62
  '(foo (x) y z)',
52
- "(foo (x (f (t (y 42 'Hey'))) (f) (r 3)) y z)"
63
+ "(foo (x (f (t (y 42 'Hey you'))) (f) (r 3)) y z)"
53
64
  ].each do |q|
54
65
  assert_equal(q, Factbase::Syntax.new(q).to_term.to_s)
55
66
  end
@@ -64,7 +75,7 @@ class TestSyntax < Minitest::Test
64
75
  {
65
76
  '(eq z 1)' => true,
66
77
  '(or (eq bar 888) (eq z 1))' => true,
67
- "(or (gt bar 100) (eq foo 'Hello,&#x20;world!'))" => true
78
+ "(or (gt bar 100) (eq foo 'Hello, world!'))" => true
68
79
  }.each do |k, v|
69
80
  assert_equal(v, Factbase::Syntax.new(k).to_term.matches?(m), k)
70
81
  end
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.0.2
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Yegor Bugayenko