feel 0.4.0 → 0.5.0

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: 5e3c6cadc65effe99f563dcd6ceca765770c00205f0b5236795da8a59e18d39b
4
- data.tar.gz: a3989725d4ea3f5d13319afd0576b332d7372bf17621c874985746fdffc09027
3
+ metadata.gz: 26fdb4664c8065677848ea5b18de3a9f7e62da890af5d086862c9a7273aea58f
4
+ data.tar.gz: 7b81758ba746aa0641a5974c74f3afecc501b498887c0eb4c86c62de60ce45a1
5
5
  SHA512:
6
- metadata.gz: 8591d4a8b94eb173eb1b05e3d739dfccc23eabf40cabd9e98c0e5216cefd59e83deb6080d8c62288f2170254c21b7ea27a91cd858defe6a8ac2e7de4fea49b7e
7
- data.tar.gz: 68c18813491cce3e569e864afe54b674b869c2c7fa9b616deb59ca1e39698c5c0cad1f813ad57eadf06df11787ead485bd261396d38bf0ac9c0aeaa65bff4018
6
+ metadata.gz: 5a4d084ec29dc0d2265a6da43946b2d88a7c67fa82ad206b0bf967cb53352c53cb5d36ad7a6c95c5f8cd4e5ed5326ff5df43e30ecc7318c7e2996b1c89608d88
7
+ data.tar.gz: 4aa63c524997dea7f8df494573e4fa45317c713585739812094d60b6fa213f95b6670f429db77edabc371bb92fe30942cae32d0d54e3fa00150e7351fd2851b5
@@ -179,7 +179,7 @@ grammar FEEL
179
179
  # 7.b interval ;
180
180
  #
181
181
  rule simple_positive_unary_test
182
- head:((unary_operator / "not") __)? tail:endpoint <SimplePositiveUnaryTest> /
182
+ head:((unary_operator / "not") __)? tail:endpoint !(__ comparison_operator) <SimplePositiveUnaryTest> /
183
183
  interval
184
184
  end
185
185
 
@@ -244,7 +244,9 @@ grammar FEEL
244
244
  rule simple_unary_tests
245
245
  expr:simple_positive_unary_tests <SimpleUnaryTests> /
246
246
  negate:"not" __ "(" __ expr:simple_positive_unary_tests __ ")" <SimpleUnaryTests> /
247
- "-" <SimpleUnaryTests>
247
+ "-" <SimpleUnaryTests> /
248
+ # Handles ? in comparisons (e.g. "? > 5") — SimplePositiveUnaryTest handles ? in endpoints (e.g. "contains(?, \"x\")").
249
+ expr:simple_expression <ExpressionUnaryTest>
248
250
  end
249
251
 
250
252
  #
@@ -372,7 +374,7 @@ grammar FEEL
372
374
  # 30. name start char = "?" | [A-Z] | "\_" | [a-z] | [\uC0-\uD6] | [\uD8-\uF6] | [\uF8-\u2FF] | [\u370-\u37D] | [\u37F-\u1FFF] | [\u200C-\u200D] | [\u2070-\u218F] | [\u2C00-\u2FEF] | [\u3001-\uD7FF] | [\uF900-\uFDCF] | [\uFDF0-\uFFFD] | [\u10000-\uEFFFF] ;
373
375
  #
374
376
  rule name_start_char
375
- [A-Z] / [a-z] / "_" / name_start_unicode_char
377
+ "?" / [A-Z] / [a-z] / "_" / name_start_unicode_char
376
378
  end
377
379
 
378
380
  rule name_start_unicode_char
@@ -575,7 +577,7 @@ grammar FEEL
575
577
  # 51.d expression , "in" , " (", positive unary tests, ")" ;
576
578
  #
577
579
  rule comparison
578
- left:non_recursive_simple_expression_for_comparison __ operator:comparision_operator __ right:expression <Comparison>
580
+ left:non_recursive_simple_expression_for_comparison __ operator:comparison_operator __ right:expression <Comparison>
579
581
  end
580
582
 
581
583
  rule non_recursive_simple_expression_for_comparison
@@ -590,7 +592,7 @@ grammar FEEL
590
592
  expression __ "[" __ filter:expression __ "]" <FilterExpression>
591
593
  end
592
594
 
593
- rule comparision_operator
595
+ rule comparison_operator
594
596
  "=" / "!=" / "<=" / ">=" / "<" / ">"
595
597
  end
596
598
 
@@ -20,6 +20,8 @@ module FEEL
20
20
  def valid?
21
21
  return false if text.blank?
22
22
  tree.present?
23
+ rescue SyntaxError
24
+ false
23
25
  end
24
26
 
25
27
  def evaluate(variables = {})
data/lib/feel/nodes.rb CHANGED
@@ -2,6 +2,13 @@
2
2
 
3
3
  module FEEL
4
4
  class Node < Treetop::Runtime::SyntaxNode
5
+ def contains_input_placeholder?
6
+ return true if is_a?(Name) && text_value == "?"
7
+ return false unless respond_to?(:elements) && elements
8
+
9
+ elements.any? { |el| el.respond_to?(:contains_input_placeholder?) && el.contains_input_placeholder? }
10
+ end
11
+
5
12
  #
6
13
  # Takes a context hash and returns an array of qualified names
7
14
  # { "person": { "name": { "first": "Eric", "last": "Carlson" }, "age": 60 } } => ["person", "person.name.first", "person.name.last", "person.age"]
@@ -125,6 +132,11 @@ module FEEL
125
132
  class SimplePositiveUnaryTest < Node
126
133
  def eval(context = {})
127
134
  operator = head.text_value.strip
135
+
136
+ if operator.empty? && tail.respond_to?(:contains_input_placeholder?) && tail.contains_input_placeholder?
137
+ return ->(input) { tail.eval(context.merge("?" => input)) }
138
+ end
139
+
128
140
  endpoint = tail.eval(context)
129
141
 
130
142
  case operator
@@ -242,6 +254,12 @@ module FEEL
242
254
  end
243
255
  end
244
256
 
257
+ class ExpressionUnaryTest < Node
258
+ def eval(context = {})
259
+ ->(input) { expr.eval(context.merge("?" => input)) }
260
+ end
261
+ end
262
+
245
263
  #
246
264
  # 15. positive unary test = simple positive unary test | "null" ;
247
265
  #
@@ -15,6 +15,8 @@ module FEEL
15
15
  def valid?
16
16
  return true if text.nil? || text == "-"
17
17
  tree.present?
18
+ rescue SyntaxError
19
+ false
18
20
  end
19
21
 
20
22
  def test(input, variables = {})
data/lib/feel/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module FEEL
4
- VERSION = "0.4.0"
4
+ VERSION = "0.5.0"
5
5
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: feel
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.0
4
+ version: 0.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Connected Bits
8
8
  bindir: bin
9
9
  cert_chain: []
10
- date: 2026-03-16 00:00:00.000000000 Z
10
+ date: 1980-01-02 00:00:00.000000000 Z
11
11
  dependencies:
12
12
  - !ruby/object:Gem::Dependency
13
13
  name: activemodel
@@ -284,7 +284,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
284
284
  - !ruby/object:Gem::Version
285
285
  version: '0'
286
286
  requirements: []
287
- rubygems_version: 3.6.2
287
+ rubygems_version: 3.6.9
288
288
  specification_version: 4
289
289
  summary: A light-weight FEEL expression evaluator in Ruby.
290
290
  test_files: []