cel 0.2.1 → 0.2.3

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: 54879dbe064eebebe6597acd098c6b10b8376f7b2333d2f822ca02c24a0815bb
4
- data.tar.gz: 95e2fed808711b64aedc8ed6aff2f8bc8eb9e5f9562907c0d794df186a35f035
3
+ metadata.gz: da576b6bec07758040135b557e1e135952bee1e4e6bb4bc19768233b817bbe8f
4
+ data.tar.gz: bce3a0b0b7cd41113898fc7ebfaa1a5e3adcd94fc84b5791ef2bd9a6e33b4a60
5
5
  SHA512:
6
- metadata.gz: 59349c9633015f0a63c297573e30e33d459de63f1af8ff032f808b045c069716c19142e2208f653864bd4a2363009dd7cb54c8feed3160e6c792c260853cc79f
7
- data.tar.gz: 2070807c5f7a01217117d96373372e111697727069b915a665acfc6fd2a58c6ff4adfb4fd747522585d7b03733cfb77ee2b7b726b6c36edb3f6d828a93ffed10
6
+ metadata.gz: 88ad2004603260595e7995be27fd3f77d0e0de8a0c90e16569ce67c3018608530b1d0e2455e6a8a65949254818bdc698d3be8fea2c45866589eb153ddb3a7d4d
7
+ data.tar.gz: '028149b8a3f5b06c0ae5ebb02f3d09144ec42af89506971c3677f8671e8ccace55ee8b575fb1282f32a041872edee4e44f1fd9a8cb14e6889ba343794e60ae0e'
data/CHANGELOG.md CHANGED
@@ -1,5 +1,21 @@
1
1
  ## [Unreleased]
2
2
 
3
+ ## [0.2.3] - 2023-09-19
4
+
5
+ ### Bugfixes
6
+
7
+ * `cel` is loadable without the need to install `google/protobuf` again.
8
+ + expressions containing te operator `<=` were failing while parsing.
9
+
10
+ ## [0.2.2] - 2023-08-17
11
+
12
+ * Reimplements `Cel::Literal#==` in a simpler way, to avoid several comparison issues arising from the previous implementation.
13
+ * fix initialization of `Cel::Duration` and `Cel::Timestamp` from string notation.
14
+ * fix protobuf-to-cel parsing of negative literals.
15
+ * more consistent usage of Cel types internally.
16
+ * fix condition clause evaluation.
17
+
18
+
3
19
  ## [0.2.1] - 2023-07-26
4
20
 
5
21
 
@@ -60,9 +60,15 @@ module Cel
60
60
 
61
61
  value = value.fetch(key, value)
62
62
 
63
- value = Number.new(:double, value) if key == "number_value"
64
-
65
- value
63
+ value = case key
64
+ when "null_value"
65
+ Null.new if value.zero?
66
+ when "number_value"
67
+ value = -value.operands.first if value.is_a?(Operation) && value.op == "-" && value.unary?
68
+ Number.new(:double, value)
69
+ else
70
+ value
71
+ end
66
72
  when "BoolValue", "google.protobuf.BoolValue"
67
73
  value = value.nil? ? Bool.new(false) : value[Identifier.new("value")]
68
74
  when "BytesValue", "google.protobuf.BytesValue"
@@ -2,10 +2,21 @@
2
2
 
3
3
  require "time"
4
4
  require "delegate"
5
- require_relative "elements/protobuf"
6
5
 
7
6
  module Cel
8
- LOGICAL_OPERATORS = %w[< <= >= > == != in].freeze
7
+ begin
8
+ require_relative "elements/protobuf"
9
+ rescue LoadError
10
+ module Protobuf
11
+ module_function
12
+
13
+ def method_missing(*) # rubocop:disable Style/MissingRespondToMissing
14
+ raise Error, "\"google/protobuf\" is required in order to use this feature"
15
+ end
16
+ end
17
+ end
18
+
19
+ LOGICAL_OPERATORS = %w[<= >= < > == != in].freeze
9
20
  MULTI_OPERATORS = %w[* / %].freeze
10
21
 
11
22
  class Identifier < SimpleDelegator
@@ -143,6 +154,7 @@ module Cel
143
154
  end
144
155
 
145
156
  def ==(other)
157
+ other = other.value if other.is_a?(Literal)
146
158
  @value == other || super
147
159
  end
148
160
 
@@ -194,7 +206,7 @@ module Cel
194
206
  OUT
195
207
  end
196
208
 
197
- LOGICAL_OPERATORS.each do |op|
209
+ (LOGICAL_OPERATORS - %w[==]).each do |op|
198
210
  class_eval(<<-OUT, __FILE__, __LINE__ + 1)
199
211
  def #{op}(other)
200
212
  Bool.new(super)
@@ -208,13 +220,17 @@ module Cel
208
220
  super(:bool, value)
209
221
  end
210
222
 
211
- LOGICAL_OPERATORS.each do |op|
223
+ (LOGICAL_OPERATORS - %w[==]).each do |op|
212
224
  class_eval(<<-OUT, __FILE__, __LINE__ + 1)
213
225
  def #{op}(other)
214
226
  Bool.new(super)
215
227
  end
216
228
  OUT
217
229
  end
230
+
231
+ def !
232
+ Bool.new(super)
233
+ end
218
234
  end
219
235
 
220
236
  class Null < Literal
@@ -246,14 +262,6 @@ module Cel
246
262
  Macro.matches(self, pattern)
247
263
  end
248
264
 
249
- LOGICAL_OPERATORS.each do |op|
250
- class_eval(<<-OUT, __FILE__, __LINE__ + 1)
251
- def #{op}(other)
252
- other.is_a?(Cel::Literal) ? Bool.new(super) : super
253
- end
254
- OUT
255
- end
256
-
257
265
  %i[+ -].each do |op|
258
266
  class_eval(<<-OUT, __FILE__, __LINE__ + 1)
259
267
  def #{op}(other)
@@ -272,7 +280,7 @@ module Cel
272
280
  [self]
273
281
  end
274
282
 
275
- LOGICAL_OPERATORS.each do |op|
283
+ (LOGICAL_OPERATORS - %w[==]).each do |op|
276
284
  class_eval(<<-OUT, __FILE__, __LINE__ + 1)
277
285
  def #{op}(other)
278
286
  Bool.new(super)
@@ -358,7 +366,7 @@ module Cel
358
366
  class Timestamp < Literal
359
367
  def initialize(value)
360
368
  value = case value
361
- when String then Time.parse(value)
369
+ when ::String then Time.parse(value)
362
370
  when Numeric then Time.at(value)
363
371
  else value
364
372
  end
@@ -443,7 +451,7 @@ module Cel
443
451
  class Duration < Literal
444
452
  def initialize(value)
445
453
  value = case value
446
- when String
454
+ when ::String
447
455
  init_from_string(value)
448
456
  when Hash
449
457
  seconds, nanos = value.values_at(:seconds, :nanos)
@@ -553,6 +561,10 @@ module Cel
553
561
  end
554
562
  end
555
563
 
564
+ def unary?
565
+ @operands.size == 1
566
+ end
567
+
556
568
  def to_s
557
569
  return "#{@op}#{@operands.first}" if @operands.size == 1
558
570
 
data/lib/cel/ast/types.rb CHANGED
@@ -21,6 +21,8 @@ module Cel
21
21
  end
22
22
 
23
23
  def cast(value)
24
+ value = value.value if value.is_a?(Literal)
25
+
24
26
  case @type
25
27
  when :int
26
28
  Number.new(:int, Integer(value))
data/lib/cel/checker.rb CHANGED
@@ -357,7 +357,7 @@ module Cel
357
357
 
