github.com/siglens/siglens@v0.0.0-20240328180423-f7ce9ae441ed/pkg/ast/pipesearch/searchQuery.go (about) 1 // Code generated by pigeon; DO NOT EDIT. 2 3 package pipesearch 4 5 import ( 6 "bytes" 7 "encoding/json" 8 "errors" 9 "fmt" 10 "io" 11 "math" 12 "os" 13 "sort" 14 "strconv" 15 "strings" 16 "sync" 17 "unicode" 18 "unicode/utf8" 19 20 "github.com/siglens/siglens/pkg/ast" 21 "github.com/siglens/siglens/pkg/segment/structs" 22 "github.com/siglens/siglens/pkg/segment/utils" 23 ) 24 25 // helper method to exfiltrate pigeon's generated error type 26 func getParseError(err error) error { 27 switch ev := err.(type) { 28 case errList: 29 if pe, ok := ev[0].(*parserError); ok { 30 return &ast.ParseError{ 31 Inner: pe.Inner, 32 Line: pe.pos.line, 33 Column: pe.pos.col, 34 Offset: pe.pos.offset, 35 Prefix: pe.prefix, 36 Expected: pe.expected, 37 } 38 } 39 } 40 return err 41 } 42 43 var g = &grammar{ 44 rules: []*rule{ 45 { 46 name: "Start", 47 pos: position{line: 30, col: 1, offset: 597}, 48 expr: &choiceExpr{ 49 pos: position{line: 30, col: 10, offset: 606}, 50 alternatives: []any{ 51 &actionExpr{ 52 pos: position{line: 30, col: 10, offset: 606}, 53 run: (*parser).callonStart2, 54 expr: &seqExpr{ 55 pos: position{line: 30, col: 10, offset: 606}, 56 exprs: []any{ 57 &labeledExpr{ 58 pos: position{line: 30, col: 10, offset: 606}, 59 label: "maggs", 60 expr: &zeroOrOneExpr{ 61 pos: position{line: 30, col: 16, offset: 612}, 62 expr: &ruleRefExpr{ 63 pos: position{line: 30, col: 16, offset: 612}, 64 name: "measureAggsList", 65 }, 66 }, 67 }, 68 &ruleRefExpr{ 69 pos: position{line: 30, col: 33, offset: 629}, 70 name: "EOF", 71 }, 72 }, 73 }, 74 }, 75 &actionExpr{ 76 pos: position{line: 36, col: 5, offset: 789}, 77 run: (*parser).callonStart8, 78 expr: &seqExpr{ 79 pos: position{line: 36, col: 5, offset: 789}, 80 exprs: []any{ 81 &labeledExpr{ 82 pos: position{line: 36, col: 5, offset: 789}, 83 label: "groupBy", 84 expr: &zeroOrOneExpr{ 85 pos: position{line: 36, col: 13, offset: 797}, 86 expr: &ruleRefExpr{ 87 pos: position{line: 36, col: 13, offset: 797}, 88 name: "groupByList", 89 }, 90 }, 91 }, 92 &zeroOrOneExpr{ 93 pos: position{line: 36, col: 26, offset: 810}, 94 expr: &ruleRefExpr{ 95 pos: position{line: 36, col: 26, offset: 810}, 96 name: "space", 97 }, 98 }, 99 &labeledExpr{ 100 pos: position{line: 36, col: 33, offset: 817}, 101 label: "lim", 102 expr: &zeroOrOneExpr{ 103 pos: position{line: 36, col: 37, offset: 821}, 104 expr: &ruleRefExpr{ 105 pos: position{line: 36, col: 37, offset: 821}, 106 name: "Limit", 107 }, 108 }, 109 }, 110 &ruleRefExpr{ 111 pos: position{line: 36, col: 44, offset: 828}, 112 name: "EOF", 113 }, 114 }, 115 }, 116 }, 117 &actionExpr{ 118 pos: position{line: 44, col: 5, offset: 1059}, 119 run: (*parser).callonStart19, 120 expr: &seqExpr{ 121 pos: position{line: 44, col: 5, offset: 1059}, 122 exprs: []any{ 123 &labeledExpr{ 124 pos: position{line: 44, col: 5, offset: 1059}, 125 label: "query", 126 expr: &zeroOrOneExpr{ 127 pos: position{line: 44, col: 11, offset: 1065}, 128 expr: &ruleRefExpr{ 129 pos: position{line: 44, col: 11, offset: 1065}, 130 name: "Query", 131 }, 132 }, 133 }, 134 &labeledExpr{ 135 pos: position{line: 44, col: 18, offset: 1072}, 136 label: "aggs", 137 expr: &zeroOrOneExpr{ 138 pos: position{line: 44, col: 23, offset: 1077}, 139 expr: &ruleRefExpr{ 140 pos: position{line: 44, col: 23, offset: 1077}, 141 name: "AggClause", 142 }, 143 }, 144 }, 145 &ruleRefExpr{ 146 pos: position{line: 44, col: 34, offset: 1088}, 147 name: "EOF", 148 }, 149 }, 150 }, 151 }, 152 &actionExpr{ 153 pos: position{line: 53, col: 5, offset: 1295}, 154 run: (*parser).callonStart28, 155 expr: &seqExpr{ 156 pos: position{line: 53, col: 5, offset: 1295}, 157 exprs: []any{ 158 &labeledExpr{ 159 pos: position{line: 53, col: 5, offset: 1295}, 160 label: "query", 161 expr: &zeroOrOneExpr{ 162 pos: position{line: 53, col: 11, offset: 1301}, 163 expr: &ruleRefExpr{ 164 pos: position{line: 53, col: 11, offset: 1301}, 165 name: "Query", 166 }, 167 }, 168 }, 169 &ruleRefExpr{ 170 pos: position{line: 53, col: 18, offset: 1308}, 171 name: "EOF", 172 }, 173 }, 174 }, 175 }, 176 &actionExpr{ 177 pos: position{line: 59, col: 5, offset: 1431}, 178 run: (*parser).callonStart34, 179 expr: &seqExpr{ 180 pos: position{line: 59, col: 5, offset: 1431}, 181 exprs: []any{ 182 &labeledExpr{ 183 pos: position{line: 59, col: 5, offset: 1431}, 184 label: "aggs", 185 expr: &zeroOrOneExpr{ 186 pos: position{line: 59, col: 10, offset: 1436}, 187 expr: &ruleRefExpr{ 188 pos: position{line: 59, col: 10, offset: 1436}, 189 name: "AggClause", 190 }, 191 }, 192 }, 193 &ruleRefExpr{ 194 pos: position{line: 59, col: 21, offset: 1447}, 195 name: "EOF", 196 }, 197 }, 198 }, 199 }, 200 }, 201 }, 202 }, 203 { 204 name: "Query", 205 pos: position{line: 67, col: 1, offset: 1584}, 206 expr: &actionExpr{ 207 pos: position{line: 67, col: 10, offset: 1593}, 208 run: (*parser).callonQuery1, 209 expr: &seqExpr{ 210 pos: position{line: 67, col: 10, offset: 1593}, 211 exprs: []any{ 212 &ruleRefExpr{ 213 pos: position{line: 67, col: 10, offset: 1593}, 214 name: "_", 215 }, 216 &labeledExpr{ 217 pos: position{line: 67, col: 12, offset: 1595}, 218 label: "clause", 219 expr: &ruleRefExpr{ 220 pos: position{line: 67, col: 19, offset: 1602}, 221 name: "OrClause", 222 }, 223 }, 224 &ruleRefExpr{ 225 pos: position{line: 67, col: 28, offset: 1611}, 226 name: "_", 227 }, 228 }, 229 }, 230 }, 231 }, 232 { 233 name: "OrClause", 234 pos: position{line: 75, col: 1, offset: 1661}, 235 expr: &choiceExpr{ 236 pos: position{line: 75, col: 13, offset: 1673}, 237 alternatives: []any{ 238 &actionExpr{ 239 pos: position{line: 75, col: 13, offset: 1673}, 240 run: (*parser).callonOrClause2, 241 expr: &seqExpr{ 242 pos: position{line: 75, col: 13, offset: 1673}, 243 exprs: []any{ 244 &labeledExpr{ 245 pos: position{line: 75, col: 13, offset: 1673}, 246 label: "lhs", 247 expr: &ruleRefExpr{ 248 pos: position{line: 75, col: 17, offset: 1677}, 249 name: "AndClause", 250 }, 251 }, 252 &ruleRefExpr{ 253 pos: position{line: 75, col: 27, offset: 1687}, 254 name: "space", 255 }, 256 &ruleRefExpr{ 257 pos: position{line: 75, col: 33, offset: 1693}, 258 name: "logicalOR", 259 }, 260 &ruleRefExpr{ 261 pos: position{line: 75, col: 43, offset: 1703}, 262 name: "space", 263 }, 264 &labeledExpr{ 265 pos: position{line: 75, col: 49, offset: 1709}, 266 label: "rhs", 267 expr: &ruleRefExpr{ 268 pos: position{line: 75, col: 53, offset: 1713}, 269 name: "OrClause", 270 }, 271 }, 272 }, 273 }, 274 }, 275 &ruleRefExpr{ 276 pos: position{line: 81, col: 5, offset: 1857}, 277 name: "AndClause", 278 }, 279 }, 280 }, 281 }, 282 { 283 name: "measureAggsList", 284 pos: position{line: 84, col: 1, offset: 1869}, 285 expr: &actionExpr{ 286 pos: position{line: 84, col: 20, offset: 1888}, 287 run: (*parser).callonmeasureAggsList1, 288 expr: &seqExpr{ 289 pos: position{line: 84, col: 20, offset: 1888}, 290 exprs: []any{ 291 &zeroOrOneExpr{ 292 pos: position{line: 84, col: 20, offset: 1888}, 293 expr: &ruleRefExpr{ 294 pos: position{line: 84, col: 20, offset: 1888}, 295 name: "space", 296 }, 297 }, 298 &labeledExpr{ 299 pos: position{line: 84, col: 27, offset: 1895}, 300 label: "first", 301 expr: &ruleRefExpr{ 302 pos: position{line: 84, col: 33, offset: 1901}, 303 name: "MeasureAggClause", 304 }, 305 }, 306 &labeledExpr{ 307 pos: position{line: 84, col: 50, offset: 1918}, 308 label: "rest", 309 expr: &zeroOrMoreExpr{ 310 pos: position{line: 84, col: 55, offset: 1923}, 311 expr: &seqExpr{ 312 pos: position{line: 84, col: 57, offset: 1925}, 313 exprs: []any{ 314 &zeroOrOneExpr{ 315 pos: position{line: 84, col: 57, offset: 1925}, 316 expr: &ruleRefExpr{ 317 pos: position{line: 84, col: 57, offset: 1925}, 318 name: "space", 319 }, 320 }, 321 &litMatcher{ 322 pos: position{line: 84, col: 64, offset: 1932}, 323 val: ",", 324 ignoreCase: false, 325 want: "\",\"", 326 }, 327 &zeroOrOneExpr{ 328 pos: position{line: 84, col: 68, offset: 1936}, 329 expr: &ruleRefExpr{ 330 pos: position{line: 84, col: 68, offset: 1936}, 331 name: "space", 332 }, 333 }, 334 &ruleRefExpr{ 335 pos: position{line: 84, col: 75, offset: 1943}, 336 name: "MeasureAggClause", 337 }, 338 }, 339 }, 340 }, 341 }, 342 &zeroOrOneExpr{ 343 pos: position{line: 84, col: 95, offset: 1963}, 344 expr: &ruleRefExpr{ 345 pos: position{line: 84, col: 95, offset: 1963}, 346 name: "space", 347 }, 348 }, 349 }, 350 }, 351 }, 352 }, 353 { 354 name: "groupByList", 355 pos: position{line: 88, col: 1, offset: 2032}, 356 expr: &actionExpr{ 357 pos: position{line: 88, col: 16, offset: 2047}, 358 run: (*parser).callongroupByList1, 359 expr: &seqExpr{ 360 pos: position{line: 88, col: 16, offset: 2047}, 361 exprs: []any{ 362 &zeroOrOneExpr{ 363 pos: position{line: 88, col: 16, offset: 2047}, 364 expr: &ruleRefExpr{ 365 pos: position{line: 88, col: 16, offset: 2047}, 366 name: "space", 367 }, 368 }, 369 &labeledExpr{ 370 pos: position{line: 88, col: 23, offset: 2054}, 371 label: "first", 372 expr: &ruleRefExpr{ 373 pos: position{line: 88, col: 29, offset: 2060}, 374 name: "MeasureAggClause", 375 }, 376 }, 377 &labeledExpr{ 378 pos: position{line: 88, col: 46, offset: 2077}, 379 label: "rest", 380 expr: &zeroOrMoreExpr{ 381 pos: position{line: 88, col: 51, offset: 2082}, 382 expr: &seqExpr{ 383 pos: position{line: 88, col: 53, offset: 2084}, 384 exprs: []any{ 385 &zeroOrOneExpr{ 386 pos: position{line: 88, col: 53, offset: 2084}, 387 expr: &ruleRefExpr{ 388 pos: position{line: 88, col: 53, offset: 2084}, 389 name: "space", 390 }, 391 }, 392 &litMatcher{ 393 pos: position{line: 88, col: 60, offset: 2091}, 394 val: ",", 395 ignoreCase: false, 396 want: "\",\"", 397 }, 398 &zeroOrOneExpr{ 399 pos: position{line: 88, col: 64, offset: 2095}, 400 expr: &ruleRefExpr{ 401 pos: position{line: 88, col: 64, offset: 2095}, 402 name: "space", 403 }, 404 }, 405 &ruleRefExpr{ 406 pos: position{line: 88, col: 71, offset: 2102}, 407 name: "MeasureAggClause", 408 }, 409 }, 410 }, 411 }, 412 }, 413 &zeroOrOneExpr{ 414 pos: position{line: 88, col: 91, offset: 2122}, 415 expr: &ruleRefExpr{ 416 pos: position{line: 88, col: 91, offset: 2122}, 417 name: "space", 418 }, 419 }, 420 &ruleRefExpr{ 421 pos: position{line: 88, col: 98, offset: 2129}, 422 name: "GroupBy", 423 }, 424 &labeledExpr{ 425 pos: position{line: 88, col: 106, offset: 2137}, 426 label: "cols", 427 expr: &zeroOrOneExpr{ 428 pos: position{line: 88, col: 111, offset: 2142}, 429 expr: &ruleRefExpr{ 430 pos: position{line: 88, col: 112, offset: 2143}, 431 name: "ColList", 432 }, 433 }, 434 }, 435 &zeroOrOneExpr{ 436 pos: position{line: 88, col: 122, offset: 2153}, 437 expr: &ruleRefExpr{ 438 pos: position{line: 88, col: 122, offset: 2153}, 439 name: "space", 440 }, 441 }, 442 &labeledExpr{ 443 pos: position{line: 88, col: 129, offset: 2160}, 444 label: "lim", 445 expr: &zeroOrOneExpr{ 446 pos: position{line: 88, col: 133, offset: 2164}, 447 expr: &ruleRefExpr{ 448 pos: position{line: 88, col: 133, offset: 2164}, 449 name: "Limit", 450 }, 451 }, 452 }, 453 }, 454 }, 455 }, 456 }, 457 { 458 name: "Limit", 459 pos: position{line: 96, col: 1, offset: 2324}, 460 expr: &actionExpr{ 461 pos: position{line: 96, col: 10, offset: 2333}, 462 run: (*parser).callonLimit1, 463 expr: &seqExpr{ 464 pos: position{line: 96, col: 10, offset: 2333}, 465 exprs: []any{ 466 &litMatcher{ 467 pos: position{line: 96, col: 10, offset: 2333}, 468 val: "limit", 469 ignoreCase: false, 470 want: "\"limit\"", 471 }, 472 &ruleRefExpr{ 473 pos: position{line: 96, col: 18, offset: 2341}, 474 name: "space", 475 }, 476 &labeledExpr{ 477 pos: position{line: 96, col: 24, offset: 2347}, 478 label: "first", 479 expr: &ruleRefExpr{ 480 pos: position{line: 96, col: 30, offset: 2353}, 481 name: "Identifier", 482 }, 483 }, 484 }, 485 }, 486 }, 487 }, 488 { 489 name: "MeasureAggClause", 490 pos: position{line: 105, col: 1, offset: 2500}, 491 expr: &actionExpr{ 492 pos: position{line: 105, col: 21, offset: 2520}, 493 run: (*parser).callonMeasureAggClause1, 494 expr: &seqExpr{ 495 pos: position{line: 105, col: 21, offset: 2520}, 496 exprs: []any{ 497 &zeroOrOneExpr{ 498 pos: position{line: 105, col: 21, offset: 2520}, 499 expr: &ruleRefExpr{ 500 pos: position{line: 105, col: 21, offset: 2520}, 501 name: "space", 502 }, 503 }, 504 &labeledExpr{ 505 pos: position{line: 105, col: 28, offset: 2527}, 506 label: "funcs", 507 expr: &ruleRefExpr{ 508 pos: position{line: 105, col: 34, offset: 2533}, 509 name: "MeasureAggsFunc", 510 }, 511 }, 512 &litMatcher{ 513 pos: position{line: 105, col: 50, offset: 2549}, 514 val: "(", 515 ignoreCase: false, 516 want: "\"(\"", 517 }, 518 &labeledExpr{ 519 pos: position{line: 105, col: 54, offset: 2553}, 520 label: "cols", 521 expr: &ruleRefExpr{ 522 pos: position{line: 105, col: 59, offset: 2558}, 523 name: "Identifier", 524 }, 525 }, 526 &litMatcher{ 527 pos: position{line: 105, col: 70, offset: 2569}, 528 val: ")", 529 ignoreCase: false, 530 want: "\")\"", 531 }, 532 }, 533 }, 534 }, 535 }, 536 { 537 name: "AggClause", 538 pos: position{line: 114, col: 1, offset: 2769}, 539 expr: &choiceExpr{ 540 pos: position{line: 114, col: 14, offset: 2782}, 541 alternatives: []any{ 542 &actionExpr{ 543 pos: position{line: 114, col: 14, offset: 2782}, 544 run: (*parser).callonAggClause2, 545 expr: &seqExpr{ 546 pos: position{line: 114, col: 14, offset: 2782}, 547 exprs: []any{ 548 &ruleRefExpr{ 549 pos: position{line: 114, col: 14, offset: 2782}, 550 name: "opPipe", 551 }, 552 &zeroOrOneExpr{ 553 pos: position{line: 114, col: 21, offset: 2789}, 554 expr: &ruleRefExpr{ 555 pos: position{line: 114, col: 21, offset: 2789}, 556 name: "space", 557 }, 558 }, 559 &ruleRefExpr{ 560 pos: position{line: 114, col: 28, offset: 2796}, 561 name: "Column", 562 }, 563 &ruleRefExpr{ 564 pos: position{line: 114, col: 35, offset: 2803}, 565 name: "space", 566 }, 567 &labeledExpr{ 568 pos: position{line: 114, col: 42, offset: 2810}, 569 label: "newCol", 570 expr: &ruleRefExpr{ 571 pos: position{line: 114, col: 49, offset: 2817}, 572 name: "Identifier", 573 }, 574 }, 575 &zeroOrOneExpr{ 576 pos: position{line: 114, col: 60, offset: 2828}, 577 expr: &ruleRefExpr{ 578 pos: position{line: 114, col: 60, offset: 2828}, 579 name: "space", 580 }, 581 }, 582 &litMatcher{ 583 pos: position{line: 114, col: 67, offset: 2835}, 584 val: "=", 585 ignoreCase: false, 586 want: "\"=\"", 587 }, 588 &zeroOrOneExpr{ 589 pos: position{line: 114, col: 71, offset: 2839}, 590 expr: &ruleRefExpr{ 591 pos: position{line: 114, col: 71, offset: 2839}, 592 name: "space", 593 }, 594 }, 595 &labeledExpr{ 596 pos: position{line: 114, col: 78, offset: 2846}, 597 label: "oldCol", 598 expr: &ruleRefExpr{ 599 pos: position{line: 114, col: 85, offset: 2853}, 600 name: "Identifier", 601 }, 602 }, 603 }, 604 }, 605 }, 606 &actionExpr{ 607 pos: position{line: 123, col: 3, offset: 3290}, 608 run: (*parser).callonAggClause18, 609 expr: &seqExpr{ 610 pos: position{line: 123, col: 3, offset: 3290}, 611 exprs: []any{ 612 &ruleRefExpr{ 613 pos: position{line: 123, col: 3, offset: 3290}, 614 name: "opPipe", 615 }, 616 &zeroOrOneExpr{ 617 pos: position{line: 123, col: 10, offset: 3297}, 618 expr: &ruleRefExpr{ 619 pos: position{line: 123, col: 10, offset: 3297}, 620 name: "space", 621 }, 622 }, 623 &ruleRefExpr{ 624 pos: position{line: 123, col: 17, offset: 3304}, 625 name: "Column", 626 }, 627 &ruleRefExpr{ 628 pos: position{line: 123, col: 24, offset: 3311}, 629 name: "space", 630 }, 631 &labeledExpr{ 632 pos: position{line: 123, col: 30, offset: 3317}, 633 label: "cols", 634 expr: &ruleRefExpr{ 635 pos: position{line: 123, col: 35, offset: 3322}, 636 name: "ColList", 637 }, 638 }, 639 }, 640 }, 641 }, 642 &actionExpr{ 643 pos: position{line: 131, col: 3, offset: 3658}, 644 run: (*parser).callonAggClause27, 645 expr: &seqExpr{ 646 pos: position{line: 131, col: 3, offset: 3658}, 647 exprs: []any{ 648 &ruleRefExpr{ 649 pos: position{line: 131, col: 3, offset: 3658}, 650 name: "opPipe", 651 }, 652 &zeroOrOneExpr{ 653 pos: position{line: 131, col: 10, offset: 3665}, 654 expr: &ruleRefExpr{ 655 pos: position{line: 131, col: 10, offset: 3665}, 656 name: "space", 657 }, 658 }, 659 &ruleRefExpr{ 660 pos: position{line: 131, col: 17, offset: 3672}, 661 name: "Column", 662 }, 663 &ruleRefExpr{ 664 pos: position{line: 131, col: 24, offset: 3679}, 665 name: "space", 666 }, 667 &litMatcher{ 668 pos: position{line: 131, col: 30, offset: 3685}, 669 val: "-", 670 ignoreCase: false, 671 want: "\"-\"", 672 }, 673 &ruleRefExpr{ 674 pos: position{line: 131, col: 34, offset: 3689}, 675 name: "space", 676 }, 677 &labeledExpr{ 678 pos: position{line: 131, col: 40, offset: 3695}, 679 label: "cols", 680 expr: &ruleRefExpr{ 681 pos: position{line: 131, col: 45, offset: 3700}, 682 name: "ColList", 683 }, 684 }, 685 }, 686 }, 687 }, 688 &actionExpr{ 689 pos: position{line: 139, col: 3, offset: 4036}, 690 run: (*parser).callonAggClause38, 691 expr: &seqExpr{ 692 pos: position{line: 139, col: 3, offset: 4036}, 693 exprs: []any{ 694 &ruleRefExpr{ 695 pos: position{line: 139, col: 3, offset: 4036}, 696 name: "opPipe", 697 }, 698 &zeroOrOneExpr{ 699 pos: position{line: 139, col: 10, offset: 4043}, 700 expr: &ruleRefExpr{ 701 pos: position{line: 139, col: 10, offset: 4043}, 702 name: "space", 703 }, 704 }, 705 &labeledExpr{ 706 pos: position{line: 139, col: 17, offset: 4050}, 707 label: "maggs", 708 expr: &ruleRefExpr{ 709 pos: position{line: 139, col: 23, offset: 4056}, 710 name: "measureAggsList", 711 }, 712 }, 713 &ruleRefExpr{ 714 pos: position{line: 139, col: 39, offset: 4072}, 715 name: "EOF", 716 }, 717 }, 718 }, 719 }, 720 &actionExpr{ 721 pos: position{line: 144, col: 3, offset: 4196}, 722 run: (*parser).callonAggClause46, 723 expr: &seqExpr{ 724 pos: position{line: 144, col: 3, offset: 4196}, 725 exprs: []any{ 726 &ruleRefExpr{ 727 pos: position{line: 144, col: 3, offset: 4196}, 728 name: "opPipe", 729 }, 730 &zeroOrOneExpr{ 731 pos: position{line: 144, col: 10, offset: 4203}, 732 expr: &ruleRefExpr{ 733 pos: position{line: 144, col: 10, offset: 4203}, 734 name: "space", 735 }, 736 }, 737 &labeledExpr{ 738 pos: position{line: 144, col: 17, offset: 4210}, 739 label: "groupBy", 740 expr: &ruleRefExpr{ 741 pos: position{line: 144, col: 25, offset: 4218}, 742 name: "groupByList", 743 }, 744 }, 745 &zeroOrOneExpr{ 746 pos: position{line: 144, col: 37, offset: 4230}, 747 expr: &ruleRefExpr{ 748 pos: position{line: 144, col: 37, offset: 4230}, 749 name: "space", 750 }, 751 }, 752 &labeledExpr{ 753 pos: position{line: 144, col: 44, offset: 4237}, 754 label: "lim", 755 expr: &zeroOrOneExpr{ 756 pos: position{line: 144, col: 48, offset: 4241}, 757 expr: &ruleRefExpr{ 758 pos: position{line: 144, col: 48, offset: 4241}, 759 name: "Limit", 760 }, 761 }, 762 }, 763 &ruleRefExpr{ 764 pos: position{line: 144, col: 55, offset: 4248}, 765 name: "EOF", 766 }, 767 }, 768 }, 769 }, 770 &actionExpr{ 771 pos: position{line: 149, col: 3, offset: 4374}, 772 run: (*parser).callonAggClause59, 773 expr: &seqExpr{ 774 pos: position{line: 149, col: 3, offset: 4374}, 775 exprs: []any{ 776 &ruleRefExpr{ 777 pos: position{line: 149, col: 3, offset: 4374}, 778 name: "opPipe", 779 }, 780 &zeroOrOneExpr{ 781 pos: position{line: 149, col: 10, offset: 4381}, 782 expr: &ruleRefExpr{ 783 pos: position{line: 149, col: 10, offset: 4381}, 784 name: "space", 785 }, 786 }, 787 &ruleRefExpr{ 788 pos: position{line: 149, col: 17, offset: 4388}, 789 name: "Let", 790 }, 791 &ruleRefExpr{ 792 pos: position{line: 149, col: 21, offset: 4392}, 793 name: "space", 794 }, 795 &labeledExpr{ 796 pos: position{line: 149, col: 27, offset: 4398}, 797 label: "newCol", 798 expr: &ruleRefExpr{ 799 pos: position{line: 149, col: 34, offset: 4405}, 800 name: "Identifier", 801 }, 802 }, 803 &zeroOrOneExpr{ 804 pos: position{line: 149, col: 45, offset: 4416}, 805 expr: &ruleRefExpr{ 806 pos: position{line: 149, col: 45, offset: 4416}, 807 name: "space", 808 }, 809 }, 810 &litMatcher{ 811 pos: position{line: 149, col: 52, offset: 4423}, 812 val: "=", 813 ignoreCase: false, 814 want: "\"=\"", 815 }, 816 &zeroOrOneExpr{ 817 pos: position{line: 149, col: 56, offset: 4427}, 818 expr: &ruleRefExpr{ 819 pos: position{line: 149, col: 56, offset: 4427}, 820 name: "space", 821 }, 822 }, 823 &zeroOrOneExpr{ 824 pos: position{line: 149, col: 63, offset: 4434}, 825 expr: &litMatcher{ 826 pos: position{line: 149, col: 63, offset: 4434}, 827 val: "(", 828 ignoreCase: false, 829 want: "\"(\"", 830 }, 831 }, 832 &zeroOrOneExpr{ 833 pos: position{line: 149, col: 68, offset: 4439}, 834 expr: &ruleRefExpr{ 835 pos: position{line: 149, col: 68, offset: 4439}, 836 name: "space", 837 }, 838 }, 839 &labeledExpr{ 840 pos: position{line: 149, col: 75, offset: 4446}, 841 label: "lhs", 842 expr: &ruleRefExpr{ 843 pos: position{line: 149, col: 79, offset: 4450}, 844 name: "Identifier", 845 }, 846 }, 847 &zeroOrOneExpr{ 848 pos: position{line: 149, col: 90, offset: 4461}, 849 expr: &ruleRefExpr{ 850 pos: position{line: 149, col: 90, offset: 4461}, 851 name: "space", 852 }, 853 }, 854 &labeledExpr{ 855 pos: position{line: 149, col: 97, offset: 4468}, 856 label: "operation", 857 expr: &ruleRefExpr{ 858 pos: position{line: 149, col: 107, offset: 4478}, 859 name: "LetOpr", 860 }, 861 }, 862 &zeroOrOneExpr{ 863 pos: position{line: 150, col: 1, offset: 4486}, 864 expr: &ruleRefExpr{ 865 pos: position{line: 150, col: 1, offset: 4486}, 866 name: "space", 867 }, 868 }, 869 &labeledExpr{ 870 pos: position{line: 150, col: 8, offset: 4493}, 871 label: "rhs", 872 expr: &ruleRefExpr{ 873 pos: position{line: 150, col: 12, offset: 4497}, 874 name: "LetIdentifier", 875 }, 876 }, 877 &zeroOrOneExpr{ 878 pos: position{line: 150, col: 26, offset: 4511}, 879 expr: &ruleRefExpr{ 880 pos: position{line: 150, col: 26, offset: 4511}, 881 name: "space", 882 }, 883 }, 884 &zeroOrOneExpr{ 885 pos: position{line: 150, col: 33, offset: 4518}, 886 expr: &litMatcher{ 887 pos: position{line: 150, col: 33, offset: 4518}, 888 val: ")", 889 ignoreCase: false, 890 want: "\")\"", 891 }, 892 }, 893 }, 894 }, 895 }, 896 &actionExpr{ 897 pos: position{line: 162, col: 3, offset: 5216}, 898 run: (*parser).callonAggClause91, 899 expr: &seqExpr{ 900 pos: position{line: 162, col: 3, offset: 5216}, 901 exprs: []any{ 902 &ruleRefExpr{ 903 pos: position{line: 162, col: 3, offset: 5216}, 904 name: "opPipe", 905 }, 906 &zeroOrOneExpr{ 907 pos: position{line: 162, col: 10, offset: 5223}, 908 expr: &ruleRefExpr{ 909 pos: position{line: 162, col: 10, offset: 5223}, 910 name: "space", 911 }, 912 }, 913 &ruleRefExpr{ 914 pos: position{line: 162, col: 17, offset: 5230}, 915 name: "Let", 916 }, 917 &ruleRefExpr{ 918 pos: position{line: 162, col: 21, offset: 5234}, 919 name: "space", 920 }, 921 &labeledExpr{ 922 pos: position{line: 162, col: 27, offset: 5240}, 923 label: "newCol", 924 expr: &ruleRefExpr{ 925 pos: position{line: 162, col: 34, offset: 5247}, 926 name: "Identifier", 927 }, 928 }, 929 &zeroOrOneExpr{ 930 pos: position{line: 162, col: 45, offset: 5258}, 931 expr: &ruleRefExpr{ 932 pos: position{line: 162, col: 45, offset: 5258}, 933 name: "space", 934 }, 935 }, 936 &litMatcher{ 937 pos: position{line: 162, col: 52, offset: 5265}, 938 val: "=", 939 ignoreCase: false, 940 want: "\"=\"", 941 }, 942 &zeroOrOneExpr{ 943 pos: position{line: 162, col: 56, offset: 5269}, 944 expr: &ruleRefExpr{ 945 pos: position{line: 162, col: 56, offset: 5269}, 946 name: "space", 947 }, 948 }, 949 &zeroOrOneExpr{ 950 pos: position{line: 162, col: 63, offset: 5276}, 951 expr: &litMatcher{ 952 pos: position{line: 162, col: 63, offset: 5276}, 953 val: "(", 954 ignoreCase: false, 955 want: "\"(\"", 956 }, 957 }, 958 &zeroOrOneExpr{ 959 pos: position{line: 162, col: 68, offset: 5281}, 960 expr: &ruleRefExpr{ 961 pos: position{line: 162, col: 68, offset: 5281}, 962 name: "space", 963 }, 964 }, 965 &labeledExpr{ 966 pos: position{line: 162, col: 75, offset: 5288}, 967 label: "lhs", 968 expr: &ruleRefExpr{ 969 pos: position{line: 162, col: 79, offset: 5292}, 970 name: "Identifier", 971 }, 972 }, 973 &zeroOrOneExpr{ 974 pos: position{line: 162, col: 90, offset: 5303}, 975 expr: &ruleRefExpr{ 976 pos: position{line: 162, col: 90, offset: 5303}, 977 name: "space", 978 }, 979 }, 980 &labeledExpr{ 981 pos: position{line: 162, col: 97, offset: 5310}, 982 label: "operation", 983 expr: &ruleRefExpr{ 984 pos: position{line: 162, col: 107, offset: 5320}, 985 name: "LetOpr", 986 }, 987 }, 988 &zeroOrOneExpr{ 989 pos: position{line: 163, col: 1, offset: 5328}, 990 expr: &ruleRefExpr{ 991 pos: position{line: 163, col: 1, offset: 5328}, 992 name: "space", 993 }, 994 }, 995 &labeledExpr{ 996 pos: position{line: 163, col: 8, offset: 5335}, 997 label: "rhs", 998 expr: &ruleRefExpr{ 999 pos: position{line: 163, col: 12, offset: 5339}, 1000 name: "Identifier", 1001 }, 1002 }, 1003 &zeroOrOneExpr{ 1004 pos: position{line: 163, col: 23, offset: 5350}, 1005 expr: &ruleRefExpr{ 1006 pos: position{line: 163, col: 23, offset: 5350}, 1007 name: "space", 1008 }, 1009 }, 1010 &zeroOrOneExpr{ 1011 pos: position{line: 163, col: 30, offset: 5357}, 1012 expr: &litMatcher{ 1013 pos: position{line: 163, col: 30, offset: 5357}, 1014 val: ")", 1015 ignoreCase: false, 1016 want: "\")\"", 1017 }, 1018 }, 1019 }, 1020 }, 1021 }, 1022 }, 1023 }, 1024 }, 1025 { 1026 name: "MeasureAggsFunc", 1027 pos: position{line: 176, col: 1, offset: 6047}, 1028 expr: &actionExpr{ 1029 pos: position{line: 176, col: 20, offset: 6066}, 1030 run: (*parser).callonMeasureAggsFunc1, 1031 expr: &labeledExpr{ 1032 pos: position{line: 176, col: 20, offset: 6066}, 1033 label: "mfunc", 1034 expr: &choiceExpr{ 1035 pos: position{line: 176, col: 28, offset: 6074}, 1036 alternatives: []any{ 1037 &litMatcher{ 1038 pos: position{line: 176, col: 28, offset: 6074}, 1039 val: "avg", 1040 ignoreCase: false, 1041 want: "\"avg\"", 1042 }, 1043 &litMatcher{ 1044 pos: position{line: 176, col: 36, offset: 6082}, 1045 val: "min", 1046 ignoreCase: false, 1047 want: "\"min\"", 1048 }, 1049 &litMatcher{ 1050 pos: position{line: 176, col: 44, offset: 6090}, 1051 val: "max", 1052 ignoreCase: false, 1053 want: "\"max\"", 1054 }, 1055 &litMatcher{ 1056 pos: position{line: 176, col: 52, offset: 6098}, 1057 val: "sum", 1058 ignoreCase: false, 1059 want: "\"sum\"", 1060 }, 1061 &litMatcher{ 1062 pos: position{line: 176, col: 60, offset: 6106}, 1063 val: "cardinality", 1064 ignoreCase: false, 1065 want: "\"cardinality\"", 1066 }, 1067 &litMatcher{ 1068 pos: position{line: 176, col: 76, offset: 6122}, 1069 val: "count", 1070 ignoreCase: false, 1071 want: "\"count\"", 1072 }, 1073 }, 1074 }, 1075 }, 1076 }, 1077 }, 1078 { 1079 name: "Column", 1080 pos: position{line: 182, col: 1, offset: 6226}, 1081 expr: &litMatcher{ 1082 pos: position{line: 182, col: 11, offset: 6236}, 1083 val: "columns", 1084 ignoreCase: false, 1085 want: "\"columns\"", 1086 }, 1087 }, 1088 { 1089 name: "GroupBy", 1090 pos: position{line: 184, col: 1, offset: 6247}, 1091 expr: &litMatcher{ 1092 pos: position{line: 184, col: 12, offset: 6258}, 1093 val: "groupby", 1094 ignoreCase: false, 1095 want: "\"groupby\"", 1096 }, 1097 }, 1098 { 1099 name: "Let", 1100 pos: position{line: 186, col: 1, offset: 6269}, 1101 expr: &litMatcher{ 1102 pos: position{line: 186, col: 8, offset: 6276}, 1103 val: "let", 1104 ignoreCase: false, 1105 want: "\"let\"", 1106 }, 1107 }, 1108 { 1109 name: "LetOpr", 1110 pos: position{line: 188, col: 1, offset: 6283}, 1111 expr: &choiceExpr{ 1112 pos: position{line: 188, col: 11, offset: 6293}, 1113 alternatives: []any{ 1114 &actionExpr{ 1115 pos: position{line: 188, col: 11, offset: 6293}, 1116 run: (*parser).callonLetOpr2, 1117 expr: &seqExpr{ 1118 pos: position{line: 188, col: 11, offset: 6293}, 1119 exprs: []any{ 1120 &charClassMatcher{ 1121 pos: position{line: 188, col: 11, offset: 6293}, 1122 val: "[>]", 1123 chars: []rune{'>'}, 1124 ignoreCase: false, 1125 inverted: false, 1126 }, 1127 &litMatcher{ 1128 pos: position{line: 188, col: 15, offset: 6297}, 1129 val: "=", 1130 ignoreCase: false, 1131 want: "\"=\"", 1132 }, 1133 }, 1134 }, 1135 }, 1136 &actionExpr{ 1137 pos: position{line: 190, col: 5, offset: 6353}, 1138 run: (*parser).callonLetOpr6, 1139 expr: &litMatcher{ 1140 pos: position{line: 190, col: 5, offset: 6353}, 1141 val: ">", 1142 ignoreCase: false, 1143 want: "\">\"", 1144 }, 1145 }, 1146 &actionExpr{ 1147 pos: position{line: 192, col: 5, offset: 6400}, 1148 run: (*parser).callonLetOpr8, 1149 expr: &seqExpr{ 1150 pos: position{line: 192, col: 5, offset: 6400}, 1151 exprs: []any{ 1152 &charClassMatcher{ 1153 pos: position{line: 192, col: 5, offset: 6400}, 1154 val: "[<]", 1155 chars: []rune{'<'}, 1156 ignoreCase: false, 1157 inverted: false, 1158 }, 1159 &litMatcher{ 1160 pos: position{line: 192, col: 9, offset: 6404}, 1161 val: "=", 1162 ignoreCase: false, 1163 want: "\"=\"", 1164 }, 1165 }, 1166 }, 1167 }, 1168 &actionExpr{ 1169 pos: position{line: 194, col: 5, offset: 6457}, 1170 run: (*parser).callonLetOpr12, 1171 expr: &litMatcher{ 1172 pos: position{line: 194, col: 5, offset: 6457}, 1173 val: "<", 1174 ignoreCase: false, 1175 want: "\"<\"", 1176 }, 1177 }, 1178 &actionExpr{ 1179 pos: position{line: 196, col: 5, offset: 6501}, 1180 run: (*parser).callonLetOpr14, 1181 expr: &seqExpr{ 1182 pos: position{line: 196, col: 5, offset: 6501}, 1183 exprs: []any{ 1184 &charClassMatcher{ 1185 pos: position{line: 196, col: 5, offset: 6501}, 1186 val: "[=]", 1187 chars: []rune{'='}, 1188 ignoreCase: false, 1189 inverted: false, 1190 }, 1191 &litMatcher{ 1192 pos: position{line: 196, col: 9, offset: 6505}, 1193 val: "=", 1194 ignoreCase: false, 1195 want: "\"=\"", 1196 }, 1197 }, 1198 }, 1199 }, 1200 &actionExpr{ 1201 pos: position{line: 198, col: 5, offset: 6547}, 1202 run: (*parser).callonLetOpr18, 1203 expr: &seqExpr{ 1204 pos: position{line: 198, col: 5, offset: 6547}, 1205 exprs: []any{ 1206 &charClassMatcher{ 1207 pos: position{line: 198, col: 5, offset: 6547}, 1208 val: "[!]", 1209 chars: []rune{'!'}, 1210 ignoreCase: false, 1211 inverted: false, 1212 }, 1213 &litMatcher{ 1214 pos: position{line: 198, col: 9, offset: 6551}, 1215 val: "=", 1216 ignoreCase: false, 1217 want: "\"=\"", 1218 }, 1219 }, 1220 }, 1221 }, 1222 &actionExpr{ 1223 pos: position{line: 200, col: 5, offset: 6596}, 1224 run: (*parser).callonLetOpr22, 1225 expr: &litMatcher{ 1226 pos: position{line: 200, col: 5, offset: 6596}, 1227 val: "+", 1228 ignoreCase: false, 1229 want: "\"+\"", 1230 }, 1231 }, 1232 &actionExpr{ 1233 pos: position{line: 202, col: 5, offset: 6635}, 1234 run: (*parser).callonLetOpr24, 1235 expr: &litMatcher{ 1236 pos: position{line: 202, col: 5, offset: 6635}, 1237 val: "-", 1238 ignoreCase: false, 1239 want: "\"-\"", 1240 }, 1241 }, 1242 &actionExpr{ 1243 pos: position{line: 204, col: 5, offset: 6679}, 1244 run: (*parser).callonLetOpr26, 1245 expr: &litMatcher{ 1246 pos: position{line: 204, col: 5, offset: 6679}, 1247 val: "/", 1248 ignoreCase: false, 1249 want: "\"/\"", 1250 }, 1251 }, 1252 &actionExpr{ 1253 pos: position{line: 206, col: 5, offset: 6721}, 1254 run: (*parser).callonLetOpr28, 1255 expr: &litMatcher{ 1256 pos: position{line: 206, col: 5, offset: 6721}, 1257 val: "*", 1258 ignoreCase: false, 1259 want: "\"*\"", 1260 }, 1261 }, 1262 &actionExpr{ 1263 pos: position{line: 208, col: 5, offset: 6765}, 1264 run: (*parser).callonLetOpr30, 1265 expr: &litMatcher{ 1266 pos: position{line: 208, col: 5, offset: 6765}, 1267 val: "%", 1268 ignoreCase: false, 1269 want: "\"%\"", 1270 }, 1271 }, 1272 }, 1273 }, 1274 }, 1275 { 1276 name: "LetIdentifier", 1277 pos: position{line: 212, col: 1, offset: 6806}, 1278 expr: &choiceExpr{ 1279 pos: position{line: 212, col: 18, offset: 6823}, 1280 alternatives: []any{ 1281 &actionExpr{ 1282 pos: position{line: 212, col: 18, offset: 6823}, 1283 run: (*parser).callonLetIdentifier2, 1284 expr: &seqExpr{ 1285 pos: position{line: 212, col: 18, offset: 6823}, 1286 exprs: []any{ 1287 &zeroOrOneExpr{ 1288 pos: position{line: 212, col: 18, offset: 6823}, 1289 expr: &litMatcher{ 1290 pos: position{line: 212, col: 18, offset: 6823}, 1291 val: "-", 1292 ignoreCase: false, 1293 want: "\"-\"", 1294 }, 1295 }, 1296 &ruleRefExpr{ 1297 pos: position{line: 212, col: 23, offset: 6828}, 1298 name: "Float", 1299 }, 1300 }, 1301 }, 1302 }, 1303 &actionExpr{ 1304 pos: position{line: 218, col: 5, offset: 7023}, 1305 run: (*parser).callonLetIdentifier7, 1306 expr: &seqExpr{ 1307 pos: position{line: 218, col: 5, offset: 7023}, 1308 exprs: []any{ 1309 &oneOrMoreExpr{ 1310 pos: position{line: 218, col: 5, offset: 7023}, 1311 expr: &litMatcher{ 1312 pos: position{line: 218, col: 5, offset: 7023}, 1313 val: "-", 1314 ignoreCase: false, 1315 want: "\"-\"", 1316 }, 1317 }, 1318 &ruleRefExpr{ 1319 pos: position{line: 218, col: 10, offset: 7028}, 1320 name: "Integer", 1321 }, 1322 }, 1323 }, 1324 }, 1325 &actionExpr{ 1326 pos: position{line: 224, col: 6, offset: 7233}, 1327 run: (*parser).callonLetIdentifier12, 1328 expr: &ruleRefExpr{ 1329 pos: position{line: 224, col: 6, offset: 7233}, 1330 name: "Integer", 1331 }, 1332 }, 1333 &actionExpr{ 1334 pos: position{line: 230, col: 5, offset: 7442}, 1335 run: (*parser).callonLetIdentifier14, 1336 expr: &ruleRefExpr{ 1337 pos: position{line: 230, col: 5, offset: 7442}, 1338 name: "BoolValue", 1339 }, 1340 }, 1341 }, 1342 }, 1343 }, 1344 { 1345 name: "BoolValue", 1346 pos: position{line: 243, col: 1, offset: 7704}, 1347 expr: &choiceExpr{ 1348 pos: position{line: 243, col: 14, offset: 7717}, 1349 alternatives: []any{ 1350 &litMatcher{ 1351 pos: position{line: 243, col: 14, offset: 7717}, 1352 val: "false", 1353 ignoreCase: false, 1354 want: "\"false\"", 1355 }, 1356 &litMatcher{ 1357 pos: position{line: 243, col: 24, offset: 7727}, 1358 val: "true", 1359 ignoreCase: false, 1360 want: "\"true\"", 1361 }, 1362 }, 1363 }, 1364 }, 1365 { 1366 name: "Float", 1367 pos: position{line: 245, col: 1, offset: 7735}, 1368 expr: &seqExpr{ 1369 pos: position{line: 245, col: 10, offset: 7744}, 1370 exprs: []any{ 1371 &oneOrMoreExpr{ 1372 pos: position{line: 245, col: 10, offset: 7744}, 1373 expr: &charClassMatcher{ 1374 pos: position{line: 245, col: 10, offset: 7744}, 1375 val: "[0-9]", 1376 ranges: []rune{'0', '9'}, 1377 ignoreCase: false, 1378 inverted: false, 1379 }, 1380 }, 1381 &litMatcher{ 1382 pos: position{line: 245, col: 17, offset: 7751}, 1383 val: ".", 1384 ignoreCase: false, 1385 want: "\".\"", 1386 }, 1387 &oneOrMoreExpr{ 1388 pos: position{line: 245, col: 21, offset: 7755}, 1389 expr: &charClassMatcher{ 1390 pos: position{line: 245, col: 21, offset: 7755}, 1391 val: "[0-9]", 1392 ranges: []rune{'0', '9'}, 1393 ignoreCase: false, 1394 inverted: false, 1395 }, 1396 }, 1397 }, 1398 }, 1399 }, 1400 { 1401 name: "Integer", 1402 pos: position{line: 247, col: 1, offset: 7763}, 1403 expr: &oneOrMoreExpr{ 1404 pos: position{line: 247, col: 12, offset: 7774}, 1405 expr: &charClassMatcher{ 1406 pos: position{line: 247, col: 12, offset: 7774}, 1407 val: "[0-9]", 1408 ranges: []rune{'0', '9'}, 1409 ignoreCase: false, 1410 inverted: false, 1411 }, 1412 }, 1413 }, 1414 { 1415 name: "ColList", 1416 pos: position{line: 249, col: 1, offset: 7782}, 1417 expr: &actionExpr{ 1418 pos: position{line: 249, col: 13, offset: 7794}, 1419 run: (*parser).callonColList1, 1420 expr: &seqExpr{ 1421 pos: position{line: 249, col: 13, offset: 7794}, 1422 exprs: []any{ 1423 &zeroOrOneExpr{ 1424 pos: position{line: 249, col: 13, offset: 7794}, 1425 expr: &ruleRefExpr{ 1426 pos: position{line: 249, col: 13, offset: 7794}, 1427 name: "space", 1428 }, 1429 }, 1430 &labeledExpr{ 1431 pos: position{line: 249, col: 20, offset: 7801}, 1432 label: "first", 1433 expr: &ruleRefExpr{ 1434 pos: position{line: 249, col: 26, offset: 7807}, 1435 name: "Identifier", 1436 }, 1437 }, 1438 &labeledExpr{ 1439 pos: position{line: 249, col: 37, offset: 7818}, 1440 label: "rest", 1441 expr: &zeroOrMoreExpr{ 1442 pos: position{line: 249, col: 42, offset: 7823}, 1443 expr: &seqExpr{ 1444 pos: position{line: 249, col: 44, offset: 7825}, 1445 exprs: []any{ 1446 &zeroOrOneExpr{ 1447 pos: position{line: 249, col: 44, offset: 7825}, 1448 expr: &ruleRefExpr{ 1449 pos: position{line: 249, col: 44, offset: 7825}, 1450 name: "space", 1451 }, 1452 }, 1453 &litMatcher{ 1454 pos: position{line: 249, col: 51, offset: 7832}, 1455 val: ",", 1456 ignoreCase: false, 1457 want: "\",\"", 1458 }, 1459 &zeroOrOneExpr{ 1460 pos: position{line: 249, col: 55, offset: 7836}, 1461 expr: &ruleRefExpr{ 1462 pos: position{line: 249, col: 55, offset: 7836}, 1463 name: "space", 1464 }, 1465 }, 1466 &ruleRefExpr{ 1467 pos: position{line: 249, col: 62, offset: 7843}, 1468 name: "Identifier", 1469 }, 1470 }, 1471 }, 1472 }, 1473 }, 1474 &zeroOrOneExpr{ 1475 pos: position{line: 249, col: 76, offset: 7857}, 1476 expr: &ruleRefExpr{ 1477 pos: position{line: 249, col: 76, offset: 7857}, 1478 name: "space", 1479 }, 1480 }, 1481 }, 1482 }, 1483 }, 1484 }, 1485 { 1486 name: "AndClause", 1487 pos: position{line: 253, col: 1, offset: 7915}, 1488 expr: &choiceExpr{ 1489 pos: position{line: 253, col: 14, offset: 7928}, 1490 alternatives: []any{ 1491 &actionExpr{ 1492 pos: position{line: 253, col: 14, offset: 7928}, 1493 run: (*parser).callonAndClause2, 1494 expr: &seqExpr{ 1495 pos: position{line: 253, col: 14, offset: 7928}, 1496 exprs: []any{ 1497 &labeledExpr{ 1498 pos: position{line: 253, col: 14, offset: 7928}, 1499 label: "lhs", 1500 expr: &ruleRefExpr{ 1501 pos: position{line: 253, col: 18, offset: 7932}, 1502 name: "NotClause", 1503 }, 1504 }, 1505 &ruleRefExpr{ 1506 pos: position{line: 253, col: 28, offset: 7942}, 1507 name: "space", 1508 }, 1509 &ruleRefExpr{ 1510 pos: position{line: 253, col: 34, offset: 7948}, 1511 name: "logicalAND", 1512 }, 1513 &ruleRefExpr{ 1514 pos: position{line: 253, col: 45, offset: 7959}, 1515 name: "space", 1516 }, 1517 &labeledExpr{ 1518 pos: position{line: 253, col: 51, offset: 7965}, 1519 label: "rhs", 1520 expr: &ruleRefExpr{ 1521 pos: position{line: 253, col: 55, offset: 7969}, 1522 name: "AndClause", 1523 }, 1524 }, 1525 }, 1526 }, 1527 }, 1528 &ruleRefExpr{ 1529 pos: position{line: 259, col: 5, offset: 8113}, 1530 name: "NotClause", 1531 }, 1532 }, 1533 }, 1534 }, 1535 { 1536 name: "NotClause", 1537 pos: position{line: 261, col: 1, offset: 8124}, 1538 expr: &choiceExpr{ 1539 pos: position{line: 261, col: 14, offset: 8137}, 1540 alternatives: []any{ 1541 &actionExpr{ 1542 pos: position{line: 261, col: 14, offset: 8137}, 1543 run: (*parser).callonNotClause2, 1544 expr: &seqExpr{ 1545 pos: position{line: 261, col: 14, offset: 8137}, 1546 exprs: []any{ 1547 &ruleRefExpr{ 1548 pos: position{line: 261, col: 14, offset: 8137}, 1549 name: "logicalNOT", 1550 }, 1551 &labeledExpr{ 1552 pos: position{line: 261, col: 25, offset: 8148}, 1553 label: "cmp", 1554 expr: &ruleRefExpr{ 1555 pos: position{line: 261, col: 29, offset: 8152}, 1556 name: "Comparison", 1557 }, 1558 }, 1559 }, 1560 }, 1561 }, 1562 &ruleRefExpr{ 1563 pos: position{line: 267, col: 5, offset: 8285}, 1564 name: "Comparison", 1565 }, 1566 }, 1567 }, 1568 }, 1569 { 1570 name: "Comparison", 1571 pos: position{line: 269, col: 1, offset: 8297}, 1572 expr: &choiceExpr{ 1573 pos: position{line: 269, col: 15, offset: 8311}, 1574 alternatives: []any{ 1575 &actionExpr{ 1576 pos: position{line: 269, col: 15, offset: 8311}, 1577 run: (*parser).callonComparison2, 1578 expr: &seqExpr{ 1579 pos: position{line: 269, col: 15, offset: 8311}, 1580 exprs: []any{ 1581 &litMatcher{ 1582 pos: position{line: 269, col: 15, offset: 8311}, 1583 val: "(", 1584 ignoreCase: false, 1585 want: "\"(\"", 1586 }, 1587 &zeroOrOneExpr{ 1588 pos: position{line: 269, col: 19, offset: 8315}, 1589 expr: &ruleRefExpr{ 1590 pos: position{line: 269, col: 19, offset: 8315}, 1591 name: "space", 1592 }, 1593 }, 1594 &labeledExpr{ 1595 pos: position{line: 269, col: 26, offset: 8322}, 1596 label: "query", 1597 expr: &ruleRefExpr{ 1598 pos: position{line: 269, col: 32, offset: 8328}, 1599 name: "OrClause", 1600 }, 1601 }, 1602 &zeroOrOneExpr{ 1603 pos: position{line: 269, col: 41, offset: 8337}, 1604 expr: &ruleRefExpr{ 1605 pos: position{line: 269, col: 41, offset: 8337}, 1606 name: "space", 1607 }, 1608 }, 1609 &litMatcher{ 1610 pos: position{line: 269, col: 48, offset: 8344}, 1611 val: ")", 1612 ignoreCase: false, 1613 want: "\")\"", 1614 }, 1615 }, 1616 }, 1617 }, 1618 &actionExpr{ 1619 pos: position{line: 271, col: 6, offset: 8376}, 1620 run: (*parser).callonComparison12, 1621 expr: &seqExpr{ 1622 pos: position{line: 271, col: 6, offset: 8376}, 1623 exprs: []any{ 1624 &labeledExpr{ 1625 pos: position{line: 271, col: 6, offset: 8376}, 1626 label: "field", 1627 expr: &ruleRefExpr{ 1628 pos: position{line: 271, col: 12, offset: 8382}, 1629 name: "Field", 1630 }, 1631 }, 1632 &zeroOrOneExpr{ 1633 pos: position{line: 271, col: 18, offset: 8388}, 1634 expr: &ruleRefExpr{ 1635 pos: position{line: 271, col: 18, offset: 8388}, 1636 name: "space", 1637 }, 1638 }, 1639 &labeledExpr{ 1640 pos: position{line: 271, col: 26, offset: 8396}, 1641 label: "operation", 1642 expr: &ruleRefExpr{ 1643 pos: position{line: 271, col: 36, offset: 8406}, 1644 name: "opCOMP", 1645 }, 1646 }, 1647 &zeroOrOneExpr{ 1648 pos: position{line: 271, col: 43, offset: 8413}, 1649 expr: &ruleRefExpr{ 1650 pos: position{line: 271, col: 43, offset: 8413}, 1651 name: "space", 1652 }, 1653 }, 1654 &labeledExpr{ 1655 pos: position{line: 271, col: 50, offset: 8420}, 1656 label: "field1", 1657 expr: &ruleRefExpr{ 1658 pos: position{line: 271, col: 57, offset: 8427}, 1659 name: "Field", 1660 }, 1661 }, 1662 }, 1663 }, 1664 }, 1665 &actionExpr{ 1666 pos: position{line: 286, col: 5, offset: 8776}, 1667 run: (*parser).callonComparison24, 1668 expr: &labeledExpr{ 1669 pos: position{line: 286, col: 5, offset: 8776}, 1670 label: "values", 1671 expr: &ruleRefExpr{ 1672 pos: position{line: 286, col: 12, offset: 8783}, 1673 name: "ValueList", 1674 }, 1675 }, 1676 }, 1677 &actionExpr{ 1678 pos: position{line: 295, col: 5, offset: 8987}, 1679 run: (*parser).callonComparison27, 1680 expr: &labeledExpr{ 1681 pos: position{line: 295, col: 5, offset: 8987}, 1682 label: "field", 1683 expr: &ruleRefExpr{ 1684 pos: position{line: 295, col: 11, offset: 8993}, 1685 name: "Field", 1686 }, 1687 }, 1688 }, 1689 }, 1690 }, 1691 }, 1692 { 1693 name: "Field", 1694 pos: position{line: 310, col: 1, offset: 9214}, 1695 expr: &choiceExpr{ 1696 pos: position{line: 310, col: 10, offset: 9223}, 1697 alternatives: []any{ 1698 &ruleRefExpr{ 1699 pos: position{line: 310, col: 10, offset: 9223}, 1700 name: "Value", 1701 }, 1702 &actionExpr{ 1703 pos: position{line: 310, col: 18, offset: 9231}, 1704 run: (*parser).callonField3, 1705 expr: &labeledExpr{ 1706 pos: position{line: 310, col: 18, offset: 9231}, 1707 label: "pieces", 1708 expr: &seqExpr{ 1709 pos: position{line: 310, col: 26, offset: 9239}, 1710 exprs: []any{ 1711 &ruleRefExpr{ 1712 pos: position{line: 310, col: 26, offset: 9239}, 1713 name: "FieldPiece", 1714 }, 1715 &zeroOrMoreExpr{ 1716 pos: position{line: 310, col: 37, offset: 9250}, 1717 expr: &seqExpr{ 1718 pos: position{line: 310, col: 38, offset: 9251}, 1719 exprs: []any{ 1720 &litMatcher{ 1721 pos: position{line: 310, col: 38, offset: 9251}, 1722 val: ".", 1723 ignoreCase: false, 1724 want: "\".\"", 1725 }, 1726 &ruleRefExpr{ 1727 pos: position{line: 310, col: 42, offset: 9255}, 1728 name: "FieldPiece", 1729 }, 1730 }, 1731 }, 1732 }, 1733 }, 1734 }, 1735 }, 1736 }, 1737 }, 1738 }, 1739 }, 1740 { 1741 name: "FieldPiece", 1742 pos: position{line: 318, col: 1, offset: 9350}, 1743 expr: &choiceExpr{ 1744 pos: position{line: 318, col: 15, offset: 9364}, 1745 alternatives: []any{ 1746 &ruleRefExpr{ 1747 pos: position{line: 318, col: 15, offset: 9364}, 1748 name: "QuotedFieldPiece", 1749 }, 1750 &ruleRefExpr{ 1751 pos: position{line: 318, col: 34, offset: 9383}, 1752 name: "UnquotedFieldPiece", 1753 }, 1754 &ruleRefExpr{ 1755 pos: position{line: 318, col: 55, offset: 9404}, 1756 name: "Star", 1757 }, 1758 }, 1759 }, 1760 }, 1761 { 1762 name: "UnquotedFieldPiece", 1763 pos: position{line: 320, col: 1, offset: 9410}, 1764 expr: &actionExpr{ 1765 pos: position{line: 320, col: 23, offset: 9432}, 1766 run: (*parser).callonUnquotedFieldPiece1, 1767 expr: &oneOrMoreExpr{ 1768 pos: position{line: 320, col: 23, offset: 9432}, 1769 expr: &charClassMatcher{ 1770 pos: position{line: 320, col: 23, offset: 9432}, 1771 val: "[-a-zA-Z0-9$&,?#%_@;[\\]{}+-./*:]i", 1772 chars: []rune{'-', '$', '&', ',', '?', '#', '%', '_', '@', ';', '[', ']', '{', '}', '/', '*', ':'}, 1773 ranges: []rune{'a', 'z', 'a', 'z', '0', '9', '+', '.'}, 1774 ignoreCase: true, 1775 inverted: false, 1776 }, 1777 }, 1778 }, 1779 }, 1780 { 1781 name: "QuotedFieldPiece", 1782 pos: position{line: 325, col: 1, offset: 9504}, 1783 expr: &ruleRefExpr{ 1784 pos: position{line: 325, col: 21, offset: 9524}, 1785 name: "QuotedValue", 1786 }, 1787 }, 1788 { 1789 name: "Star", 1790 pos: position{line: 327, col: 1, offset: 9537}, 1791 expr: &actionExpr{ 1792 pos: position{line: 327, col: 9, offset: 9545}, 1793 run: (*parser).callonStar1, 1794 expr: &litMatcher{ 1795 pos: position{line: 327, col: 9, offset: 9545}, 1796 val: "*", 1797 ignoreCase: false, 1798 want: "\"*\"", 1799 }, 1800 }, 1801 }, 1802 { 1803 name: "QuotedValue", 1804 pos: position{line: 330, col: 1, offset: 9573}, 1805 expr: &actionExpr{ 1806 pos: position{line: 330, col: 16, offset: 9588}, 1807 run: (*parser).callonQuotedValue1, 1808 expr: &seqExpr{ 1809 pos: position{line: 330, col: 16, offset: 9588}, 1810 exprs: []any{ 1811 &litMatcher{ 1812 pos: position{line: 330, col: 16, offset: 9588}, 1813 val: "\"", 1814 ignoreCase: false, 1815 want: "\"\\\"\"", 1816 }, 1817 &zeroOrMoreExpr{ 1818 pos: position{line: 330, col: 20, offset: 9592}, 1819 expr: &choiceExpr{ 1820 pos: position{line: 330, col: 22, offset: 9594}, 1821 alternatives: []any{ 1822 &seqExpr{ 1823 pos: position{line: 330, col: 22, offset: 9594}, 1824 exprs: []any{ 1825 ¬Expr{ 1826 pos: position{line: 330, col: 22, offset: 9594}, 1827 expr: &ruleRefExpr{ 1828 pos: position{line: 330, col: 23, offset: 9595}, 1829 name: "EscapedChar", 1830 }, 1831 }, 1832 &anyMatcher{ 1833 line: 330, col: 35, offset: 9607, 1834 }, 1835 }, 1836 }, 1837 &seqExpr{ 1838 pos: position{line: 330, col: 39, offset: 9611}, 1839 exprs: []any{ 1840 &litMatcher{ 1841 pos: position{line: 330, col: 39, offset: 9611}, 1842 val: "\\", 1843 ignoreCase: false, 1844 want: "\"\\\\\"", 1845 }, 1846 &ruleRefExpr{ 1847 pos: position{line: 330, col: 44, offset: 9616}, 1848 name: "EscapeSequence", 1849 }, 1850 }, 1851 }, 1852 }, 1853 }, 1854 }, 1855 &litMatcher{ 1856 pos: position{line: 330, col: 62, offset: 9634}, 1857 val: "\"", 1858 ignoreCase: false, 1859 want: "\"\\\"\"", 1860 }, 1861 }, 1862 }, 1863 }, 1864 }, 1865 { 1866 name: "EscapedChar", 1867 pos: position{line: 334, col: 1, offset: 9751}, 1868 expr: &charClassMatcher{ 1869 pos: position{line: 334, col: 16, offset: 9766}, 1870 val: "[\\x00-\\x1f\"\\\\]", 1871 chars: []rune{'"', '\\'}, 1872 ranges: []rune{'\x00', '\x1f'}, 1873 ignoreCase: false, 1874 inverted: false, 1875 }, 1876 }, 1877 { 1878 name: "EscapeSequence", 1879 pos: position{line: 336, col: 1, offset: 9782}, 1880 expr: &choiceExpr{ 1881 pos: position{line: 336, col: 19, offset: 9800}, 1882 alternatives: []any{ 1883 &ruleRefExpr{ 1884 pos: position{line: 336, col: 19, offset: 9800}, 1885 name: "SingleCharEscape", 1886 }, 1887 &ruleRefExpr{ 1888 pos: position{line: 336, col: 38, offset: 9819}, 1889 name: "UnicodeEscape", 1890 }, 1891 }, 1892 }, 1893 }, 1894 { 1895 name: "SingleCharEscape", 1896 pos: position{line: 338, col: 1, offset: 9834}, 1897 expr: &charClassMatcher{ 1898 pos: position{line: 338, col: 21, offset: 9854}, 1899 val: "[\"\\\\/bfnrt]", 1900 chars: []rune{'"', '\\', '/', 'b', 'f', 'n', 'r', 't'}, 1901 ignoreCase: false, 1902 inverted: false, 1903 }, 1904 }, 1905 { 1906 name: "UnicodeEscape", 1907 pos: position{line: 340, col: 1, offset: 9867}, 1908 expr: &seqExpr{ 1909 pos: position{line: 340, col: 18, offset: 9884}, 1910 exprs: []any{ 1911 &litMatcher{ 1912 pos: position{line: 340, col: 18, offset: 9884}, 1913 val: "u", 1914 ignoreCase: false, 1915 want: "\"u\"", 1916 }, 1917 &ruleRefExpr{ 1918 pos: position{line: 340, col: 22, offset: 9888}, 1919 name: "HexDigit", 1920 }, 1921 &ruleRefExpr{ 1922 pos: position{line: 340, col: 31, offset: 9897}, 1923 name: "HexDigit", 1924 }, 1925 &ruleRefExpr{ 1926 pos: position{line: 340, col: 40, offset: 9906}, 1927 name: "HexDigit", 1928 }, 1929 &ruleRefExpr{ 1930 pos: position{line: 340, col: 49, offset: 9915}, 1931 name: "HexDigit", 1932 }, 1933 }, 1934 }, 1935 }, 1936 { 1937 name: "HexDigit", 1938 pos: position{line: 342, col: 1, offset: 9925}, 1939 expr: &charClassMatcher{ 1940 pos: position{line: 342, col: 13, offset: 9937}, 1941 val: "[0-9a-f]i", 1942 ranges: []rune{'0', '9', 'a', 'f'}, 1943 ignoreCase: true, 1944 inverted: false, 1945 }, 1946 }, 1947 { 1948 name: "ValueList", 1949 pos: position{line: 348, col: 1, offset: 9971}, 1950 expr: &choiceExpr{ 1951 pos: position{line: 348, col: 14, offset: 9984}, 1952 alternatives: []any{ 1953 &actionExpr{ 1954 pos: position{line: 348, col: 14, offset: 9984}, 1955 run: (*parser).callonValueList2, 1956 expr: &seqExpr{ 1957 pos: position{line: 348, col: 14, offset: 9984}, 1958 exprs: []any{ 1959 &litMatcher{ 1960 pos: position{line: 348, col: 14, offset: 9984}, 1961 val: "[", 1962 ignoreCase: false, 1963 want: "\"[\"", 1964 }, 1965 &zeroOrOneExpr{ 1966 pos: position{line: 348, col: 18, offset: 9988}, 1967 expr: &ruleRefExpr{ 1968 pos: position{line: 348, col: 18, offset: 9988}, 1969 name: "space", 1970 }, 1971 }, 1972 &labeledExpr{ 1973 pos: position{line: 348, col: 25, offset: 9995}, 1974 label: "first", 1975 expr: &ruleRefExpr{ 1976 pos: position{line: 348, col: 31, offset: 10001}, 1977 name: "Value", 1978 }, 1979 }, 1980 &labeledExpr{ 1981 pos: position{line: 348, col: 37, offset: 10007}, 1982 label: "rest", 1983 expr: &zeroOrMoreExpr{ 1984 pos: position{line: 348, col: 42, offset: 10012}, 1985 expr: &seqExpr{ 1986 pos: position{line: 348, col: 44, offset: 10014}, 1987 exprs: []any{ 1988 &zeroOrOneExpr{ 1989 pos: position{line: 348, col: 44, offset: 10014}, 1990 expr: &ruleRefExpr{ 1991 pos: position{line: 348, col: 44, offset: 10014}, 1992 name: "space", 1993 }, 1994 }, 1995 &litMatcher{ 1996 pos: position{line: 348, col: 51, offset: 10021}, 1997 val: ",", 1998 ignoreCase: false, 1999 want: "\",\"", 2000 }, 2001 &zeroOrOneExpr{ 2002 pos: position{line: 348, col: 55, offset: 10025}, 2003 expr: &ruleRefExpr{ 2004 pos: position{line: 348, col: 55, offset: 10025}, 2005 name: "space", 2006 }, 2007 }, 2008 &ruleRefExpr{ 2009 pos: position{line: 348, col: 62, offset: 10032}, 2010 name: "Value", 2011 }, 2012 }, 2013 }, 2014 }, 2015 }, 2016 &zeroOrOneExpr{ 2017 pos: position{line: 348, col: 71, offset: 10041}, 2018 expr: &ruleRefExpr{ 2019 pos: position{line: 348, col: 71, offset: 10041}, 2020 name: "space", 2021 }, 2022 }, 2023 &litMatcher{ 2024 pos: position{line: 348, col: 78, offset: 10048}, 2025 val: "]", 2026 ignoreCase: false, 2027 want: "\"]\"", 2028 }, 2029 }, 2030 }, 2031 }, 2032 &labeledExpr{ 2033 pos: position{line: 350, col: 5, offset: 10104}, 2034 label: "value", 2035 expr: &ruleRefExpr{ 2036 pos: position{line: 350, col: 11, offset: 10110}, 2037 name: "Value", 2038 }, 2039 }, 2040 }, 2041 }, 2042 }, 2043 { 2044 name: "Value", 2045 pos: position{line: 352, col: 1, offset: 10118}, 2046 expr: &actionExpr{ 2047 pos: position{line: 352, col: 10, offset: 10127}, 2048 run: (*parser).callonValue1, 2049 expr: &labeledExpr{ 2050 pos: position{line: 352, col: 10, offset: 10127}, 2051 label: "val", 2052 expr: &choiceExpr{ 2053 pos: position{line: 353, col: 5, offset: 10137}, 2054 alternatives: []any{ 2055 &ruleRefExpr{ 2056 pos: position{line: 353, col: 5, offset: 10137}, 2057 name: "Float", 2058 }, 2059 &ruleRefExpr{ 2060 pos: position{line: 354, col: 7, offset: 10149}, 2061 name: "Integer", 2062 }, 2063 }, 2064 }, 2065 }, 2066 }, 2067 }, 2068 { 2069 name: "String", 2070 pos: position{line: 360, col: 1, offset: 10204}, 2071 expr: &actionExpr{ 2072 pos: position{line: 361, col: 5, offset: 10215}, 2073 run: (*parser).callonString1, 2074 expr: &seqExpr{ 2075 pos: position{line: 361, col: 5, offset: 10215}, 2076 exprs: []any{ 2077 &litMatcher{ 2078 pos: position{line: 361, col: 5, offset: 10215}, 2079 val: "\"", 2080 ignoreCase: false, 2081 want: "\"\\\"\"", 2082 }, 2083 &labeledExpr{ 2084 pos: position{line: 361, col: 9, offset: 10219}, 2085 label: "chars", 2086 expr: &zeroOrMoreExpr{ 2087 pos: position{line: 361, col: 15, offset: 10225}, 2088 expr: &charClassMatcher{ 2089 pos: position{line: 361, col: 15, offset: 10225}, 2090 val: "[^\"]", 2091 chars: []rune{'"'}, 2092 ignoreCase: false, 2093 inverted: true, 2094 }, 2095 }, 2096 }, 2097 &litMatcher{ 2098 pos: position{line: 361, col: 21, offset: 10231}, 2099 val: "\"", 2100 ignoreCase: false, 2101 want: "\"\\\"\"", 2102 }, 2103 }, 2104 }, 2105 }, 2106 }, 2107 { 2108 name: "Integer", 2109 pos: position{line: 365, col: 1, offset: 10286}, 2110 expr: &actionExpr{ 2111 pos: position{line: 365, col: 12, offset: 10297}, 2112 run: (*parser).callonInteger1, 2113 expr: &seqExpr{ 2114 pos: position{line: 365, col: 12, offset: 10297}, 2115 exprs: []any{ 2116 &zeroOrOneExpr{ 2117 pos: position{line: 365, col: 12, offset: 10297}, 2118 expr: &charClassMatcher{ 2119 pos: position{line: 365, col: 12, offset: 10297}, 2120 val: "[+-]", 2121 chars: []rune{'+', '-'}, 2122 ignoreCase: false, 2123 inverted: false, 2124 }, 2125 }, 2126 &oneOrMoreExpr{ 2127 pos: position{line: 365, col: 18, offset: 10303}, 2128 expr: &charClassMatcher{ 2129 pos: position{line: 365, col: 18, offset: 10303}, 2130 val: "[0-9]", 2131 ranges: []rune{'0', '9'}, 2132 ignoreCase: false, 2133 inverted: false, 2134 }, 2135 }, 2136 }, 2137 }, 2138 }, 2139 }, 2140 { 2141 name: "Float", 2142 pos: position{line: 369, col: 1, offset: 10361}, 2143 expr: &actionExpr{ 2144 pos: position{line: 369, col: 10, offset: 10370}, 2145 run: (*parser).callonFloat1, 2146 expr: &seqExpr{ 2147 pos: position{line: 369, col: 10, offset: 10370}, 2148 exprs: []any{ 2149 &zeroOrOneExpr{ 2150 pos: position{line: 369, col: 10, offset: 10370}, 2151 expr: &charClassMatcher{ 2152 pos: position{line: 369, col: 10, offset: 10370}, 2153 val: "[+-]", 2154 chars: []rune{'+', '-'}, 2155 ignoreCase: false, 2156 inverted: false, 2157 }, 2158 }, 2159 &seqExpr{ 2160 pos: position{line: 369, col: 17, offset: 10377}, 2161 exprs: []any{ 2162 &zeroOrMoreExpr{ 2163 pos: position{line: 369, col: 17, offset: 10377}, 2164 expr: &charClassMatcher{ 2165 pos: position{line: 369, col: 17, offset: 10377}, 2166 val: "[0-9]", 2167 ranges: []rune{'0', '9'}, 2168 ignoreCase: false, 2169 inverted: false, 2170 }, 2171 }, 2172 &litMatcher{ 2173 pos: position{line: 369, col: 24, offset: 10384}, 2174 val: ".", 2175 ignoreCase: false, 2176 want: "\".\"", 2177 }, 2178 &oneOrMoreExpr{ 2179 pos: position{line: 369, col: 28, offset: 10388}, 2180 expr: &charClassMatcher{ 2181 pos: position{line: 369, col: 28, offset: 10388}, 2182 val: "[0-9]", 2183 ranges: []rune{'0', '9'}, 2184 ignoreCase: false, 2185 inverted: false, 2186 }, 2187 }, 2188 }, 2189 }, 2190 }, 2191 }, 2192 }, 2193 }, 2194 { 2195 name: "Identifier", 2196 pos: position{line: 374, col: 1, offset: 10453}, 2197 expr: &actionExpr{ 2198 pos: position{line: 375, col: 4, offset: 10470}, 2199 run: (*parser).callonIdentifier1, 2200 expr: &oneOrMoreExpr{ 2201 pos: position{line: 375, col: 4, offset: 10470}, 2202 expr: &charClassMatcher{ 2203 pos: position{line: 375, col: 4, offset: 10470}, 2204 val: "[a-zA-Z0-9_@./*]i", 2205 chars: []rune{'_', '@', '.', '/', '*'}, 2206 ranges: []rune{'a', 'z', 'a', 'z', '0', '9'}, 2207 ignoreCase: true, 2208 inverted: false, 2209 }, 2210 }, 2211 }, 2212 }, 2213 { 2214 name: "opPipe", 2215 pos: position{line: 380, col: 1, offset: 10529}, 2216 expr: &litMatcher{ 2217 pos: position{line: 380, col: 11, offset: 10539}, 2218 val: "|", 2219 ignoreCase: false, 2220 want: "\"|\"", 2221 }, 2222 }, 2223 { 2224 name: "logicalOR", 2225 pos: position{line: 386, col: 1, offset: 10601}, 2226 expr: &litMatcher{ 2227 pos: position{line: 386, col: 14, offset: 10614}, 2228 val: "OR", 2229 ignoreCase: false, 2230 want: "\"OR\"", 2231 }, 2232 }, 2233 { 2234 name: "logicalAND", 2235 pos: position{line: 388, col: 1, offset: 10620}, 2236 expr: &litMatcher{ 2237 pos: position{line: 388, col: 15, offset: 10634}, 2238 val: "AND", 2239 ignoreCase: false, 2240 want: "\"AND\"", 2241 }, 2242 }, 2243 { 2244 name: "logicalNOT", 2245 pos: position{line: 390, col: 1, offset: 10641}, 2246 expr: &choiceExpr{ 2247 pos: position{line: 390, col: 15, offset: 10655}, 2248 alternatives: []any{ 2249 &seqExpr{ 2250 pos: position{line: 390, col: 15, offset: 10655}, 2251 exprs: []any{ 2252 &litMatcher{ 2253 pos: position{line: 390, col: 15, offset: 10655}, 2254 val: "NOT", 2255 ignoreCase: false, 2256 want: "\"NOT\"", 2257 }, 2258 &ruleRefExpr{ 2259 pos: position{line: 390, col: 21, offset: 10661}, 2260 name: "space", 2261 }, 2262 }, 2263 }, 2264 &seqExpr{ 2265 pos: position{line: 390, col: 29, offset: 10669}, 2266 exprs: []any{ 2267 &litMatcher{ 2268 pos: position{line: 390, col: 29, offset: 10669}, 2269 val: "!", 2270 ignoreCase: false, 2271 want: "\"!\"", 2272 }, 2273 &zeroOrOneExpr{ 2274 pos: position{line: 390, col: 33, offset: 10673}, 2275 expr: &ruleRefExpr{ 2276 pos: position{line: 390, col: 33, offset: 10673}, 2277 name: "space", 2278 }, 2279 }, 2280 }, 2281 }, 2282 }, 2283 }, 2284 }, 2285 { 2286 name: "opCOMP", 2287 pos: position{line: 398, col: 1, offset: 10748}, 2288 expr: &choiceExpr{ 2289 pos: position{line: 398, col: 11, offset: 10758}, 2290 alternatives: []any{ 2291 &ruleRefExpr{ 2292 pos: position{line: 398, col: 11, offset: 10758}, 2293 name: "opCustom", 2294 }, 2295 &actionExpr{ 2296 pos: position{line: 399, col: 3, offset: 10769}, 2297 run: (*parser).callonopCOMP3, 2298 expr: &litMatcher{ 2299 pos: position{line: 399, col: 3, offset: 10769}, 2300 val: "<=", 2301 ignoreCase: false, 2302 want: "\"<=\"", 2303 }, 2304 }, 2305 &actionExpr{ 2306 pos: position{line: 401, col: 5, offset: 10811}, 2307 run: (*parser).callonopCOMP5, 2308 expr: &litMatcher{ 2309 pos: position{line: 401, col: 5, offset: 10811}, 2310 val: ">=", 2311 ignoreCase: false, 2312 want: "\">=\"", 2313 }, 2314 }, 2315 &actionExpr{ 2316 pos: position{line: 403, col: 5, offset: 10853}, 2317 run: (*parser).callonopCOMP7, 2318 expr: &litMatcher{ 2319 pos: position{line: 403, col: 5, offset: 10853}, 2320 val: "=", 2321 ignoreCase: false, 2322 want: "\"=\"", 2323 }, 2324 }, 2325 &actionExpr{ 2326 pos: position{line: 405, col: 5, offset: 10894}, 2327 run: (*parser).callonopCOMP9, 2328 expr: &litMatcher{ 2329 pos: position{line: 405, col: 5, offset: 10894}, 2330 val: "<", 2331 ignoreCase: false, 2332 want: "\"<\"", 2333 }, 2334 }, 2335 &actionExpr{ 2336 pos: position{line: 407, col: 5, offset: 10935}, 2337 run: (*parser).callonopCOMP11, 2338 expr: &litMatcher{ 2339 pos: position{line: 407, col: 5, offset: 10935}, 2340 val: ">", 2341 ignoreCase: false, 2342 want: "\">\"", 2343 }, 2344 }, 2345 &actionExpr{ 2346 pos: position{line: 409, col: 5, offset: 10976}, 2347 run: (*parser).callonopCOMP13, 2348 expr: &litMatcher{ 2349 pos: position{line: 409, col: 5, offset: 10976}, 2350 val: "!=", 2351 ignoreCase: false, 2352 want: "\"!=\"", 2353 }, 2354 }, 2355 }, 2356 }, 2357 }, 2358 { 2359 name: "opCustom", 2360 pos: position{line: 414, col: 1, offset: 11020}, 2361 expr: &actionExpr{ 2362 pos: position{line: 414, col: 13, offset: 11032}, 2363 run: (*parser).callonopCustom1, 2364 expr: &seqExpr{ 2365 pos: position{line: 414, col: 13, offset: 11032}, 2366 exprs: []any{ 2367 &litMatcher{ 2368 pos: position{line: 414, col: 13, offset: 11032}, 2369 val: "=", 2370 ignoreCase: false, 2371 want: "\"=\"", 2372 }, 2373 &labeledExpr{ 2374 pos: position{line: 414, col: 17, offset: 11036}, 2375 label: "opname", 2376 expr: &oneOrMoreExpr{ 2377 pos: position{line: 414, col: 24, offset: 11043}, 2378 expr: &charClassMatcher{ 2379 pos: position{line: 414, col: 24, offset: 11043}, 2380 val: "[a-z]i", 2381 ranges: []rune{'a', 'z'}, 2382 ignoreCase: true, 2383 inverted: false, 2384 }, 2385 }, 2386 }, 2387 &litMatcher{ 2388 pos: position{line: 414, col: 32, offset: 11051}, 2389 val: "=", 2390 ignoreCase: false, 2391 want: "\"=\"", 2392 }, 2393 }, 2394 }, 2395 }, 2396 }, 2397 { 2398 name: "_", 2399 displayName: "\"whitespace\"", 2400 pos: position{line: 422, col: 1, offset: 11171}, 2401 expr: &zeroOrMoreExpr{ 2402 pos: position{line: 422, col: 19, offset: 11189}, 2403 expr: &charClassMatcher{ 2404 pos: position{line: 422, col: 19, offset: 11189}, 2405 val: "[ \\n\\t\\r]", 2406 chars: []rune{' ', '\n', '\t', '\r'}, 2407 ignoreCase: false, 2408 inverted: false, 2409 }, 2410 }, 2411 }, 2412 { 2413 name: "space", 2414 pos: position{line: 424, col: 1, offset: 11201}, 2415 expr: &oneOrMoreExpr{ 2416 pos: position{line: 424, col: 10, offset: 11210}, 2417 expr: &charClassMatcher{ 2418 pos: position{line: 424, col: 10, offset: 11210}, 2419 val: "[ \\n\\t\\r]", 2420 chars: []rune{' ', '\n', '\t', '\r'}, 2421 ignoreCase: false, 2422 inverted: false, 2423 }, 2424 }, 2425 }, 2426 { 2427 name: "EOL", 2428 pos: position{line: 426, col: 1, offset: 11222}, 2429 expr: &litMatcher{ 2430 pos: position{line: 426, col: 8, offset: 11229}, 2431 val: "\n", 2432 ignoreCase: false, 2433 want: "\"\\n\"", 2434 }, 2435 }, 2436 { 2437 name: "EOF", 2438 pos: position{line: 428, col: 1, offset: 11235}, 2439 expr: ¬Expr{ 2440 pos: position{line: 428, col: 7, offset: 11241}, 2441 expr: &anyMatcher{ 2442 line: 428, col: 8, offset: 11242, 2443 }, 2444 }, 2445 }, 2446 }, 2447 } 2448 2449 func (c *current) onStart2(maggs any) (any, error) { 2450 var q ast.QueryStruct 2451 if maggs != nil { 2452 q.PipeCommands = maggs.(*structs.QueryAggregators) 2453 } 2454 return q, nil 2455 } 2456 2457 func (p *parser) callonStart2() (any, error) { 2458 stack := p.vstack[len(p.vstack)-1] 2459 _ = stack 2460 return p.cur.onStart2(stack["maggs"]) 2461 } 2462 2463 func (c *current) onStart8(groupBy, lim any) (any, error) { 2464 var q ast.QueryStruct 2465 if groupBy != nil { 2466 q.PipeCommands = groupBy.(*structs.QueryAggregators) 2467 q.PipeCommands.BucketLimit = groupBy.(*structs.QueryAggregators).BucketLimit 2468 } 2469 return q, nil 2470 2471 } 2472 2473 func (p *parser) callonStart8() (any, error) { 2474 stack := p.vstack[len(p.vstack)-1] 2475 _ = stack 2476 return p.cur.onStart8(stack["groupBy"], stack["lim"]) 2477 } 2478 2479 func (c *current) onStart19(query, aggs any) (any, error) { 2480 var q ast.QueryStruct 2481 if query != nil { 2482 q.SearchFilter = query.(*ast.Node) 2483 } 2484 if aggs != nil { 2485 q.PipeCommands = aggs.(*structs.QueryAggregators) 2486 } 2487 return q, nil 2488 } 2489 2490 func (p *parser) callonStart19() (any, error) { 2491 stack := p.vstack[len(p.vstack)-1] 2492 _ = stack 2493 return p.cur.onStart19(stack["query"], stack["aggs"]) 2494 } 2495 2496 func (c *current) onStart28(query any) (any, error) { 2497 var q ast.QueryStruct 2498 if query != nil { 2499 q.SearchFilter = query.(*ast.Node) 2500 } 2501 return q, nil 2502 } 2503 2504 func (p *parser) callonStart28() (any, error) { 2505 stack := p.vstack[len(p.vstack)-1] 2506 _ = stack 2507 return p.cur.onStart28(stack["query"]) 2508 } 2509 2510 func (c *current) onStart34(aggs any) (any, error) { 2511 var q ast.QueryStruct 2512 if aggs != nil { 2513 q.PipeCommands = aggs.(*structs.QueryAggregators) 2514 } 2515 return q, nil 2516 } 2517 2518 func (p *parser) callonStart34() (any, error) { 2519 stack := p.vstack[len(p.vstack)-1] 2520 _ = stack 2521 return p.cur.onStart34(stack["aggs"]) 2522 } 2523 2524 func (c *current) onQuery1(clause any) (any, error) { 2525 return clause, nil 2526 } 2527 2528 func (p *parser) callonQuery1() (any, error) { 2529 stack := p.vstack[len(p.vstack)-1] 2530 _ = stack 2531 return p.cur.onQuery1(stack["clause"]) 2532 } 2533 2534 func (c *current) onOrClause2(lhs, rhs any) (any, error) { 2535 return &ast.Node{ 2536 NodeType: ast.NodeOr, 2537 Left: lhs.(*ast.Node), 2538 Right: rhs.(*ast.Node), 2539 }, nil 2540 } 2541 2542 func (p *parser) callonOrClause2() (any, error) { 2543 stack := p.vstack[len(p.vstack)-1] 2544 _ = stack 2545 return p.cur.onOrClause2(stack["lhs"], stack["rhs"]) 2546 } 2547 2548 func (c *current) onmeasureAggsList1(first, rest any) (any, error) { 2549 return ast.GetMeasureAggsTokens(first, rest, 3), nil 2550 } 2551 2552 func (p *parser) callonmeasureAggsList1() (any, error) { 2553 stack := p.vstack[len(p.vstack)-1] 2554 _ = stack 2555 return p.cur.onmeasureAggsList1(stack["first"], stack["rest"]) 2556 } 2557 2558 func (c *current) ongroupByList1(first, rest, cols, lim any) (any, error) { 2559 limit := int(3000) 2560 if lim != nil { 2561 limit = int(lim.(int64)) 2562 } 2563 return ast.GetGroupByTokens(cols, first, rest, 3, limit), nil 2564 } 2565 2566 func (p *parser) callongroupByList1() (any, error) { 2567 stack := p.vstack[len(p.vstack)-1] 2568 _ = stack 2569 return p.cur.ongroupByList1(stack["first"], stack["rest"], stack["cols"], stack["lim"]) 2570 } 2571 2572 func (c *current) onLimit1(first any) (any, error) { 2573 limit, err := strconv.ParseInt(first.(string), 10, 64) 2574 if err != nil { 2575 return nil, err 2576 } 2577 return limit, err 2578 } 2579 2580 func (p *parser) callonLimit1() (any, error) { 2581 stack := p.vstack[len(p.vstack)-1] 2582 _ = stack 2583 return p.cur.onLimit1(stack["first"]) 2584 } 2585 2586 func (c *current) onMeasureAggClause1(funcs, cols any) (any, error) { 2587 2588 tempMeasureAgg := &structs.MeasureAggregator{} 2589 tempMeasureAgg.MeasureCol = cols.(string) 2590 tempMeasureAgg.MeasureFunc = funcs.(utils.AggregateFunctions) 2591 return tempMeasureAgg, nil 2592 } 2593 2594 func (p *parser) callonMeasureAggClause1() (any, error) { 2595 stack := p.vstack[len(p.vstack)-1] 2596 _ = stack 2597 return p.cur.onMeasureAggClause1(stack["funcs"], stack["cols"]) 2598 } 2599 2600 func (c *current) onAggClause2(newCol, oldCol any) (any, error) { 2601 aggNode := &structs.QueryAggregators{} 2602 aggNode.PipeCommandType = structs.OutputTransformType 2603 aggNode.OutputTransforms = &structs.OutputTransforms{} 2604 aggNode.OutputTransforms.OutputColumns = &structs.ColumnsRequest{} 2605 aggNode.OutputTransforms.OutputColumns.RenameColumns = make(map[string]string) 2606 aggNode.OutputTransforms.OutputColumns.RenameColumns[oldCol.(string)] = newCol.(string) 2607 return aggNode, nil 2608 } 2609 2610 func (p *parser) callonAggClause2() (any, error) { 2611 stack := p.vstack[len(p.vstack)-1] 2612 _ = stack 2613 return p.cur.onAggClause2(stack["newCol"], stack["oldCol"]) 2614 } 2615 2616 func (c *current) onAggClause18(cols any) (any, error) { 2617 aggNode := &structs.QueryAggregators{} 2618 aggNode.PipeCommandType = structs.OutputTransformType 2619 aggNode.OutputTransforms = &structs.OutputTransforms{} 2620 aggNode.OutputTransforms.OutputColumns = &structs.ColumnsRequest{} 2621 aggNode.OutputTransforms.OutputColumns.IncludeColumns = cols.([]string) 2622 return aggNode, nil 2623 } 2624 2625 func (p *parser) callonAggClause18() (any, error) { 2626 stack := p.vstack[len(p.vstack)-1] 2627 _ = stack 2628 return p.cur.onAggClause18(stack["cols"]) 2629 } 2630 2631 func (c *current) onAggClause27(cols any) (any, error) { 2632 aggNode := &structs.QueryAggregators{} 2633 aggNode.PipeCommandType = structs.OutputTransformType 2634 aggNode.OutputTransforms = &structs.OutputTransforms{} 2635 aggNode.OutputTransforms.OutputColumns = &structs.ColumnsRequest{} 2636 aggNode.OutputTransforms.OutputColumns.ExcludeColumns = cols.([]string) 2637 return aggNode, nil 2638 } 2639 2640 func (p *parser) callonAggClause27() (any, error) { 2641 stack := p.vstack[len(p.vstack)-1] 2642 _ = stack 2643 return p.cur.onAggClause27(stack["cols"]) 2644 } 2645 2646 func (c *current) onAggClause38(maggs any) (any, error) { 2647 aggNode := &structs.QueryAggregators{} 2648 aggNode = maggs.(*structs.QueryAggregators) 2649 return aggNode, nil 2650 } 2651 2652 func (p *parser) callonAggClause38() (any, error) { 2653 stack := p.vstack[len(p.vstack)-1] 2654 _ = stack 2655 return p.cur.onAggClause38(stack["maggs"]) 2656 } 2657 2658 func (c *current) onAggClause46(groupBy, lim any) (any, error) { 2659 aggNode := &structs.QueryAggregators{} 2660 aggNode = groupBy.(*structs.QueryAggregators) 2661 return aggNode, nil 2662 } 2663 2664 func (p *parser) callonAggClause46() (any, error) { 2665 stack := p.vstack[len(p.vstack)-1] 2666 _ = stack 2667 return p.cur.onAggClause46(stack["groupBy"], stack["lim"]) 2668 } 2669 2670 func (c *current) onAggClause59(newCol, lhs, operation, rhs any) (any, error) { 2671 aggNode := &structs.QueryAggregators{} 2672 aggNode.PipeCommandType = structs.OutputTransformType 2673 aggNode.OutputTransforms = &structs.OutputTransforms{} 2674 aggNode.OutputTransforms.LetColumns = &structs.LetColumnsRequest{} 2675 aggNode.OutputTransforms.LetColumns.NewColName = newCol.(string) 2676 aggNode.OutputTransforms.LetColumns.SingleColRequest = &structs.SingleColLetRequest{} 2677 aggNode.OutputTransforms.LetColumns.SingleColRequest.CName = lhs.(string) 2678 aggNode.OutputTransforms.LetColumns.SingleColRequest.Oper = operation.(utils.LogicalAndArithmeticOperator) 2679 aggNode.OutputTransforms.LetColumns.SingleColRequest.Value = rhs.(*utils.DtypeEnclosure) 2680 return aggNode, nil 2681 } 2682 2683 func (p *parser) callonAggClause59() (any, error) { 2684 stack := p.vstack[len(p.vstack)-1] 2685 _ = stack 2686 return p.cur.onAggClause59(stack["newCol"], stack["lhs"], stack["operation"], stack["rhs"]) 2687 } 2688 2689 func (c *current) onAggClause91(newCol, lhs, operation, rhs any) (any, error) { 2690 aggNode := &structs.QueryAggregators{} 2691 aggNode.PipeCommandType = structs.OutputTransformType 2692 aggNode.OutputTransforms = &structs.OutputTransforms{} 2693 aggNode.OutputTransforms.LetColumns = &structs.LetColumnsRequest{} 2694 aggNode.OutputTransforms.LetColumns.NewColName = newCol.(string) 2695 aggNode.OutputTransforms.LetColumns.MultiColsRequest = &structs.MultiColLetRequest{} 2696 aggNode.OutputTransforms.LetColumns.MultiColsRequest.LeftCName = lhs.(string) 2697 aggNode.OutputTransforms.LetColumns.MultiColsRequest.Oper = operation.(utils.LogicalAndArithmeticOperator) 2698 aggNode.OutputTransforms.LetColumns.MultiColsRequest.RightCName = rhs.(string) 2699 return aggNode, nil 2700 } 2701 2702 func (p *parser) callonAggClause91() (any, error) { 2703 stack := p.vstack[len(p.vstack)-1] 2704 _ = stack 2705 return p.cur.onAggClause91(stack["newCol"], stack["lhs"], stack["operation"], stack["rhs"]) 2706 } 2707 2708 func (c *current) onMeasureAggsFunc1(mfunc any) (any, error) { 2709 aggFunc, _ := ast.AggTypeToAggregateFunction(string(c.text)) 2710 return aggFunc, nil 2711 } 2712 2713 func (p *parser) callonMeasureAggsFunc1() (any, error) { 2714 stack := p.vstack[len(p.vstack)-1] 2715 _ = stack 2716 return p.cur.onMeasureAggsFunc1(stack["mfunc"]) 2717 } 2718 2719 func (c *current) onLetOpr2() (any, error) { 2720 return utils.LetGreaterThanOrEqualTo, nil 2721 } 2722 2723 func (p *parser) callonLetOpr2() (any, error) { 2724 stack := p.vstack[len(p.vstack)-1] 2725 _ = stack 2726 return p.cur.onLetOpr2() 2727 } 2728 2729 func (c *current) onLetOpr6() (any, error) { 2730 return utils.LetGreaterThan, nil 2731 } 2732 2733 func (p *parser) callonLetOpr6() (any, error) { 2734 stack := p.vstack[len(p.vstack)-1] 2735 _ = stack 2736 return p.cur.onLetOpr6() 2737 } 2738 2739 func (c *current) onLetOpr8() (any, error) { 2740 return utils.LetLessThanOrEqualTo, nil 2741 } 2742 2743 func (p *parser) callonLetOpr8() (any, error) { 2744 stack := p.vstack[len(p.vstack)-1] 2745 _ = stack 2746 return p.cur.onLetOpr8() 2747 } 2748 2749 func (c *current) onLetOpr12() (any, error) { 2750 return utils.LetLessThan, nil 2751 } 2752 2753 func (p *parser) callonLetOpr12() (any, error) { 2754 stack := p.vstack[len(p.vstack)-1] 2755 _ = stack 2756 return p.cur.onLetOpr12() 2757 } 2758 2759 func (c *current) onLetOpr14() (any, error) { 2760 return utils.LetEquals, nil 2761 } 2762 2763 func (p *parser) callonLetOpr14() (any, error) { 2764 stack := p.vstack[len(p.vstack)-1] 2765 _ = stack 2766 return p.cur.onLetOpr14() 2767 } 2768 2769 func (c *current) onLetOpr18() (any, error) { 2770 return utils.LetNotEquals, nil 2771 } 2772 2773 func (p *parser) callonLetOpr18() (any, error) { 2774 stack := p.vstack[len(p.vstack)-1] 2775 _ = stack 2776 return p.cur.onLetOpr18() 2777 } 2778 2779 func (c *current) onLetOpr22() (any, error) { 2780 return utils.LetAdd, nil 2781 } 2782 2783 func (p *parser) callonLetOpr22() (any, error) { 2784 stack := p.vstack[len(p.vstack)-1] 2785 _ = stack 2786 return p.cur.onLetOpr22() 2787 } 2788 2789 func (c *current) onLetOpr24() (any, error) { 2790 return utils.LetSubtract, nil 2791 } 2792 2793 func (p *parser) callonLetOpr24() (any, error) { 2794 stack := p.vstack[len(p.vstack)-1] 2795 _ = stack 2796 return p.cur.onLetOpr24() 2797 } 2798 2799 func (c *current) onLetOpr26() (any, error) { 2800 return utils.LetDivide, nil 2801 } 2802 2803 func (p *parser) callonLetOpr26() (any, error) { 2804 stack := p.vstack[len(p.vstack)-1] 2805 _ = stack 2806 return p.cur.onLetOpr26() 2807 } 2808 2809 func (c *current) onLetOpr28() (any, error) { 2810 return utils.LetMultiply, nil 2811 } 2812 2813 func (p *parser) callonLetOpr28() (any, error) { 2814 stack := p.vstack[len(p.vstack)-1] 2815 _ = stack 2816 return p.cur.onLetOpr28() 2817 } 2818 2819 func (c *current) onLetOpr30() (any, error) { 2820 return utils.LetModulo, nil 2821 } 2822 2823 func (p *parser) callonLetOpr30() (any, error) { 2824 stack := p.vstack[len(p.vstack)-1] 2825 _ = stack 2826 return p.cur.onLetOpr30() 2827 } 2828 2829 func (c *current) onLetIdentifier2() (any, error) { 2830 var dte utils.DtypeEnclosure 2831 dte.Dtype = utils.SS_DT_FLOAT 2832 dte.FloatVal, _ = strconv.ParseFloat(string(c.text), 64) 2833 dte.StringVal = string(c.text) 2834 return &dte, nil 2835 } 2836 2837 func (p *parser) callonLetIdentifier2() (any, error) { 2838 stack := p.vstack[len(p.vstack)-1] 2839 _ = stack 2840 return p.cur.onLetIdentifier2() 2841 } 2842 2843 func (c *current) onLetIdentifier7() (any, error) { 2844 var dte utils.DtypeEnclosure 2845 dte.Dtype = utils.SS_DT_SIGNED_NUM 2846 dte.SignedVal, _ = strconv.ParseInt(string(c.text), 10, 64) 2847 dte.StringVal = string(c.text) 2848 return &dte, nil 2849 } 2850 2851 func (p *parser) callonLetIdentifier7() (any, error) { 2852 stack := p.vstack[len(p.vstack)-1] 2853 _ = stack 2854 return p.cur.onLetIdentifier7() 2855 } 2856 2857 func (c *current) onLetIdentifier12() (any, error) { 2858 var dte utils.DtypeEnclosure 2859 dte.Dtype = utils.SS_DT_UNSIGNED_NUM 2860 dte.UnsignedVal, _ = strconv.ParseUint(string(c.text), 10, 64) 2861 dte.StringVal = string(c.text) 2862 return &dte, nil 2863 } 2864 2865 func (p *parser) callonLetIdentifier12() (any, error) { 2866 stack := p.vstack[len(p.vstack)-1] 2867 _ = stack 2868 return p.cur.onLetIdentifier12() 2869 } 2870 2871 func (c *current) onLetIdentifier14() (any, error) { 2872 var dte utils.DtypeEnclosure 2873 dte.Dtype = utils.SS_DT_BOOL 2874 bVal, _ := strconv.ParseBool(string(c.text)) 2875 if bVal == true { 2876 dte.BoolVal = 1 2877 } else { 2878 dte.BoolVal = 0 2879 } 2880 dte.StringVal = string(c.text) 2881 return &dte, nil 2882 } 2883 2884 func (p *parser) callonLetIdentifier14() (any, error) { 2885 stack := p.vstack[len(p.vstack)-1] 2886 _ = stack 2887 return p.cur.onLetIdentifier14() 2888 } 2889 2890 func (c *current) onColList1(first, rest any) (any, error) { 2891 return ast.GetTokens(first, rest, 3), nil 2892 } 2893 2894 func (p *parser) callonColList1() (any, error) { 2895 stack := p.vstack[len(p.vstack)-1] 2896 _ = stack 2897 return p.cur.onColList1(stack["first"], stack["rest"]) 2898 } 2899 2900 func (c *current) onAndClause2(lhs, rhs any) (any, error) { 2901 return &ast.Node{ 2902 NodeType: ast.NodeAnd, 2903 Left: lhs.(*ast.Node), 2904 Right: rhs.(*ast.Node), 2905 }, nil 2906 } 2907 2908 func (p *parser) callonAndClause2() (any, error) { 2909 stack := p.vstack[len(p.vstack)-1] 2910 _ = stack 2911 return p.cur.onAndClause2(stack["lhs"], stack["rhs"]) 2912 } 2913 2914 func (c *current) onNotClause2(cmp any) (any, error) { 2915 return &ast.Node{ 2916 NodeType: ast.NodeNot, 2917 Left: cmp.(*ast.Node), 2918 Right: nil, 2919 }, nil 2920 } 2921 2922 func (p *parser) callonNotClause2() (any, error) { 2923 stack := p.vstack[len(p.vstack)-1] 2924 _ = stack 2925 return p.cur.onNotClause2(stack["cmp"]) 2926 } 2927 2928 func (c *current) onComparison2(query any) (any, error) { 2929 return query, nil 2930 } 2931 2932 func (p *parser) callonComparison2() (any, error) { 2933 stack := p.vstack[len(p.vstack)-1] 2934 _ = stack 2935 return p.cur.onComparison2(stack["query"]) 2936 } 2937 2938 func (c *current) onComparison12(field, operation, field1 any) (any, error) { 2939 var opOut string 2940 if operation == nil && field != nil { 2941 opOut = "=" 2942 } else { 2943 opOut = operation.(string) 2944 } 2945 return &ast.Node{ 2946 NodeType: ast.NodeTerminal, 2947 Comparison: ast.Comparison{ 2948 Op: opOut, 2949 Field: field.(string), 2950 Values: field1, 2951 }, 2952 }, nil 2953 } 2954 2955 func (p *parser) callonComparison12() (any, error) { 2956 stack := p.vstack[len(p.vstack)-1] 2957 _ = stack 2958 return p.cur.onComparison12(stack["field"], stack["operation"], stack["field1"]) 2959 } 2960 2961 func (c *current) onComparison24(values any) (any, error) { 2962 return &ast.Node{ 2963 NodeType: ast.NodeTerminal, 2964 Comparison: ast.Comparison{ 2965 Op: "=", 2966 Field: "*", 2967 Values: values, 2968 }, 2969 }, nil 2970 } 2971 2972 func (p *parser) callonComparison24() (any, error) { 2973 stack := p.vstack[len(p.vstack)-1] 2974 _ = stack 2975 return p.cur.onComparison24(stack["values"]) 2976 } 2977 2978 func (c *current) onComparison27(field any) (any, error) { 2979 return &ast.Node{ 2980 NodeType: ast.NodeTerminal, 2981 Comparison: ast.Comparison{ 2982 Op: "=", 2983 Field: "*", 2984 Values: field, 2985 }, 2986 }, nil 2987 } 2988 2989 func (p *parser) callonComparison27() (any, error) { 2990 stack := p.vstack[len(p.vstack)-1] 2991 _ = stack 2992 return p.cur.onComparison27(stack["field"]) 2993 } 2994 2995 func (c *current) onField3(pieces any) (any, error) { 2996 if pieces == nil { 2997 return "*", nil 2998 } 2999 3000 return string(c.text), nil 3001 } 3002 3003 func (p *parser) callonField3() (any, error) { 3004 stack := p.vstack[len(p.vstack)-1] 3005 _ = stack 3006 return p.cur.onField3(stack["pieces"]) 3007 } 3008 3009 func (c *current) onUnquotedFieldPiece1() (any, error) { 3010 return string(c.text), nil 3011 } 3012 3013 func (p *parser) callonUnquotedFieldPiece1() (any, error) { 3014 stack := p.vstack[len(p.vstack)-1] 3015 _ = stack 3016 return p.cur.onUnquotedFieldPiece1() 3017 } 3018 3019 func (c *current) onStar1() (any, error) { 3020 return "*", nil 3021 } 3022 3023 func (p *parser) callonStar1() (any, error) { 3024 stack := p.vstack[len(p.vstack)-1] 3025 _ = stack 3026 return p.cur.onStar1() 3027 } 3028 3029 func (c *current) onQuotedValue1() (any, error) { 3030 c.text = bytes.Replace(c.text, []byte(`\/`), []byte(`/`), -1) 3031 return strconv.Unquote(string(c.text)) 3032 } 3033 3034 func (p *parser) callonQuotedValue1() (any, error) { 3035 stack := p.vstack[len(p.vstack)-1] 3036 _ = stack 3037 return p.cur.onQuotedValue1() 3038 } 3039 3040 func (c *current) onValueList2(first, rest any) (any, error) { 3041 return ast.GetTokens(first, rest, 3), nil 3042 } 3043 3044 func (p *parser) callonValueList2() (any, error) { 3045 stack := p.vstack[len(p.vstack)-1] 3046 _ = stack 3047 return p.cur.onValueList2(stack["first"], stack["rest"]) 3048 } 3049 3050 func (c *current) onValue1(val any) (any, error) { 3051 return ast.MakeValue(val) 3052 3053 } 3054 3055 func (p *parser) callonValue1() (any, error) { 3056 stack := p.vstack[len(p.vstack)-1] 3057 _ = stack 3058 return p.cur.onValue1(stack["val"]) 3059 } 3060 3061 func (c *current) onString1(chars any) (any, error) { 3062 return ast.StringFromChars(chars), nil 3063 3064 } 3065 3066 func (p *parser) callonString1() (any, error) { 3067 stack := p.vstack[len(p.vstack)-1] 3068 _ = stack 3069 return p.cur.onString1(stack["chars"]) 3070 } 3071 3072 func (c *current) onInteger1() (any, error) { 3073 return json.Number(string(c.text)), nil 3074 3075 } 3076 3077 func (p *parser) callonInteger1() (any, error) { 3078 stack := p.vstack[len(p.vstack)-1] 3079 _ = stack 3080 return p.cur.onInteger1() 3081 } 3082 3083 func (c *current) onFloat1() (any, error) { 3084 return json.Number(string(c.text)), nil 3085 3086 } 3087 3088 func (p *parser) callonFloat1() (any, error) { 3089 stack := p.vstack[len(p.vstack)-1] 3090 _ = stack 3091 return p.cur.onFloat1() 3092 } 3093 3094 func (c *current) onIdentifier1() (any, error) { 3095 3096 return string(c.text), nil 3097 } 3098 3099 func (p *parser) callonIdentifier1() (any, error) { 3100 stack := p.vstack[len(p.vstack)-1] 3101 _ = stack 3102 return p.cur.onIdentifier1() 3103 } 3104 3105 func (c *current) onopCOMP3() (any, error) { 3106 return string(c.text), nil 3107 } 3108 3109 func (p *parser) callonopCOMP3() (any, error) { 3110 stack := p.vstack[len(p.vstack)-1] 3111 _ = stack 3112 return p.cur.onopCOMP3() 3113 } 3114 3115 func (c *current) onopCOMP5() (any, error) { 3116 return string(c.text), nil 3117 } 3118 3119 func (p *parser) callonopCOMP5() (any, error) { 3120 stack := p.vstack[len(p.vstack)-1] 3121 _ = stack 3122 return p.cur.onopCOMP5() 3123 } 3124 3125 func (c *current) onopCOMP7() (any, error) { 3126 return string(c.text), nil 3127 } 3128 3129 func (p *parser) callonopCOMP7() (any, error) { 3130 stack := p.vstack[len(p.vstack)-1] 3131 _ = stack 3132 return p.cur.onopCOMP7() 3133 } 3134 3135 func (c *current) onopCOMP9() (any, error) { 3136 return string(c.text), nil 3137 } 3138 3139 func (p *parser) callonopCOMP9() (any, error) { 3140 stack := p.vstack[len(p.vstack)-1] 3141 _ = stack 3142 return p.cur.onopCOMP9() 3143 } 3144 3145 func (c *current) onopCOMP11() (any, error) { 3146 return string(c.text), nil 3147 } 3148 3149 func (p *parser) callonopCOMP11() (any, error) { 3150 stack := p.vstack[len(p.vstack)-1] 3151 _ = stack 3152 return p.cur.onopCOMP11() 3153 } 3154 3155 func (c *current) onopCOMP13() (any, error) { 3156 return string(c.text), nil 3157 3158 } 3159 3160 func (p *parser) callonopCOMP13() (any, error) { 3161 stack := p.vstack[len(p.vstack)-1] 3162 _ = stack 3163 return p.cur.onopCOMP13() 3164 } 3165 3166 func (c *current) onopCustom1(opname any) (any, error) { 3167 return ast.OpNameToString(opname) 3168 } 3169 3170 func (p *parser) callonopCustom1() (any, error) { 3171 stack := p.vstack[len(p.vstack)-1] 3172 _ = stack 3173 return p.cur.onopCustom1(stack["opname"]) 3174 } 3175 3176 var ( 3177 // errNoRule is returned when the grammar to parse has no rule. 3178 errNoRule = errors.New("grammar has no rule") 3179 3180 // errInvalidEntrypoint is returned when the specified entrypoint rule 3181 // does not exit. 3182 errInvalidEntrypoint = errors.New("invalid entrypoint") 3183 3184 // errInvalidEncoding is returned when the source is not properly 3185 // utf8-encoded. 3186 errInvalidEncoding = errors.New("invalid encoding") 3187 3188 // errMaxExprCnt is used to signal that the maximum number of 3189 // expressions have been parsed. 3190 errMaxExprCnt = errors.New("max number of expresssions parsed") 3191 ) 3192 3193 // Option is a function that can set an option on the parser. It returns 3194 // the previous setting as an Option. 3195 type Option func(*parser) Option 3196 3197 // MaxExpressions creates an Option to stop parsing after the provided 3198 // number of expressions have been parsed, if the value is 0 then the parser will 3199 // parse for as many steps as needed (possibly an infinite number). 3200 // 3201 // The default for maxExprCnt is 0. 3202 func MaxExpressions(maxExprCnt uint64) Option { 3203 return func(p *parser) Option { 3204 oldMaxExprCnt := p.maxExprCnt 3205 p.maxExprCnt = maxExprCnt 3206 return MaxExpressions(oldMaxExprCnt) 3207 } 3208 } 3209 3210 // Entrypoint creates an Option to set the rule name to use as entrypoint. 3211 // The rule name must have been specified in the -alternate-entrypoints 3212 // if generating the parser with the -optimize-grammar flag, otherwise 3213 // it may have been optimized out. Passing an empty string sets the 3214 // entrypoint to the first rule in the grammar. 3215 // 3216 // The default is to start parsing at the first rule in the grammar. 3217 func Entrypoint(ruleName string) Option { 3218 return func(p *parser) Option { 3219 oldEntrypoint := p.entrypoint 3220 p.entrypoint = ruleName 3221 if ruleName == "" { 3222 p.entrypoint = g.rules[0].name 3223 } 3224 return Entrypoint(oldEntrypoint) 3225 } 3226 } 3227 3228 // Statistics adds a user provided Stats struct to the parser to allow 3229 // the user to process the results after the parsing has finished. 3230 // Also the key for the "no match" counter is set. 3231 // 3232 // Example usage: 3233 // 3234 // input := "input" 3235 // stats := Stats{} 3236 // _, err := Parse("input-file", []byte(input), Statistics(&stats, "no match")) 3237 // if err != nil { 3238 // log.Panicln(err) 3239 // } 3240 // b, err := json.MarshalIndent(stats.ChoiceAltCnt, "", " ") 3241 // if err != nil { 3242 // log.Panicln(err) 3243 // } 3244 // fmt.Println(string(b)) 3245 func Statistics(stats *Stats, choiceNoMatch string) Option { 3246 return func(p *parser) Option { 3247 oldStats := p.Stats 3248 p.Stats = stats 3249 oldChoiceNoMatch := p.choiceNoMatch 3250 p.choiceNoMatch = choiceNoMatch 3251 if p.Stats.ChoiceAltCnt == nil { 3252 p.Stats.ChoiceAltCnt = make(map[string]map[string]int) 3253 } 3254 return Statistics(oldStats, oldChoiceNoMatch) 3255 } 3256 } 3257 3258 // Debug creates an Option to set the debug flag to b. When set to true, 3259 // debugging information is printed to stdout while parsing. 3260 // 3261 // The default is false. 3262 func Debug(b bool) Option { 3263 return func(p *parser) Option { 3264 old := p.debug 3265 p.debug = b 3266 return Debug(old) 3267 } 3268 } 3269 3270 // Memoize creates an Option to set the memoize flag to b. When set to true, 3271 // the parser will cache all results so each expression is evaluated only 3272 // once. This guarantees linear parsing time even for pathological cases, 3273 // at the expense of more memory and slower times for typical cases. 3274 // 3275 // The default is false. 3276 func Memoize(b bool) Option { 3277 return func(p *parser) Option { 3278 old := p.memoize 3279 p.memoize = b 3280 return Memoize(old) 3281 } 3282 } 3283 3284 // AllowInvalidUTF8 creates an Option to allow invalid UTF-8 bytes. 3285 // Every invalid UTF-8 byte is treated as a utf8.RuneError (U+FFFD) 3286 // by character class matchers and is matched by the any matcher. 3287 // The returned matched value, c.text and c.offset are NOT affected. 3288 // 3289 // The default is false. 3290 func AllowInvalidUTF8(b bool) Option { 3291 return func(p *parser) Option { 3292 old := p.allowInvalidUTF8 3293 p.allowInvalidUTF8 = b 3294 return AllowInvalidUTF8(old) 3295 } 3296 } 3297 3298 // Recover creates an Option to set the recover flag to b. When set to 3299 // true, this causes the parser to recover from panics and convert it 3300 // to an error. Setting it to false can be useful while debugging to 3301 // access the full stack trace. 3302 // 3303 // The default is true. 3304 func Recover(b bool) Option { 3305 return func(p *parser) Option { 3306 old := p.recover 3307 p.recover = b 3308 return Recover(old) 3309 } 3310 } 3311 3312 // GlobalStore creates an Option to set a key to a certain value in 3313 // the globalStore. 3314 func GlobalStore(key string, value any) Option { 3315 return func(p *parser) Option { 3316 old := p.cur.globalStore[key] 3317 p.cur.globalStore[key] = value 3318 return GlobalStore(key, old) 3319 } 3320 } 3321 3322 // InitState creates an Option to set a key to a certain value in 3323 // the global "state" store. 3324 func InitState(key string, value any) Option { 3325 return func(p *parser) Option { 3326 old := p.cur.state[key] 3327 p.cur.state[key] = value 3328 return InitState(key, old) 3329 } 3330 } 3331 3332 // ParseFile parses the file identified by filename. 3333 func ParseFile(filename string, opts ...Option) (i any, err error) { 3334 f, err := os.Open(filename) 3335 if err != nil { 3336 return nil, err 3337 } 3338 defer func() { 3339 if closeErr := f.Close(); closeErr != nil { 3340 err = closeErr 3341 } 3342 }() 3343 return ParseReader(filename, f, opts...) 3344 } 3345 3346 // ParseReader parses the data from r using filename as information in the 3347 // error messages. 3348 func ParseReader(filename string, r io.Reader, opts ...Option) (any, error) { 3349 b, err := io.ReadAll(r) 3350 if err != nil { 3351 return nil, err 3352 } 3353 3354 return Parse(filename, b, opts...) 3355 } 3356 3357 // Parse parses the data from b using filename as information in the 3358 // error messages. 3359 func Parse(filename string, b []byte, opts ...Option) (any, error) { 3360 return newParser(filename, b, opts...).parse(g) 3361 } 3362 3363 // position records a position in the text. 3364 type position struct { 3365 line, col, offset int 3366 } 3367 3368 func (p position) String() string { 3369 return strconv.Itoa(p.line) + ":" + strconv.Itoa(p.col) + " [" + strconv.Itoa(p.offset) + "]" 3370 } 3371 3372 // savepoint stores all state required to go back to this point in the 3373 // parser. 3374 type savepoint struct { 3375 position 3376 rn rune 3377 w int 3378 } 3379 3380 type current struct { 3381 pos position // start position of the match 3382 text []byte // raw text of the match 3383 3384 // state is a store for arbitrary key,value pairs that the user wants to be 3385 // tied to the backtracking of the parser. 3386 // This is always rolled back if a parsing rule fails. 3387 state storeDict 3388 3389 // globalStore is a general store for the user to store arbitrary key-value 3390 // pairs that they need to manage and that they do not want tied to the 3391 // backtracking of the parser. This is only modified by the user and never 3392 // rolled back by the parser. It is always up to the user to keep this in a 3393 // consistent state. 3394 globalStore storeDict 3395 } 3396 3397 type storeDict map[string]any 3398 3399 // the AST types... 3400 3401 type grammar struct { 3402 pos position 3403 rules []*rule 3404 } 3405 3406 type rule struct { 3407 pos position 3408 name string 3409 displayName string 3410 expr any 3411 } 3412 3413 type choiceExpr struct { 3414 pos position 3415 alternatives []any 3416 } 3417 3418 type actionExpr struct { 3419 pos position 3420 expr any 3421 run func(*parser) (any, error) 3422 } 3423 3424 type recoveryExpr struct { 3425 pos position 3426 expr any 3427 recoverExpr any 3428 failureLabel []string 3429 } 3430 3431 type seqExpr struct { 3432 pos position 3433 exprs []any 3434 } 3435 3436 type throwExpr struct { 3437 pos position 3438 label string 3439 } 3440 3441 type labeledExpr struct { 3442 pos position 3443 label string 3444 expr any 3445 } 3446 3447 type expr struct { 3448 pos position 3449 expr any 3450 } 3451 3452 type ( 3453 andExpr expr 3454 notExpr expr 3455 zeroOrOneExpr expr 3456 zeroOrMoreExpr expr 3457 oneOrMoreExpr expr 3458 ) 3459 3460 type ruleRefExpr struct { 3461 pos position 3462 name string 3463 } 3464 3465 type stateCodeExpr struct { 3466 pos position 3467 run func(*parser) error 3468 } 3469 3470 type andCodeExpr struct { 3471 pos position 3472 run func(*parser) (bool, error) 3473 } 3474 3475 type notCodeExpr struct { 3476 pos position 3477 run func(*parser) (bool, error) 3478 } 3479 3480 type litMatcher struct { 3481 pos position 3482 val string 3483 ignoreCase bool 3484 want string 3485 } 3486 3487 type charClassMatcher struct { 3488 pos position 3489 val string 3490 basicLatinChars [128]bool 3491 chars []rune 3492 ranges []rune 3493 classes []*unicode.RangeTable 3494 ignoreCase bool 3495 inverted bool 3496 } 3497 3498 type anyMatcher position 3499 3500 // errList cumulates the errors found by the parser. 3501 type errList []error 3502 3503 func (e *errList) add(err error) { 3504 *e = append(*e, err) 3505 } 3506 3507 func (e errList) err() error { 3508 if len(e) == 0 { 3509 return nil 3510 } 3511 e.dedupe() 3512 return e 3513 } 3514 3515 func (e *errList) dedupe() { 3516 var cleaned []error 3517 set := make(map[string]bool) 3518 for _, err := range *e { 3519 if msg := err.Error(); !set[msg] { 3520 set[msg] = true 3521 cleaned = append(cleaned, err) 3522 } 3523 } 3524 *e = cleaned 3525 } 3526 3527 func (e errList) Error() string { 3528 switch len(e) { 3529 case 0: 3530 return "" 3531 case 1: 3532 return e[0].Error() 3533 default: 3534 var buf bytes.Buffer 3535 3536 for i, err := range e { 3537 if i > 0 { 3538 buf.WriteRune('\n') 3539 } 3540 buf.WriteString(err.Error()) 3541 } 3542 return buf.String() 3543 } 3544 } 3545 3546 // parserError wraps an error with a prefix indicating the rule in which 3547 // the error occurred. The original error is stored in the Inner field. 3548 type parserError struct { 3549 Inner error 3550 pos position 3551 prefix string 3552 expected []string 3553 } 3554 3555 // Error returns the error message. 3556 func (p *parserError) Error() string { 3557 return p.prefix + ": " + p.Inner.Error() 3558 } 3559 3560 // newParser creates a parser with the specified input source and options. 3561 func newParser(filename string, b []byte, opts ...Option) *parser { 3562 stats := Stats{ 3563 ChoiceAltCnt: make(map[string]map[string]int), 3564 } 3565 3566 p := &parser{ 3567 filename: filename, 3568 errs: new(errList), 3569 data: b, 3570 pt: savepoint{position: position{line: 1}}, 3571 recover: true, 3572 cur: current{ 3573 state: make(storeDict), 3574 globalStore: make(storeDict), 3575 }, 3576 maxFailPos: position{col: 1, line: 1}, 3577 maxFailExpected: make([]string, 0, 20), 3578 Stats: &stats, 3579 // start rule is rule [0] unless an alternate entrypoint is specified 3580 entrypoint: g.rules[0].name, 3581 } 3582 p.setOptions(opts) 3583 3584 if p.maxExprCnt == 0 { 3585 p.maxExprCnt = math.MaxUint64 3586 } 3587 3588 return p 3589 } 3590 3591 // setOptions applies the options to the parser. 3592 func (p *parser) setOptions(opts []Option) { 3593 for _, opt := range opts { 3594 opt(p) 3595 } 3596 } 3597 3598 type resultTuple struct { 3599 v any 3600 b bool 3601 end savepoint 3602 } 3603 3604 const choiceNoMatch = -1 3605 3606 // Stats stores some statistics, gathered during parsing 3607 type Stats struct { 3608 // ExprCnt counts the number of expressions processed during parsing 3609 // This value is compared to the maximum number of expressions allowed 3610 // (set by the MaxExpressions option). 3611 ExprCnt uint64 3612 3613 // ChoiceAltCnt is used to count for each ordered choice expression, 3614 // which alternative is used how may times. 3615 // These numbers allow to optimize the order of the ordered choice expression 3616 // to increase the performance of the parser 3617 // 3618 // The outer key of ChoiceAltCnt is composed of the name of the rule as well 3619 // as the line and the column of the ordered choice. 3620 // The inner key of ChoiceAltCnt is the number (one-based) of the matching alternative. 3621 // For each alternative the number of matches are counted. If an ordered choice does not 3622 // match, a special counter is incremented. The name of this counter is set with 3623 // the parser option Statistics. 3624 // For an alternative to be included in ChoiceAltCnt, it has to match at least once. 3625 ChoiceAltCnt map[string]map[string]int 3626 } 3627 3628 type parser struct { 3629 filename string 3630 pt savepoint 3631 cur current 3632 3633 data []byte 3634 errs *errList 3635 3636 depth int 3637 recover bool 3638 debug bool 3639 3640 memoize bool 3641 // memoization table for the packrat algorithm: 3642 // map[offset in source] map[expression or rule] {value, match} 3643 memo map[int]map[any]resultTuple 3644 3645 // rules table, maps the rule identifier to the rule node 3646 rules map[string]*rule 3647 // variables stack, map of label to value 3648 vstack []map[string]any 3649 // rule stack, allows identification of the current rule in errors 3650 rstack []*rule 3651 3652 // parse fail 3653 maxFailPos position 3654 maxFailExpected []string 3655 maxFailInvertExpected bool 3656 3657 // max number of expressions to be parsed 3658 maxExprCnt uint64 3659 // entrypoint for the parser 3660 entrypoint string 3661 3662 allowInvalidUTF8 bool 3663 3664 *Stats 3665 3666 choiceNoMatch string 3667 // recovery expression stack, keeps track of the currently available recovery expression, these are traversed in reverse 3668 recoveryStack []map[string]any 3669 } 3670 3671 // push a variable set on the vstack. 3672 func (p *parser) pushV() { 3673 if cap(p.vstack) == len(p.vstack) { 3674 // create new empty slot in the stack 3675 p.vstack = append(p.vstack, nil) 3676 } else { 3677 // slice to 1 more 3678 p.vstack = p.vstack[:len(p.vstack)+1] 3679 } 3680 3681 // get the last args set 3682 m := p.vstack[len(p.vstack)-1] 3683 if m != nil && len(m) == 0 { 3684 // empty map, all good 3685 return 3686 } 3687 3688 m = make(map[string]any) 3689 p.vstack[len(p.vstack)-1] = m 3690 } 3691 3692 // pop a variable set from the vstack. 3693 func (p *parser) popV() { 3694 // if the map is not empty, clear it 3695 m := p.vstack[len(p.vstack)-1] 3696 if len(m) > 0 { 3697 // GC that map 3698 p.vstack[len(p.vstack)-1] = nil 3699 } 3700 p.vstack = p.vstack[:len(p.vstack)-1] 3701 } 3702 3703 // push a recovery expression with its labels to the recoveryStack 3704 func (p *parser) pushRecovery(labels []string, expr any) { 3705 if cap(p.recoveryStack) == len(p.recoveryStack) { 3706 // create new empty slot in the stack 3707 p.recoveryStack = append(p.recoveryStack, nil) 3708 } else { 3709 // slice to 1 more 3710 p.recoveryStack = p.recoveryStack[:len(p.recoveryStack)+1] 3711 } 3712 3713 m := make(map[string]any, len(labels)) 3714 for _, fl := range labels { 3715 m[fl] = expr 3716 } 3717 p.recoveryStack[len(p.recoveryStack)-1] = m 3718 } 3719 3720 // pop a recovery expression from the recoveryStack 3721 func (p *parser) popRecovery() { 3722 // GC that map 3723 p.recoveryStack[len(p.recoveryStack)-1] = nil 3724 3725 p.recoveryStack = p.recoveryStack[:len(p.recoveryStack)-1] 3726 } 3727 3728 func (p *parser) print(prefix, s string) string { 3729 if !p.debug { 3730 return s 3731 } 3732 3733 fmt.Printf("%s %d:%d:%d: %s [%#U]\n", 3734 prefix, p.pt.line, p.pt.col, p.pt.offset, s, p.pt.rn) 3735 return s 3736 } 3737 3738 func (p *parser) printIndent(mark string, s string) string { 3739 return p.print(strings.Repeat(" ", p.depth)+mark, s) 3740 } 3741 3742 func (p *parser) in(s string) string { 3743 res := p.printIndent(">", s) 3744 p.depth++ 3745 return res 3746 } 3747 3748 func (p *parser) out(s string) string { 3749 p.depth-- 3750 return p.printIndent("<", s) 3751 } 3752 3753 func (p *parser) addErr(err error) { 3754 p.addErrAt(err, p.pt.position, []string{}) 3755 } 3756 3757 func (p *parser) addErrAt(err error, pos position, expected []string) { 3758 var buf bytes.Buffer 3759 if p.filename != "" { 3760 buf.WriteString(p.filename) 3761 } 3762 if buf.Len() > 0 { 3763 buf.WriteString(":") 3764 } 3765 buf.WriteString(fmt.Sprintf("%d:%d (%d)", pos.line, pos.col, pos.offset)) 3766 if len(p.rstack) > 0 { 3767 if buf.Len() > 0 { 3768 buf.WriteString(": ") 3769 } 3770 rule := p.rstack[len(p.rstack)-1] 3771 if rule.displayName != "" { 3772 buf.WriteString("rule " + rule.displayName) 3773 } else { 3774 buf.WriteString("rule " + rule.name) 3775 } 3776 } 3777 pe := &parserError{Inner: err, pos: pos, prefix: buf.String(), expected: expected} 3778 p.errs.add(pe) 3779 } 3780 3781 func (p *parser) failAt(fail bool, pos position, want string) { 3782 // process fail if parsing fails and not inverted or parsing succeeds and invert is set 3783 if fail == p.maxFailInvertExpected { 3784 if pos.offset < p.maxFailPos.offset { 3785 return 3786 } 3787 3788 if pos.offset > p.maxFailPos.offset { 3789 p.maxFailPos = pos 3790 p.maxFailExpected = p.maxFailExpected[:0] 3791 } 3792 3793 if p.maxFailInvertExpected { 3794 want = "!" + want 3795 } 3796 p.maxFailExpected = append(p.maxFailExpected, want) 3797 } 3798 } 3799 3800 // read advances the parser to the next rune. 3801 func (p *parser) read() { 3802 p.pt.offset += p.pt.w 3803 rn, n := utf8.DecodeRune(p.data[p.pt.offset:]) 3804 p.pt.rn = rn 3805 p.pt.w = n 3806 p.pt.col++ 3807 if rn == '\n' { 3808 p.pt.line++ 3809 p.pt.col = 0 3810 } 3811 3812 if rn == utf8.RuneError && n == 1 { // see utf8.DecodeRune 3813 if !p.allowInvalidUTF8 { 3814 p.addErr(errInvalidEncoding) 3815 } 3816 } 3817 } 3818 3819 // restore parser position to the savepoint pt. 3820 func (p *parser) restore(pt savepoint) { 3821 if p.debug { 3822 defer p.out(p.in("restore")) 3823 } 3824 if pt.offset == p.pt.offset { 3825 return 3826 } 3827 p.pt = pt 3828 } 3829 3830 // Cloner is implemented by any value that has a Clone method, which returns a 3831 // copy of the value. This is mainly used for types which are not passed by 3832 // value (e.g map, slice, chan) or structs that contain such types. 3833 // 3834 // This is used in conjunction with the global state feature to create proper 3835 // copies of the state to allow the parser to properly restore the state in 3836 // the case of backtracking. 3837 type Cloner interface { 3838 Clone() any 3839 } 3840 3841 var statePool = &sync.Pool{ 3842 New: func() any { return make(storeDict) }, 3843 } 3844 3845 func (sd storeDict) Discard() { 3846 for k := range sd { 3847 delete(sd, k) 3848 } 3849 statePool.Put(sd) 3850 } 3851 3852 // clone and return parser current state. 3853 func (p *parser) cloneState() storeDict { 3854 if p.debug { 3855 defer p.out(p.in("cloneState")) 3856 } 3857 3858 state := statePool.Get().(storeDict) 3859 for k, v := range p.cur.state { 3860 if c, ok := v.(Cloner); ok { 3861 state[k] = c.Clone() 3862 } else { 3863 state[k] = v 3864 } 3865 } 3866 return state 3867 } 3868 3869 // restore parser current state to the state storeDict. 3870 // every restoreState should applied only one time for every cloned state 3871 func (p *parser) restoreState(state storeDict) { 3872 if p.debug { 3873 defer p.out(p.in("restoreState")) 3874 } 3875 p.cur.state.Discard() 3876 p.cur.state = state 3877 } 3878 3879 // get the slice of bytes from the savepoint start to the current position. 3880 func (p *parser) sliceFrom(start savepoint) []byte { 3881 return p.data[start.position.offset:p.pt.position.offset] 3882 } 3883 3884 func (p *parser) getMemoized(node any) (resultTuple, bool) { 3885 if len(p.memo) == 0 { 3886 return resultTuple{}, false 3887 } 3888 m := p.memo[p.pt.offset] 3889 if len(m) == 0 { 3890 return resultTuple{}, false 3891 } 3892 res, ok := m[node] 3893 return res, ok 3894 } 3895 3896 func (p *parser) setMemoized(pt savepoint, node any, tuple resultTuple) { 3897 if p.memo == nil { 3898 p.memo = make(map[int]map[any]resultTuple) 3899 } 3900 m := p.memo[pt.offset] 3901 if m == nil { 3902 m = make(map[any]resultTuple) 3903 p.memo[pt.offset] = m 3904 } 3905 m[node] = tuple 3906 } 3907 3908 func (p *parser) buildRulesTable(g *grammar) { 3909 p.rules = make(map[string]*rule, len(g.rules)) 3910 for _, r := range g.rules { 3911 p.rules[r.name] = r 3912 } 3913 } 3914 3915 func (p *parser) parse(g *grammar) (val any, err error) { 3916 if len(g.rules) == 0 { 3917 p.addErr(errNoRule) 3918 return nil, p.errs.err() 3919 } 3920 3921 // TODO : not super critical but this could be generated 3922 p.buildRulesTable(g) 3923 3924 if p.recover { 3925 // panic can be used in action code to stop parsing immediately 3926 // and return the panic as an error. 3927 defer func() { 3928 if e := recover(); e != nil { 3929 if p.debug { 3930 defer p.out(p.in("panic handler")) 3931 } 3932 val = nil 3933 switch e := e.(type) { 3934 case error: 3935 p.addErr(e) 3936 default: 3937 p.addErr(fmt.Errorf("%v", e)) 3938 } 3939 err = p.errs.err() 3940 } 3941 }() 3942 } 3943 3944 startRule, ok := p.rules[p.entrypoint] 3945 if !ok { 3946 p.addErr(errInvalidEntrypoint) 3947 return nil, p.errs.err() 3948 } 3949 3950 p.read() // advance to first rune 3951 val, ok = p.parseRuleWrap(startRule) 3952 if !ok { 3953 if len(*p.errs) == 0 { 3954 // If parsing fails, but no errors have been recorded, the expected values 3955 // for the farthest parser position are returned as error. 3956 maxFailExpectedMap := make(map[string]struct{}, len(p.maxFailExpected)) 3957 for _, v := range p.maxFailExpected { 3958 maxFailExpectedMap[v] = struct{}{} 3959 } 3960 expected := make([]string, 0, len(maxFailExpectedMap)) 3961 eof := false 3962 if _, ok := maxFailExpectedMap["!."]; ok { 3963 delete(maxFailExpectedMap, "!.") 3964 eof = true 3965 } 3966 for k := range maxFailExpectedMap { 3967 expected = append(expected, k) 3968 } 3969 sort.Strings(expected) 3970 if eof { 3971 expected = append(expected, "EOF") 3972 } 3973 p.addErrAt(errors.New("no match found, expected: "+listJoin(expected, ", ", "or")), p.maxFailPos, expected) 3974 } 3975 3976 return nil, p.errs.err() 3977 } 3978 return val, p.errs.err() 3979 } 3980 3981 func listJoin(list []string, sep string, lastSep string) string { 3982 switch len(list) { 3983 case 0: 3984 return "" 3985 case 1: 3986 return list[0] 3987 default: 3988 return strings.Join(list[:len(list)-1], sep) + " " + lastSep + " " + list[len(list)-1] 3989 } 3990 } 3991 3992 func (p *parser) parseRuleMemoize(rule *rule) (any, bool) { 3993 res, ok := p.getMemoized(rule) 3994 if ok { 3995 p.restore(res.end) 3996 return res.v, res.b 3997 } 3998 3999 startMark := p.pt 4000 val, ok := p.parseRule(rule) 4001 p.setMemoized(startMark, rule, resultTuple{val, ok, p.pt}) 4002 4003 return val, ok 4004 } 4005 4006 func (p *parser) parseRuleWrap(rule *rule) (any, bool) { 4007 if p.debug { 4008 defer p.out(p.in("parseRule " + rule.name)) 4009 } 4010 var ( 4011 val any 4012 ok bool 4013 startMark = p.pt 4014 ) 4015 4016 if p.memoize { 4017 val, ok = p.parseRuleMemoize(rule) 4018 } else { 4019 val, ok = p.parseRule(rule) 4020 } 4021 4022 if ok && p.debug { 4023 p.printIndent("MATCH", string(p.sliceFrom(startMark))) 4024 } 4025 return val, ok 4026 } 4027 4028 func (p *parser) parseRule(rule *rule) (any, bool) { 4029 p.rstack = append(p.rstack, rule) 4030 p.pushV() 4031 val, ok := p.parseExprWrap(rule.expr) 4032 p.popV() 4033 p.rstack = p.rstack[:len(p.rstack)-1] 4034 return val, ok 4035 } 4036 4037 func (p *parser) parseExprWrap(expr any) (any, bool) { 4038 var pt savepoint 4039 4040 if p.memoize { 4041 res, ok := p.getMemoized(expr) 4042 if ok { 4043 p.restore(res.end) 4044 return res.v, res.b 4045 } 4046 pt = p.pt 4047 } 4048 4049 val, ok := p.parseExpr(expr) 4050 4051 if p.memoize { 4052 p.setMemoized(pt, expr, resultTuple{val, ok, p.pt}) 4053 } 4054 return val, ok 4055 } 4056 4057 func (p *parser) parseExpr(expr any) (any, bool) { 4058 p.ExprCnt++ 4059 if p.ExprCnt > p.maxExprCnt { 4060 panic(errMaxExprCnt) 4061 } 4062 4063 var val any 4064 var ok bool 4065 switch expr := expr.(type) { 4066 case *actionExpr: 4067 val, ok = p.parseActionExpr(expr) 4068 case *andCodeExpr: 4069 val, ok = p.parseAndCodeExpr(expr) 4070 case *andExpr: 4071 val, ok = p.parseAndExpr(expr) 4072 case *anyMatcher: 4073 val, ok = p.parseAnyMatcher(expr) 4074 case *charClassMatcher: 4075 val, ok = p.parseCharClassMatcher(expr) 4076 case *choiceExpr: 4077 val, ok = p.parseChoiceExpr(expr) 4078 case *labeledExpr: 4079 val, ok = p.parseLabeledExpr(expr) 4080 case *litMatcher: 4081 val, ok = p.parseLitMatcher(expr) 4082 case *notCodeExpr: 4083 val, ok = p.parseNotCodeExpr(expr) 4084 case *notExpr: 4085 val, ok = p.parseNotExpr(expr) 4086 case *oneOrMoreExpr: 4087 val, ok = p.parseOneOrMoreExpr(expr) 4088 case *recoveryExpr: 4089 val, ok = p.parseRecoveryExpr(expr) 4090 case *ruleRefExpr: 4091 val, ok = p.parseRuleRefExpr(expr) 4092 case *seqExpr: 4093 val, ok = p.parseSeqExpr(expr) 4094 case *stateCodeExpr: 4095 val, ok = p.parseStateCodeExpr(expr) 4096 case *throwExpr: 4097 val, ok = p.parseThrowExpr(expr) 4098 case *zeroOrMoreExpr: 4099 val, ok = p.parseZeroOrMoreExpr(expr) 4100 case *zeroOrOneExpr: 4101 val, ok = p.parseZeroOrOneExpr(expr) 4102 default: 4103 panic(fmt.Sprintf("unknown expression type %T", expr)) 4104 } 4105 return val, ok 4106 } 4107 4108 func (p *parser) parseActionExpr(act *actionExpr) (any, bool) { 4109 if p.debug { 4110 defer p.out(p.in("parseActionExpr")) 4111 } 4112 4113 start := p.pt 4114 val, ok := p.parseExprWrap(act.expr) 4115 if ok { 4116 p.cur.pos = start.position 4117 p.cur.text = p.sliceFrom(start) 4118 state := p.cloneState() 4119 actVal, err := act.run(p) 4120 if err != nil { 4121 p.addErrAt(err, start.position, []string{}) 4122 } 4123 p.restoreState(state) 4124 4125 val = actVal 4126 } 4127 if ok && p.debug { 4128 p.printIndent("MATCH", string(p.sliceFrom(start))) 4129 } 4130 return val, ok 4131 } 4132 4133 func (p *parser) parseAndCodeExpr(and *andCodeExpr) (any, bool) { 4134 if p.debug { 4135 defer p.out(p.in("parseAndCodeExpr")) 4136 } 4137 4138 state := p.cloneState() 4139 4140 ok, err := and.run(p) 4141 if err != nil { 4142 p.addErr(err) 4143 } 4144 p.restoreState(state) 4145 4146 return nil, ok 4147 } 4148 4149 func (p *parser) parseAndExpr(and *andExpr) (any, bool) { 4150 if p.debug { 4151 defer p.out(p.in("parseAndExpr")) 4152 } 4153 4154 pt := p.pt 4155 state := p.cloneState() 4156 p.pushV() 4157 _, ok := p.parseExprWrap(and.expr) 4158 p.popV() 4159 p.restoreState(state) 4160 p.restore(pt) 4161 4162 return nil, ok 4163 } 4164 4165 func (p *parser) parseAnyMatcher(any *anyMatcher) (any, bool) { 4166 if p.debug { 4167 defer p.out(p.in("parseAnyMatcher")) 4168 } 4169 4170 if p.pt.rn == utf8.RuneError && p.pt.w == 0 { 4171 // EOF - see utf8.DecodeRune 4172 p.failAt(false, p.pt.position, ".") 4173 return nil, false 4174 } 4175 start := p.pt 4176 p.read() 4177 p.failAt(true, start.position, ".") 4178 return p.sliceFrom(start), true 4179 } 4180 4181 func (p *parser) parseCharClassMatcher(chr *charClassMatcher) (any, bool) { 4182 if p.debug { 4183 defer p.out(p.in("parseCharClassMatcher")) 4184 } 4185 4186 cur := p.pt.rn 4187 start := p.pt 4188 4189 // can't match EOF 4190 if cur == utf8.RuneError && p.pt.w == 0 { // see utf8.DecodeRune 4191 p.failAt(false, start.position, chr.val) 4192 return nil, false 4193 } 4194 4195 if chr.ignoreCase { 4196 cur = unicode.ToLower(cur) 4197 } 4198 4199 // try to match in the list of available chars 4200 for _, rn := range chr.chars { 4201 if rn == cur { 4202 if chr.inverted { 4203 p.failAt(false, start.position, chr.val) 4204 return nil, false 4205 } 4206 p.read() 4207 p.failAt(true, start.position, chr.val) 4208 return p.sliceFrom(start), true 4209 } 4210 } 4211 4212 // try to match in the list of ranges 4213 for i := 0; i < len(chr.ranges); i += 2 { 4214 if cur >= chr.ranges[i] && cur <= chr.ranges[i+1] { 4215 if chr.inverted { 4216 p.failAt(false, start.position, chr.val) 4217 return nil, false 4218 } 4219 p.read() 4220 p.failAt(true, start.position, chr.val) 4221 return p.sliceFrom(start), true 4222 } 4223 } 4224 4225 // try to match in the list of Unicode classes 4226 for _, cl := range chr.classes { 4227 if unicode.Is(cl, cur) { 4228 if chr.inverted { 4229 p.failAt(false, start.position, chr.val) 4230 return nil, false 4231 } 4232 p.read() 4233 p.failAt(true, start.position, chr.val) 4234 return p.sliceFrom(start), true 4235 } 4236 } 4237 4238 if chr.inverted { 4239 p.read() 4240 p.failAt(true, start.position, chr.val) 4241 return p.sliceFrom(start), true 4242 } 4243 p.failAt(false, start.position, chr.val) 4244 return nil, false 4245 } 4246 4247 func (p *parser) incChoiceAltCnt(ch *choiceExpr, altI int) { 4248 choiceIdent := fmt.Sprintf("%s %d:%d", p.rstack[len(p.rstack)-1].name, ch.pos.line, ch.pos.col) 4249 m := p.ChoiceAltCnt[choiceIdent] 4250 if m == nil { 4251 m = make(map[string]int) 4252 p.ChoiceAltCnt[choiceIdent] = m 4253 } 4254 // We increment altI by 1, so the keys do not start at 0 4255 alt := strconv.Itoa(altI + 1) 4256 if altI == choiceNoMatch { 4257 alt = p.choiceNoMatch 4258 } 4259 m[alt]++ 4260 } 4261 4262 func (p *parser) parseChoiceExpr(ch *choiceExpr) (any, bool) { 4263 if p.debug { 4264 defer p.out(p.in("parseChoiceExpr")) 4265 } 4266 4267 for altI, alt := range ch.alternatives { 4268 // dummy assignment to prevent compile error if optimized 4269 _ = altI 4270 4271 state := p.cloneState() 4272 4273 p.pushV() 4274 val, ok := p.parseExprWrap(alt) 4275 p.popV() 4276 if ok { 4277 p.incChoiceAltCnt(ch, altI) 4278 return val, ok 4279 } 4280 p.restoreState(state) 4281 } 4282 p.incChoiceAltCnt(ch, choiceNoMatch) 4283 return nil, false 4284 } 4285 4286 func (p *parser) parseLabeledExpr(lab *labeledExpr) (any, bool) { 4287 if p.debug { 4288 defer p.out(p.in("parseLabeledExpr")) 4289 } 4290 4291 p.pushV() 4292 val, ok := p.parseExprWrap(lab.expr) 4293 p.popV() 4294 if ok && lab.label != "" { 4295 m := p.vstack[len(p.vstack)-1] 4296 m[lab.label] = val 4297 } 4298 return val, ok 4299 } 4300 4301 func (p *parser) parseLitMatcher(lit *litMatcher) (any, bool) { 4302 if p.debug { 4303 defer p.out(p.in("parseLitMatcher")) 4304 } 4305 4306 start := p.pt 4307 for _, want := range lit.val { 4308 cur := p.pt.rn 4309 if lit.ignoreCase { 4310 cur = unicode.ToLower(cur) 4311 } 4312 if cur != want { 4313 p.failAt(false, start.position, lit.want) 4314 p.restore(start) 4315 return nil, false 4316 } 4317 p.read() 4318 } 4319 p.failAt(true, start.position, lit.want) 4320 return p.sliceFrom(start), true 4321 } 4322 4323 func (p *parser) parseNotCodeExpr(not *notCodeExpr) (any, bool) { 4324 if p.debug { 4325 defer p.out(p.in("parseNotCodeExpr")) 4326 } 4327 4328 state := p.cloneState() 4329 4330 ok, err := not.run(p) 4331 if err != nil { 4332 p.addErr(err) 4333 } 4334 p.restoreState(state) 4335 4336 return nil, !ok 4337 } 4338 4339 func (p *parser) parseNotExpr(not *notExpr) (any, bool) { 4340 if p.debug { 4341 defer p.out(p.in("parseNotExpr")) 4342 } 4343 4344 pt := p.pt 4345 state := p.cloneState() 4346 p.pushV() 4347 p.maxFailInvertExpected = !p.maxFailInvertExpected 4348 _, ok := p.parseExprWrap(not.expr) 4349 p.maxFailInvertExpected = !p.maxFailInvertExpected 4350 p.popV() 4351 p.restoreState(state) 4352 p.restore(pt) 4353 4354 return nil, !ok 4355 } 4356 4357 func (p *parser) parseOneOrMoreExpr(expr *oneOrMoreExpr) (any, bool) { 4358 if p.debug { 4359 defer p.out(p.in("parseOneOrMoreExpr")) 4360 } 4361 4362 var vals []any 4363 4364 for { 4365 p.pushV() 4366 val, ok := p.parseExprWrap(expr.expr) 4367 p.popV() 4368 if !ok { 4369 if len(vals) == 0 { 4370 // did not match once, no match 4371 return nil, false 4372 } 4373 return vals, true 4374 } 4375 vals = append(vals, val) 4376 } 4377 } 4378 4379 func (p *parser) parseRecoveryExpr(recover *recoveryExpr) (any, bool) { 4380 if p.debug { 4381 defer p.out(p.in("parseRecoveryExpr (" + strings.Join(recover.failureLabel, ",") + ")")) 4382 } 4383 4384 p.pushRecovery(recover.failureLabel, recover.recoverExpr) 4385 val, ok := p.parseExprWrap(recover.expr) 4386 p.popRecovery() 4387 4388 return val, ok 4389 } 4390 4391 func (p *parser) parseRuleRefExpr(ref *ruleRefExpr) (any, bool) { 4392 if p.debug { 4393 defer p.out(p.in("parseRuleRefExpr " + ref.name)) 4394 } 4395 4396 if ref.name == "" { 4397 panic(fmt.Sprintf("%s: invalid rule: missing name", ref.pos)) 4398 } 4399 4400 rule := p.rules[ref.name] 4401 if rule == nil { 4402 p.addErr(fmt.Errorf("undefined rule: %s", ref.name)) 4403 return nil, false 4404 } 4405 return p.parseRuleWrap(rule) 4406 } 4407 4408 func (p *parser) parseSeqExpr(seq *seqExpr) (any, bool) { 4409 if p.debug { 4410 defer p.out(p.in("parseSeqExpr")) 4411 } 4412 4413 vals := make([]any, 0, len(seq.exprs)) 4414 4415 pt := p.pt 4416 state := p.cloneState() 4417 for _, expr := range seq.exprs { 4418 val, ok := p.parseExprWrap(expr) 4419 if !ok { 4420 p.restoreState(state) 4421 p.restore(pt) 4422 return nil, false 4423 } 4424 vals = append(vals, val) 4425 } 4426 return vals, true 4427 } 4428 4429 func (p *parser) parseStateCodeExpr(state *stateCodeExpr) (any, bool) { 4430 if p.debug { 4431 defer p.out(p.in("parseStateCodeExpr")) 4432 } 4433 4434 err := state.run(p) 4435 if err != nil { 4436 p.addErr(err) 4437 } 4438 return nil, true 4439 } 4440 4441 func (p *parser) parseThrowExpr(expr *throwExpr) (any, bool) { 4442 if p.debug { 4443 defer p.out(p.in("parseThrowExpr")) 4444 } 4445 4446 for i := len(p.recoveryStack) - 1; i >= 0; i-- { 4447 if recoverExpr, ok := p.recoveryStack[i][expr.label]; ok { 4448 if val, ok := p.parseExprWrap(recoverExpr); ok { 4449 return val, ok 4450 } 4451 } 4452 } 4453 4454 return nil, false 4455 } 4456 4457 func (p *parser) parseZeroOrMoreExpr(expr *zeroOrMoreExpr) (any, bool) { 4458 if p.debug { 4459 defer p.out(p.in("parseZeroOrMoreExpr")) 4460 } 4461 4462 var vals []any 4463 4464 for { 4465 p.pushV() 4466 val, ok := p.parseExprWrap(expr.expr) 4467 p.popV() 4468 if !ok { 4469 return vals, true 4470 } 4471 vals = append(vals, val) 4472 } 4473 } 4474 4475 func (p *parser) parseZeroOrOneExpr(expr *zeroOrOneExpr) (any, bool) { 4476 if p.debug { 4477 defer p.out(p.in("parseZeroOrOneExpr")) 4478 } 4479 4480 p.pushV() 4481 val, _ := p.parseExprWrap(expr.expr) 4482 p.popV() 4483 // whether it matched or not, consider it a match 4484 return val, true 4485 }