feel 0.4.1 → 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: 8de0fedb1a035e540ac1d2b2e7e7f0cfd6c85dfa0b0919b69d3690ae1fe81a78
4
- data.tar.gz: 99975ce815f3c1fb9b63d064f303edb9599d7a1f49b5470daac2494143cd0cf1
3
+ metadata.gz: 26fdb4664c8065677848ea5b18de3a9f7e62da890af5d086862c9a7273aea58f
4
+ data.tar.gz: 7b81758ba746aa0641a5974c74f3afecc501b498887c0eb4c86c62de60ce45a1
5
5
  SHA512:
6
- metadata.gz: 1c283691f93b500f00aa4c23f68ce6dc8321e56691321c86d9d0e5a340e7cae48ca62a842500d17e9ddbaf12beadbdef39dda1819cfe3a4f8c6e866cedfd6ba1
7
- data.tar.gz: 9ee3653ab96ee639d01c052d03783890ca9b31a505091edb3d58562e49031cd1711069c6abe92d103bac899dca0763b78c879e9b35dfe000b744e6e13da7447d
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
 
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
  #
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.1"
4
+ VERSION = "0.5.0"
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: feel
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.1
4
+ version: 0.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Connected Bits