# # DO NOT MODIFY!!!! # This file is automatically generated by Racc 1.6.0 # from Racc grammar file "". # require 'racc/parser.rb' require 'strscan' require 'bigdecimal' require 'cel/ast/elements' module Cel class Parser < Racc::Parser module_eval(<<'...end parser.ry/module_eval...', 'parser.ry', 97) OPERATORS = if RUBY_VERSION < "2.7.0" { "&&" => :tANDOP, "||" => :tOROP, "+" => :tADDOP, "-" => :tSUBOP, }.merge(Hash[Cel::LOGICAL_OPERATORS.map{|op| [op, :tRELOP] }]) .merge(Hash[Cel::MULTI_OPERATORS.map{|op| [op, :tMULTIOP] }]) else { **Hash[Cel::LOGICAL_OPERATORS.map{|op| [op, :tRELOP] }], **Hash[Cel::MULTI_OPERATORS.map{|op| [op, :tMULTIOP] }], "&&" => :tANDOP, "||" => :tOROP, "+" => :tADDOP, "-" => :tSUBOP, } end.freeze OPERATORS_RE = Regexp.union(*OPERATORS.keys) RESERVED = %W[ as break const continue else for function if import let loop package namespace return var void while ].freeze IDENTIFIER_REGEX = /[a-zA-Z][_a-zA-Z0-9]*/ STRING_LIT_REGEX = Regexp.union( /"""(?~""")*"""/, /'''(?~''')*'''/, /"(\\"|[^"])*"/, /'(\\'|[^'])*'/, ) NUMBER_REGEX = Regexp.union( /(0x[0-9a-fA-F]+)[uU]?/, # hexadecimal /(\d+)[uU]/, # uinteger /((\d*\.\d+)|\d+)([eE][+\-]?\d+)?/, # integer, float, exponent ) def parse(str) tokenize(str) do_parse rescue Racc::ParseError => err raise parse_error(err) end def parse_error(error) parse_error = case error.message when /parse error on value "([^"]+)" \(tRESERVED\)/ Cel::ParseError.new("invalid usage of the reserved word \"#{$1}\"") else Cel::ParseError.new(error.message) end parse_error.set_backtrace(error.backtrace) parse_error end def tokenize(str) str.force_encoding(Encoding::BINARY) unless str.valid_encoding? scanner = StringScanner.new(str) @q = [] until scanner.eos? case when scanner.scan(/\s+/) # skip whitespace when scanner.scan(/#(( *)|( ?(?.*)))\n/) # skip comment lines when scanner.scan(NUMBER_REGEX) @q << convert_to_number(scanner) when scanner.scan(/[bB]?[rR]?#{STRING_LIT_REGEX}/) # string # s = scanner.matched.yield_self {|s| s[1, s.length - 2] } # .gsub(DBL_QUOTE_STR_ESCAPE_SEQUENCES_RE) do |match| # case match # when '\\a' then "\a" # when '\\b' then "\b" # when '\\e' then "\e" # when '\\f' then "\f" # when '\\n' then "\n" # when '\\r' then "\r" # when '\\s' then "\s" # when '\\t' then "\t" # when '\\v' then "\v" # when '\\"' then '"' # end # end # s = scanner.matched.yield_self {|s| s[1, s.length - 2] }.gsub(/\\'/, "'") str = scanner.matched @q << if str.start_with?("b") [:tBYTES, convert_to_bytes(str.byteslice(2..-2))] else [:tSTRING, convert_to_string(str)] end when scanner.scan(IDENTIFIER_REGEX) word = scanner.matched if word == "null" @q << [:tNULL, nil] elsif word == "true" @q << [:tBOOL, true] elsif word == "false" @q << [:tBOOL, false] elsif RESERVED.include?(word) @q << [:tRESERVED, scanner.matched] elsif word == "in" @q << [OPERATORS[scanner.matched], scanner.matched] else @q << [:tIDENTIFIER, scanner.matched] end when scanner.scan(OPERATORS_RE) @q << [OPERATORS[scanner.matched], scanner.matched] when scanner.scan(/\A.|\n/o) s = scanner.matched @q << [s, s] else raise ParseError, "unexpected value: #{scanner.string}" end end @q << [:tEOF, false] end def next_token @q.shift end def convert_to_number(scanner) matched = scanner.matched hexa, uint, number, floating, exp = scanner.captures if hexa && !hexa.empty? return [:tINT, hexa.to_i(16)] end if uint && !uint.empty? return [:tUINT, Integer(uint)] end if exp && !exp.empty? # third matched group, can only be a floating exponential, let's convert tout suite [:tDOUBLE, BigDecimal(matched)] elsif floating && !floating.empty? if number == floating || floating.start_with?(".") [:tDOUBLE, Float(matched)] elsif number.nil? || number.empty? [:tDOUBLE, BigDecimal(matched)] end else if matched[-1].downcase == "u" [:tINT, Integer(matched[0..-2]).abs] else [:tINT, Integer(matched)] end end end TRIPE_DOUBLE_QUOTES = %Q{"""} TRIPE_SINGLE_QUOTES = %Q{'''} def convert_to_string(str) if str.start_with?("r") # If preceded by an r or R character, the string is a raw string # and does not interpret escape sequences. str = str.byteslice(2..-2).inspect.byteslice(1..-2) return str end if str.size > 6 && ( (str.start_with?(TRIPE_DOUBLE_QUOTES) && str.end_with?(TRIPE_DOUBLE_QUOTES)) || (str.start_with?(TRIPE_SINGLE_QUOTES) && str.end_with?(TRIPE_SINGLE_QUOTES))) str = str.byteslice(3..-4) else str = str.byteslice(1..-2) end cleanup_escape_sequences(str) end def convert_to_bytes(str) str.unpack("C*") end BIN_ESCAPE = /\\([0-3][0-7][0-7])/ HEX_ESCAPE = /\\x([0-9a-fA-F]{2})/ BPM_ESCAPE = /\\u([0-9a-fA-F]{4})/ UNICODE_ESCAPE = /\\u([0-9a-fA-F]{4})/ WHITESPACE_ESCAPE = /\\([bfnrt"'\\])/ ESCAPE_UNION = Regexp.union(BIN_ESCAPE, HEX_ESCAPE, BPM_ESCAPE, WHITESPACE_ESCAPE) # For the sake of a readable representation, the escape sequences (ESCAPE) are kept # implicit in string tokens. This means that strings without the r or R (raw) prefix # process ESCAPE sequences, while in strings with the raw prefix they stay uninterpreted. # See documentation of string literals below. def cleanup_escape_sequences(str) str.gsub!(ESCAPE_UNION) do |match| case match when /\\"/ "\"" when BIN_ESCAPE # For strings, it denotes the unicode code point. Regexp.last_match(1).to_i.chr(Encoding::UTF_8) when HEX_ESCAPE # For strings, it denotes the unicode code point. Regexp.last_match(1).hex.chr(Encoding::UTF_8) when BPM_ESCAPE Regexp.last_match(1).hex.chr(Encoding::BPM) when UNICODE_ESCAPE # encoding a Unicode code point. Valid only for string literals. Regexp.last_match(1).hex.chr(Encoding::UTF_8) when WHITESPACE_ESCAPE Regexp.last_match(0) end end str end ...end parser.ry/module_eval... ##### State transition tables begin ### racc_action_table = [ 22, 23, 24, 25, 26, 27, 28, 38, 20, 29, 39, 13, 40, 38, 32, 4, 39, 31, 40, 12, 21, 16, 4, 17, 33, 18, 22, 23, 24, 25, 26, 27, 28, 38, 20, 32, 39, 34, 40, 78, 35, 36, 35, 36, 37, 42, 21, 16, 47, 17, 55, 18, 22, 23, 24, 25, 26, 27, 28, 56, 20, 64, 68, 45, 72, 73, 74, 75, 76, 77, 33, 34, 21, 16, 37, 17, 37, 18, 22, 23, 24, 25, 26, 27, 28, 79, 20, 80, 81, 13, 82, 83, 84, 90, 92, 93, 94, 12, 21, 16, nil, 17, nil, 18, 22, 23, 24, 25, 26, 27, 28, nil, 20, nil, nil, 13, nil, nil, nil, nil, nil, nil, nil, 12, 21, 16, nil, 17, nil, 18, 22, 23, 24, 25, 26, 27, 28, nil, 20, nil, nil, 13, nil, nil, nil, nil, nil, nil, nil, 12, 21, 16, nil, 17, nil, 18, 22, 23, 24, 25, 26, 27, 28, nil, 20, nil, nil, 13, nil, nil, nil, nil, nil, nil, nil, 12, 21, 16, nil, 17, nil, 18, 22, 23, 24, 25, 26, 27, 28, nil, 20, nil, nil, 13, nil, nil, nil, nil, nil, nil, nil, 12, 21, 16, nil, 17, nil, 18, 22, 23, 24, 25, 26, 27, 28, nil, 20, nil, nil, 13, nil, nil, nil, nil, nil, nil, nil, 12, 21, 16, nil, 17, nil, 18, 22, 23, 24, 25, 26, 27, 28, nil, 20, nil, nil, 13, nil, nil, nil, nil, nil, nil, nil, 12, 21, 16, nil, 17, nil, 18, 22, 23, 24, 25, 26, 27, 28, nil, 20, nil, nil, 13, nil, nil, nil, nil, nil, nil, nil, 12, 21, 16, nil, 17, nil, 18, 22, 23, 24, 25, 26, 27, 28, nil, 20, nil, nil, 13, nil, nil, nil, nil, nil, nil, nil, 12, 21, 16, nil, 17, nil, 18, 22, 23, 24, 25, 26, 27, 28, nil, 20, nil, nil, 13, nil, nil, nil, nil, nil, nil, nil, 12, 21, 16, nil, 17, nil, 18, 22, 23, 24, 25, 26, 27, 28, nil, 20, nil, nil, 13, nil, nil, nil, nil, nil, nil, nil, 12, 21, 16, nil, 17, nil, 18, 22, 23, 24, 25, 26, 27, 28, nil, 20, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, 42, 21, 16, nil, 17, nil, 18, 22, 23, 24, 25, 26, 27, 28, nil, 20, nil, nil, 45, nil, nil, nil, nil, nil, nil, nil, nil, 21, 16, nil, 17, nil, 18, 22, 23, 24, 25, 26, 27, 28, nil, 20, nil, nil, 13, nil, nil, nil, nil, nil, nil, nil, 12, 21, 16, nil, 17, nil, 18, 22, 23, 24, 25, 26, 27, 28, nil, 20, nil, nil, 13, nil, nil, nil, nil, nil, nil, nil, 12, 21, 16, nil, 17, nil, 18, 22, 23, 24, 25, 26, 27, 28, nil, 20, nil, nil, 13, nil, nil, nil, nil, nil, nil, nil, 12, 21, 16, nil, 17, nil, 18, 22, 23, 24, 25, 26, 27, 28, nil, 20, nil, nil, 13, nil, nil, nil, nil, nil, nil, nil, 12, 21, 16, nil, 17, nil, 18, 22, 23, 24, 25, 26, 27, 28, nil, 20, nil, nil, 13, nil, nil, nil, nil, nil, nil, nil, 12, 21, 16, nil, 17, nil, 18, 22, 23, 24, 25, 26, 27, 28, nil, 20, nil, nil, 13, nil, nil, nil, nil, nil, nil, nil, 12, 21, 16, nil, 17, nil, 18, 22, 23, 24, 25, 26, 27, 28, nil, 20, nil, nil, 13, nil, nil, nil, nil, nil, nil, nil, 12, 21, 16, nil, 17, nil, 18, 22, 23, 24, 25, 26, 27, 28, nil, 20, nil, nil, 13, nil, nil, nil, nil, nil, nil, nil, 12, 21, 16, nil, 17, nil, 18, 22, 23, 24, 25, 26, 27, 28, nil, 20, nil, nil, 13, nil, nil, nil, nil, nil, nil, nil, 12, 21, 16, nil, 17, nil, 18 ] racc_action_check = [ 0, 0, 0, 0, 0, 0, 0, 11, 0, 1, 11, 0, 11, 43, 5, 0, 43, 5, 43, 0, 0, 0, 2, 0, 6, 0, 12, 12, 12, 12, 12, 12, 12, 46, 12, 57, 46, 7, 46, 57, 8, 8, 60, 60, 9, 12, 12, 12, 15, 12, 21, 12, 13, 13, 13, 13, 13, 13, 13, 29, 13, 38, 40, 13, 48, 49, 50, 52, 53, 54, 58, 59, 13, 13, 61, 13, 62, 13, 16, 16, 16, 16, 16, 16, 16, 64, 16, 65, 66, 16, 67, 68, 71, 82, 86, 89, 90, 16, 16, 16, nil, 16, nil, 16, 17, 17, 17, 17, 17, 17, 17, nil, 17, nil, nil, 17, nil, nil, nil, nil, nil, nil, nil, 17, 17, 17, nil, 17, nil, 17, 18, 18, 18, 18, 18, 18, 18, nil, 18, nil, nil, 18, nil, nil, nil, nil, nil, nil, nil, 18, 18, 18, nil, 18, nil, 18, 31, 31, 31, 31, 31, 31, 31, nil, 31, nil, nil, 31, nil, nil, nil, nil, nil, nil, nil, 31, 31, 31, nil, 31, nil, 31, 32, 32, 32, 32, 32, 32, 32, nil, 32, nil, nil, 32, nil, nil, nil, nil, nil, nil, nil, 32, 32, 32, nil, 32, nil, 32, 33, 33, 33, 33, 33, 33, 33, nil, 33, nil, nil, 33, nil, nil, nil, nil, nil, nil, nil, 33, 33, 33, nil, 33, nil, 33, 34, 34, 34, 34, 34, 34, 34, nil, 34, nil, nil, 34, nil, nil, nil, nil, nil, nil, nil, 34, 34, 34, nil, 34, nil, 34, 35, 35, 35, 35, 35, 35, 35, nil, 35, nil, nil, 35, nil, nil, nil, nil, nil, nil, nil, 35, 35, 35, nil, 35, nil, 35, 36, 36, 36, 36, 36, 36, 36, nil, 36, nil, nil, 36, nil, nil, nil, nil, nil, nil, nil, 36, 36, 36, nil, 36, nil, 36, 37, 37, 37, 37, 37, 37, 37, nil, 37, nil, nil, 37, nil, nil, nil, nil, nil, nil, nil, 37, 37, 37, nil, 37, nil, 37, 39, 39, 39, 39, 39, 39, 39, nil, 39, nil, nil, 39, nil, nil, nil, nil, nil, nil, nil, 39, 39, 39, nil, 39, nil, 39, 42, 42, 42, 42, 42, 42, 42, nil, 42, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, 42, 42, 42, nil, 42, nil, 42, 45, 45, 45, 45, 45, 45, 45, nil, 45, nil, nil, 45, nil, nil, nil, nil, nil, nil, nil, nil, 45, 45, nil, 45, nil, 45, 47, 47, 47, 47, 47, 47, 47, nil, 47, nil, nil, 47, nil, nil, nil, nil, nil, nil, nil, 47, 47, 47, nil, 47, nil, 47, 74, 74, 74, 74, 74, 74, 74, nil, 74, nil, nil, 74, nil, nil, nil, nil, nil, nil, nil, 74, 74, 74, nil, 74, nil, 74, 76, 76, 76, 76, 76, 76, 76, nil, 76, nil, nil, 76, nil, nil, nil, nil, nil, nil, nil, 76, 76, 76, nil, 76, nil, 76, 77, 77, 77, 77, 77, 77, 77, nil, 77, nil, nil, 77, nil, nil, nil, nil, nil, nil, nil, 77, 77, 77, nil, 77, nil, 77, 78, 78, 78, 78, 78, 78, 78, nil, 78, nil, nil, 78, nil, nil, nil, nil, nil, nil, nil, 78, 78, 78, nil, 78, nil, 78, 79, 79, 79, 79, 79, 79, 79, nil, 79, nil, nil, 79, nil, nil, nil, nil, nil, nil, nil, 79, 79, 79, nil, 79, nil, 79, 83, 83, 83, 83, 83, 83, 83, nil, 83, nil, nil, 83, nil, nil, nil, nil, nil, nil, nil, 83, 83, 83, nil, 83, nil, 83, 92, 92, 92, 92, 92, 92, 92, nil, 92, nil, nil, 92, nil, nil, nil, nil, nil, nil, nil, 92, 92, 92, nil, 92, nil, 92, 94, 94, 94, 94, 94, 94, 94, nil, 94, nil, nil, 94, nil, nil, nil, nil, nil, nil, nil, 94, 94, 94, nil, 94, nil, 94 ] racc_action_pointer = [ -2, 9, 5, nil, nil, -2, 9, 23, 28, 33, nil, -15, 24, 50, nil, 25, 76, 102, 128, nil, nil, 40, nil, nil, nil, nil, nil, nil, nil, 59, nil, 154, 180, 206, 232, 258, 284, 310, 51, 336, 52, nil, 362, -9, nil, 388, 11, 414, 40, 39, 37, nil, 39, 39, 49, nil, nil, 19, 55, 57, 30, 63, 65, nil, 62, 61, 60, 61, 71, nil, nil, 68, nil, nil, 440, nil, 466, 492, 518, 544, nil, nil, 83, 570, nil, nil, 74, nil, nil, 71, 76, nil, 596, nil, 622, nil, nil ] racc_action_default = [ -56, -56, -56, -2, -3, -5, -7, -9, -11, -14, -16, -17, -56, -56, -24, -29, -56, -38, -39, -34, -35, -56, -49, -50, -51, -52, -53, -54, -55, -56, -1, -56, -56, -56, -56, -56, -56, -56, -56, -56, -43, -18, -56, -21, -19, -56, -23, -38, -56, -56, -37, -42, -56, -40, -56, -36, 97, -56, -6, -8, -10, -12, -13, -15, -25, -56, -56, -44, -56, -20, -22, -56, -31, -32, -56, -33, -56, -56, -56, -38, -27, -28, -56, -56, -30, -41, -56, -48, -4, -56, -56, -46, -56, -26, -56, -47, -45 ] racc_goto_table = [ 2, 49, 43, 46, 44, 1, 3, 41, 30, 61, 62, 57, 58, 59, 60, 63, 48, 66, 54, 52, 53, 67, nil, nil, nil, nil, nil, nil, nil, nil, nil, 71, 43, nil, nil, 46, 70, 69, nil, 65, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, 89, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, 85, nil, 86, 87, 88, nil, nil, nil, nil, 91, nil, nil, nil, nil, nil, nil, nil, nil, 95, nil, 96 ] racc_goto_check = [ 2, 14, 10, 10, 12, 1, 3, 11, 3, 8, 8, 4, 5, 6, 7, 9, 2, 15, 2, 17, 20, 21, nil, nil, nil, nil, nil, nil, nil, nil, nil, 14, 10, nil, nil, 10, 12, 11, nil, 2, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, 14, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, 2, nil, 2, 2, 2, nil, nil, nil, nil, 2, nil, nil, nil, nil, nil, nil, nil, nil, 2, nil, 2 ] racc_goto_pointer = [ nil, 5, 0, 6, -20, -20, -20, -20, -26, -22, -10, -5, -9, nil, -16, -23, nil, 1, nil, nil, 2, -19 ] racc_goto_default = [ nil, nil, 51, nil, 5, 6, 7, 8, 9, 10, 11, nil, nil, 14, nil, nil, 15, nil, 19, 50, nil, nil ] racc_reduce_table = [ 0, 0, :racc_error, 2, 31, :_reduce_none, 1, 31, :_reduce_none, 1, 33, :_reduce_none, 5, 32, :_reduce_4, 1, 32, :_reduce_none, 3, 34, :_reduce_6, 1, 34, :_reduce_none, 3, 35, :_reduce_8, 1, 35, :_reduce_none, 3, 36, :_reduce_10, 1, 36, :_reduce_none, 3, 37, :_reduce_12, 3, 37, :_reduce_13, 1, 37, :_reduce_none, 3, 38, :_reduce_15, 1, 38, :_reduce_none, 1, 39, :_reduce_none, 2, 39, :_reduce_18, 2, 39, :_reduce_19, 2, 41, :_reduce_20, 1, 41, :_reduce_none, 2, 42, :_reduce_22, 1, 42, :_reduce_none, 1, 40, :_reduce_none, 3, 40, :_reduce_25, 6, 40, :_reduce_26, 4, 40, :_reduce_27, 4, 40, :_reduce_28, 1, 43, :_reduce_29, 4, 43, :_reduce_30, 3, 43, :_reduce_31, 3, 43, :_reduce_32, 3, 43, :_reduce_33, 1, 43, :_reduce_none, 1, 46, :_reduce_none, 2, 46, :_reduce_none, 1, 44, :_reduce_none, 0, 44, :_reduce_38, 0, 47, :_reduce_39, 1, 47, :_reduce_none, 3, 49, :_reduce_41, 1, 49, :_reduce_42, 0, 45, :_reduce_43, 1, 45, :_reduce_none, 5, 51, :_reduce_45, 3, 51, :_reduce_46, 5, 50, :_reduce_47, 3, 50, :_reduce_48, 1, 48, :_reduce_49, 1, 48, :_reduce_50, 1, 48, :_reduce_51, 1, 48, :_reduce_52, 1, 48, :_reduce_53, 1, 48, :_reduce_54, 1, 48, :_reduce_55 ] racc_reduce_n = 56 racc_shift_n = 97 racc_token_table = { false => 0, :error => 1, :tINT => 2, :tUINT => 3, :tDOUBLE => 4, :tBOOL => 5, :tNULL => 6, :tSTRING => 7, :tBYTES => 8, :tRESERVED => 9, :tIDENTIFIER => 10, :tMULTIOP => 11, :tADDOP => 12, :tSUBOP => 13, :tRELOP => 14, :tANDOP => 15, :tOROP => 16, :tEOF => 17, :UMINUS => 18, "?" => 19, ":" => 20, "!" => 21, "." => 22, "(" => 23, ")" => 24, "[" => 25, "]" => 26, "{" => 27, "}" => 28, "," => 29 } racc_nt_base = 30 racc_use_result_var = true Racc_arg = [ racc_action_table, racc_action_check, racc_action_default, racc_action_pointer, racc_goto_table, racc_goto_check, racc_goto_default, racc_goto_pointer, racc_nt_base, racc_reduce_table, racc_token_table, racc_shift_n, racc_reduce_n, racc_use_result_var ] Racc_token_to_s_table = [ "$end", "error", "tINT", "tUINT", "tDOUBLE", "tBOOL", "tNULL", "tSTRING", "tBYTES", "tRESERVED", "tIDENTIFIER", "tMULTIOP", "tADDOP", "tSUBOP", "tRELOP", "tANDOP", "tOROP", "tEOF", "UMINUS", "\"?\"", "\":\"", "\"!\"", "\".\"", "\"(\"", "\")\"", "\"[\"", "\"]\"", "\"{\"", "\"}\"", "\",\"", "$start", "target", "expr", "eof", "conditional_or", "conditional_and", "relation", "addition", "multiplication", "unary", "member", "negated_member", "negative_member", "primary", "maybe_expr_list", "maybe_field_inits", "identifier", "maybe_map_inits", "literal", "expr_list", "map_inits", "field_inits" ] Racc_debug_parser = false ##### State transition tables end ##### # reduce 0 omitted # reduce 1 omitted # reduce 2 omitted # reduce 3 omitted module_eval(<<'.,.,', 'parser.ry', 17) def _reduce_4(val, _values, result) result = Cel::Condition.new(val[0], val[2], val[4]) result end .,., # reduce 5 omitted module_eval(<<'.,.,', 'parser.ry', 20) def _reduce_6(val, _values, result) result = Cel::Operation.new(val[1], [val[0], val[2]]) result end .,., # reduce 7 omitted module_eval(<<'.,.,', 'parser.ry', 23) def _reduce_8(val, _values, result) result = Cel::Operation.new(val[1], [val[0], val[2]]) result end .,., # reduce 9 omitted module_eval(<<'.,.,', 'parser.ry', 26) def _reduce_10(val, _values, result) result = Cel::Operation.new(val[1], [val[0], val[2]]) result end .,., # reduce 11 omitted module_eval(<<'.,.,', 'parser.ry', 29) def _reduce_12(val, _values, result) result = Cel::Operation.new(val[1], [val[0], val[2]]) result end .,., module_eval(<<'.,.,', 'parser.ry', 30) def _reduce_13(val, _values, result) result = Cel::Operation.new(val[1], [val[0], val[2]]) result end .,., # reduce 14 omitted module_eval(<<'.,.,', 'parser.ry', 33) def _reduce_15(val, _values, result) result = Cel::Operation.new(val[1], [val[0], val[2]]) result end .,., # reduce 16 omitted # reduce 17 omitted module_eval(<<'.,.,', 'parser.ry', 38) def _reduce_18(val, _values, result) result = Cel::Operation.new("!", [val[1]]) result end .,., module_eval(<<'.,.,', 'parser.ry', 39) def _reduce_19(val, _values, result) result = Cel::Operation.new("-", [val[1]]) result end .,., module_eval(<<'.,.,', 'parser.ry', 41) def _reduce_20(val, _values, result) result = Cel::Operation.new("!", [val[1]]) result end .,., # reduce 21 omitted module_eval(<<'.,.,', 'parser.ry', 44) def _reduce_22(val, _values, result) result = Cel::Operation.new("-", [val[1]]) result end .,., # reduce 23 omitted # reduce 24 omitted module_eval(<<'.,.,', 'parser.ry', 48) def _reduce_25(val, _values, result) result = Cel::Invoke.new(var: val[0], func: val[2]) result end .,., module_eval(<<'.,.,', 'parser.ry', 49) def _reduce_26(val, _values, result) result = Cel::Invoke.new(var: val[0], func: val[2], args: [val[4]].flatten(1)) result end .,., module_eval(<<'.,.,', 'parser.ry', 50) def _reduce_27(val, _values, result) result = Cel::Invoke.new(var: val[0], func: "[]", args: val[2]) result end .,., module_eval(<<'.,.,', 'parser.ry', 51) def _reduce_28(val, _values, result) result = Cel::Message.new(val[0], val[2]) result end .,., module_eval(<<'.,.,', 'parser.ry', 54) def _reduce_29(val, _values, result) result = Cel::Identifier.new(val[0]) result end .,., module_eval(<<'.,.,', 'parser.ry', 55) def _reduce_30(val, _values, result) result = Cel::Invoke.new(func: val[0], args: [val[2]].flatten(1)) result end .,., module_eval(<<'.,.,', 'parser.ry', 56) def _reduce_31(val, _values, result) result = Cel::Group.new(val[1]) result end .,., module_eval(<<'.,.,', 'parser.ry', 57) def _reduce_32(val, _values, result) result = Cel::List.new(Array(val[1])) result end .,., module_eval(<<'.,.,', 'parser.ry', 58) def _reduce_33(val, _values, result) result = Cel::Map.new(Hash[val[1]]) result end .,., # reduce 34 omitted # reduce 35 omitted # reduce 36 omitted # reduce 37 omitted module_eval(<<'.,.,', 'parser.ry', 65) def _reduce_38(val, _values, result) result = [] result end .,., module_eval(<<'.,.,', 'parser.ry', 67) def _reduce_39(val, _values, result) result = nil result end .,., # reduce 40 omitted module_eval(<<'.,.,', 'parser.ry', 70) def _reduce_41(val, _values, result) result = Array(val[0]) << val[2] result end .,., module_eval(<<'.,.,', 'parser.ry', 71) def _reduce_42(val, _values, result) [val[0]] result end .,., module_eval(<<'.,.,', 'parser.ry', 73) def _reduce_43(val, _values, result) result = nil result end .,., # reduce 44 omitted module_eval(<<'.,.,', 'parser.ry', 76) def _reduce_45(val, _values, result) result = val[0].merge(Cel::Identifier.new(val[2]) => val[4]) result end .,., module_eval(<<'.,.,', 'parser.ry', 77) def _reduce_46(val, _values, result) result = { Cel::Identifier.new(val[0]) => val[2] } result end .,., module_eval(<<'.,.,', 'parser.ry', 79) def _reduce_47(val, _values, result) val[0][val[2]] = val[4]; result = val[0] result end .,., module_eval(<<'.,.,', 'parser.ry', 80) def _reduce_48(val, _values, result) result = { val[0] => val[2] } result end .,., module_eval(<<'.,.,', 'parser.ry', 82) def _reduce_49(val, _values, result) result = Cel::Number.new(:int, val[0]) result end .,., module_eval(<<'.,.,', 'parser.ry', 83) def _reduce_50(val, _values, result) result = Cel::Number.new(:uint, val[0]) result end .,., module_eval(<<'.,.,', 'parser.ry', 84) def _reduce_51(val, _values, result) result = Cel::Number.new(:double, val[0]) result end .,., module_eval(<<'.,.,', 'parser.ry', 85) def _reduce_52(val, _values, result) result = Cel::Bool.new(val[0]) result end .,., module_eval(<<'.,.,', 'parser.ry', 86) def _reduce_53(val, _values, result) result = Cel::Null.new() result end .,., module_eval(<<'.,.,', 'parser.ry', 87) def _reduce_54(val, _values, result) result = Cel::String.new(val[0]) result end .,., module_eval(<<'.,.,', 'parser.ry', 88) def _reduce_55(val, _values, result) result = Cel::Bytes.new(val[0]) result end .,., def _reduce_none(val, _values, result) val[0] end end # class Parser end # module Cel # if $0 == __FILE__ # examples = < 2 # a.b.c * 3 == 1 && d > 2 # a.b.c # wiri # // a.driving_license = "CA" # // 1 = 2 # // 2 = "a" # // a.b.c > "a" # EOS # puts 'Parsing...' # parser = Cel::Parser.new # examples.each_line do |line| # puts "line: #{line.inspect}" # puts parser.parse(line) # end # end # The grammar of CEL is defined below, using | for alternatives, [] for optional, {} for repeated, and () for grouping. # Expr = ConditionalOr ["?" ConditionalOr ":" Expr] ; # ConditionalOr = [ConditionalOr "||"] ConditionalAnd ; # ConditionalAnd = [ConditionalAnd "&&"] Relation ; # Relation = [Relation Relop] Addition ; # Relop = "<" | "<=" | ">=" | ">" | "==" | "!=" | "in" ; # Addition = [Addition ("+" | "-")] Multiplication ; # Multiplication = [Multiplication ("*" | "/" | "%")] Unary ; # Unary = Member # | "!" {"!"} Member # | "-" {"-"} Member # ; # Member = Primary # | Member "." IDENT ["(" [ExprList] ")"] # | Member "[" Expr "]" # | Member "{" [FieldInits] "}" # ; # Primary = ["."] IDENT ["(" [ExprList] ")"] # | "(" Expr ")" # | "[" [ExprList] "]" # | "{" [MapInits] "}" # | LITERAL # ; # ExprList = Expr {"," Expr} ; # FieldInits = IDENT ":" Expr {"," IDENT ":" Expr} ; # MapInits = Expr ":" Expr {"," Expr ":" Expr} ; # IDENT ::= [_a-zA-Z][_a-zA-Z0-9]* - RESERVED # LITERAL ::= INT_LIT | UINT_LIT | FLOAT_LIT | STRING_LIT | BYTES_LIT # | BOOL_LIT | NULL_LIT # INT_LIT ::= -? DIGIT+ | -? 0x HEXDIGIT+ # UINT_LIT ::= INT_LIT [uU] # FLOAT_LIT ::= -? DIGIT* . DIGIT+ EXPONENT? | -? DIGIT+ EXPONENT # DIGIT ::= [0-9] # HEXDIGIT ::= [0-9abcdefABCDEF] # EXPONENT ::= [eE] [+-]? DIGIT+ # STRING_LIT ::= [rR]? ( " ~( " | NEWLINE )* " # | ' ~( ' | NEWLINE )* ' # | """ ~"""* """ # | ''' ~'''* ''' # ) # BYTES_LIT ::= [bB] STRING_LIT # ESCAPE ::= \ [bfnrt"'\] # | \ x HEXDIGIT HEXDIGIT # | \ u HEXDIGIT HEXDIGIT HEXDIGIT HEXDIGIT # | \ U HEXDIGIT HEXDIGIT HEXDIGIT HEXDIGIT HEXDIGIT HEXDIGIT HEXDIGIT HEXDIGIT # | \ [0-3] [0-7] [0-7] # NEWLINE ::= \r\n | \r | \n # BOOL_LIT ::= "true" | "false" # NULL_LIT ::= "null" # RESERVED ::= BOOL_LIT | NULL_LIT | "in" # | "as" | "break" | "const" | "continue" | "else" # | "for" | "function" | "if" | "import" | "let" # | "loop" | "package" | "namespace" | "return" # | "var" | "void" | "while" # WHITESPACE ::= [\t\n\f\r ]+ # COMMENT ::= '//' ~NEWLINE* NEWLINE