factbase 0.0.37 → 0.0.38

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: a464f6fa40a3aef098e4ab4a58b6f6905ac101421f22fb806b63c4fb624aa610
4
- data.tar.gz: ad19a0147890d8b4ff8fff96f7e9f47b09ecb264b3cb52fa606be892278fa380
3
+ metadata.gz: f3c7e0abf7bec6e53f050b4eeaeddd2b9954ee77b2a5f9a0332394c995d91ba9
4
+ data.tar.gz: 5da4b8574d7b1a93fd67f3d833bf51952eb5b3d9c303b9e20a084dc5953d71bc
5
5
  SHA512:
6
- metadata.gz: 6abb74b759ef7eea421e8a7f4f1ebdbf7ae46836dfefcd324286508fbb82e207a787265c0cf9f8931b43b00d50e5df983266fa9442f9c277111dfa9ea3a778de
7
- data.tar.gz: b0ed97f83f59230bafce810488f3e720d098a748149f7fbd58b7f1c25425b2fba6b742ce16b18692df34607eb3c42f9f11196ca212bc0273d7bdffe15e759efe
6
+ metadata.gz: f472603e32966c098979c2a461d94cd60f1f6213c4cea4abae225694d59ae88df252bbd42dcfb3292efb97352618cfa35fe56bef86bf87310dc74b4dbce65a20
7
+ data.tar.gz: fb91b271a5d57c59268dd386f8960e1c3c3c1577ea80e5c9bc3b623eaa6c559b15ce326f23ec9035e795d08ce647af353f4ae12aef5a34a124286f41fdf79130
data/.rubocop.yml CHANGED
@@ -43,7 +43,7 @@ Metrics/BlockLength:
43
43
  Metrics/CyclomaticComplexity:
44
44
  Max: 25
45
45
  Metrics/PerceivedComplexity:
46
- Max: 25
46
+ Max: 30
47
47
  Metrics/ClassLength:
48
48
  Enabled: false
49
49
  Layout/EmptyLineAfterGuardClause:
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
- * `(nonil a b)` returns `b` if `a` is `nil`
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
 
@@ -44,7 +44,9 @@ class Factbase::Syntax
44
44
  def to_term
45
45
  build.simplify
46
46
  rescue StandardError => e
47
- raise "#{e.message} in \"#{@query}\""
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
- @query.to_s.gsub(/#.*$/, '').chars.each do |c|
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
@@ -158,7 +158,7 @@ class Factbase::Term
158
158
  by_symbol(0, fact).nil?
159
159
  end
160
160
 
161
- def nonil(fact, maps)
161
+ def either(fact, maps)
162
162
  assert_args(2)
163
163
  v = the_values(0, fact, maps)
164
164
  return v unless v.nil?
data/lib/factbase.rb CHANGED
@@ -49,7 +49,7 @@ require 'yaml'
49
49
  # License:: MIT
50
50
  class Factbase
51
51
  # Current version of the gem (changed by .rultor.yml on every release)
52
- VERSION = '0.0.37'
52
+ VERSION = '0.0.38'
53
53
 
54
54
  # Constructor.
55
55
  def initialize(facts = [])
@@ -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 (nonil (at 0 (prev num)) 0)))' => 3,
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!' 33)",
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
- assert(
110
- assert_raises(q) do
111
- Factbase::Syntax.new(q).to_term
112
- end.message.include?(q)
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
 
@@ -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 test_nonil
182
- t = Factbase::Term.new(:nonil, [Factbase::Term.new(:at, [5, :foo]), 42])
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
 
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.37
4
+ version: 0.0.38
5
5
  platform: ruby
6
6
  authors:
7
7
  - Yegor Bugayenko