Class: Fluent::FilterWhere::Parser
- Inherits:
-
Racc::Parser
- Object
- Racc::Parser
- Fluent::FilterWhere::Parser
- Defined in:
- lib/fluent/plugin/filter_where/parser.rex.rb,
lib/fluent/plugin/filter_where/parser.tab.rb,
lib/fluent/plugin/filter_where/parser/exp.rb,
lib/fluent/plugin/filter_where/parser/literal.rb
Defined Under Namespace
Classes: BinaryOpExp, BooleanLiteral, BooleanOpExp, Exp, IdentifierLiteral, Literal, LogicalOpExp, NegateOpExp, NullOpExp, NumberLiteral, NumberOpExp, RegexpOpExp, ScanError, StringLiteral, StringOpExp
Constant Summary collapse
- 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", "OR", "AND", "NOT", "EQ", "NEQ", "GT", "GE", "LT", "LE", "START_WITH", "END_WITH", "INCLUDE", "REGEXP", "IS", "NULL", "BOOLEAN", "STRING", "NUMBER", "IDENTIFIER", "\"(\"", "\")\"", "$start", "input", "exp" ]
- Racc_debug_parser =
false
Instance Attribute Summary collapse
-
#filename ⇒ Object
readonly
Returns the value of attribute filename.
-
#lineno ⇒ Object
readonly
Returns the value of attribute lineno.
-
#state ⇒ Object
Returns the value of attribute state.
Instance Method Summary collapse
- #_next_token ⇒ Object
- #_reduce_none(val, _values) ⇒ Object
- #action ⇒ Object
- #load_file(filename) ⇒ Object
- #next_token ⇒ Object
-
#on_error(error_token_id, error_value, value_stack) ⇒ Object
def _next_token.
- #scan_file(filename) ⇒ Object
- #scan_setup(str) ⇒ Object
- #scan_str(str) ⇒ Object (also: #scan)
Instance Attribute Details
#filename ⇒ Object (readonly)
Returns the value of attribute filename.
14 15 16 |
# File 'lib/fluent/plugin/filter_where/parser.rex.rb', line 14 def filename @filename end |
#lineno ⇒ Object (readonly)
Returns the value of attribute lineno.
13 14 15 |
# File 'lib/fluent/plugin/filter_where/parser.rex.rb', line 13 def lineno @lineno end |
#state ⇒ Object
Returns the value of attribute state.
15 16 17 |
# File 'lib/fluent/plugin/filter_where/parser.rex.rb', line 15 def state @state end |
Instance Method Details
#_next_token ⇒ Object
54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 |
# File 'lib/fluent/plugin/filter_where/parser.rex.rb', line 54 def _next_token text = @ss.peek(1) @lineno += 1 if text == "\n" token = case @state when nil case when (text = @ss.scan(/\(/i)) action { [:"(", text] } when (text = @ss.scan(/\)/i)) action { [:")", text] } when (text = @ss.scan(/\=/i)) action { [:EQ, text] } when (text = @ss.scan(/\<\>/i)) action { [:NEQ, text] } when (text = @ss.scan(/\!\=/i)) action { [:NEQ, text] } when (text = @ss.scan(/\>\=/i)) action { [:GE, text] } when (text = @ss.scan(/\>/i)) action { [:GT, text] } when (text = @ss.scan(/\<\=/i)) action { [:LE, text] } when (text = @ss.scan(/\</i)) action { [:LT, text] } when (text = @ss.scan(/-?[0-9]+(\.[0-9]+)?/i)) action { [:NUMBER, NumberLiteral.new(text)] } when (text = @ss.scan(/[a-zA-Z$][a-zA-z0-9\.\-_]*/i)) action { case text.downcase when 'and'.freeze [:AND, text] when 'or'.freeze [:OR, text] when 'start_with'.freeze [:START_WITH, text] when 'end_with'.freeze [:END_WITH, text] when 'include'.freeze [:INCLUDE, text] when 'regexp'.freeze [:REGEXP, text] when 'is'.freeze [:IS, text] when 'not'.freeze [:NOT, text] when 'null'.freeze [:NULL, text] when 'true'.freeze [:BOOLEAN, BooleanLiteral.new(text)] when 'false'.freeze [:BOOLEAN, BooleanLiteral.new(text)] else [:IDENTIFIER, IdentifierLiteral.new(text)] end } when (text = @ss.scan(/\"/i)) action { @state = :IDENTIFIER; @string = ''; nil } when (text = @ss.scan(/\'/i)) action { @state = :STRING; @string = ''; nil } when (text = @ss.scan(/[ \t]+/i)) action { } when (text = @ss.scan(/\n|\r|\r\n/i)) action { } else text = @ss.string[@ss.pos .. -1] raise ScanError, "can not match: '" + text + "'" end # if when :IDENTIFIER case when (text = @ss.scan(/\"/i)) action { @state = nil; [:IDENTIFIER, IdentifierLiteral.new(@string)] } when (text = @ss.scan(/[^\r\n\"\\]+/i)) action { @string << text; nil } when (text = @ss.scan(/\\\"/i)) action { @string << '"'; nil } when (text = @ss.scan(/\\\'/i)) action { @string << "'"; nil } when (text = @ss.scan(/\\\\/i)) action { @string << "\\"; nil } else text = @ss.string[@ss.pos .. -1] raise ScanError, "can not match: '" + text + "'" end # if when :STRING case when (text = @ss.scan(/\'/i)) action { @state = nil; [:STRING, StringLiteral.new(@string)] } when (text = @ss.scan(/[^\r\n\'\\]+/i)) action { @string << text; nil } when (text = @ss.scan(/\b/i)) action { @string << "\b"; nil } when (text = @ss.scan(/\t/i)) action { @string << "\t"; nil } when (text = @ss.scan(/\n/i)) action { @string << "\n"; nil } when (text = @ss.scan(/\f/i)) action { @string << "\f"; nil } when (text = @ss.scan(/\r/i)) action { @string << "\r"; nil } when (text = @ss.scan(/\"/i)) action { @string << '"'; nil } when (text = @ss.scan(/\'/i)) action { @string << "'"; nil } when (text = @ss.scan(/\\/i)) action { @string << "\\"; nil } else text = @ss.string[@ss.pos .. -1] raise ScanError, "can not match: '" + text + "'" end # if else raise ScanError, "undefined state: '" + state.to_s + "'" end # case state token end |
#_reduce_none(val, _values) ⇒ Object
411 412 413 |
# File 'lib/fluent/plugin/filter_where/parser.tab.rb', line 411 def _reduce_none(val, _values) val[0] end |
#action ⇒ Object
23 24 25 |
# File 'lib/fluent/plugin/filter_where/parser.rex.rb', line 23 def action yield end |
#load_file(filename) ⇒ Object
33 34 35 36 37 38 |
# File 'lib/fluent/plugin/filter_where/parser.rex.rb', line 33 def load_file( filename ) @filename = filename open(filename, "r") do |f| scan_setup(f.read) end end |
#next_token ⇒ Object
46 47 48 49 50 51 52 |
# File 'lib/fluent/plugin/filter_where/parser.rex.rb', line 46 def next_token return if @ss.eos? # skips empty actions until token = _next_token or @ss.eos?; end token end |
#on_error(error_token_id, error_value, value_stack) ⇒ Object
def _next_token
203 204 205 |
# File 'lib/fluent/plugin/filter_where/parser.rex.rb', line 203 def on_error(error_token_id, error_value, value_stack) super end |
#scan_file(filename) ⇒ Object
40 41 42 43 |
# File 'lib/fluent/plugin/filter_where/parser.rex.rb', line 40 def scan_file( filename ) load_file(filename) do_parse end |
#scan_setup(str) ⇒ Object
17 18 19 20 21 |
# File 'lib/fluent/plugin/filter_where/parser.rex.rb', line 17 def scan_setup(str) @ss = StringScanner.new(str) @lineno = 1 @state = nil end |
#scan_str(str) ⇒ Object Also known as: scan
27 28 29 30 |
# File 'lib/fluent/plugin/filter_where/parser.rex.rb', line 27 def scan_str(str) scan_setup(str) do_parse end |