| 1 | |
| 2 | #line 1 "control_verbs.rl" |
| 3 | /* |
| 4 | * Copyright (c) 2017, Intel Corporation |
| 5 | * |
| 6 | * Redistribution and use in source and binary forms, with or without |
| 7 | * modification, are permitted provided that the following conditions are met: |
| 8 | * |
| 9 | * * Redistributions of source code must retain the above copyright notice, |
| 10 | * this list of conditions and the following disclaimer. |
| 11 | * * Redistributions in binary form must reproduce the above copyright |
| 12 | * notice, this list of conditions and the following disclaimer in the |
| 13 | * documentation and/or other materials provided with the distribution. |
| 14 | * * Neither the name of Intel Corporation nor the names of its contributors |
| 15 | * may be used to endorse or promote products derived from this software |
| 16 | * without specific prior written permission. |
| 17 | * |
| 18 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
| 19 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
| 20 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
| 21 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE |
| 22 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
| 23 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
| 24 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
| 25 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
| 26 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
| 27 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
| 28 | * POSSIBILITY OF SUCH DAMAGE. |
| 29 | */ |
| 30 | |
| 31 | /** |
| 32 | * \file |
| 33 | * \brief Parser for control verbs that can occur at the beginning of a pattern. |
| 34 | */ |
| 35 | |
| 36 | #include "parser/control_verbs.h" |
| 37 | |
| 38 | #include "parser/Parser.h" |
| 39 | #include "parser/parse_error.h" |
| 40 | |
| 41 | #include <cstring> |
| 42 | #include <sstream> |
| 43 | |
| 44 | using namespace std; |
| 45 | |
| 46 | namespace ue2 { |
| 47 | |
| 48 | const char *read_control_verbs(const char *ptr, const char *end, size_t start, |
| 49 | ParseMode &mode) { |
| 50 | const char *p = ptr; |
| 51 | const char *pe = end; |
| 52 | const char *eof = pe; |
| 53 | const char *ts, *te; |
| 54 | int cs; |
| 55 | UNUSED int act; |
| 56 | |
| 57 | |
| 58 | #line 59 "control_verbs.cpp" |
| 59 | static const char _ControlVerbs_actions[] = { |
| 60 | 0, 1, 0, 1, 1, 1, 2, 1, |
| 61 | 3, 1, 4, 1, 5, 1, 6, 1, |
| 62 | 7, 1, 8, 1, 9 |
| 63 | }; |
| 64 | |
| 65 | static const unsigned char _ControlVerbs_key_offsets[] = { |
| 66 | 0, 7, 8, 10, 12, 14, 16, 18, |
| 67 | 20, 21, 23, 25, 27, 30, 32, 34, |
| 68 | 36, 38, 40, 42, 44, 46, 48, 50, |
| 69 | 52, 55, 57, 59, 61, 63, 66, 68, |
| 70 | 70, 72, 74, 76, 79, 82, 84, 86, |
| 71 | 88, 90, 92, 94, 96, 98, 100, 102, |
| 72 | 105, 107, 109, 111, 113, 115, 117, 119, |
| 73 | 121, 123, 125, 127, 129, 131, 133, 135, |
| 74 | 137, 139, 141, 143, 146, 148, 149, 151, |
| 75 | 155, 157, 159, 160, 161 |
| 76 | }; |
| 77 | |
| 78 | static const char _ControlVerbs_trans_keys[] = { |
| 79 | 41, 65, 66, 67, 76, 78, 85, 41, |
| 80 | 41, 78, 41, 89, 41, 67, 41, 82, |
| 81 | 41, 76, 41, 70, 41, 41, 83, 41, |
| 82 | 82, 41, 95, 41, 65, 85, 41, 78, |
| 83 | 41, 89, 41, 67, 41, 78, 41, 73, |
| 84 | 41, 67, 41, 79, 41, 68, 41, 69, |
| 85 | 41, 82, 41, 76, 41, 70, 73, 41, |
| 86 | 77, 41, 73, 41, 84, 41, 95, 41, |
| 87 | 77, 82, 41, 65, 41, 84, 41, 67, |
| 88 | 41, 72, 41, 61, 41, 48, 57, 41, |
| 89 | 48, 57, 41, 69, 41, 67, 41, 85, |
| 90 | 41, 82, 41, 83, 41, 73, 41, 79, |
| 91 | 41, 78, 41, 79, 41, 95, 41, 65, |
| 92 | 83, 41, 85, 41, 84, 41, 79, 41, |
| 93 | 95, 41, 80, 41, 79, 41, 83, 41, |
| 94 | 83, 41, 69, 41, 83, 41, 83, 41, |
| 95 | 84, 41, 65, 41, 82, 41, 84, 41, |
| 96 | 95, 41, 79, 41, 80, 41, 84, 41, |
| 97 | 67, 84, 41, 80, 41, 41, 70, 41, |
| 98 | 49, 51, 56, 41, 54, 41, 50, 41, |
| 99 | 40, 42, 0 |
| 100 | }; |
| 101 | |
| 102 | static const char _ControlVerbs_single_lengths[] = { |
| 103 | 7, 1, 2, 2, 2, 2, 2, 2, |
| 104 | 1, 2, 2, 2, 3, 2, 2, 2, |
| 105 | 2, 2, 2, 2, 2, 2, 2, 2, |
| 106 | 3, 2, 2, 2, 2, 3, 2, 2, |
| 107 | 2, 2, 2, 1, 1, 2, 2, 2, |
| 108 | 2, 2, 2, 2, 2, 2, 2, 3, |
| 109 | 2, 2, 2, 2, 2, 2, 2, 2, |
| 110 | 2, 2, 2, 2, 2, 2, 2, 2, |
| 111 | 2, 2, 2, 3, 2, 1, 2, 4, |
| 112 | 2, 2, 1, 1, 1 |
| 113 | }; |
| 114 | |
| 115 | static const char _ControlVerbs_range_lengths[] = { |
| 116 | 0, 0, 0, 0, 0, 0, 0, 0, |
| 117 | 0, 0, 0, 0, 0, 0, 0, 0, |
| 118 | 0, 0, 0, 0, 0, 0, 0, 0, |
| 119 | 0, 0, 0, 0, 0, 0, 0, 0, |
| 120 | 0, 0, 0, 1, 1, 0, 0, 0, |
| 121 | 0, 0, 0, 0, 0, 0, 0, 0, |
| 122 | 0, 0, 0, 0, 0, 0, 0, 0, |
| 123 | 0, 0, 0, 0, 0, 0, 0, 0, |
| 124 | 0, 0, 0, 0, 0, 0, 0, 0, |
| 125 | 0, 0, 0, 0, 0 |
| 126 | }; |
| 127 | |
| 128 | static const short _ControlVerbs_index_offsets[] = { |
| 129 | 0, 8, 10, 13, 16, 19, 22, 25, |
| 130 | 28, 30, 33, 36, 39, 43, 46, 49, |
| 131 | 52, 55, 58, 61, 64, 67, 70, 73, |
| 132 | 76, 80, 83, 86, 89, 92, 96, 99, |
| 133 | 102, 105, 108, 111, 114, 117, 120, 123, |
| 134 | 126, 129, 132, 135, 138, 141, 144, 147, |
| 135 | 151, 154, 157, 160, 163, 166, 169, 172, |
| 136 | 175, 178, 181, 184, 187, 190, 193, 196, |
| 137 | 199, 202, 205, 208, 212, 215, 217, 220, |
| 138 | 225, 228, 231, 233, 235 |
| 139 | }; |
| 140 | |
| 141 | static const char _ControlVerbs_indicies[] = { |
| 142 | 0, 2, 3, 4, 5, 6, 7, 1, |
| 143 | 8, 1, 8, 9, 1, 8, 10, 1, |
| 144 | 11, 12, 1, 8, 13, 1, 8, 14, |
| 145 | 1, 8, 15, 1, 11, 1, 8, 16, |
| 146 | 1, 8, 17, 1, 8, 18, 1, 8, |
| 147 | 19, 20, 1, 8, 21, 1, 8, 22, |
| 148 | 1, 8, 12, 1, 8, 23, 1, 8, |
| 149 | 24, 1, 8, 25, 1, 8, 26, 1, |
| 150 | 8, 27, 1, 8, 15, 1, 8, 28, |
| 151 | 1, 11, 14, 1, 8, 15, 29, 1, |
| 152 | 8, 30, 1, 8, 31, 1, 8, 32, |
| 153 | 1, 8, 33, 1, 8, 34, 35, 1, |
| 154 | 8, 36, 1, 8, 37, 1, 8, 38, |
| 155 | 1, 8, 39, 1, 8, 40, 1, 8, |
| 156 | 41, 1, 11, 41, 1, 8, 42, 1, |
| 157 | 8, 43, 1, 8, 44, 1, 8, 45, |
| 158 | 1, 8, 46, 1, 8, 47, 1, 8, |
| 159 | 48, 1, 8, 39, 1, 8, 49, 1, |
| 160 | 8, 50, 1, 8, 51, 52, 1, 8, |
| 161 | 53, 1, 8, 54, 1, 8, 55, 1, |
| 162 | 8, 56, 1, 8, 57, 1, 8, 58, |
| 163 | 1, 8, 59, 1, 8, 60, 1, 8, |
| 164 | 61, 1, 8, 62, 1, 8, 15, 1, |
| 165 | 8, 63, 1, 8, 64, 1, 8, 65, |
| 166 | 1, 8, 66, 1, 8, 67, 1, 8, |
| 167 | 68, 1, 8, 69, 1, 8, 15, 1, |
| 168 | 8, 70, 71, 1, 8, 72, 1, 73, |
| 169 | 1, 8, 74, 1, 75, 76, 77, 78, |
| 170 | 1, 8, 15, 1, 8, 15, 1, 75, |
| 171 | 1, 80, 79, 82, 81, 0 |
| 172 | }; |
| 173 | |
| 174 | static const char _ControlVerbs_trans_targs[] = { |
| 175 | 75, 1, 2, 9, 22, 24, 45, 67, |
| 176 | 75, 3, 4, 75, 5, 6, 7, 8, |
| 177 | 10, 11, 12, 13, 16, 14, 15, 17, |
| 178 | 18, 19, 20, 21, 23, 25, 26, 27, |
| 179 | 28, 29, 30, 37, 31, 32, 33, 34, |
| 180 | 35, 36, 38, 39, 40, 41, 42, 43, |
| 181 | 44, 46, 47, 48, 59, 49, 50, 51, |
| 182 | 52, 53, 54, 55, 56, 57, 58, 60, |
| 183 | 61, 62, 63, 64, 65, 66, 68, 70, |
| 184 | 69, 75, 71, 75, 72, 73, 74, 75, |
| 185 | 76, 75, 0 |
| 186 | }; |
| 187 | |
| 188 | static const char _ControlVerbs_trans_actions[] = { |
| 189 | 19, 0, 0, 0, 0, 0, 0, 0, |
| 190 | 13, 0, 0, 11, 0, 0, 0, 0, |
| 191 | 0, 0, 0, 0, 0, 0, 0, 0, |
| 192 | 0, 0, 0, 0, 0, 0, 0, 0, |
| 193 | 0, 0, 0, 0, 0, 0, 0, 0, |
| 194 | 0, 0, 0, 0, 0, 0, 0, 0, |
| 195 | 0, 0, 0, 0, 0, 0, 0, 0, |
| 196 | 0, 0, 0, 0, 0, 0, 0, 0, |
| 197 | 0, 0, 0, 0, 0, 0, 0, 0, |
| 198 | 0, 9, 0, 7, 0, 0, 0, 15, |
| 199 | 5, 17, 0 |
| 200 | }; |
| 201 | |
| 202 | static const char _ControlVerbs_to_state_actions[] = { |
| 203 | 0, 0, 0, 0, 0, 0, 0, 0, |
| 204 | 0, 0, 0, 0, 0, 0, 0, 0, |
| 205 | 0, 0, 0, 0, 0, 0, 0, 0, |
| 206 | 0, 0, 0, 0, 0, 0, 0, 0, |
| 207 | 0, 0, 0, 0, 0, 0, 0, 0, |
| 208 | 0, 0, 0, 0, 0, 0, 0, 0, |
| 209 | 0, 0, 0, 0, 0, 0, 0, 0, |
| 210 | 0, 0, 0, 0, 0, 0, 0, 0, |
| 211 | 0, 0, 0, 0, 0, 0, 0, 0, |
| 212 | 0, 0, 0, 1, 0 |
| 213 | }; |
| 214 | |
| 215 | static const char _ControlVerbs_from_state_actions[] = { |
| 216 | 0, 0, 0, 0, 0, 0, 0, 0, |
| 217 | 0, 0, 0, 0, 0, 0, 0, 0, |
| 218 | 0, 0, 0, 0, 0, 0, 0, 0, |
| 219 | 0, 0, 0, 0, 0, 0, 0, 0, |
| 220 | 0, 0, 0, 0, 0, 0, 0, 0, |
| 221 | 0, 0, 0, 0, 0, 0, 0, 0, |
| 222 | 0, 0, 0, 0, 0, 0, 0, 0, |
| 223 | 0, 0, 0, 0, 0, 0, 0, 0, |
| 224 | 0, 0, 0, 0, 0, 0, 0, 0, |
| 225 | 0, 0, 0, 3, 0 |
| 226 | }; |
| 227 | |
| 228 | static const short _ControlVerbs_eof_trans[] = { |
| 229 | 1, 1, 1, 1, 1, 1, 1, 1, |
| 230 | 1, 1, 1, 1, 1, 1, 1, 1, |
| 231 | 1, 1, 1, 1, 1, 1, 1, 1, |
| 232 | 1, 1, 1, 1, 1, 1, 1, 1, |
| 233 | 1, 1, 1, 1, 1, 1, 1, 1, |
| 234 | 1, 1, 1, 1, 1, 1, 1, 1, |
| 235 | 1, 1, 1, 1, 1, 1, 1, 1, |
| 236 | 1, 1, 1, 1, 1, 1, 1, 1, |
| 237 | 1, 1, 1, 1, 1, 1, 1, 1, |
| 238 | 1, 1, 1, 0, 82 |
| 239 | }; |
| 240 | |
| 241 | static const int ControlVerbs_start = 75; |
| 242 | //static const int ControlVerbs_first_final = 75; |
| 243 | //static const int ControlVerbs_error = -1; |
| 244 | |
| 245 | //static const int ControlVerbs_en_main = 75; |
| 246 | |
| 247 | |
| 248 | #line 249 "control_verbs.cpp" |
| 249 | { |
| 250 | cs = ControlVerbs_start; |
| 251 | ts = 0; |
| 252 | te = 0; |
| 253 | act = 0; |
| 254 | } |
| 255 | |
| 256 | #line 105 "control_verbs.rl" |
| 257 | |
| 258 | |
| 259 | try { |
| 260 | |
| 261 | #line 262 "control_verbs.cpp" |
| 262 | { |
| 263 | int _klen; |
| 264 | unsigned int _trans; |
| 265 | const char *_acts; |
| 266 | unsigned int _nacts; |
| 267 | const char *_keys; |
| 268 | |
| 269 | if ( p == pe ) |
| 270 | goto _test_eof; |
| 271 | _resume: |
| 272 | _acts = _ControlVerbs_actions + _ControlVerbs_from_state_actions[cs]; |
| 273 | _nacts = (unsigned int) *_acts++; |
| 274 | while ( _nacts-- > 0 ) { |
| 275 | switch ( *_acts++ ) { |
| 276 | case 1: |
| 277 | #line 1 "NONE" |
| 278 | {ts = p;} |
| 279 | break; |
| 280 | #line 281 "control_verbs.cpp" |
| 281 | } |
| 282 | } |
| 283 | |
| 284 | _keys = _ControlVerbs_trans_keys + _ControlVerbs_key_offsets[cs]; |
| 285 | _trans = _ControlVerbs_index_offsets[cs]; |
| 286 | |
| 287 | _klen = _ControlVerbs_single_lengths[cs]; |
| 288 | if ( _klen > 0 ) { |
| 289 | const char *_lower = _keys; |
| 290 | const char *_mid; |
| 291 | const char *_upper = _keys + _klen - 1; |
| 292 | while (1) { |
| 293 | if ( _upper < _lower ) |
| 294 | break; |
| 295 | |
| 296 | _mid = _lower + ((_upper-_lower) >> 1); |
| 297 | if ( (*p) < *_mid ) |
| 298 | _upper = _mid - 1; |
| 299 | else if ( (*p) > *_mid ) |
| 300 | _lower = _mid + 1; |
| 301 | else { |
| 302 | _trans += (unsigned int)(_mid - _keys); |
| 303 | goto _match; |
| 304 | } |
| 305 | } |
| 306 | _keys += _klen; |
| 307 | _trans += _klen; |
| 308 | } |
| 309 | |
| 310 | _klen = _ControlVerbs_range_lengths[cs]; |
| 311 | if ( _klen > 0 ) { |
| 312 | const char *_lower = _keys; |
| 313 | const char *_mid; |
| 314 | const char *_upper = _keys + (_klen<<1) - 2; |
| 315 | while (1) { |
| 316 | if ( _upper < _lower ) |
| 317 | break; |
| 318 | |
| 319 | _mid = _lower + (((_upper-_lower) >> 1) & ~1); |
| 320 | if ( (*p) < _mid[0] ) |
| 321 | _upper = _mid - 2; |
| 322 | else if ( (*p) > _mid[1] ) |
| 323 | _lower = _mid + 2; |
| 324 | else { |
| 325 | _trans += (unsigned int)((_mid - _keys)>>1); |
| 326 | goto _match; |
| 327 | } |
| 328 | } |
| 329 | _trans += _klen; |
| 330 | } |
| 331 | |
| 332 | _match: |
| 333 | _trans = _ControlVerbs_indicies[_trans]; |
| 334 | _eof_trans: |
| 335 | cs = _ControlVerbs_trans_targs[_trans]; |
| 336 | |
| 337 | if ( _ControlVerbs_trans_actions[_trans] == 0 ) |
| 338 | goto _again; |
| 339 | |
| 340 | _acts = _ControlVerbs_actions + _ControlVerbs_trans_actions[_trans]; |
| 341 | _nacts = (unsigned int) *_acts++; |
| 342 | while ( _nacts-- > 0 ) |
| 343 | { |
| 344 | switch ( *_acts++ ) |
| 345 | { |
| 346 | case 2: |
| 347 | #line 1 "NONE" |
| 348 | {te = p+1;} |
| 349 | break; |
| 350 | case 3: |
| 351 | #line 76 "control_verbs.rl" |
| 352 | {te = p+1;{ |
| 353 | mode.utf8 = true; |
| 354 | }} |
| 355 | break; |
| 356 | case 4: |
| 357 | #line 80 "control_verbs.rl" |
| 358 | {te = p+1;{ |
| 359 | mode.ucp = true; |
| 360 | }} |
| 361 | break; |
| 362 | case 5: |
| 363 | #line 84 "control_verbs.rl" |
| 364 | {te = p+1;{ |
| 365 | ostringstream str; |
| 366 | str << "Unsupported control verb " << string(ts, te - ts); |
| 367 | throw LocatedParseError(str.str()); |
| 368 | }} |
| 369 | break; |
| 370 | case 6: |
| 371 | #line 90 "control_verbs.rl" |
| 372 | {te = p+1;{ |
| 373 | ostringstream str; |
| 374 | str << "Unknown control verb " << string(ts, te - ts); |
| 375 | throw LocatedParseError(str.str()); |
| 376 | }} |
| 377 | break; |
| 378 | case 7: |
| 379 | #line 97 "control_verbs.rl" |
| 380 | {te = p+1;{ |
| 381 | p--; |
| 382 | {p++; goto _out; } |
| 383 | }} |
| 384 | break; |
| 385 | case 8: |
| 386 | #line 97 "control_verbs.rl" |
| 387 | {te = p;p--;{ |
| 388 | p--; |
| 389 | {p++; goto _out; } |
| 390 | }} |
| 391 | break; |
| 392 | case 9: |
| 393 | #line 97 "control_verbs.rl" |
| 394 | {{p = ((te))-1;}{ |
| 395 | p--; |
| 396 | {p++; goto _out; } |
| 397 | }} |
| 398 | break; |
| 399 | #line 400 "control_verbs.cpp" |
| 400 | } |
| 401 | } |
| 402 | |
| 403 | _again: |
| 404 | _acts = _ControlVerbs_actions + _ControlVerbs_to_state_actions[cs]; |
| 405 | _nacts = (unsigned int) *_acts++; |
| 406 | while ( _nacts-- > 0 ) { |
| 407 | switch ( *_acts++ ) { |
| 408 | case 0: |
| 409 | #line 1 "NONE" |
| 410 | {ts = 0;} |
| 411 | break; |
| 412 | #line 413 "control_verbs.cpp" |
| 413 | } |
| 414 | } |
| 415 | |
| 416 | if ( ++p != pe ) |
| 417 | goto _resume; |
| 418 | _test_eof: {} |
| 419 | if ( p == eof ) |
| 420 | { |
| 421 | if ( _ControlVerbs_eof_trans[cs] > 0 ) { |
| 422 | _trans = _ControlVerbs_eof_trans[cs] - 1; |
| 423 | goto _eof_trans; |
| 424 | } |
| 425 | } |
| 426 | |
| 427 | _out: {} |
| 428 | } |
| 429 | |
| 430 | #line 109 "control_verbs.rl" |
| 431 | } catch (LocatedParseError &error) { |
| 432 | if (ts >= ptr && ts <= pe) { |
| 433 | error.locate(ts - ptr + start); |
| 434 | } else { |
| 435 | error.locate(0); |
| 436 | } |
| 437 | throw; |
| 438 | } |
| 439 | |
| 440 | return p; |
| 441 | } |
| 442 | |
| 443 | } // namespace ue2 |
| 444 | |