358
358
  return unless typ
359
359
 
360
- return convert(typ) if id_call_chain.empty?
360
+ convert(typ) if id_call_chain.empty?
361
361
  end
362
362
 
363
363
  def convert(typ)
data/lib/cel/macro.rb CHANGED
@@ -43,21 +43,24 @@ module Cel
43
43
  end
44
44
 
45
45
  def all(collection, identifier, predicate, context:)
46
- collection.all? do |element, *|
46
+ return_value = collection.all? do |element, *|
47
47
  Program.new(context.merge(identifier.to_sym => element)).evaluate(predicate).value
48
48
  end
49
+ Bool.new(return_value)
49
50
  end
50
51
 
51
52
  def exists(collection, identifier, predicate, context:)
52
- collection.any? do |element, *|
53
+ return_value = collection.any? do |element, *|
53
54
  Program.new(context.merge(identifier.to_sym => element)).evaluate(predicate).value
54
55
  end
56
+ Bool.new(return_value)
55
57
  end
56
58
 
57
59
  def exists_one(collection, identifier, predicate, context:)
58
- collection.one? do |element, *|
60
+ return_value = collection.one? do |element, *|
59
61
  Program.new(context.merge(identifier.to_sym => element)).evaluate(predicate).value
60
62
  end
63
+ Bool.new(return_value)
61
64
  end
62
65
 
63
66
  def filter(collection, identifier, predicate, context:)
data/lib/cel/parser.rb CHANGED
@@ -1,6 +1,6 @@
1
1
  #
2
2
  # DO NOT MODIFY!!!!
3
- # This file is automatically generated by Racc 1.6.0
3
+ # This file is automatically generated by Racc 1.7.1
4
4
  # from Racc grammar file "".
5
5
  #
6
6
 
@@ -548,6 +548,7 @@ Racc_arg = [
548
548
  racc_shift_n,
549
549
  racc_reduce_n,
550
550
  racc_use_result_var ]
551
+ Ractor.make_shareable(Racc_arg) if defined?(Ractor)
551
552
 
