Module: NginxConfigParser::Scanner
- Defined in:
- lib/nginx_config_parser/scanner.rb
Defined Under Namespace
Classes: ConfigurationError
Class Method Summary collapse
Class Method Details
.parse(data) ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 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 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 |
# File 'lib/nginx_config_parser/scanner.rb', line 14 def parse(data) # Stuff for Ragel data = data.unpack("c*") if data.is_a?(String) eof, stack = 0, [] # The list of words to fill for identifiers and values words = [] # The stack of contexts, used to accumulate data at # the appropriate level contexts = [Configuration.new] # line 25 "src/scanner.rb" class << self attr_accessor :_nginx_actions private :_nginx_actions, :_nginx_actions= end self._nginx_actions = [ 0, 1, 0, 1, 1, 1, 2, 1, 3, 1, 4, 1, 5, 1, 6, 1, 7, 1, 8, 1, 9, 1, 10, 1, 11, 1, 12, 1, 13, 1, 14, 1, 15 ] class << self attr_accessor :_nginx_key_offsets private :_nginx_key_offsets, :_nginx_key_offsets= end self._nginx_key_offsets = [ 0, 1, 5, 6, 11, 12, 13, 18, 21, 22, 23, 30, 35, 39, 42, 48 ] class << self attr_accessor :_nginx_trans_keys private :_nginx_trans_keys, :_nginx_trans_keys= end self._nginx_trans_keys = [ 10, 32, 40, 9, 13, 41, 32, 41, 123, 9, 13, 125, 10, 32, 35, 105, 9, 13, 32, 9, 13, 10, 102, 32, 35, 59, 123, 125, 9, 13, 32, 59, 123, 9, 13, 32, 125, 9, 13, 32, 9, 13, 10, 32, 59, 123, 9, 13, 32, 59, 123, 9, 13, 0 ] class << self attr_accessor :_nginx_single_lengths private :_nginx_single_lengths, :_nginx_single_lengths= end self._nginx_single_lengths = [ 1, 2, 1, 3, 1, 1, 3, 1, 1, 1, 5, 3, 2, 1, 4, 3 ] class << self attr_accessor :_nginx_range_lengths private :_nginx_range_lengths, :_nginx_range_lengths= end self._nginx_range_lengths = [ 0, 1, 0, 1, 0, 0, 1, 1, 0, 0, 1, 1, 1, 1, 1, 1 ] class << self attr_accessor :_nginx_index_offsets private :_nginx_index_offsets, :_nginx_index_offsets= end self._nginx_index_offsets = [ 0, 2, 6, 8, 13, 15, 17, 22, 25, 27, 29, 36, 41, 45, 48, 54 ] class << self attr_accessor :_nginx_indicies private :_nginx_indicies, :_nginx_indicies= end self._nginx_indicies = [ 2, 1, 3, 4, 3, 0, 5, 4, 5, 5, 6, 5, 4, 7, 6, 10, 9, 12, 13, 14, 12, 11, 12, 12, 15, 2, 1, 3, 16, 18, 19, 20, 21, 22, 18, 17, 23, 23, 23, 23, 17, 18, 25, 18, 24, 25, 25, 26, 10, 9, 9, 9, 9, 19, 25, 23, 23, 25, 17, 0 ] class << self attr_accessor :_nginx_trans_targs_wi private :_nginx_trans_targs_wi, :_nginx_trans_targs_wi= end self._nginx_trans_targs_wi = [ 6, 0, 6, 1, 2, 3, 4, 6, 10, 5, 10, 6, 7, 8, 9, 6, 6, 11, 12, 14, 10, 10, 15, 10, 10, 13, 10 ] class << self attr_accessor :_nginx_trans_actions_wi private :_nginx_trans_actions_wi, :_nginx_trans_actions_wi= end self._nginx_trans_actions_wi = [ 31, 0, 25, 0, 0, 0, 0, 21, 19, 0, 11, 23, 0, 5, 5, 29, 27, 0, 0, 5, 7, 9, 0, 13, 17, 0, 15 ] class << self attr_accessor :_nginx_to_state_actions private :_nginx_to_state_actions, :_nginx_to_state_actions= end self._nginx_to_state_actions = [ 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 0, 0 ] class << self attr_accessor :_nginx_from_state_actions private :_nginx_from_state_actions, :_nginx_from_state_actions= end self._nginx_from_state_actions = [ 0, 0, 0, 0, 0, 0, 3, 0, 0, 0, 3, 0, 0, 0, 0, 0 ] class << self attr_accessor :_nginx_eof_trans private :_nginx_eof_trans, :_nginx_eof_trans= end self._nginx_eof_trans = [ 1, 1, 1, 1, 1, 9, 0, 16, 17, 17, 0, 24, 25, 27, 24, 24 ] class << self attr_accessor :nginx_start end self.nginx_start = 6; class << self attr_accessor :nginx_first_final end self.nginx_first_final = 6; class << self attr_accessor :nginx_error end self.nginx_error = -1; class << self attr_accessor :nginx_en_statement end self.nginx_en_statement = 10; class << self attr_accessor :nginx_en_main end self.nginx_en_main = 6; # line 68 "src/scanner.rl" # line 176 "src/scanner.rb" begin p ||= 0 pe ||= data.length cs = nginx_start top = 0 ts = nil te = nil act = 0 end # line 69 "src/scanner.rl" # line 188 "src/scanner.rb" begin _klen, _trans, _keys, _acts, _nacts = nil _goto_level = 0 _resume = 10 _eof_trans = 15 _again = 20 _test_eof = 30 _out = 40 while true _trigger_goto = false if _goto_level <= 0 if p == pe _goto_level = _test_eof next end end if _goto_level <= _resume _acts = _nginx_from_state_actions[cs] _nacts = _nginx_actions[_acts] _acts += 1 while _nacts > 0 _nacts -= 1 _acts += 1 case _nginx_actions[_acts - 1] when 1 then # line 1 "src/scanner.rl" begin ts = p end # line 1 "src/scanner.rl" # line 219 "src/scanner.rb" end # from state action switch end if _trigger_goto next end _keys = _nginx_key_offsets[cs] _trans = _nginx_index_offsets[cs] _klen = _nginx_single_lengths[cs] _break_match = false begin if _klen > 0 _lower = _keys _upper = _keys + _klen - 1 loop do break if _upper < _lower _mid = _lower + ( (_upper - _lower) >> 1 ) if data[p] < _nginx_trans_keys[_mid] _upper = _mid - 1 elsif data[p] > _nginx_trans_keys[_mid] _lower = _mid + 1 else _trans += (_mid - _keys) _break_match = true break end end # loop break if _break_match _keys += _klen _trans += _klen end _klen = _nginx_range_lengths[cs] if _klen > 0 _lower = _keys _upper = _keys + (_klen << 1) - 2 loop do break if _upper < _lower _mid = _lower + (((_upper-_lower) >> 1) & ~1) if data[p] < _nginx_trans_keys[_mid] _upper = _mid - 2 elsif data[p] > _nginx_trans_keys[_mid+1] _lower = _mid + 2 else _trans += ((_mid - _keys) >> 1) _break_match = true break end end # loop break if _break_match _trans += _klen end end while false _trans = _nginx_indicies[_trans] end if _goto_level <= _eof_trans cs = _nginx_trans_targs_wi[_trans] if _nginx_trans_actions_wi[_trans] != 0 _acts = _nginx_trans_actions_wi[_trans] _nacts = _nginx_actions[_acts] _acts += 1 while _nacts > 0 _nacts -= 1 _acts += 1 case _nginx_actions[_acts - 1] when 2 then # line 1 "src/scanner.rl" begin te = p+1 end # line 1 "src/scanner.rl" when 3 then # line 20 "src/scanner.rl" begin te = p+1 begin name = words.shift values = words.dup contexts.last[name] = value_of(values) words.clear begin top -= 1 cs = stack[top] _trigger_goto = true _goto_level = _again break end end end # line 20 "src/scanner.rl" when 4 then # line 31 "src/scanner.rl" begin te = p+1 begin name = words.shift values = words.dup contexts << contexts.last.section(name, value_of(values)) words.clear begin stack[top] = cs top+= 1 cs = 10 _trigger_goto = true _goto_level = _again break end end end # line 31 "src/scanner.rl" when 5 then # line 43 "src/scanner.rl" begin te = p+1 end # line 43 "src/scanner.rl" when 6 then # line 28 "src/scanner.rl" begin te = p p = p - 1; begin words << data[ts...te].pack('c*') end end # line 28 "src/scanner.rl" when 7 then # line 39 "src/scanner.rl" begin te = p p = p - 1; begin contexts.pop begin top -= 1 cs = stack[top] _trigger_goto = true _goto_level = _again break end end end # line 39 "src/scanner.rl" when 8 then # line 43 "src/scanner.rl" begin te = p p = p - 1; end # line 43 "src/scanner.rl" when 9 then # line 28 "src/scanner.rl" begin begin p = ((te))-1; end begin words << data[ts...te].pack('c*') end end # line 28 "src/scanner.rl" when 10 then # line 48 "src/scanner.rl" begin te = p+1 end # line 48 "src/scanner.rl" when 11 then # line 50 "src/scanner.rl" begin te = p+1 begin words.clear; p = p - 1; begin stack[top] = cs top+= 1 cs = 10 _trigger_goto = true _goto_level = _again break end end end # line 50 "src/scanner.rl" when 12 then # line 52 "src/scanner.rl" begin te = p+1 end # line 52 "src/scanner.rl" when 13 then # line 50 "src/scanner.rl" begin te = p p = p - 1; begin words.clear; p = p - 1; begin stack[top] = cs top+= 1 cs = 10 _trigger_goto = true _goto_level = _again break end end end # line 50 "src/scanner.rl" when 14 then # line 52 "src/scanner.rl" begin te = p p = p - 1; end # line 52 "src/scanner.rl" when 15 then # line 50 "src/scanner.rl" begin begin p = ((te))-1; end begin words.clear; p = p - 1; begin stack[top] = cs top+= 1 cs = 10 _trigger_goto = true _goto_level = _again break end end end # line 50 "src/scanner.rl" # line 439 "src/scanner.rb" end # action switch end end if _trigger_goto next end end if _goto_level <= _again _acts = _nginx_to_state_actions[cs] _nacts = _nginx_actions[_acts] _acts += 1 while _nacts > 0 _nacts -= 1 _acts += 1 case _nginx_actions[_acts - 1] when 0 then # line 1 "src/scanner.rl" begin ts = nil; end # line 1 "src/scanner.rl" # line 460 "src/scanner.rb" end # to state action switch end if _trigger_goto next end p += 1 if p != pe _goto_level = _resume next end end if _goto_level <= _test_eof if p == eof if _nginx_eof_trans[cs] > 0 _trans = _nginx_eof_trans[cs] - 1; _goto_level = _eof_trans next; end end end if _goto_level <= _out break end end end # line 70 "src/scanner.rl" # This is a little more forgiving than # using <tt>pop</tt> and validating balance contexts.first end |