552
553
  Racc_token_to_s_table = [
553
554
  "$end",
@@ -602,6 +603,7 @@ Racc_token_to_s_table = [
602
603
  "expr_list",
603
604
  "map_inits",
604
605
  "field_inits" ]
606
+ Ractor.make_shareable(Racc_token_to_s_table) if defined?(Ractor)
605
607
 
606
608
  Racc_debug_parser = false
607
609
 
@@ -0,0 +1,1023 @@
1
+ #
2
+ # DO NOT MODIFY!!!!
3
+ # This file is automatically generated by Racc 1.7.1
4
+ # from Racc grammar file "".
5
+ #
6
+
7
+ require "racc/parser"
8
+
9
+ require "strscan"
10
+ require "bigdecimal"
11
+ require "cel/ast/elements"
12
+ module Cel
13
+ class Parser < Racc::Parser
14
+ module_eval(<<~'...END PARSER.RY/MODULE_EVAL...', __FILE__, __LINE__ + 1)
15
+
16
+
17
+
18
+ OPERATORS = if RUBY_VERSION < "2.7.0"
19
+ {
20
+ "&&" => :tANDOP,
21
+ "||" => :tOROP,
22
+ "+" => :tADDOP,
23
+ "-" => :tSUBOP,
24
+ }.merge(Hash[Cel::LOGICAL_OPERATORS.map{|op| [op, :tRELOP] }])
25
+ .merge(Hash[Cel::MULTI_OPERATORS.map{|op| [op, :tMULTIOP] }])
26
+ else
27
+ {
28
+ **Hash[Cel::LOGICAL_OPERATORS.map{|op| [op, :tRELOP] }],
29
+ **Hash[Cel::MULTI_OPERATORS.map{|op| [op, :tMULTIOP] }],
30
+ "&&" => :tANDOP,
31
+ "||" => :tOROP,
32
+ "+" => :tADDOP,
33
+ "-" => :tSUBOP,
34
+ }
35
+ end.freeze
36
+
37
+ OPERATORS_RE = Regexp.union(*OPERATORS.keys)
38
+
39
+ RESERVED = %W[
40
+ as break const continue else
41
+ for function if import let
42
+ loop package namespace return
43
+ var void while
44
+ ].freeze
45
+
46
+ IDENTIFIER_REGEX = /[a-zA-Z][_a-zA-Z0-9]*/
47
+
48
+ STRING_LIT_REGEX = Regexp.union(
49
+ /"""(?~""")*"""/,
50
+ /'''(?~''')*'''/,
51
+ /"(\\"|[^"])*"/,
52
+ /'(\\'|[^'])*'/,
53
+ )
54
+
55
+ NUMBER_REGEX = Regexp.union(
56
+ /(0x[0-9a-fA-F]+)[uU]?/, # hexadecimal
57
+ /(\d+)[uU]/, # uinteger
58
+ /((\d*\.\d+)|\d+)([eE][+\-]?\d+)?/, # integer, float, exponent
59
+ )
60
+
61
+ def parse(str)
62
+ tokenize(str)
63
+ do_parse
64
+ rescue Racc::ParseError => err
65
+ raise parse_error(err)
66
+ end
67
+
68
+ def parse_error(error)
69
+ parse_error = case error.message
70
+ when /parse error on value "([^"]+)" \(tRESERVED\)/
71
+ Cel::ParseError.new("invalid usage of the reserved word \"#{$1}\"")
72
+ else
73
+ Cel::ParseError.new(error.message)
74
+ end
75
+ parse_error.set_backtrace(error.backtrace)
76
+ parse_error
77
+ end
78
+
79
+ def tokenize(str)
80
+ str.force_encoding(Encoding::BINARY) unless str.valid_encoding?
81
+
82
+ scanner = StringScanner.new(str)
83
+
84
+ @q = []
85
+
86
+ until scanner.eos?
87
+ case
88
+ when scanner.scan(/\s+/)
89
+ # skip whitespace
90
+ when scanner.scan(/#(( *)|( ?(?<string>.*)))\n/)
91
+ # skip comment lines
92
+ when scanner.scan(NUMBER_REGEX)
93
+ @q << convert_to_number(scanner)
94
+ when scanner.scan(/[bB]?[rR]?#{STRING_LIT_REGEX}/) # string
95
+ # s = scanner.matched.yield_self {|s| s[1, s.length - 2] }
96
+ # .gsub(DBL_QUOTE_STR_ESCAPE_SEQUENCES_RE) do |match|
97
+ # case match
98
+ # when '\\a' then "\a"
99
+ # when '\\b' then "\b"
100
+ # when '\\e' then "\e"
101
+ # when '\\f' then "\f"
102
+ # when '\\n' then "\n"
103
+ # when '\\r' then "\r"
104
+ # when '\\s' then "\s"
105
+ # when '\\t' then "\t"
106
+ # when '\\v' then "\v"
107
+ # when '\\"' then '"'
108
+ # end
109
+ # end
110
+
111
+ # s = scanner.matched.yield_self {|s| s[1, s.length - 2] }.gsub(/\\'/, "'")
112
+
113
+ str = scanner.matched
114
+
115
+ @q << if str.start_with?("b")
116
+ [:tBYTES, convert_to_bytes(str.byteslice(2..-2))]
117
+ else
118
+ [:tSTRING, convert_to_string(str)]
119
+ end
120
+ when scanner.scan(IDENTIFIER_REGEX)
121
+ word = scanner.matched
122
+ if word == "null"
123
+ @q << [:tNULL, nil]
124
+ elsif word == "true"
125
+ @q << [:tBOOL, true]
126
+ elsif word == "false"
127
+ @q << [:tBOOL, false]
128
+ elsif RESERVED.include?(word)
129
+ @q << [:tRESERVED, scanner.matched]
130
+ elsif word == "in"
131
+ @q << [OPERATORS[scanner.matched], scanner.matched]
132
+ else
133
+ @q << [:tIDENTIFIER, scanner.matched]
134
+ end
135
+ when scanner.scan(OPERATORS_RE)
136
+ @q << [OPERATORS[scanner.matched], scanner.matched]
137
+ when scanner.scan(/\A.|\n/o)
138
+ s = scanner.matched
139
+ @q << [s, s]
140
+ else
141
+ raise ParseError, "unexpected value: #{scanner.string}"
142
+ end
143
+ end
144
+ @q << [:tEOF, false]
145
+ end
146
+
147
+ def next_token
148
+ @q.shift
149
+ end
150
+
151
+ def convert_to_number(scanner)
152
+ matched = scanner.matched
153
+ hexa, uint, number, floating, exp = scanner.captures
154
+
155
+ if hexa && !hexa.empty?
156
+ return [:tINT, hexa.to_i(16)]
157
+ end
158
+
159
+ if uint && !uint.empty?
160
+ return [:tUINT, Integer(uint)]
161
+ end
162
+
163
+ if exp && !exp.empty?
164
+ # third matched group, can only be a floating exponential, let's convert tout suite
165
+ [:tDOUBLE, BigDecimal(matched)]
166
+ elsif floating && !floating.empty?
167
+ if number == floating || floating.start_with?(".")
168
+ [:tDOUBLE, Float(matched)]
169
+ elsif number.nil? || number.empty?
170
+ [:tDOUBLE, BigDecimal(matched)]
171
+ end
172
+ else
173
+ if matched[-1].downcase == "u"
174
+ [:tINT, Integer(matched[0..-2]).abs]
175
+ else
176
+ [:tINT, Integer(matched)]
177
+ end
178
+ end
179
+ end
180
+
181
+ TRIPE_DOUBLE_QUOTES = %Q{"""}
182
+ TRIPE_SINGLE_QUOTES = %Q{'''}
183
+
184
+ def convert_to_string(str)
185
+
186
+ if str.start_with?("r")
187
+ # If preceded by an r or R character, the string is a raw string
188
+ # and does not interpret escape sequences.
189
+ str = str.byteslice(2..-2).inspect.byteslice(1..-2)
190
+ return str
191
+ end
192
+
193
+ if str.size > 6 && (
194
+ (str.start_with?(TRIPE_DOUBLE_QUOTES) && str.end_with?(TRIPE_DOUBLE_QUOTES)) ||
195
+ (str.start_with?(TRIPE_SINGLE_QUOTES) && str.end_with?(TRIPE_SINGLE_QUOTES)))
196
+ str = str.byteslice(3..-4)
197
+ else
198
+ str = str.byteslice(1..-2)
199
+ end
200
+
201
+ cleanup_escape_sequences(str)
202
+ end
203
+
204
+ def convert_to_bytes(str)
205
+ str.unpack("C*")
206
+ end
207
+
208
+
209
+ BIN_ESCAPE = /\\([0-3][0-7][0-7])/
210
+ HEX_ESCAPE = /\\x([0-9a-fA-F]{2})/
211
+ BPM_ESCAPE = /\\u([0-9a-fA-F]{4})/
212
+ UNICODE_ESCAPE = /\\u([0-9a-fA-F]{4})/
213
+ WHITESPACE_ESCAPE = /\\([bfnrt"'\\])/
214
+ ESCAPE_UNION = Regexp.union(BIN_ESCAPE, HEX_ESCAPE, BPM_ESCAPE, WHITESPACE_ESCAPE)
215
+ # For the sake of a readable representation, the escape sequences (ESCAPE) are kept
216
+ # implicit in string tokens. This means that strings without the r or R (raw) prefix
217
+ # process ESCAPE sequences, while in strings with the raw prefix they stay uninterpreted.
218
+ # See documentation of string literals below.
219
+ def cleanup_escape_sequences(str)
220
+ str.gsub!(ESCAPE_UNION) do |match|
221
+ case match
222
+ when /\\"/
223
+ "\""
224
+ when BIN_ESCAPE
225
+ # For strings, it denotes the unicode code point.
226
+ Regexp.last_match(1).to_i.chr(Encoding::UTF_8)
227
+ when HEX_ESCAPE
228
+ # For strings, it denotes the unicode code point.
229
+ Regexp.last_match(1).hex.chr(Encoding::UTF_8)
230
+ when BPM_ESCAPE
231
+ Regexp.last_match(1).hex.chr(Encoding::BPM)
232
+ when UNICODE_ESCAPE
233
+ # encoding a Unicode code point. Valid only for string literals.
234
+ Regexp.last_match(1).hex.chr(Encoding::UTF_8)
235
+ when WHITESPACE_ESCAPE
236
+ Regexp.last_match(0)
237
+ end
238
+ end
239
+ str
240
+ end
241
+
242
+ ...END PARSER.RY/MODULE_EVAL...
243
+ ##### State transition tables begin ###
244
+
245
+ racc_action_table = [
246
+ 22, 23, 24, 25, 26, 27, 28, 38, 20, 29,
247
+ 39, 13, 40, 38, 32, 4, 39, 31, 40, 12,
248
+ 21, 16, 4, 17, 33, 18, 22, 23, 24, 25,
249
+ 26, 27, 28, 38, 20, 32, 39, 34, 40, 78,
250
+ 35, 36, 35, 36, 37, 42, 21, 16, 47, 17,
251
+ 55, 18, 22, 23, 24, 25, 26, 27, 28, 56,
252
+ 20, 64, 68, 45, 72, 73, 74, 75, 76, 77,
253
+ 33, 34, 21, 16, 37, 17, 37, 18, 22, 23,
254
+ 24, 25, 26, 27, 28, 79, 20, 80, 81, 13,
255
+ 82, 83, 84, 90, 92, 93, 94, 12, 21, 16,
256
+ nil, 17, nil, 18, 22, 23, 24, 25, 26, 27,
257
+ 28, nil, 20, nil, nil, 13, nil, nil, nil, nil,
258
+ nil, nil, nil, 12, 21, 16, nil, 17, nil, 18,
259
+ 22, 23, 24, 25, 26, 27, 28, nil, 20, nil,
260
+ nil, 13, nil, nil, nil, nil, nil, nil, nil, 12,
261
+ 21, 16, nil, 17, nil, 18, 22, 23, 24, 25,
262
+ 26, 27, 28, nil, 20, nil, nil, 13, nil, nil,
263
+ nil, nil, nil, nil, nil, 12, 21, 16, nil, 17,
264
+ nil, 18, 22, 23, 24, 25, 26, 27, 28, nil,
265
+ 20, nil, nil, 13, nil, nil, nil, nil, nil, nil,
266
+ nil, 12, 21, 16, nil, 17, nil, 18, 22, 23,
267
+ 24, 25, 26, 27, 28, nil, 20, nil, nil, 13,
268
+ nil, nil, nil, nil, nil, nil, nil, 12, 21, 16,
269
+ nil, 17, nil, 18, 22, 23, 24, 25, 26, 27,
270
+ 28, nil, 20, nil, nil, 13, nil, nil, nil, nil,
271
+ nil, nil, nil, 12, 21, 16, nil, 17, nil, 18,
272
+ 22, 23, 24, 25, 26, 27, 28, nil, 20, nil,
273
+ nil, 13, nil, nil, nil, nil, nil, nil, nil, 12,
274
+ 21, 16, nil, 17, nil, 18, 22, 23, 24, 25,
275
+ 26, 27, 28, nil, 20, nil, nil, 13, nil, nil,
276
+ nil, nil, nil, nil, nil, 12, 21, 16, nil, 17,
277
+ nil, 18, 22, 23, 24, 25, 26, 27, 28, nil,
278
+ 20, nil, nil, 13, nil, nil, nil, nil, nil, nil,
279
+ nil, 12, 21, 16, nil, 17, nil, 18, 22, 23,
280
+ 24, 25, 26, 27, 28, nil, 20, nil, nil, 13,
281
+ nil, nil, nil, nil, nil, nil, nil, 12, 21, 16,
282
+ nil, 17, nil, 18, 22, 23, 24, 25, 26, 27,
283
+ 28, nil, 20, nil, nil, nil, nil, nil, nil, nil,
284
+ nil, nil, nil, 42, 21, 16, nil, 17, nil, 18,
285
+ 22, 23, 24, 25, 26, 27, 28, nil, 20, nil,
286
+ nil, 45, nil, nil, nil, nil, nil, nil, nil, nil,
287
+ 21, 16, nil, 17, nil, 18, 22, 23, 24, 25,
288
+ 26, 27, 28, nil, 20, nil, nil, 13, nil, nil,
289
+ nil, nil, nil, nil, nil, 12, 21, 16, nil, 17,
290
+ nil, 18, 22, 23, 24, 25, 26, 27, 28, nil,
291
+ 20, nil, nil, 13, nil, nil, nil, nil, nil, nil,
292
+ nil, 12, 21, 16, nil, 17, nil, 18, 22, 23,
293
+ 24, 25, 26, 27, 28, nil, 20, nil, nil, 13,
294
+ nil, nil, nil, nil, nil, nil, nil, 12, 21, 16,
295
+ nil, 17, nil, 18, 22, 23, 24, 25, 26, 27,
296
+ 28, nil, 20, nil, nil, 13, nil, nil, nil, nil,
297
+ nil, nil, nil, 12, 21, 16, nil, 17, nil, 18,
298
+ 22, 23, 24, 25, 26, 27, 28, nil, 20, nil,
299
+ nil, 13, nil, nil, nil, nil, nil, nil, nil, 12,
300
+ 21, 16, nil, 17, nil, 18, 22, 23, 24, 25,
301
+ 26, 27, 28, nil, 20, nil, nil, 13, nil, nil,
302
+ nil, nil, nil, nil, nil, 12, 21, 16, nil, 17,
303
+ nil, 18, 22, 23, 24, 25, 26, 27, 28, nil,
304
+ 20, nil, nil, 13, nil, nil, nil, nil, nil, nil,
305
+ nil, 12, 21, 16, nil, 17, nil, 18, 22, 23,
306
+ 24, 25, 26, 27, 28, nil, 20, nil, nil, 13,
307
+ nil, nil, nil, nil, nil, nil, nil, 12, 21, 16,
308
+ nil, 17, nil, 18, 22, 23, 24, 25, 26, 27,
309
+ 28, nil, 20, nil, nil, 13, nil, nil, nil, nil,
310
+ nil, nil, nil, 12, 21, 16, nil, 17, nil, 18
311
+ ]
312
+
313
+ racc_action_check = [
314
+ 0, 0, 0, 0, 0, 0, 0, 11, 0, 1,
315
+ 11, 0, 11, 43, 5, 0, 43, 5, 43, 0,
316
+ 0, 0, 2, 0, 6, 0, 12, 12, 12, 12,
317
+ 12, 12, 12, 46, 12, 57, 46, 7, 46, 57,
318
+ 8, 8, 60, 60, 9, 12, 12, 12, 15, 12,
319
+ 21, 12, 13, 13, 13, 13, 13, 13, 13, 29,
320
+ 13, 38, 40, 13, 48, 49, 50, 52, 53, 54,
321
+ 58, 59, 13, 13, 61, 13, 62, 13, 16, 16,
322
+ 16, 16, 16, 16, 16, 64, 16, 65, 66, 16,
323
+ 67, 68, 71, 82, 86, 89, 90, 16, 16, 16,
324
+ nil, 16, nil, 16, 17, 17, 17, 17, 17, 17,
325
+ 17, nil, 17, nil, nil, 17, nil, nil, nil, nil,
326
+ nil, nil, nil, 17, 17, 17, nil, 17, nil, 17,
327
+ 18, 18, 18, 18, 18, 18, 18, nil, 18, nil,
328
+ nil, 18, nil, nil, nil, nil, nil, nil, nil, 18,
329
+ 18, 18, nil, 18, nil, 18, 31, 31, 31, 31,
330
+ 31, 31, 31, nil, 31, nil, nil, 31, nil, nil,
331
+ nil, nil, nil, nil, nil, 31, 31, 31, nil, 31,
332
+ nil, 31, 32, 32, 32, 32, 32, 32, 32, nil,
333
+ 32, nil, nil, 32, nil, nil, nil, nil, nil, nil,
334
+ nil, 32, 32, 32, nil, 32, nil, 32, 33, 33,
335
+ 33, 33, 33, 33, 33, nil, 33, nil, nil, 33,
336
+ nil, nil, nil, nil, nil, nil, nil, 33, 33, 33,
337
+ nil, 33, nil, 33, 34, 34, 34, 34, 34, 34,
338
+ 34, nil, 34, nil, nil, 34, nil, nil, nil, nil,
339
+ nil, nil, nil, 34, 34, 34, nil, 34, nil, 34,
340
+ 35, 35, 35, 35, 35, 35, 35, nil, 35, nil,
341
+ nil, 35, nil, nil, nil, nil, nil, nil, nil, 35,
342
+ 35, 35, nil, 35, nil, 35, 36, 36, 36, 36,
343
+ 36, 36, 36, nil, 36, nil, nil, 36, nil, nil,
344
+ nil, nil, nil, nil, nil, 36, 36, 36, nil, 36,
345
+ nil, 36, 37, 37, 37, 37, 37, 37, 37, nil,
346
+ 37, nil, nil, 37, nil, nil, nil, nil, nil, nil,
347
+ nil, 37, 37, 37, nil, 37, nil, 37, 39, 39,
348
+ 39, 39, 39, 39, 39, nil, 39, nil, nil, 39,
349
+ nil, nil, nil, nil, nil, nil, nil, 39, 39, 39,
350
+ nil, 39, nil, 39, 42, 42, 42, 42, 42, 42,
351
+ 42, nil, 42, nil, nil, nil, nil, nil, nil, nil,
352
+ nil, nil, nil, 42, 42, 42, nil, 42, nil, 42,
353
+ 45, 45, 45, 45, 45, 45, 45, nil, 45, nil,
354
+ nil, 45, nil, nil, nil, nil, nil, nil, nil, nil,
355
+ 45, 45, nil, 45, nil, 45, 47, 47, 47, 47,
356
+ 47, 47, 47, nil, 47, nil, nil, 47, nil, nil,
357
+ nil, nil, nil, nil, nil, 47, 47, 47, nil, 47,
358
+ nil, 47, 74, 74, 74, 74, 74, 74, 74, nil,
359
+ 74, nil, nil, 74, nil, nil, nil, nil, nil, nil,
360
+ nil, 74, 74, 74, nil, 74, nil, 74, 76, 76,
361
+ 76, 76, 76, 76, 76, nil, 76, nil, nil, 76,
362
+ nil, nil, nil, nil, nil, nil, nil, 76, 76, 76,
363
+ nil, 76, nil, 76, 77, 77, 77, 77, 77, 77,
364
+ 77, nil, 77, nil, nil, 77, nil, nil, nil, nil,
365
+ nil, nil, nil, 77, 77, 77, nil, 77, nil, 77,
366
+ 78, 78, 78, 78, 78, 78, 78, nil, 78, nil,
367
+ nil, 78, nil, nil, nil, nil, nil, nil, nil, 78,
368
+ 78, 78, nil, 78, nil, 78, 79, 79, 79, 79,
369
+ 79, 79, 79, nil, 79, nil, nil, 79, nil, nil,
370
+ nil, nil, nil, nil, nil, 79, 79, 79, nil, 79,
371
+ nil, 79, 83, 83, 83, 83, 83, 83, 83, nil,
372
+ 83, nil, nil, 83, nil, nil, nil, nil, nil, nil,
373
+ nil, 83, 83, 83, nil, 83, nil, 83, 92, 92,
374
+ 92, 92, 92, 92, 92, nil, 92, nil, nil, 92,
375
+ nil, nil, nil, nil, nil, nil, nil, 92, 92, 92,
376
+ nil, 92, nil, 92, 94, 94, 94, 94, 94, 94,
377
+ 94, nil, 94, nil, nil, 94, nil, nil, nil, nil,
378
+ nil, nil, nil, 94, 94, 94, nil, 94, nil, 94
379
+ ]
380
+
381
+ racc_action_pointer = [
382
+ -2, 9, 5, nil, nil, -2, 9, 23, 28, 33,
383
+ nil, -15, 24, 50, nil, 25, 76, 102, 128, nil,
384
+ nil, 40, nil, nil, nil, nil, nil, nil, nil, 59,
385
+ nil, 154, 180, 206, 232, 258, 284, 310, 51, 336,
386
+ 52, nil, 362, -9, nil, 388, 11, 414, 40, 39,
387
+ 37, nil, 39, 39, 49, nil, nil, 19, 55, 57,
388
+ 30, 63, 65, nil, 62, 61, 60, 61, 71, nil,
389
+ nil, 68, nil, nil, 440, nil, 466, 492, 518, 544,
390
+ nil, nil, 83, 570, nil, nil, 74, nil, nil, 71,
391
+ 76, nil, 596, nil, 622, nil, nil
392
+ ]
393
+
394
+ racc_action_default = [
395
+ -56, -56, -56, -2, -3, -5, -7, -9, -11, -14,
396
+ -16, -17, -56, -56, -24, -29, -56, -38, -39, -34,
397
+ -35, -56, -49, -50, -51, -52, -53, -54, -55, -56,
398
+ -1, -56, -56, -56, -56, -56, -56, -56, -56, -56,
399
+ -43, -18, -56, -21, -19, -56, -23, -38, -56, -56,
400
+ -37, -42, -56, -40, -56, -36, 97, -56, -6, -8,
401
+ -10, -12, -13, -15, -25, -56, -56, -44, -56, -20,
402
+ -22, -56, -31, -32, -56, -33, -56, -56, -56, -38,
403
+ -27, -28, -56, -56, -30, -41, -56, -48, -4, -56,
404
+ -56, -46, -56, -26, -56, -47, -45
405
+ ]
406
+
407
+ racc_goto_table = [
408
+ 2, 49, 43, 46, 44, 1, 3, 41, 30, 61,
409
+ 62, 57, 58, 59, 60, 63, 48, 66, 54, 52,
410
+ 53, 67, nil, nil, nil, nil, nil, nil, nil, nil,
411
+ nil, 71, 43, nil, nil, 46, 70, 69, nil, 65,
412
+ nil, nil, nil, nil, nil, nil, nil, nil, nil, nil,
413
+ nil, nil, nil, nil, nil, nil, nil, nil, nil, nil,
414
+ nil, nil, nil, 89, nil, nil, nil, nil, nil, nil,
415
+ nil, nil, nil, nil, 85, nil, 86, 87, 88, nil,
416
+ nil, nil, nil, 91, nil, nil, nil, nil, nil, nil,
417
+ nil, nil, 95, nil, 96
418
+ ]
419
+
420
+ racc_goto_check = [
421
+ 2, 14, 10, 10, 12, 1, 3, 11, 3, 8,
422
+ 8, 4, 5, 6, 7, 9, 2, 15, 2, 17,
423
+ 20, 21, nil, nil, nil, nil, nil, nil, nil, nil,
424
+ nil, 14, 10, nil, nil, 10, 12, 11, nil, 2,
425
+ nil, nil, nil, nil, nil, nil, nil, nil, nil, nil,
426
+ nil, nil, nil, nil, nil, nil, nil, nil, nil, nil,
427
+ nil, nil, nil, 14, nil, nil, nil, nil, nil, nil,
428
+ nil, nil, nil, nil, 2, nil, 2, 2, 2, nil,
429
+ nil, nil, nil, 2, nil, nil, nil, nil, nil, nil,
430
+ nil, nil, 2, nil, 2
431
+ ]
432
+
433
+ racc_goto_pointer = [
434
+ nil, 5, 0, 6, -20, -20, -20, -20, -26, -22,
435
+ -10, -5, -9, nil, -16, -23, nil, 1, nil, nil,
436
+ 2, -19
437
+ ]
438
+
439
+ racc_goto_default = [
440
+ nil, nil, 51, nil, 5, 6, 7, 8, 9, 10,
441
+ 11, nil, nil, 14, nil, nil, 15, nil, 19, 50,
442
+ nil, nil
443
+ ]
444
+
445
+ racc_reduce_table = [
446
+ 0, 0, :racc_error,
447
+ 2, 31, :_reduce_none,
448
+ 1, 31, :_reduce_none,
449
+ 1, 33, :_reduce_none,
450
+ 5, 32, :_reduce_4,
451
+ 1, 32, :_reduce_none,
452
+ 3, 34, :_reduce_6,
453
+ 1, 34, :_reduce_none,
454
+ 3, 35, :_reduce_8,
455
+ 1, 35, :_reduce_none,
456
+ 3, 36, :_reduce_10,
457
+ 1, 36, :_reduce_none,
458
+ 3, 37, :_reduce_12,
459
+ 3, 37, :_reduce_13,
460
+ 1, 37, :_reduce_none,
461
+ 3, 38, :_reduce_15,
462
+ 1, 38, :_reduce_none,
463
+ 1, 39, :_reduce_none,
464
+ 2, 39, :_reduce_18,
465
+ 2, 39, :_reduce_19,
466
+ 2, 41, :_reduce_20,
467
+ 1, 41, :_reduce_none,
468
+ 2, 42, :_reduce_22,
469
+ 1, 42, :_reduce_none,
470
+ 1, 40, :_reduce_none,
471
+ 3, 40, :_reduce_25,
472
+ 6, 40, :_reduce_26,
473
+ 4, 40, :_reduce_27,
474
+ 4, 40, :_reduce_28,
475
+ 1, 43, :_reduce_29,
476
+ 4, 43, :_reduce_30,
477
+ 3, 43, :_reduce_31,
478
+ 3, 43, :_reduce_32,
479
+ 3, 43, :_reduce_33,
480
+ 1, 43, :_reduce_none,
481
+ 1, 46, :_reduce_none,
482
+ 2, 46, :_reduce_none,
483
+ 1, 44, :_reduce_none,
484
+ 0, 44, :_reduce_38,
485
+ 0, 47, :_reduce_39,
486
+ 1, 47, :_reduce_none,
487
+ 3, 49, :_reduce_41,
488
+ 1, 49, :_reduce_42,
489
+ 0, 45, :_reduce_43,
490
+ 1, 45, :_reduce_none,
491
+ 5, 51, :_reduce_45,
492
+ 3, 51, :_reduce_46,
493
+ 5, 50, :_reduce_47,
494
+ 3, 50, :_reduce_48,
495
+ 1, 48, :_reduce_49,
496
+ 1, 48, :_reduce_50,
497
+ 1, 48, :_reduce_51,
498
+ 1, 48, :_reduce_52,
499
+ 1, 48, :_reduce_53,
500
+ 1, 48, :_reduce_54,
501
+ 1, 48, :_reduce_55
502
+ ]
503
+
504
+ racc_reduce_n = 56
505
+
506
+ racc_shift_n = 97
507
+
508
+ racc_token_table = {
509
+ false => 0,
510
+ :error => 1,
511
+ :tINT => 2,
512
+ :tUINT => 3,
513
+ :tDOUBLE => 4,
514
+ :tBOOL => 5,
515
+ :tNULL => 6,
516
+ :tSTRING => 7,
517
+ :tBYTES => 8,
518
+ :tRESERVED => 9,
519
+ :tIDENTIFIER => 10,
520
+ :tMULTIOP => 11,
521
+ :tADDOP => 12,
522
+ :tSUBOP => 13,
523
+ :tRELOP => 14,
524
+ :tANDOP => 15,
525
+ :tOROP => 16,
526
+ :tEOF => 17,
527
+ :UMINUS => 18,
528
+ "?" => 19,
529
+ ":" => 20,
530
+ "!" => 21,
531
+ "." => 22,
532
+ "(" => 23,
533
+ ")" => 24,
534
+ "[" => 25,
535
+ "]" => 26,
536
+ "{" => 27,
537
+ "}" => 28,
538
+ "," => 29,
539
+ }
540
+
541
+ racc_nt_base = 30
542
+
543
+ racc_use_result_var = true
544
+
545
+ Racc_arg = [
546
+ racc_action_table,
547
+ racc_action_check,
548
+ racc_action_default,
549
+ racc_action_pointer,
550
+ racc_goto_table,
551
+ racc_goto_check,
552
+ racc_goto_default,
553
+ racc_goto_pointer,
554
+ racc_nt_base,
555
+ racc_reduce_table,
556
+ racc_token_table,
557
+ racc_shift_n,
558
+ racc_reduce_n,
559
+ racc_use_result_var,
560
+ ]
561
+ Ractor.make_shareable(Racc_arg) if defined?(Ractor)
562
+
563
+ Racc_token_to_s_table = [
564
+ "$end",
565
+ "error",
566
+ "tINT",
567
+ "tUINT",
568
+ "tDOUBLE",
569
+ "tBOOL",
570
+ "tNULL",
571
+ "tSTRING",
572
+ "tBYTES",
573
+ "tRESERVED",
574
+ "tIDENTIFIER",
575
+ "tMULTIOP",
576
+ "tADDOP",
577
+ "tSUBOP",
578
+ "tRELOP",
579
+ "tANDOP",
580
+ "tOROP",
581
+ "tEOF",
582
+ "UMINUS",
583
+ "\"?\"",
584
+ "\":\"",
585
+ "\"!\"",
586
+ "\".\"",
587
+ "\"(\"",
588
+ "\")\"",
589
+ "\"[\"",
590
+ "\"]\"",
591
+ "\"{\"",
592
+ "\"}\"",
593
+ "\",\"",
594
+ "$start",
595
+ "target",
596
+ "expr",
597
+ "eof",
598
+ "conditional_or",
599
+ "conditional_and",
600
+ "relation",
601
+ "addition",
602
+ "multiplication",
603
+ "unary",
604
+ "member",
605
+ "negated_member",
606
+ "negative_member",
607
+ "primary",
608
+ "maybe_expr_list",
609
+ "maybe_field_inits",
610
+ "identifier",
611
+ "maybe_map_inits",
612
+ "literal",
613
+ "expr_list",
614
+ "map_inits",
615
+ "field_inits",
616
+ ]
617
+ Ractor.make_shareable(Racc_token_to_s_table) if defined?(Ractor)
618
+
619
+ Racc_debug_parser = false
620
+
621
+ ##### State transition tables end #####
622
+
623
+ # reduce 0 omitted
624
+
625
+ # reduce 1 omitted
626
+
627
+ # reduce 2 omitted
628
+
629
+ # reduce 3 omitted
630
+
631
+ module_eval(<<'.,.,', __FILE__, __LINE__ + 1)
632
+ def _reduce_4(val, _values, result)
633
+ result = Cel::Condition.new(val[0], val[2], val[4])
634
+ result
635
+ end
636
+ .,.,
637
+
638
+ # reduce 5 omitted
639
+
640
+ module_eval(<<'.,.,', __FILE__, __LINE__ + 1)
641
+ def _reduce_6(val, _values, result)
642
+ result = Cel::Operation.new(val[1], [val[0], val[2]])
643
+ result
644
+ end
645
+ .,.,
646
+
647
+ # reduce 7 omitted
648
+
649
+ module_eval(<<'.,.,', __FILE__, __LINE__ + 1)
650
+ def _reduce_8(val, _values, result)
651
+ result = Cel::Operation.new(val[1], [val[0], val[2]])
652
+ result
653
+ end
654
+ .,.,
655
+
656
+ # reduce 9 omitted
657
+
658
+ module_eval(<<'.,.,', __FILE__, __LINE__ + 1)
659
+ def _reduce_10(val, _values, result)
660
+ result = Cel::Operation.new(val[1], [val[0], val[2]])
661
+ result
662
+ end
663
+ .,.,
664
+
665
+ # reduce 11 omitted
666
+
667
+ module_eval(<<'.,.,', __FILE__, __LINE__ + 1)
668
+ def _reduce_12(val, _values, result)
669
+ result = Cel::Operation.new(val[1], [val[0], val[2]])
670
+ result
671
+ end
672
+ .,.,
673
+
674
+ module_eval(<<'.,.,', __FILE__, __LINE__ + 1)
675
+ def _reduce_13(val, _values, result)
676
+ result = Cel::Operation.new(val[1], [val[0], val[2]])
677
+ result
678
+ end
679
+ .,.,
680
+
681
+ # reduce 14 omitted
682
+
683
+ module_eval(<<'.,.,', __FILE__, __LINE__ + 1)
684
+ def _reduce_15(val, _values, result)
685
+ result = Cel::Operation.new(val[1], [val[0], val[2]])
686
+ result
687
+ end
688
+ .,.,
689
+
690
+ # reduce 16 omitted
691
+
692
+ # reduce 17 omitted
693
+
694
+ module_eval(<<'.,.,', __FILE__, __LINE__ + 1)
695
+ def _reduce_18(val, _values, result)
696
+ result = Cel::Operation.new("!", [val[1]])
697
+ result
698
+ end
699
+ .,.,
700
+
701
+ module_eval(<<'.,.,', __FILE__, __LINE__ + 1)
702
+ def _reduce_19(val, _values, result)
703
+ result = Cel::Operation.new("-", [val[1]])
704
+ result
705
+ end
706
+ .,.,
707
+
708
+ module_eval(<<'.,.,', __FILE__, __LINE__ + 1)
709
+ def _reduce_20(val, _values, result)
710
+ result = Cel::Operation.new("!", [val[1]])
711
+ result
712
+ end
713
+ .,.,
714
+
715
+ # reduce 21 omitted
716
+
717
+ module_eval(<<'.,.,', __FILE__, __LINE__ + 1)
718
+ def _reduce_22(val, _values, result)
719
+ result = Cel::Operation.new("-", [val[1]])
720
+ result
721
+ end
722
+ .,.,
723
+
724
+ # reduce 23 omitted
725
+
726
+ # reduce 24 omitted
727
+
728
+ module_eval(<<'.,.,', __FILE__, __LINE__ + 1)
729
+ def _reduce_25(val, _values, result)
730
+ result = Cel::Invoke.new(var: val[0], func: val[2])
731
+ result
732
+ end
733
+ .,.,
734
+
735
+ module_eval(<<'.,.,', __FILE__, __LINE__ + 1)
736
+ def _reduce_26(val, _values, result)
737
+ result = Cel::Invoke.new(var: val[0], func: val[2], args: [val[4]].flatten(1))
738
+ result
739
+ end
740
+ .,.,
741
+
742
+ module_eval(<<'.,.,', __FILE__, __LINE__ + 1)
743
+ def _reduce_27(val, _values, result)
744
+ result = Cel::Invoke.new(var: val[0], func: "[]", args: val[2])
745
+ result
746
+ end
747
+ .,.,
748
+
749
+ module_eval(<<'.,.,', __FILE__, __LINE__ + 1)
750
+ def _reduce_28(val, _values, result)
751
+ result = Cel::Message.new(val[0], val[2])
752
+ result
753
+ end
754
+ .,.,
755
+
756
+ module_eval(<<'.,.,', __FILE__, __LINE__ + 1)
757
+ def _reduce_29(val, _values, result)
758
+ result = Cel::Identifier.new(val[0])
759
+ result
760
+ end
761
+ .,.,
762
+
763
+ module_eval(<<'.,.,', __FILE__, __LINE__ + 1)
764
+ def _reduce_30(val, _values, result)
765
+ result = Cel::Invoke.new(func: val[0], args: [val[2]].flatten(1))
766
+ result
767
+ end
768
+ .,.,
769
+
770
+ module_eval(<<'.,.,', __FILE__, __LINE__ + 1)
771
+ def _reduce_31(val, _values, result)
772
+ result = Cel::Group.new(val[1])
773
+ result
774
+ end
775
+ .,.,
776
+
777
+ module_eval(<<'.,.,', __FILE__, __LINE__ + 1)
778
+ def _reduce_32(val, _values, result)
779
+ result = Cel::List.new(Array(val[1]))
780
+ result
781
+ end
782
+ .,.,
783
+
784
+ module_eval(<<'.,.,', __FILE__, __LINE__ + 1)
785
+ def _reduce_33(val, _values, result)
786
+ result = Cel::Map.new(Hash[val[1]])
787
+ result
788
+ end
789
+ .,.,
790
+
791
+ # reduce 34 omitted
792
+
793
+ # reduce 35 omitted
794
+
795
+ # reduce 36 omitted
796
+
797
+ # reduce 37 omitted
798
+
799
+ module_eval(<<'.,.,', __FILE__, __LINE__ + 1)
800
+ def _reduce_38(val, _values, result)
801
+ result = []
802
+ result
803
+ end
804
+ .,.,
805
+
806
+ module_eval(<<'.,.,', __FILE__, __LINE__ + 1)
807
+ def _reduce_39(val, _values, result)
808
+ result = nil
809
+ result
810
+ end
811
+ .,.,
812
+
813
+ # reduce 40 omitted
814
+
815
+ module_eval(<<'.,.,', __FILE__, __LINE__ + 1)
816
+ def _reduce_41(val, _values, result)
817
+ result = Array(val[0]) << val[2]
818
+ result
819
+ end
820
+ .,.,
821
+
822
+ module_eval(<<'.,.,', __FILE__, __LINE__ + 1)
823
+ def _reduce_42(val, _values, result)
824
+ [val[0]]
825
+ result
826
+ end
827
+ .,.,
828
+
829
+ module_eval(<<'.,.,', __FILE__, __LINE__ + 1)
830
+ def _reduce_43(val, _values, result)
831
+ result = nil
832
+ result
833
+ end
834
+ .,.,
835
+
836
+ # reduce 44 omitted
837
+
838
+ module_eval(<<'.,.,', __FILE__, __LINE__ + 1)
839
+ def _reduce_45(val, _values, result)
840
+ result = val[0].merge(Cel::Identifier.new(val[2]) => val[4])
841
+ result
842
+ end
843
+ .,.,
844
+
845
+ module_eval(<<'.,.,', __FILE__, __LINE__ + 1)
846
+ def _reduce_46(val, _values, result)
847
+ result = { Cel::Identifier.new(val[0]) => val[2] }
848
+ result
849
+ end
850
+ .,.,
851
+
852
+ module_eval(<<'.,.,', __FILE__, __LINE__ + 1)
853
+ def _reduce_47(val, _values, result)
854
+ val[0][val[2]] = val[4]; result = val[0]
855
+ result
856
+ end
857
+ .,.,
858
+
859
+ module_eval(<<'.,.,', __FILE__, __LINE__ + 1)
860
+ def _reduce_48(val, _values, result)
861
+ result = { val[0] => val[2] }
862
+ result
863
+ end
864
+ .,.,
865
+
866
+ module_eval(<<'.,.,', __FILE__, __LINE__ + 1)
867
+ def _reduce_49(val, _values, result)
868
+ result = Cel::Number.new(:int, val[0])
869
+ result
870
+ end
871
+ .,.,
872
+
873
+ module_eval(<<'.,.,', __FILE__, __LINE__ + 1)
874
+ def _reduce_50(val, _values, result)
875
+ result = Cel::Number.new(:uint, val[0])
876
+ result
877
+ end
878
+ .,.,
879
+
880
+ module_eval(<<'.,.,', __FILE__, __LINE__ + 1)
881
+ def _reduce_51(val, _values, result)
882
+ result = Cel::Number.new(:double, val[0])
883
+ result
884
+ end
885
+ .,.,
886
+
887
+ module_eval(<<'.,.,', __FILE__, __LINE__ + 1)
888
+ def _reduce_52(val, _values, result)
889
+ result = Cel::Bool.new(val[0])
890
+ result
891
+ end
892
+ .,.,
893
+
894
+ module_eval(<<'.,.,', __FILE__, __LINE__ + 1)
895
+ def _reduce_53(val, _values, result)
896
+ result = Cel::Null.new()
897
+ result
898
+ end
899
+ .,.,
900
+
901
+ module_eval(<<'.,.,', __FILE__, __LINE__ + 1)
902
+ def _reduce_54(val, _values, result)
903
+ result = Cel::String.new(val[0])
904
+ result
905
+ end
906
+ .,.,
907
+
908
+ module_eval(<<'.,.,', __FILE__, __LINE__ + 1)
909
+ def _reduce_55(val, _values, result)
910
+ result = Cel::Bytes.new(val[0])
911
+ result
912
+ end
913
+ .,.,
914
+
915
+ def _reduce_none(val, _values, _result)
916
+ val[0]
917
+ end
918
+ end # class Parser
919
+ end # module Cel
920
+
921
+ # if $0 == __FILE__
922
+ # examples = <<EOS
923
+ # 123
924
+ # 12345
925
+ # 1.2
926
+ # 1e2
927
+ # -1.2e2
928
+ # 12u
929
+ # 0xa123
930
+ # ""
931
+ # '""'
932
+ # '''x''x'''
933
+ # "\""
934
+ # "\\"
935
+ # r"\\"
936
+ # b"abc"
937
+ # b"ÿ"
938
+ # b"\303\277"
939
+ # "\303\277"
940
+ # "\377"
941
+ # b"\377"
942
+ # "\xFF"
943
+ # b"\xFF"
944
+
945
+ # 1 + 2
946
+ # 3 - 2
947
+ # " Some String with \"escapes\""
948
+ # 'another string'
949
+ # a.b.c == 1
950
+ # d > 2
951
+ # a.b.c * 3 == 1 && d > 2
952
+ # a.b.c
953
+ # wiri
954
+ # // a.driving_license = "CA"
955
+ # // 1 = 2
956
+ # // 2 = "a"
957
+ # // a.b.c > "a"
958
+ # EOS
959
+ # puts 'Parsing...'
960
+ # parser = Cel::Parser.new
961
+ # examples.each_line do |line|
962
+ # puts "line: #{line.inspect}"
963
+ # puts parser.parse(line)
964
+ # end
965
+ # end
966
+
967
+ # The grammar of CEL is defined below, using | for alternatives, [] for optional, {} for repeated, and () for grouping.
968
+ # Expr = ConditionalOr ["?" ConditionalOr ":" Expr] ;
969
+ # ConditionalOr = [ConditionalOr "||"] ConditionalAnd ;
970
+ # ConditionalAnd = [ConditionalAnd "&&"] Relation ;
971
+ # Relation = [Relation Relop] Addition ;
972
+ # Relop = "<" | "<=" | ">=" | ">" | "==" | "!=" | "in" ;
973
+ # Addition = [Addition ("+" | "-")] Multiplication ;
974
+ # Multiplication = [Multiplication ("*" | "/" | "%")] Unary ;
975
+ # Unary = Member
976
+ # | "!" {"!"} Member
977
+ # | "-" {"-"} Member
978
+ # ;
979
+ # Member = Primary
980
+ # | Member "." IDENT ["(" [ExprList] ")"]
981
+ # | Member "[" Expr "]"
982
+ # | Member "{" [FieldInits] "}"
983
+ # ;
984
+ # Primary = ["."] IDENT ["(" [ExprList] ")"]
985
+ # | "(" Expr ")"
986
+ # | "[" [ExprList] "]"
987
+ # | "{" [MapInits] "}"
988
+ # | LITERAL
989
+ # ;
990
+ # ExprList = Expr {"," Expr} ;
991
+ # FieldInits = IDENT ":" Expr {"," IDENT ":" Expr} ;
992
+ # MapInits = Expr ":" Expr {"," Expr ":" Expr} ;
993
+
994
+ # IDENT ::= [_a-zA-Z][_a-zA-Z0-9]* - RESERVED
995
+ # LITERAL ::= INT_LIT | UINT_LIT | FLOAT_LIT | STRING_LIT | BYTES_LIT
996
+ # | BOOL_LIT | NULL_LIT
997
+ # INT_LIT ::= -? DIGIT+ | -? 0x HEXDIGIT+
998
+ # UINT_LIT ::= INT_LIT [uU]
999
+ # FLOAT_LIT ::= -? DIGIT* . DIGIT+ EXPONENT? | -? DIGIT+ EXPONENT
1000
+ # DIGIT ::= [0-9]
1001
+ # HEXDIGIT ::= [0-9abcdefABCDEF]
1002
+ # EXPONENT ::= [eE] [+-]? DIGIT+
1003
+ # STRING_LIT ::= [rR]? ( " ~( " | NEWLINE )* "
1004
+ # | ' ~( ' | NEWLINE )* '
1005
+ # | """ ~"""* """
1006
+ # | ''' ~'''* '''
1007
+ # )
1008
+ # BYTES_LIT ::= [bB] STRING_LIT
1009
+ # ESCAPE ::= \ [bfnrt"'\]
1010
+ # | \ x HEXDIGIT HEXDIGIT
1011
+ # | \ u HEXDIGIT HEXDIGIT HEXDIGIT HEXDIGIT
1012
+ # | \ U HEXDIGIT HEXDIGIT HEXDIGIT HEXDIGIT HEXDIGIT HEXDIGIT HEXDIGIT HEXDIGIT
1013
+ # | \ [0-3] [0-7] [0-7]
1014
+ # NEWLINE ::= \r\n | \r | \n
1015
+ # BOOL_LIT ::= "true" | "false"
1016
+ # NULL_LIT ::= "null"
1017
+ # RESERVED ::= BOOL_LIT | NULL_LIT | "in"
1018
+ # | "as" | "break" | "const" | "continue" | "else"
1019
+ # | "for" | "function" | "if" | "import" | "let"
1020
+ # | "loop" | "package" | "namespace" | "return"
1021
+ # | "var" | "void" | "while"
1022
+ # WHITESPACE ::= [\t\n\f\r ]+
1023
+ # COMMENT ::= '//' ~NEWLINE* NEWLINE
data/lib/cel/program.rb CHANGED
@@ -57,20 +57,22 @@ module Cel
57
57
  ev_operand
58
58
  end
59
59
 
60
- if values.size == 1 &&
60
+ if operation.unary? &&
61
61
  op != "!" # https://bugs.ruby-lang.org/issues/18246
62
62
  # unary operations
63
- values.first.__send__(:"#{op}@")
63
+ Literal.to_cel_type(values.first.__send__(:"#{op}@"))
64
64
  elsif op == "&&"
65
- Bool.new(values.all? { |x| true == x }) # rubocop:disable Style/YodaCondition
65
+ Bool.new(values.all? { |x| true == x.value }) # rubocop:disable Style/YodaCondition
66
66
  elsif op == "||"
67
- Bool.new(values.any? { |x| true == x }) # rubocop:disable Style/YodaCondition
67
+ Bool.new(values.any? { |x| true == x.value }) # rubocop:disable Style/YodaCondition
68
68
  elsif op == "in"
69
69
  element, collection = values
70
70
  Bool.new(collection.include?(element))
71
71
  else
72
72
  op_value, *values = values
73
- op_value.public_send(op, *values)
73
+ val = op_value.public_send(op, *values)
74
+
75
+ Literal.to_cel_type(val)
74
76
  end
75
77
  end
76
78
 
@@ -120,7 +122,7 @@ module Cel
120
122
  end
121
123
 
122
124
  def evaluate_condition(condition)
123
- call(condition.if) ? call(condition.then) : call(condition.else)
125
+ call(condition.if).value ? call(condition.then) : call(condition.else)
124
126
  end
125
127
 
126
128
  def evaluate_standard_func(funcall)
@@ -135,11 +137,11 @@ module Cel
135
137
  val.class
136
138
  # MACROS
137
139
  when :has
138
- Bool.new(Macro.__send__(func, *args))
140
+ Macro.__send__(func, *args)
139
141
  when :size
140
142
  Cel::Number.new(:int, Macro.__send__(func, *args))
141
143
  when :matches
142
- Bool.new(Macro.__send__(func, *args.map(&method(:call))))
144
+ Macro.__send__(func, *args.map(&method(:call)))
143
145
  when :int, :uint, :string, :double, :bytes, :duration, :timestamp
144
146
  type = TYPES[func]
145
147
  type.cast(call(args.first))
data/lib/cel/version.rb CHANGED
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Cel
4
4
  module Ruby
5
- VERSION = "0.2.1"
5
+ VERSION = "0.2.3"
6
6
  end
7
7
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cel
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.1
4
+ version: 0.2.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tiago Cardoso
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-07-26 00:00:00.000000000 Z
11
+ date: 2023-09-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: minitest
@@ -62,6 +62,7 @@ files:
62
62
  - lib/cel/errors.rb
63
63
  - lib/cel/macro.rb
64
64
  - lib/cel/parser.rb
65
+ - lib/cel/parser.tab.rb
65
66
  - lib/cel/program.rb
66
67
  - lib/cel/version.rb
67
68
  homepage: