// Code generated by pigeon; DO NOT EDIT. package kql import ( "bytes" "errors" "fmt" "io" "math" "os" "sort" "strconv" "strings" "unicode" "unicode/utf8" ) var g = &grammar{ rules: []*rule{ { name: "AST", pos: position{line: 9, col: 1, offset: 143}, expr: &actionExpr{ pos: position{line: 10, col: 5, offset: 154}, run: (*parser).callonAST1, expr: &labeledExpr{ pos: position{line: 10, col: 5, offset: 154}, label: "n", expr: &ruleRefExpr{ pos: position{line: 10, col: 7, offset: 156}, name: "Nodes", }, }, }, }, { name: "Nodes", pos: position{line: 18, col: 1, offset: 337}, expr: &oneOrMoreExpr{ pos: position{line: 19, col: 5, offset: 350}, expr: &seqExpr{ pos: position{line: 19, col: 6, offset: 351}, exprs: []any{ &actionExpr{ pos: position{line: 238, col: 5, offset: 4858}, run: (*parser).callonNodes3, expr: &zeroOrMoreExpr{ pos: position{line: 238, col: 5, offset: 4858}, expr: &charClassMatcher{ pos: position{line: 238, col: 5, offset: 4858}, val: "[ \\t]", chars: []rune{' ', '\t'}, ignoreCase: false, inverted: false, }, }, }, &ruleRefExpr{ pos: position{line: 19, col: 8, offset: 353}, name: "Node", }, }, }, }, }, { name: "Node", pos: position{line: 21, col: 1, offset: 361}, expr: &choiceExpr{ pos: position{line: 22, col: 5, offset: 373}, alternatives: []any{ &ruleRefExpr{ pos: position{line: 22, col: 5, offset: 373}, name: "GroupNode", }, &actionExpr{ pos: position{line: 46, col: 5, offset: 1038}, run: (*parser).callonNode3, expr: &seqExpr{ pos: position{line: 46, col: 5, offset: 1038}, exprs: []any{ &labeledExpr{ pos: position{line: 46, col: 5, offset: 1038}, label: "k", expr: &actionExpr{ pos: position{line: 223, col: 5, offset: 4678}, run: (*parser).callonNode6, expr: &seqExpr{ pos: position{line: 223, col: 5, offset: 4678}, exprs: []any{ &oneOrMoreExpr{ pos: position{line: 223, col: 5, offset: 4678}, expr: &actionExpr{ pos: position{line: 218, col: 5, offset: 4622}, run: (*parser).callonNode9, expr: &charClassMatcher{ pos: position{line: 218, col: 5, offset: 4622}, val: "[A-Za-z]", ranges: []rune{'A', 'Z', 'a', 'z'}, ignoreCase: false, inverted: false, }, }, }, &zeroOrMoreExpr{ pos: position{line: 223, col: 11, offset: 4684}, expr: &seqExpr{ pos: position{line: 223, col: 12, offset: 4685}, exprs: []any{ &litMatcher{ pos: position{line: 223, col: 12, offset: 4685}, val: ".", ignoreCase: false, want: "\".\"", }, &oneOrMoreExpr{ pos: position{line: 223, col: 16, offset: 4689}, expr: &actionExpr{ pos: position{line: 218, col: 5, offset: 4622}, run: (*parser).callonNode15, expr: &charClassMatcher{ pos: position{line: 218, col: 5, offset: 4622}, val: "[A-Za-z]", ranges: []rune{'A', 'Z', 'a', 'z'}, ignoreCase: false, inverted: false, }, }, }, }, }, }, }, }, }, }, &choiceExpr{ pos: position{line: 46, col: 12, offset: 1045}, alternatives: []any{ &actionExpr{ pos: position{line: 120, col: 5, offset: 2899}, run: (*parser).callonNode18, expr: &litMatcher{ pos: position{line: 120, col: 5, offset: 2899}, val: ":", ignoreCase: false, want: "\":\"", }, }, &actionExpr{ pos: position{line: 125, col: 5, offset: 2985}, run: (*parser).callonNode20, expr: &litMatcher{ pos: position{line: 125, col: 5, offset: 2985}, val: "=", ignoreCase: false, want: "\"=\"", }, }, }, }, &labeledExpr{ pos: position{line: 46, col: 51, offset: 1084}, label: "v", expr: &choiceExpr{ pos: position{line: 46, col: 54, offset: 1087}, alternatives: []any{ &litMatcher{ pos: position{line: 46, col: 54, offset: 1087}, val: "true", ignoreCase: false, want: "\"true\"", }, &litMatcher{ pos: position{line: 46, col: 63, offset: 1096}, val: "false", ignoreCase: false, want: "\"false\"", }, }, }, }, }, }, }, &actionExpr{ pos: position{line: 51, col: 5, offset: 1197}, run: (*parser).callonNode26, expr: &seqExpr{ pos: position{line: 51, col: 5, offset: 1197}, exprs: []any{ &labeledExpr{ pos: position{line: 51, col: 5, offset: 1197}, label: "k", expr: &actionExpr{ pos: position{line: 223, col: 5, offset: 4678}, run: (*parser).callonNode29, expr: &seqExpr{ pos: position{line: 223, col: 5, offset: 4678}, exprs: []any{ &oneOrMoreExpr{ pos: position{line: 223, col: 5, offset: 4678}, expr: &actionExpr{ pos: position{line: 218, col: 5, offset: 4622}, run: (*parser).callonNode32, expr: &charClassMatcher{ pos: position{line: 218, col: 5, offset: 4622}, val: "[A-Za-z]", ranges: []rune{'A', 'Z', 'a', 'z'}, ignoreCase: false, inverted: false, }, }, }, &zeroOrMoreExpr{ pos: position{line: 223, col: 11, offset: 4684}, expr: &seqExpr{ pos: position{line: 223, col: 12, offset: 4685}, exprs: []any{ &litMatcher{ pos: position{line: 223, col: 12, offset: 4685}, val: ".", ignoreCase: false, want: "\".\"", }, &oneOrMoreExpr{ pos: position{line: 223, col: 16, offset: 4689}, expr: &actionExpr{ pos: position{line: 218, col: 5, offset: 4622}, run: (*parser).callonNode38, expr: &charClassMatcher{ pos: position{line: 218, col: 5, offset: 4622}, val: "[A-Za-z]", ranges: []rune{'A', 'Z', 'a', 'z'}, ignoreCase: false, inverted: false, }, }, }, }, }, }, }, }, }, }, &labeledExpr{ pos: position{line: 51, col: 11, offset: 1203}, label: "o", expr: &choiceExpr{ pos: position{line: 52, col: 9, offset: 1215}, alternatives: []any{ &actionExpr{ pos: position{line: 145, col: 5, offset: 3346}, run: (*parser).callonNode42, expr: &litMatcher{ pos: position{line: 145, col: 5, offset: 3346}, val: ">=", ignoreCase: false, want: "\">=\"", }, }, &actionExpr{ pos: position{line: 135, col: 5, offset: 3162}, run: (*parser).callonNode44, expr: &litMatcher{ pos: position{line: 135, col: 5, offset: 3162}, val: "<=", ignoreCase: false, want: "\"<=\"", }, }, &actionExpr{ pos: position{line: 140, col: 5, offset: 3251}, run: (*parser).callonNode46, expr: &litMatcher{ pos: position{line: 140, col: 5, offset: 3251}, val: ">", ignoreCase: false, want: "\">\"", }, }, &actionExpr{ pos: position{line: 130, col: 5, offset: 3070}, run: (*parser).callonNode48, expr: &litMatcher{ pos: position{line: 130, col: 5, offset: 3070}, val: "<", ignoreCase: false, want: "\"<\"", }, }, &actionExpr{ pos: position{line: 125, col: 5, offset: 2985}, run: (*parser).callonNode50, expr: &litMatcher{ pos: position{line: 125, col: 5, offset: 2985}, val: "=", ignoreCase: false, want: "\"=\"", }, }, &actionExpr{ pos: position{line: 120, col: 5, offset: 2899}, run: (*parser).callonNode52, expr: &litMatcher{ pos: position{line: 120, col: 5, offset: 2899}, val: ":", ignoreCase: false, want: "\":\"", }, }, }, }, }, &zeroOrOneExpr{ pos: position{line: 58, col: 7, offset: 1395}, expr: &litMatcher{ pos: position{line: 58, col: 7, offset: 1395}, val: "\"", ignoreCase: false, want: "\"\\\"\"", }, }, &labeledExpr{ pos: position{line: 58, col: 12, offset: 1400}, label: "v", expr: &choiceExpr{ pos: position{line: 59, col: 9, offset: 1412}, alternatives: []any{ &actionExpr{ pos: position{line: 195, col: 5, offset: 4185}, run: (*parser).callonNode58, expr: &seqExpr{ pos: position{line: 195, col: 5, offset: 4185}, exprs: []any{ &actionExpr{ pos: position{line: 185, col: 5, offset: 3948}, run: (*parser).callonNode60, expr: &seqExpr{ pos: position{line: 185, col: 5, offset: 3948}, exprs: []any{ &actionExpr{ pos: position{line: 155, col: 5, offset: 3548}, run: (*parser).callonNode62, expr: &seqExpr{ pos: position{line: 155, col: 5, offset: 3548}, exprs: []any{ &actionExpr{ pos: position{line: 233, col: 5, offset: 4807}, run: (*parser).callonNode64, expr: &charClassMatcher{ pos: position{line: 233, col: 5, offset: 4807}, val: "[0-9]", ranges: []rune{'0', '9'}, ignoreCase: false, inverted: false, }, }, &actionExpr{ pos: position{line: 233, col: 5, offset: 4807}, run: (*parser).callonNode66, expr: &charClassMatcher{ pos: position{line: 233, col: 5, offset: 4807}, val: "[0-9]", ranges: []rune{'0', '9'}, ignoreCase: false, inverted: false, }, }, &actionExpr{ pos: position{line: 233, col: 5, offset: 4807}, run: (*parser).callonNode68, expr: &charClassMatcher{ pos: position{line: 233, col: 5, offset: 4807}, val: "[0-9]", ranges: []rune{'0', '9'}, ignoreCase: false, inverted: false, }, }, &actionExpr{ pos: position{line: 233, col: 5, offset: 4807}, run: (*parser).callonNode70, expr: &charClassMatcher{ pos: position{line: 233, col: 5, offset: 4807}, val: "[0-9]", ranges: []rune{'0', '9'}, ignoreCase: false, inverted: false, }, }, }, }, }, &litMatcher{ pos: position{line: 185, col: 14, offset: 3957}, val: "-", ignoreCase: false, want: "\"-\"", }, &actionExpr{ pos: position{line: 160, col: 5, offset: 3625}, run: (*parser).callonNode73, expr: &seqExpr{ pos: position{line: 160, col: 5, offset: 3625}, exprs: []any{ &actionExpr{ pos: position{line: 233, col: 5, offset: 4807}, run: (*parser).callonNode75, expr: &charClassMatcher{ pos: position{line: 233, col: 5, offset: 4807}, val: "[0-9]", ranges: []rune{'0', '9'}, ignoreCase: false, inverted: false, }, }, &actionExpr{ pos: position{line: 233, col: 5, offset: 4807}, run: (*parser).callonNode77, expr: &charClassMatcher{ pos: position{line: 233, col: 5, offset: 4807}, val: "[0-9]", ranges: []rune{'0', '9'}, ignoreCase: false, inverted: false, }, }, }, }, }, &litMatcher{ pos: position{line: 185, col: 28, offset: 3971}, val: "-", ignoreCase: false, want: "\"-\"", }, &actionExpr{ pos: position{line: 165, col: 5, offset: 3688}, run: (*parser).callonNode80, expr: &seqExpr{ pos: position{line: 165, col: 5, offset: 3688}, exprs: []any{ &actionExpr{ pos: position{line: 233, col: 5, offset: 4807}, run: (*parser).callonNode82, expr: &charClassMatcher{ pos: position{line: 233, col: 5, offset: 4807}, val: "[0-9]", ranges: []rune{'0', '9'}, ignoreCase: false, inverted: false, }, }, &actionExpr{ pos: position{line: 233, col: 5, offset: 4807}, run: (*parser).callonNode84, expr: &charClassMatcher{ pos: position{line: 233, col: 5, offset: 4807}, val: "[0-9]", ranges: []rune{'0', '9'}, ignoreCase: false, inverted: false, }, }, }, }, }, }, }, }, &litMatcher{ pos: position{line: 195, col: 14, offset: 4194}, val: "T", ignoreCase: false, want: "\"T\"", }, &actionExpr{ pos: position{line: 190, col: 5, offset: 4035}, run: (*parser).callonNode87, expr: &seqExpr{ pos: position{line: 190, col: 5, offset: 4035}, exprs: []any{ &actionExpr{ pos: position{line: 170, col: 5, offset: 3752}, run: (*parser).callonNode89, expr: &seqExpr{ pos: position{line: 170, col: 5, offset: 3752}, exprs: []any{ &actionExpr{ pos: position{line: 233, col: 5, offset: 4807}, run: (*parser).callonNode91, expr: &charClassMatcher{ pos: position{line: 233, col: 5, offset: 4807}, val: "[0-9]", ranges: []rune{'0', '9'}, ignoreCase: false, inverted: false, }, }, &actionExpr{ pos: position{line: 233, col: 5, offset: 4807}, run: (*parser).callonNode93, expr: &charClassMatcher{ pos: position{line: 233, col: 5, offset: 4807}, val: "[0-9]", ranges: []rune{'0', '9'}, ignoreCase: false, inverted: false, }, }, }, }, }, &litMatcher{ pos: position{line: 190, col: 14, offset: 4044}, val: ":", ignoreCase: false, want: "\":\"", }, &actionExpr{ pos: position{line: 175, col: 5, offset: 3818}, run: (*parser).callonNode96, expr: &seqExpr{ pos: position{line: 175, col: 5, offset: 3818}, exprs: []any{ &actionExpr{ pos: position{line: 233, col: 5, offset: 4807}, run: (*parser).callonNode98, expr: &charClassMatcher{ pos: position{line: 233, col: 5, offset: 4807}, val: "[0-9]", ranges: []rune{'0', '9'}, ignoreCase: false, inverted: false, }, }, &actionExpr{ pos: position{line: 233, col: 5, offset: 4807}, run: (*parser).callonNode100, expr: &charClassMatcher{ pos: position{line: 233, col: 5, offset: 4807}, val: "[0-9]", ranges: []rune{'0', '9'}, ignoreCase: false, inverted: false, }, }, }, }, }, &litMatcher{ pos: position{line: 190, col: 29, offset: 4059}, val: ":", ignoreCase: false, want: "\":\"", }, &actionExpr{ pos: position{line: 180, col: 5, offset: 3884}, run: (*parser).callonNode103, expr: &seqExpr{ pos: position{line: 180, col: 5, offset: 3884}, exprs: []any{ &actionExpr{ pos: position{line: 233, col: 5, offset: 4807}, run: (*parser).callonNode105, expr: &charClassMatcher{ pos: position{line: 233, col: 5, offset: 4807}, val: "[0-9]", ranges: []rune{'0', '9'}, ignoreCase: false, inverted: false, }, }, &actionExpr{ pos: position{line: 233, col: 5, offset: 4807}, run: (*parser).callonNode107, expr: &charClassMatcher{ pos: position{line: 233, col: 5, offset: 4807}, val: "[0-9]", ranges: []rune{'0', '9'}, ignoreCase: false, inverted: false, }, }, }, }, }, &zeroOrOneExpr{ pos: position{line: 190, col: 44, offset: 4074}, expr: &seqExpr{ pos: position{line: 190, col: 45, offset: 4075}, exprs: []any{ &litMatcher{ pos: position{line: 190, col: 45, offset: 4075}, val: ".", ignoreCase: false, want: "\".\"", }, &oneOrMoreExpr{ pos: position{line: 190, col: 49, offset: 4079}, expr: &actionExpr{ pos: position{line: 233, col: 5, offset: 4807}, run: (*parser).callonNode113, expr: &charClassMatcher{ pos: position{line: 233, col: 5, offset: 4807}, val: "[0-9]", ranges: []rune{'0', '9'}, ignoreCase: false, inverted: false, }, }, }, }, }, }, &choiceExpr{ pos: position{line: 190, col: 59, offset: 4089}, alternatives: []any{ &litMatcher{ pos: position{line: 190, col: 59, offset: 4089}, val: "Z", ignoreCase: false, want: "\"Z\"", }, &seqExpr{ pos: position{line: 190, col: 65, offset: 4095}, exprs: []any{ &charClassMatcher{ pos: position{line: 190, col: 66, offset: 4096}, val: "[+-]", chars: []rune{'+', '-'}, ignoreCase: false, inverted: false, }, &actionExpr{ pos: position{line: 170, col: 5, offset: 3752}, run: (*parser).callonNode119, expr: &seqExpr{ pos: position{line: 170, col: 5, offset: 3752}, exprs: []any{ &actionExpr{ pos: position{line: 233, col: 5, offset: 4807}, run: (*parser).callonNode121, expr: &charClassMatcher{ pos: position{line: 233, col: 5, offset: 4807}, val: "[0-9]", ranges: []rune{'0', '9'}, ignoreCase: false, inverted: false, }, }, &actionExpr{ pos: position{line: 233, col: 5, offset: 4807}, run: (*parser).callonNode123, expr: &charClassMatcher{ pos: position{line: 233, col: 5, offset: 4807}, val: "[0-9]", ranges: []rune{'0', '9'}, ignoreCase: false, inverted: false, }, }, }, }, }, &litMatcher{ pos: position{line: 190, col: 86, offset: 4116}, val: ":", ignoreCase: false, want: "\":\"", }, &actionExpr{ pos: position{line: 175, col: 5, offset: 3818}, run: (*parser).callonNode126, expr: &seqExpr{ pos: position{line: 175, col: 5, offset: 3818}, exprs: []any{ &actionExpr{ pos: position{line: 233, col: 5, offset: 4807}, run: (*parser).callonNode128, expr: &charClassMatcher{ pos: position{line: 233, col: 5, offset: 4807}, val: "[0-9]", ranges: []rune{'0', '9'}, ignoreCase: false, inverted: false, }, }, &actionExpr{ pos: position{line: 233, col: 5, offset: 4807}, run: (*parser).callonNode130, expr: &charClassMatcher{ pos: position{line: 233, col: 5, offset: 4807}, val: "[0-9]", ranges: []rune{'0', '9'}, ignoreCase: false, inverted: false, }, }, }, }, }, }, }, }, }, }, }, }, }, }, }, &actionExpr{ pos: position{line: 185, col: 5, offset: 3948}, run: (*parser).callonNode132, expr: &seqExpr{ pos: position{line: 185, col: 5, offset: 3948}, exprs: []any{ &actionExpr{ pos: position{line: 155, col: 5, offset: 3548}, run: (*parser).callonNode134, expr: &seqExpr{ pos: position{line: 155, col: 5, offset: 3548}, exprs: []any{ &actionExpr{ pos: position{line: 233, col: 5, offset: 4807}, run: (*parser).callonNode136, expr: &charClassMatcher{ pos: position{line: 233, col: 5, offset: 4807}, val: "[0-9]", ranges: []rune{'0', '9'}, ignoreCase: false, inverted: false, }, }, &actionExpr{ pos: position{line: 233, col: 5, offset: 4807}, run: (*parser).callonNode138, expr: &charClassMatcher{ pos: position{line: 233, col: 5, offset: 4807}, val: "[0-9]", ranges: []rune{'0', '9'}, ignoreCase: false, inverted: false, }, }, &actionExpr{ pos: position{line: 233, col: 5, offset: 4807}, run: (*parser).callonNode140, expr: &charClassMatcher{ pos: position{line: 233, col: 5, offset: 4807}, val: "[0-9]", ranges: []rune{'0', '9'}, ignoreCase: false, inverted: false, }, }, &actionExpr{ pos: position{line: 233, col: 5, offset: 4807}, run: (*parser).callonNode142, expr: &charClassMatcher{ pos: position{line: 233, col: 5, offset: 4807}, val: "[0-9]", ranges: []rune{'0', '9'}, ignoreCase: false, inverted: false, }, }, }, }, }, &litMatcher{ pos: position{line: 185, col: 14, offset: 3957}, val: "-", ignoreCase: false, want: "\"-\"", }, &actionExpr{ pos: position{line: 160, col: 5, offset: 3625}, run: (*parser).callonNode145, expr: &seqExpr{ pos: position{line: 160, col: 5, offset: 3625}, exprs: []any{ &actionExpr{ pos: position{line: 233, col: 5, offset: 4807}, run: (*parser).callonNode147, expr: &charClassMatcher{ pos: position{line: 233, col: 5, offset: 4807}, val: "[0-9]", ranges: []rune{'0', '9'}, ignoreCase: false, inverted: false, }, }, &actionExpr{ pos: position{line: 233, col: 5, offset: 4807}, run: (*parser).callonNode149, expr: &charClassMatcher{ pos: position{line: 233, col: 5, offset: 4807}, val: "[0-9]", ranges: []rune{'0', '9'}, ignoreCase: false, inverted: false, }, }, }, }, }, &litMatcher{ pos: position{line: 185, col: 28, offset: 3971}, val: "-", ignoreCase: false, want: "\"-\"", }, &actionExpr{ pos: position{line: 165, col: 5, offset: 3688}, run: (*parser).callonNode152, expr: &seqExpr{ pos: position{line: 165, col: 5, offset: 3688}, exprs: []any{ &actionExpr{ pos: position{line: 233, col: 5, offset: 4807}, run: (*parser).callonNode154, expr: &charClassMatcher{ pos: position{line: 233, col: 5, offset: 4807}, val: "[0-9]", ranges: []rune{'0', '9'}, ignoreCase: false, inverted: false, }, }, &actionExpr{ pos: position{line: 233, col: 5, offset: 4807}, run: (*parser).callonNode156, expr: &charClassMatcher{ pos: position{line: 233, col: 5, offset: 4807}, val: "[0-9]", ranges: []rune{'0', '9'}, ignoreCase: false, inverted: false, }, }, }, }, }, }, }, }, &actionExpr{ pos: position{line: 190, col: 5, offset: 4035}, run: (*parser).callonNode158, expr: &seqExpr{ pos: position{line: 190, col: 5, offset: 4035}, exprs: []any{ &actionExpr{ pos: position{line: 170, col: 5, offset: 3752}, run: (*parser).callonNode160, expr: &seqExpr{ pos: position{line: 170, col: 5, offset: 3752}, exprs: []any{ &actionExpr{ pos: position{line: 233, col: 5, offset: 4807}, run: (*parser).callonNode162, expr: &charClassMatcher{ pos: position{line: 233, col: 5, offset: 4807}, val: "[0-9]", ranges: []rune{'0', '9'}, ignoreCase: false, inverted: false, }, }, &actionExpr{ pos: position{line: 233, col: 5, offset: 4807}, run: (*parser).callonNode164, expr: &charClassMatcher{ pos: position{line: 233, col: 5, offset: 4807}, val: "[0-9]", ranges: []rune{'0', '9'}, ignoreCase: false, inverted: false, }, }, }, }, }, &litMatcher{ pos: position{line: 190, col: 14, offset: 4044}, val: ":", ignoreCase: false, want: "\":\"", }, &actionExpr{ pos: position{line: 175, col: 5, offset: 3818}, run: (*parser).callonNode167, expr: &seqExpr{ pos: position{line: 175, col: 5, offset: 3818}, exprs: []any{ &actionExpr{ pos: position{line: 233, col: 5, offset: 4807}, run: (*parser).callonNode169, expr: &charClassMatcher{ pos: position{line: 233, col: 5, offset: 4807}, val: "[0-9]", ranges: []rune{'0', '9'}, ignoreCase: false, inverted: false, }, }, &actionExpr{ pos: position{line: 233, col: 5, offset: 4807}, run: (*parser).callonNode171, expr: &charClassMatcher{ pos: position{line: 233, col: 5, offset: 4807}, val: "[0-9]", ranges: []rune{'0', '9'}, ignoreCase: false, inverted: false, }, }, }, }, }, &litMatcher{ pos: position{line: 190, col: 29, offset: 4059}, val: ":", ignoreCase: false, want: "\":\"", }, &actionExpr{ pos: position{line: 180, col: 5, offset: 3884}, run: (*parser).callonNode174, expr: &seqExpr{ pos: position{line: 180, col: 5, offset: 3884}, exprs: []any{ &actionExpr{ pos: position{line: 233, col: 5, offset: 4807}, run: (*parser).callonNode176, expr: &charClassMatcher{ pos: position{line: 233, col: 5, offset: 4807}, val: "[0-9]", ranges: []rune{'0', '9'}, ignoreCase: false, inverted: false, }, }, &actionExpr{ pos: position{line: 233, col: 5, offset: 4807}, run: (*parser).callonNode178, expr: &charClassMatcher{ pos: position{line: 233, col: 5, offset: 4807}, val: "[0-9]", ranges: []rune{'0', '9'}, ignoreCase: false, inverted: false, }, }, }, }, }, &zeroOrOneExpr{ pos: position{line: 190, col: 44, offset: 4074}, expr: &seqExpr{ pos: position{line: 190, col: 45, offset: 4075}, exprs: []any{ &litMatcher{ pos: position{line: 190, col: 45, offset: 4075}, val: ".", ignoreCase: false, want: "\".\"", }, &oneOrMoreExpr{ pos: position{line: 190, col: 49, offset: 4079}, expr: &actionExpr{ pos: position{line: 233, col: 5, offset: 4807}, run: (*parser).callonNode184, expr: &charClassMatcher{ pos: position{line: 233, col: 5, offset: 4807}, val: "[0-9]", ranges: []rune{'0', '9'}, ignoreCase: false, inverted: false, }, }, }, }, }, }, &choiceExpr{ pos: position{line: 190, col: 59, offset: 4089}, alternatives: []any{ &litMatcher{ pos: position{line: 190, col: 59, offset: 4089}, val: "Z", ignoreCase: false, want: "\"Z\"", }, &seqExpr{ pos: position{line: 190, col: 65, offset: 4095}, exprs: []any{ &charClassMatcher{ pos: position{line: 190, col: 66, offset: 4096}, val: "[+-]", chars: []rune{'+', '-'}, ignoreCase: false, inverted: false, }, &actionExpr{ pos: position{line: 170, col: 5, offset: 3752}, run: (*parser).callonNode190, expr: &seqExpr{ pos: position{line: 170, col: 5, offset: 3752}, exprs: []any{ &actionExpr{ pos: position{line: 233, col: 5, offset: 4807}, run: (*parser).callonNode192, expr: &charClassMatcher{ pos: position{line: 233, col: 5, offset: 4807}, val: "[0-9]", ranges: []rune{'0', '9'}, ignoreCase: false, inverted: false, }, }, &actionExpr{ pos: position{line: 233, col: 5, offset: 4807}, run: (*parser).callonNode194, expr: &charClassMatcher{ pos: position{line: 233, col: 5, offset: 4807}, val: "[0-9]", ranges: []rune{'0', '9'}, ignoreCase: false, inverted: false, }, }, }, }, }, &litMatcher{ pos: position{line: 190, col: 86, offset: 4116}, val: ":", ignoreCase: false, want: "\":\"", }, &actionExpr{ pos: position{line: 175, col: 5, offset: 3818}, run: (*parser).callonNode197, expr: &seqExpr{ pos: position{line: 175, col: 5, offset: 3818}, exprs: []any{ &actionExpr{ pos: position{line: 233, col: 5, offset: 4807}, run: (*parser).callonNode199, expr: &charClassMatcher{ pos: position{line: 233, col: 5, offset: 4807}, val: "[0-9]", ranges: []rune{'0', '9'}, ignoreCase: false, inverted: false, }, }, &actionExpr{ pos: position{line: 233, col: 5, offset: 4807}, run: (*parser).callonNode201, expr: &charClassMatcher{ pos: position{line: 233, col: 5, offset: 4807}, val: "[0-9]", ranges: []rune{'0', '9'}, ignoreCase: false, inverted: false, }, }, }, }, }, }, }, }, }, }, }, }, }, }, }, &zeroOrOneExpr{ pos: position{line: 62, col: 7, offset: 1465}, expr: &litMatcher{ pos: position{line: 62, col: 7, offset: 1465}, val: "\"", ignoreCase: false, want: "\"\\\"\"", }, }, }, }, }, &actionExpr{ pos: position{line: 65, col: 5, offset: 1541}, run: (*parser).callonNode205, expr: &seqExpr{ pos: position{line: 65, col: 5, offset: 1541}, exprs: []any{ &labeledExpr{ pos: position{line: 65, col: 5, offset: 1541}, label: "k", expr: &actionExpr{ pos: position{line: 223, col: 5, offset: 4678}, run: (*parser).callonNode208, expr: &seqExpr{ pos: position{line: 223, col: 5, offset: 4678}, exprs: []any{ &oneOrMoreExpr{ pos: position{line: 223, col: 5, offset: 4678}, expr: &actionExpr{ pos: position{line: 218, col: 5, offset: 4622}, run: (*parser).callonNode211, expr: &charClassMatcher{ pos: position{line: 218, col: 5, offset: 4622}, val: "[A-Za-z]", ranges: []rune{'A', 'Z', 'a', 'z'}, ignoreCase: false, inverted: false, }, }, }, &zeroOrMoreExpr{ pos: position{line: 223, col: 11, offset: 4684}, expr: &seqExpr{ pos: position{line: 223, col: 12, offset: 4685}, exprs: []any{ &litMatcher{ pos: position{line: 223, col: 12, offset: 4685}, val: ".", ignoreCase: false, want: "\".\"", }, &oneOrMoreExpr{ pos: position{line: 223, col: 16, offset: 4689}, expr: &actionExpr{ pos: position{line: 218, col: 5, offset: 4622}, run: (*parser).callonNode217, expr: &charClassMatcher{ pos: position{line: 218, col: 5, offset: 4622}, val: "[A-Za-z]", ranges: []rune{'A', 'Z', 'a', 'z'}, ignoreCase: false, inverted: false, }, }, }, }, }, }, }, }, }, }, &choiceExpr{ pos: position{line: 66, col: 9, offset: 1557}, alternatives: []any{ &actionExpr{ pos: position{line: 125, col: 5, offset: 2985}, run: (*parser).callonNode220, expr: &litMatcher{ pos: position{line: 125, col: 5, offset: 2985}, val: "=", ignoreCase: false, want: "\"=\"", }, }, &actionExpr{ pos: position{line: 120, col: 5, offset: 2899}, run: (*parser).callonNode222, expr: &litMatcher{ pos: position{line: 120, col: 5, offset: 2899}, val: ":", ignoreCase: false, want: "\":\"", }, }, }, }, &zeroOrOneExpr{ pos: position{line: 68, col: 7, offset: 1609}, expr: &litMatcher{ pos: position{line: 68, col: 7, offset: 1609}, val: "\"", ignoreCase: false, want: "\"\\\"\"", }, }, &labeledExpr{ pos: position{line: 68, col: 12, offset: 1614}, label: "v", expr: &choiceExpr{ pos: position{line: 200, col: 5, offset: 4273}, alternatives: []any{ &litMatcher{ pos: position{line: 200, col: 5, offset: 4273}, val: "today", ignoreCase: false, want: "\"today\"", }, &litMatcher{ pos: position{line: 201, col: 5, offset: 4287}, val: "yesterday", ignoreCase: false, want: "\"yesterday\"", }, &litMatcher{ pos: position{line: 202, col: 5, offset: 4305}, val: "this week", ignoreCase: false, want: "\"this week\"", }, &litMatcher{ pos: position{line: 203, col: 5, offset: 4323}, val: "last week", ignoreCase: false, want: "\"last week\"", }, &litMatcher{ pos: position{line: 204, col: 5, offset: 4341}, val: "last 7 days", ignoreCase: false, want: "\"last 7 days\"", }, &litMatcher{ pos: position{line: 205, col: 5, offset: 4361}, val: "this month", ignoreCase: false, want: "\"this month\"", }, &litMatcher{ pos: position{line: 206, col: 5, offset: 4380}, val: "last month", ignoreCase: false, want: "\"last month\"", }, &litMatcher{ pos: position{line: 207, col: 5, offset: 4399}, val: "last 30 days", ignoreCase: false, want: "\"last 30 days\"", }, &litMatcher{ pos: position{line: 208, col: 5, offset: 4420}, val: "this year", ignoreCase: false, want: "\"this year\"", }, &actionExpr{ pos: position{line: 209, col: 5, offset: 4438}, run: (*parser).callonNode237, expr: &litMatcher{ pos: position{line: 209, col: 5, offset: 4438}, val: "last year", ignoreCase: false, want: "\"last year\"", }, }, }, }, }, &zeroOrOneExpr{ pos: position{line: 68, col: 38, offset: 1640}, expr: &litMatcher{ pos: position{line: 68, col: 38, offset: 1640}, val: "\"", ignoreCase: false, want: "\"\\\"\"", }, }, }, }, }, &actionExpr{ pos: position{line: 73, col: 5, offset: 1759}, run: (*parser).callonNode241, expr: &seqExpr{ pos: position{line: 73, col: 5, offset: 1759}, exprs: []any{ &labeledExpr{ pos: position{line: 73, col: 5, offset: 1759}, label: "k", expr: &actionExpr{ pos: position{line: 223, col: 5, offset: 4678}, run: (*parser).callonNode244, expr: &seqExpr{ pos: position{line: 223, col: 5, offset: 4678}, exprs: []any{ &oneOrMoreExpr{ pos: position{line: 223, col: 5, offset: 4678}, expr: &actionExpr{ pos: position{line: 218, col: 5, offset: 4622}, run: (*parser).callonNode247, expr: &charClassMatcher{ pos: position{line: 218, col: 5, offset: 4622}, val: "[A-Za-z]", ranges: []rune{'A', 'Z', 'a', 'z'}, ignoreCase: false, inverted: false, }, }, }, &zeroOrMoreExpr{ pos: position{line: 223, col: 11, offset: 4684}, expr: &seqExpr{ pos: position{line: 223, col: 12, offset: 4685}, exprs: []any{ &litMatcher{ pos: position{line: 223, col: 12, offset: 4685}, val: ".", ignoreCase: false, want: "\".\"", }, &oneOrMoreExpr{ pos: position{line: 223, col: 16, offset: 4689}, expr: &actionExpr{ pos: position{line: 218, col: 5, offset: 4622}, run: (*parser).callonNode253, expr: &charClassMatcher{ pos: position{line: 218, col: 5, offset: 4622}, val: "[A-Za-z]", ranges: []rune{'A', 'Z', 'a', 'z'}, ignoreCase: false, inverted: false, }, }, }, }, }, }, }, }, }, }, &choiceExpr{ pos: position{line: 73, col: 12, offset: 1766}, alternatives: []any{ &actionExpr{ pos: position{line: 120, col: 5, offset: 2899}, run: (*parser).callonNode256, expr: &litMatcher{ pos: position{line: 120, col: 5, offset: 2899}, val: ":", ignoreCase: false, want: "\":\"", }, }, &actionExpr{ pos: position{line: 125, col: 5, offset: 2985}, run: (*parser).callonNode258, expr: &litMatcher{ pos: position{line: 125, col: 5, offset: 2985}, val: "=", ignoreCase: false, want: "\"=\"", }, }, }, }, &labeledExpr{ pos: position{line: 73, col: 51, offset: 1805}, label: "v", expr: &choiceExpr{ pos: position{line: 73, col: 54, offset: 1808}, alternatives: []any{ &actionExpr{ pos: position{line: 228, col: 5, offset: 4747}, run: (*parser).callonNode262, expr: &seqExpr{ pos: position{line: 228, col: 5, offset: 4747}, exprs: []any{ &litMatcher{ pos: position{line: 228, col: 5, offset: 4747}, val: "\"", ignoreCase: false, want: "\"\\\"\"", }, &labeledExpr{ pos: position{line: 228, col: 9, offset: 4751}, label: "v", expr: &zeroOrMoreExpr{ pos: position{line: 228, col: 11, offset: 4753}, expr: &charClassMatcher{ pos: position{line: 228, col: 11, offset: 4753}, val: "[^\"]", chars: []rune{'"'}, ignoreCase: false, inverted: true, }, }, }, &litMatcher{ pos: position{line: 228, col: 17, offset: 4759}, val: "\"", ignoreCase: false, want: "\"\\\"\"", }, }, }, }, &oneOrMoreExpr{ pos: position{line: 73, col: 63, offset: 1817}, expr: &charClassMatcher{ pos: position{line: 73, col: 63, offset: 1817}, val: "[^ ()]", chars: []rune{' ', '(', ')'}, ignoreCase: false, inverted: true, }, }, }, }, }, }, }, }, &actionExpr{ pos: position{line: 105, col: 5, offset: 2609}, run: (*parser).callonNode271, expr: &choiceExpr{ pos: position{line: 105, col: 6, offset: 2610}, alternatives: []any{ &litMatcher{ pos: position{line: 105, col: 6, offset: 2610}, val: "AND", ignoreCase: false, want: "\"AND\"", }, &litMatcher{ pos: position{line: 105, col: 14, offset: 2618}, val: "+", ignoreCase: false, want: "\"+\"", }, }, }, }, &actionExpr{ pos: position{line: 110, col: 5, offset: 2710}, run: (*parser).callonNode275, expr: &choiceExpr{ pos: position{line: 110, col: 6, offset: 2711}, alternatives: []any{ &litMatcher{ pos: position{line: 110, col: 6, offset: 2711}, val: "NOT", ignoreCase: false, want: "\"NOT\"", }, &litMatcher{ pos: position{line: 110, col: 14, offset: 2719}, val: "-", ignoreCase: false, want: "\"-\"", }, }, }, }, &actionExpr{ pos: position{line: 115, col: 5, offset: 2810}, run: (*parser).callonNode279, expr: &litMatcher{ pos: position{line: 115, col: 6, offset: 2811}, val: "OR", ignoreCase: false, want: "\"OR\"", }, }, &actionExpr{ pos: position{line: 86, col: 6, offset: 2097}, run: (*parser).callonNode281, expr: &seqExpr{ pos: position{line: 86, col: 6, offset: 2097}, exprs: []any{ &zeroOrOneExpr{ pos: position{line: 86, col: 6, offset: 2097}, expr: &actionExpr{ pos: position{line: 120, col: 5, offset: 2899}, run: (*parser).callonNode284, expr: &litMatcher{ pos: position{line: 120, col: 5, offset: 2899}, val: ":", ignoreCase: false, want: "\":\"", }, }, }, &actionExpr{ pos: position{line: 238, col: 5, offset: 4858}, run: (*parser).callonNode286, expr: &zeroOrMoreExpr{ pos: position{line: 238, col: 5, offset: 4858}, expr: &charClassMatcher{ pos: position{line: 238, col: 5, offset: 4858}, val: "[ \\t]", chars: []rune{' ', '\t'}, ignoreCase: false, inverted: false, }, }, }, &labeledExpr{ pos: position{line: 86, col: 27, offset: 2118}, label: "v", expr: &actionExpr{ pos: position{line: 228, col: 5, offset: 4747}, run: (*parser).callonNode290, expr: &seqExpr{ pos: position{line: 228, col: 5, offset: 4747}, exprs: []any{ &litMatcher{ pos: position{line: 228, col: 5, offset: 4747}, val: "\"", ignoreCase: false, want: "\"\\\"\"", }, &labeledExpr{ pos: position{line: 228, col: 9, offset: 4751}, label: "v", expr: &zeroOrMoreExpr{ pos: position{line: 228, col: 11, offset: 4753}, expr: &charClassMatcher{ pos: position{line: 228, col: 11, offset: 4753}, val: "[^\"]", chars: []rune{'"'}, ignoreCase: false, inverted: true, }, }, }, &litMatcher{ pos: position{line: 228, col: 17, offset: 4759}, val: "\"", ignoreCase: false, want: "\"\\\"\"", }, }, }, }, }, &actionExpr{ pos: position{line: 238, col: 5, offset: 4858}, run: (*parser).callonNode297, expr: &zeroOrMoreExpr{ pos: position{line: 238, col: 5, offset: 4858}, expr: &charClassMatcher{ pos: position{line: 238, col: 5, offset: 4858}, val: "[ \\t]", chars: []rune{' ', '\t'}, ignoreCase: false, inverted: false, }, }, }, &zeroOrOneExpr{ pos: position{line: 86, col: 38, offset: 2129}, expr: &actionExpr{ pos: position{line: 120, col: 5, offset: 2899}, run: (*parser).callonNode301, expr: &litMatcher{ pos: position{line: 120, col: 5, offset: 2899}, val: ":", ignoreCase: false, want: "\":\"", }, }, }, }, }, }, &actionExpr{ pos: position{line: 91, col: 6, offset: 2227}, run: (*parser).callonNode303, expr: &seqExpr{ pos: position{line: 91, col: 6, offset: 2227}, exprs: []any{ &zeroOrOneExpr{ pos: position{line: 91, col: 6, offset: 2227}, expr: &actionExpr{ pos: position{line: 120, col: 5, offset: 2899}, run: (*parser).callonNode306, expr: &litMatcher{ pos: position{line: 120, col: 5, offset: 2899}, val: ":", ignoreCase: false, want: "\":\"", }, }, }, &actionExpr{ pos: position{line: 238, col: 5, offset: 4858}, run: (*parser).callonNode308, expr: &zeroOrMoreExpr{ pos: position{line: 238, col: 5, offset: 4858}, expr: &charClassMatcher{ pos: position{line: 238, col: 5, offset: 4858}, val: "[ \\t]", chars: []rune{' ', '\t'}, ignoreCase: false, inverted: false, }, }, }, &labeledExpr{ pos: position{line: 91, col: 27, offset: 2248}, label: "v", expr: &oneOrMoreExpr{ pos: position{line: 91, col: 29, offset: 2250}, expr: &charClassMatcher{ pos: position{line: 91, col: 29, offset: 2250}, val: "[^ :()]", chars: []rune{' ', ':', '(', ')'}, ignoreCase: false, inverted: true, }, }, }, &actionExpr{ pos: position{line: 238, col: 5, offset: 4858}, run: (*parser).callonNode314, expr: &zeroOrMoreExpr{ pos: position{line: 238, col: 5, offset: 4858}, expr: &charClassMatcher{ pos: position{line: 238, col: 5, offset: 4858}, val: "[ \\t]", chars: []rune{' ', '\t'}, ignoreCase: false, inverted: false, }, }, }, &zeroOrOneExpr{ pos: position{line: 91, col: 40, offset: 2261}, expr: &actionExpr{ pos: position{line: 120, col: 5, offset: 2899}, run: (*parser).callonNode318, expr: &litMatcher{ pos: position{line: 120, col: 5, offset: 2899}, val: ":", ignoreCase: false, want: "\":\"", }, }, }, }, }, }, }, }, }, { name: "GroupNode", pos: position{line: 31, col: 1, offset: 595}, expr: &actionExpr{ pos: position{line: 32, col: 5, offset: 612}, run: (*parser).callonGroupNode1, expr: &seqExpr{ pos: position{line: 32, col: 5, offset: 612}, exprs: []any{ &labeledExpr{ pos: position{line: 32, col: 5, offset: 612}, label: "k", expr: &zeroOrOneExpr{ pos: position{line: 32, col: 7, offset: 614}, expr: &actionExpr{ pos: position{line: 223, col: 5, offset: 4678}, run: (*parser).callonGroupNode5, expr: &seqExpr{ pos: position{line: 223, col: 5, offset: 4678}, exprs: []any{ &oneOrMoreExpr{ pos: position{line: 223, col: 5, offset: 4678}, expr: &actionExpr{ pos: position{line: 218, col: 5, offset: 4622}, run: (*parser).callonGroupNode8, expr: &charClassMatcher{ pos: position{line: 218, col: 5, offset: 4622}, val: "[A-Za-z]", ranges: []rune{'A', 'Z', 'a', 'z'}, ignoreCase: false, inverted: false, }, }, }, &zeroOrMoreExpr{ pos: position{line: 223, col: 11, offset: 4684}, expr: &seqExpr{ pos: position{line: 223, col: 12, offset: 4685}, exprs: []any{ &litMatcher{ pos: position{line: 223, col: 12, offset: 4685}, val: ".", ignoreCase: false, want: "\".\"", }, &oneOrMoreExpr{ pos: position{line: 223, col: 16, offset: 4689}, expr: &actionExpr{ pos: position{line: 218, col: 5, offset: 4622}, run: (*parser).callonGroupNode14, expr: &charClassMatcher{ pos: position{line: 218, col: 5, offset: 4622}, val: "[A-Za-z]", ranges: []rune{'A', 'Z', 'a', 'z'}, ignoreCase: false, inverted: false, }, }, }, }, }, }, }, }, }, }, }, &zeroOrOneExpr{ pos: position{line: 32, col: 12, offset: 619}, expr: &choiceExpr{ pos: position{line: 32, col: 13, offset: 620}, alternatives: []any{ &actionExpr{ pos: position{line: 120, col: 5, offset: 2899}, run: (*parser).callonGroupNode18, expr: &litMatcher{ pos: position{line: 120, col: 5, offset: 2899}, val: ":", ignoreCase: false, want: "\":\"", }, }, &actionExpr{ pos: position{line: 125, col: 5, offset: 2985}, run: (*parser).callonGroupNode20, expr: &litMatcher{ pos: position{line: 125, col: 5, offset: 2985}, val: "=", ignoreCase: false, want: "\"=\"", }, }, }, }, }, &litMatcher{ pos: position{line: 32, col: 53, offset: 660}, val: "(", ignoreCase: false, want: "\"(\"", }, &labeledExpr{ pos: position{line: 32, col: 57, offset: 664}, label: "v", expr: &ruleRefExpr{ pos: position{line: 32, col: 59, offset: 666}, name: "Nodes", }, }, &litMatcher{ pos: position{line: 32, col: 65, offset: 672}, val: ")", ignoreCase: false, want: "\")\"", }, }, }, }, }, }, } func (c *current) onAST1(n any) (any, error) { return buildAST(n, c.text, c.pos) } func (p *parser) callonAST1() (any, error) { stack := p.vstack[len(p.vstack)-1] _ = stack return p.cur.onAST1(stack["n"]) } func (c *current) onNodes3() (any, error) { return nil, nil } func (p *parser) callonNodes3() (any, error) { stack := p.vstack[len(p.vstack)-1] _ = stack return p.cur.onNodes3() } func (c *current) onNode9() (any, error) { return c.text, nil } func (p *parser) callonNode9() (any, error) { stack := p.vstack[len(p.vstack)-1] _ = stack return p.cur.onNode9() } func (c *current) onNode15() (any, error) { return c.text, nil } func (p *parser) callonNode15() (any, error) { stack := p.vstack[len(p.vstack)-1] _ = stack return p.cur.onNode15() } func (c *current) onNode6() (any, error) { return c.text, nil } func (p *parser) callonNode6() (any, error) { stack := p.vstack[len(p.vstack)-1] _ = stack return p.cur.onNode6() } func (c *current) onNode18() (any, error) { return buildOperatorNode(c.text, c.pos) } func (p *parser) callonNode18() (any, error) { stack := p.vstack[len(p.vstack)-1] _ = stack return p.cur.onNode18() } func (c *current) onNode20() (any, error) { return buildOperatorNode(c.text, c.pos) } func (p *parser) callonNode20() (any, error) { stack := p.vstack[len(p.vstack)-1] _ = stack return p.cur.onNode20() } func (c *current) onNode3(k, v any) (any, error) { return buildBooleanNode(k, v, c.text, c.pos) } func (p *parser) callonNode3() (any, error) { stack := p.vstack[len(p.vstack)-1] _ = stack return p.cur.onNode3(stack["k"], stack["v"]) } func (c *current) onNode32() (any, error) { return c.text, nil } func (p *parser) callonNode32() (any, error) { stack := p.vstack[len(p.vstack)-1] _ = stack return p.cur.onNode32() } func (c *current) onNode38() (any, error) { return c.text, nil } func (p *parser) callonNode38() (any, error) { stack := p.vstack[len(p.vstack)-1] _ = stack return p.cur.onNode38() } func (c *current) onNode29() (any, error) { return c.text, nil } func (p *parser) callonNode29() (any, error) { stack := p.vstack[len(p.vstack)-1] _ = stack return p.cur.onNode29() } func (c *current) onNode42() (any, error) { return buildOperatorNode(c.text, c.pos) } func (p *parser) callonNode42() (any, error) { stack := p.vstack[len(p.vstack)-1] _ = stack return p.cur.onNode42() } func (c *current) onNode44() (any, error) { return buildOperatorNode(c.text, c.pos) } func (p *parser) callonNode44() (any, error) { stack := p.vstack[len(p.vstack)-1] _ = stack return p.cur.onNode44() } func (c *current) onNode46() (any, error) { return buildOperatorNode(c.text, c.pos) } func (p *parser) callonNode46() (any, error) { stack := p.vstack[len(p.vstack)-1] _ = stack return p.cur.onNode46() } func (c *current) onNode48() (any, error) { return buildOperatorNode(c.text, c.pos) } func (p *parser) callonNode48() (any, error) { stack := p.vstack[len(p.vstack)-1] _ = stack return p.cur.onNode48() } func (c *current) onNode50() (any, error) { return buildOperatorNode(c.text, c.pos) } func (p *parser) callonNode50() (any, error) { stack := p.vstack[len(p.vstack)-1] _ = stack return p.cur.onNode50() } func (c *current) onNode52() (any, error) { return buildOperatorNode(c.text, c.pos) } func (p *parser) callonNode52() (any, error) { stack := p.vstack[len(p.vstack)-1] _ = stack return p.cur.onNode52() } func (c *current) onNode64() (any, error) { return c.text, nil } func (p *parser) callonNode64() (any, error) { stack := p.vstack[len(p.vstack)-1] _ = stack return p.cur.onNode64() } func (c *current) onNode66() (any, error) { return c.text, nil } func (p *parser) callonNode66() (any, error) { stack := p.vstack[len(p.vstack)-1] _ = stack return p.cur.onNode66() } func (c *current) onNode68() (any, error) { return c.text, nil } func (p *parser) callonNode68() (any, error) { stack := p.vstack[len(p.vstack)-1] _ = stack return p.cur.onNode68() } func (c *current) onNode70() (any, error) { return c.text, nil } func (p *parser) callonNode70() (any, error) { stack := p.vstack[len(p.vstack)-1] _ = stack return p.cur.onNode70() } func (c *current) onNode62() (any, error) { return c.text, nil } func (p *parser) callonNode62() (any, error) { stack := p.vstack[len(p.vstack)-1] _ = stack return p.cur.onNode62() } func (c *current) onNode75() (any, error) { return c.text, nil } func (p *parser) callonNode75() (any, error) { stack := p.vstack[len(p.vstack)-1] _ = stack return p.cur.onNode75() } func (c *current) onNode77() (any, error) { return c.text, nil } func (p *parser) callonNode77() (any, error) { stack := p.vstack[len(p.vstack)-1] _ = stack return p.cur.onNode77() } func (c *current) onNode73() (any, error) { return c.text, nil } func (p *parser) callonNode73() (any, error) { stack := p.vstack[len(p.vstack)-1] _ = stack return p.cur.onNode73() } func (c *current) onNode82() (any, error) { return c.text, nil } func (p *parser) callonNode82() (any, error) { stack := p.vstack[len(p.vstack)-1] _ = stack return p.cur.onNode82() } func (c *current) onNode84() (any, error) { return c.text, nil } func (p *parser) callonNode84() (any, error) { stack := p.vstack[len(p.vstack)-1] _ = stack return p.cur.onNode84() } func (c *current) onNode80() (any, error) { return c.text, nil } func (p *parser) callonNode80() (any, error) { stack := p.vstack[len(p.vstack)-1] _ = stack return p.cur.onNode80() } func (c *current) onNode60() (any, error) { return c.text, nil } func (p *parser) callonNode60() (any, error) { stack := p.vstack[len(p.vstack)-1] _ = stack return p.cur.onNode60() } func (c *current) onNode91() (any, error) { return c.text, nil } func (p *parser) callonNode91() (any, error) { stack := p.vstack[len(p.vstack)-1] _ = stack return p.cur.onNode91() } func (c *current) onNode93() (any, error) { return c.text, nil } func (p *parser) callonNode93() (any, error) { stack := p.vstack[len(p.vstack)-1] _ = stack return p.cur.onNode93() } func (c *current) onNode89() (any, error) { return c.text, nil } func (p *parser) callonNode89() (any, error) { stack := p.vstack[len(p.vstack)-1] _ = stack return p.cur.onNode89() } func (c *current) onNode98() (any, error) { return c.text, nil } func (p *parser) callonNode98() (any, error) { stack := p.vstack[len(p.vstack)-1] _ = stack return p.cur.onNode98() } func (c *current) onNode100() (any, error) { return c.text, nil } func (p *parser) callonNode100() (any, error) { stack := p.vstack[len(p.vstack)-1] _ = stack return p.cur.onNode100() } func (c *current) onNode96() (any, error) { return c.text, nil } func (p *parser) callonNode96() (any, error) { stack := p.vstack[len(p.vstack)-1] _ = stack return p.cur.onNode96() } func (c *current) onNode105() (any, error) { return c.text, nil } func (p *parser) callonNode105() (any, error) { stack := p.vstack[len(p.vstack)-1] _ = stack return p.cur.onNode105() } func (c *current) onNode107() (any, error) { return c.text, nil } func (p *parser) callonNode107() (any, error) { stack := p.vstack[len(p.vstack)-1] _ = stack return p.cur.onNode107() } func (c *current) onNode103() (any, error) { return c.text, nil } func (p *parser) callonNode103() (any, error) { stack := p.vstack[len(p.vstack)-1] _ = stack return p.cur.onNode103() } func (c *current) onNode113() (any, error) { return c.text, nil } func (p *parser) callonNode113() (any, error) { stack := p.vstack[len(p.vstack)-1] _ = stack return p.cur.onNode113() } func (c *current) onNode121() (any, error) { return c.text, nil } func (p *parser) callonNode121() (any, error) { stack := p.vstack[len(p.vstack)-1] _ = stack return p.cur.onNode121() } func (c *current) onNode123() (any, error) { return c.text, nil } func (p *parser) callonNode123() (any, error) { stack := p.vstack[len(p.vstack)-1] _ = stack return p.cur.onNode123() } func (c *current) onNode119() (any, error) { return c.text, nil } func (p *parser) callonNode119() (any, error) { stack := p.vstack[len(p.vstack)-1] _ = stack return p.cur.onNode119() } func (c *current) onNode128() (any, error) { return c.text, nil } func (p *parser) callonNode128() (any, error) { stack := p.vstack[len(p.vstack)-1] _ = stack return p.cur.onNode128() } func (c *current) onNode130() (any, error) { return c.text, nil } func (p *parser) callonNode130() (any, error) { stack := p.vstack[len(p.vstack)-1] _ = stack return p.cur.onNode130() } func (c *current) onNode126() (any, error) { return c.text, nil } func (p *parser) callonNode126() (any, error) { stack := p.vstack[len(p.vstack)-1] _ = stack return p.cur.onNode126() } func (c *current) onNode87() (any, error) { return c.text, nil } func (p *parser) callonNode87() (any, error) { stack := p.vstack[len(p.vstack)-1] _ = stack return p.cur.onNode87() } func (c *current) onNode58() (any, error) { return c.text, nil } func (p *parser) callonNode58() (any, error) { stack := p.vstack[len(p.vstack)-1] _ = stack return p.cur.onNode58() } func (c *current) onNode136() (any, error) { return c.text, nil } func (p *parser) callonNode136() (any, error) { stack := p.vstack[len(p.vstack)-1] _ = stack return p.cur.onNode136() } func (c *current) onNode138() (any, error) { return c.text, nil } func (p *parser) callonNode138() (any, error) { stack := p.vstack[len(p.vstack)-1] _ = stack return p.cur.onNode138() } func (c *current) onNode140() (any, error) { return c.text, nil } func (p *parser) callonNode140() (any, error) { stack := p.vstack[len(p.vstack)-1] _ = stack return p.cur.onNode140() } func (c *current) onNode142() (any, error) { return c.text, nil } func (p *parser) callonNode142() (any, error) { stack := p.vstack[len(p.vstack)-1] _ = stack return p.cur.onNode142() } func (c *current) onNode134() (any, error) { return c.text, nil } func (p *parser) callonNode134() (any, error) { stack := p.vstack[len(p.vstack)-1] _ = stack return p.cur.onNode134() } func (c *current) onNode147() (any, error) { return c.text, nil } func (p *parser) callonNode147() (any, error) { stack := p.vstack[len(p.vstack)-1] _ = stack return p.cur.onNode147() } func (c *current) onNode149() (any, error) { return c.text, nil } func (p *parser) callonNode149() (any, error) { stack := p.vstack[len(p.vstack)-1] _ = stack return p.cur.onNode149() } func (c *current) onNode145() (any, error) { return c.text, nil } func (p *parser) callonNode145() (any, error) { stack := p.vstack[len(p.vstack)-1] _ = stack return p.cur.onNode145() } func (c *current) onNode154() (any, error) { return c.text, nil } func (p *parser) callonNode154() (any, error) { stack := p.vstack[len(p.vstack)-1] _ = stack return p.cur.onNode154() } func (c *current) onNode156() (any, error) { return c.text, nil } func (p *parser) callonNode156() (any, error) { stack := p.vstack[len(p.vstack)-1] _ = stack return p.cur.onNode156() } func (c *current) onNode152() (any, error) { return c.text, nil } func (p *parser) callonNode152() (any, error) { stack := p.vstack[len(p.vstack)-1] _ = stack return p.cur.onNode152() } func (c *current) onNode132() (any, error) { return c.text, nil } func (p *parser) callonNode132() (any, error) { stack := p.vstack[len(p.vstack)-1] _ = stack return p.cur.onNode132() } func (c *current) onNode162() (any, error) { return c.text, nil } func (p *parser) callonNode162() (any, error) { stack := p.vstack[len(p.vstack)-1] _ = stack return p.cur.onNode162() } func (c *current) onNode164() (any, error) { return c.text, nil } func (p *parser) callonNode164() (any, error) { stack := p.vstack[len(p.vstack)-1] _ = stack return p.cur.onNode164() } func (c *current) onNode160() (any, error) { return c.text, nil } func (p *parser) callonNode160() (any, error) { stack := p.vstack[len(p.vstack)-1] _ = stack return p.cur.onNode160() } func (c *current) onNode169() (any, error) { return c.text, nil } func (p *parser) callonNode169() (any, error) { stack := p.vstack[len(p.vstack)-1] _ = stack return p.cur.onNode169() } func (c *current) onNode171() (any, error) { return c.text, nil } func (p *parser) callonNode171() (any, error) { stack := p.vstack[len(p.vstack)-1] _ = stack return p.cur.onNode171() } func (c *current) onNode167() (any, error) { return c.text, nil } func (p *parser) callonNode167() (any, error) { stack := p.vstack[len(p.vstack)-1] _ = stack return p.cur.onNode167() } func (c *current) onNode176() (any, error) { return c.text, nil } func (p *parser) callonNode176() (any, error) { stack := p.vstack[len(p.vstack)-1] _ = stack return p.cur.onNode176() } func (c *current) onNode178() (any, error) { return c.text, nil } func (p *parser) callonNode178() (any, error) { stack := p.vstack[len(p.vstack)-1] _ = stack return p.cur.onNode178() } func (c *current) onNode174() (any, error) { return c.text, nil } func (p *parser) callonNode174() (any, error) { stack := p.vstack[len(p.vstack)-1] _ = stack return p.cur.onNode174() } func (c *current) onNode184() (any, error) { return c.text, nil } func (p *parser) callonNode184() (any, error) { stack := p.vstack[len(p.vstack)-1] _ = stack return p.cur.onNode184() } func (c *current) onNode192() (any, error) { return c.text, nil } func (p *parser) callonNode192() (any, error) { stack := p.vstack[len(p.vstack)-1] _ = stack return p.cur.onNode192() } func (c *current) onNode194() (any, error) { return c.text, nil } func (p *parser) callonNode194() (any, error) { stack := p.vstack[len(p.vstack)-1] _ = stack return p.cur.onNode194() } func (c *current) onNode190() (any, error) { return c.text, nil } func (p *parser) callonNode190() (any, error) { stack := p.vstack[len(p.vstack)-1] _ = stack return p.cur.onNode190() } func (c *current) onNode199() (any, error) { return c.text, nil } func (p *parser) callonNode199() (any, error) { stack := p.vstack[len(p.vstack)-1] _ = stack return p.cur.onNode199() } func (c *current) onNode201() (any, error) { return c.text, nil } func (p *parser) callonNode201() (any, error) { stack := p.vstack[len(p.vstack)-1] _ = stack return p.cur.onNode201() } func (c *current) onNode197() (any, error) { return c.text, nil } func (p *parser) callonNode197() (any, error) { stack := p.vstack[len(p.vstack)-1] _ = stack return p.cur.onNode197() } func (c *current) onNode158() (any, error) { return c.text, nil } func (p *parser) callonNode158() (any, error) { stack := p.vstack[len(p.vstack)-1] _ = stack return p.cur.onNode158() } func (c *current) onNode26(k, o, v any) (any, error) { return buildDateTimeNode(k, o, v, c.text, c.pos) } func (p *parser) callonNode26() (any, error) { stack := p.vstack[len(p.vstack)-1] _ = stack return p.cur.onNode26(stack["k"], stack["o"], stack["v"]) } func (c *current) onNode211() (any, error) { return c.text, nil } func (p *parser) callonNode211() (any, error) { stack := p.vstack[len(p.vstack)-1] _ = stack return p.cur.onNode211() } func (c *current) onNode217() (any, error) { return c.text, nil } func (p *parser) callonNode217() (any, error) { stack := p.vstack[len(p.vstack)-1] _ = stack return p.cur.onNode217() } func (c *current) onNode208() (any, error) { return c.text, nil } func (p *parser) callonNode208() (any, error) { stack := p.vstack[len(p.vstack)-1] _ = stack return p.cur.onNode208() } func (c *current) onNode220() (any, error) { return buildOperatorNode(c.text, c.pos) } func (p *parser) callonNode220() (any, error) { stack := p.vstack[len(p.vstack)-1] _ = stack return p.cur.onNode220() } func (c *current) onNode222() (any, error) { return buildOperatorNode(c.text, c.pos) } func (p *parser) callonNode222() (any, error) { stack := p.vstack[len(p.vstack)-1] _ = stack return p.cur.onNode222() } func (c *current) onNode237() (any, error) { return c.text, nil } func (p *parser) callonNode237() (any, error) { stack := p.vstack[len(p.vstack)-1] _ = stack return p.cur.onNode237() } func (c *current) onNode205(k, v any) (any, error) { return buildNaturalLanguageDateTimeNodes(k, v, c.text, c.pos) } func (p *parser) callonNode205() (any, error) { stack := p.vstack[len(p.vstack)-1] _ = stack return p.cur.onNode205(stack["k"], stack["v"]) } func (c *current) onNode247() (any, error) { return c.text, nil } func (p *parser) callonNode247() (any, error) { stack := p.vstack[len(p.vstack)-1] _ = stack return p.cur.onNode247() } func (c *current) onNode253() (any, error) { return c.text, nil } func (p *parser) callonNode253() (any, error) { stack := p.vstack[len(p.vstack)-1] _ = stack return p.cur.onNode253() } func (c *current) onNode244() (any, error) { return c.text, nil } func (p *parser) callonNode244() (any, error) { stack := p.vstack[len(p.vstack)-1] _ = stack return p.cur.onNode244() } func (c *current) onNode256() (any, error) { return buildOperatorNode(c.text, c.pos) } func (p *parser) callonNode256() (any, error) { stack := p.vstack[len(p.vstack)-1] _ = stack return p.cur.onNode256() } func (c *current) onNode258() (any, error) { return buildOperatorNode(c.text, c.pos) } func (p *parser) callonNode258() (any, error) { stack := p.vstack[len(p.vstack)-1] _ = stack return p.cur.onNode258() } func (c *current) onNode262(v any) (any, error) { return v, nil } func (p *parser) callonNode262() (any, error) { stack := p.vstack[len(p.vstack)-1] _ = stack return p.cur.onNode262(stack["v"]) } func (c *current) onNode241(k, v any) (any, error) { return buildStringNode(k, v, c.text, c.pos) } func (p *parser) callonNode241() (any, error) { stack := p.vstack[len(p.vstack)-1] _ = stack return p.cur.onNode241(stack["k"], stack["v"]) } func (c *current) onNode271() (any, error) { return buildOperatorNode(c.text, c.pos) } func (p *parser) callonNode271() (any, error) { stack := p.vstack[len(p.vstack)-1] _ = stack return p.cur.onNode271() } func (c *current) onNode275() (any, error) { return buildOperatorNode(c.text, c.pos) } func (p *parser) callonNode275() (any, error) { stack := p.vstack[len(p.vstack)-1] _ = stack return p.cur.onNode275() } func (c *current) onNode279() (any, error) { return buildOperatorNode(c.text, c.pos) } func (p *parser) callonNode279() (any, error) { stack := p.vstack[len(p.vstack)-1] _ = stack return p.cur.onNode279() } func (c *current) onNode284() (any, error) { return buildOperatorNode(c.text, c.pos) } func (p *parser) callonNode284() (any, error) { stack := p.vstack[len(p.vstack)-1] _ = stack return p.cur.onNode284() } func (c *current) onNode286() (any, error) { return nil, nil } func (p *parser) callonNode286() (any, error) { stack := p.vstack[len(p.vstack)-1] _ = stack return p.cur.onNode286() } func (c *current) onNode290(v any) (any, error) { return v, nil } func (p *parser) callonNode290() (any, error) { stack := p.vstack[len(p.vstack)-1] _ = stack return p.cur.onNode290(stack["v"]) } func (c *current) onNode297(v any) (any, error) { return nil, nil } func (p *parser) callonNode297() (any, error) { stack := p.vstack[len(p.vstack)-1] _ = stack return p.cur.onNode297(stack["v"]) } func (c *current) onNode301() (any, error) { return buildOperatorNode(c.text, c.pos) } func (p *parser) callonNode301() (any, error) { stack := p.vstack[len(p.vstack)-1] _ = stack return p.cur.onNode301() } func (c *current) onNode281(v any) (any, error) { return buildStringNode("", v, c.text, c.pos) } func (p *parser) callonNode281() (any, error) { stack := p.vstack[len(p.vstack)-1] _ = stack return p.cur.onNode281(stack["v"]) } func (c *current) onNode306() (any, error) { return buildOperatorNode(c.text, c.pos) } func (p *parser) callonNode306() (any, error) { stack := p.vstack[len(p.vstack)-1] _ = stack return p.cur.onNode306() } func (c *current) onNode308() (any, error) { return nil, nil } func (p *parser) callonNode308() (any, error) { stack := p.vstack[len(p.vstack)-1] _ = stack return p.cur.onNode308() } func (c *current) onNode314(v any) (any, error) { return nil, nil } func (p *parser) callonNode314() (any, error) { stack := p.vstack[len(p.vstack)-1] _ = stack return p.cur.onNode314(stack["v"]) } func (c *current) onNode318() (any, error) { return buildOperatorNode(c.text, c.pos) } func (p *parser) callonNode318() (any, error) { stack := p.vstack[len(p.vstack)-1] _ = stack return p.cur.onNode318() } func (c *current) onNode303(v any) (any, error) { return buildStringNode("", v, c.text, c.pos) } func (p *parser) callonNode303() (any, error) { stack := p.vstack[len(p.vstack)-1] _ = stack return p.cur.onNode303(stack["v"]) } func (c *current) onGroupNode8() (any, error) { return c.text, nil } func (p *parser) callonGroupNode8() (any, error) { stack := p.vstack[len(p.vstack)-1] _ = stack return p.cur.onGroupNode8() } func (c *current) onGroupNode14() (any, error) { return c.text, nil } func (p *parser) callonGroupNode14() (any, error) { stack := p.vstack[len(p.vstack)-1] _ = stack return p.cur.onGroupNode14() } func (c *current) onGroupNode5() (any, error) { return c.text, nil } func (p *parser) callonGroupNode5() (any, error) { stack := p.vstack[len(p.vstack)-1] _ = stack return p.cur.onGroupNode5() } func (c *current) onGroupNode18() (any, error) { return buildOperatorNode(c.text, c.pos) } func (p *parser) callonGroupNode18() (any, error) { stack := p.vstack[len(p.vstack)-1] _ = stack return p.cur.onGroupNode18() } func (c *current) onGroupNode20() (any, error) { return buildOperatorNode(c.text, c.pos) } func (p *parser) callonGroupNode20() (any, error) { stack := p.vstack[len(p.vstack)-1] _ = stack return p.cur.onGroupNode20() } func (c *current) onGroupNode1(k, v any) (any, error) { return buildGroupNode(k, v, c.text, c.pos) } func (p *parser) callonGroupNode1() (any, error) { stack := p.vstack[len(p.vstack)-1] _ = stack return p.cur.onGroupNode1(stack["k"], stack["v"]) } var ( // errNoRule is returned when the grammar to parse has no rule. errNoRule = errors.New("grammar has no rule") // errInvalidEntrypoint is returned when the specified entrypoint rule // does not exit. errInvalidEntrypoint = errors.New("invalid entrypoint") // errInvalidEncoding is returned when the source is not properly // utf8-encoded. errInvalidEncoding = errors.New("invalid encoding") // errMaxExprCnt is used to signal that the maximum number of // expressions have been parsed. errMaxExprCnt = errors.New("max number of expressions parsed") ) // Option is a function that can set an option on the parser. It returns // the previous setting as an Option. type Option func(*parser) Option // MaxExpressions creates an Option to stop parsing after the provided // number of expressions have been parsed, if the value is 0 then the parser will // parse for as many steps as needed (possibly an infinite number). // // The default for maxExprCnt is 0. func MaxExpressions(maxExprCnt uint64) Option { return func(p *parser) Option { oldMaxExprCnt := p.maxExprCnt p.maxExprCnt = maxExprCnt return MaxExpressions(oldMaxExprCnt) } } // Entrypoint creates an Option to set the rule name to use as entrypoint. // The rule name must have been specified in the -alternate-entrypoints // if generating the parser with the -optimize-grammar flag, otherwise // it may have been optimized out. Passing an empty string sets the // entrypoint to the first rule in the grammar. // // The default is to start parsing at the first rule in the grammar. func Entrypoint(ruleName string) Option { return func(p *parser) Option { oldEntrypoint := p.entrypoint p.entrypoint = ruleName if ruleName == "" { p.entrypoint = g.rules[0].name } return Entrypoint(oldEntrypoint) } } // AllowInvalidUTF8 creates an Option to allow invalid UTF-8 bytes. // Every invalid UTF-8 byte is treated as a utf8.RuneError (U+FFFD) // by character class matchers and is matched by the any matcher. // The returned matched value, c.text and c.offset are NOT affected. // // The default is false. func AllowInvalidUTF8(b bool) Option { return func(p *parser) Option { old := p.allowInvalidUTF8 p.allowInvalidUTF8 = b return AllowInvalidUTF8(old) } } // Recover creates an Option to set the recover flag to b. When set to // true, this causes the parser to recover from panics and convert it // to an error. Setting it to false can be useful while debugging to // access the full stack trace. // // The default is true. func Recover(b bool) Option { return func(p *parser) Option { old := p.recover p.recover = b return Recover(old) } } // GlobalStore creates an Option to set a key to a certain value in // the globalStore. func GlobalStore(key string, value any) Option { return func(p *parser) Option { old := p.cur.globalStore[key] p.cur.globalStore[key] = value return GlobalStore(key, old) } } // ParseFile parses the file identified by filename. func ParseFile(filename string, opts ...Option) (i any, err error) { f, err := os.Open(filename) if err != nil { return nil, err } defer func() { if closeErr := f.Close(); closeErr != nil { err = closeErr } }() return ParseReader(filename, f, opts...) } // ParseReader parses the data from r using filename as information in the // error messages. func ParseReader(filename string, r io.Reader, opts ...Option) (any, error) { b, err := io.ReadAll(r) if err != nil { return nil, err } return Parse(filename, b, opts...) } // Parse parses the data from b using filename as information in the // error messages. func Parse(filename string, b []byte, opts ...Option) (any, error) { return newParser(filename, b, opts...).parse(g) } // position records a position in the text. type position struct { line, col, offset int } func (p position) String() string { return strconv.Itoa(p.line) + ":" + strconv.Itoa(p.col) + " [" + strconv.Itoa(p.offset) + "]" } // savepoint stores all state required to go back to this point in the // parser. type savepoint struct { position rn rune w int } type current struct { pos position // start position of the match text []byte // raw text of the match // globalStore is a general store for the user to store arbitrary key-value // pairs that they need to manage and that they do not want tied to the // backtracking of the parser. This is only modified by the user and never // rolled back by the parser. It is always up to the user to keep this in a // consistent state. globalStore storeDict } type storeDict map[string]any // the AST types... type grammar struct { pos position rules []*rule } type rule struct { pos position name string displayName string expr any } type choiceExpr struct { pos position alternatives []any } type actionExpr struct { pos position expr any run func(*parser) (any, error) } type recoveryExpr struct { pos position expr any recoverExpr any failureLabel []string } type seqExpr struct { pos position exprs []any } type throwExpr struct { pos position label string } type labeledExpr struct { pos position label string expr any } type expr struct { pos position expr any } type ( andExpr expr notExpr expr zeroOrOneExpr expr zeroOrMoreExpr expr oneOrMoreExpr expr ) type ruleRefExpr struct { pos position name string } type andCodeExpr struct { pos position run func(*parser) (bool, error) } type notCodeExpr struct { pos position run func(*parser) (bool, error) } type litMatcher struct { pos position val string ignoreCase bool want string } type charClassMatcher struct { pos position val string basicLatinChars [128]bool chars []rune ranges []rune classes []*unicode.RangeTable ignoreCase bool inverted bool } type anyMatcher position // errList cumulates the errors found by the parser. type errList []error func (e *errList) add(err error) { *e = append(*e, err) } func (e errList) err() error { if len(e) == 0 { return nil } e.dedupe() return e } func (e *errList) dedupe() { var cleaned []error set := make(map[string]bool) for _, err := range *e { if msg := err.Error(); !set[msg] { set[msg] = true cleaned = append(cleaned, err) } } *e = cleaned } func (e errList) Error() string { switch len(e) { case 0: return "" case 1: return e[0].Error() default: var buf bytes.Buffer for i, err := range e { if i > 0 { buf.WriteRune('\n') } buf.WriteString(err.Error()) } return buf.String() } } // parserError wraps an error with a prefix indicating the rule in which // the error occurred. The original error is stored in the Inner field. type parserError struct { Inner error pos position prefix string expected []string } // Error returns the error message. func (p *parserError) Error() string { return p.prefix + ": " + p.Inner.Error() } // newParser creates a parser with the specified input source and options. func newParser(filename string, b []byte, opts ...Option) *parser { stats := Stats{ ChoiceAltCnt: make(map[string]map[string]int), } p := &parser{ filename: filename, errs: new(errList), data: b, pt: savepoint{position: position{line: 1}}, recover: true, cur: current{ globalStore: make(storeDict), }, maxFailPos: position{col: 1, line: 1}, maxFailExpected: make([]string, 0, 20), Stats: &stats, // start rule is rule [0] unless an alternate entrypoint is specified entrypoint: g.rules[0].name, } p.setOptions(opts) if p.maxExprCnt == 0 { p.maxExprCnt = math.MaxUint64 } return p } // setOptions applies the options to the parser. func (p *parser) setOptions(opts []Option) { for _, opt := range opts { opt(p) } } type resultTuple struct { v any b bool end savepoint } const choiceNoMatch = -1 // Stats stores some statistics, gathered during parsing type Stats struct { // ExprCnt counts the number of expressions processed during parsing // This value is compared to the maximum number of expressions allowed // (set by the MaxExpressions option). ExprCnt uint64 // ChoiceAltCnt is used to count for each ordered choice expression, // which alternative is used how may times. // These numbers allow to optimize the order of the ordered choice expression // to increase the performance of the parser // // The outer key of ChoiceAltCnt is composed of the name of the rule as well // as the line and the column of the ordered choice. // The inner key of ChoiceAltCnt is the number (one-based) of the matching alternative. // For each alternative the number of matches are counted. If an ordered choice does not // match, a special counter is incremented. The name of this counter is set with // the parser option Statistics. // For an alternative to be included in ChoiceAltCnt, it has to match at least once. ChoiceAltCnt map[string]map[string]int } type parser struct { filename string pt savepoint cur current data []byte errs *errList depth int recover bool // rules table, maps the rule identifier to the rule node rules map[string]*rule // variables stack, map of label to value vstack []map[string]any // rule stack, allows identification of the current rule in errors rstack []*rule // parse fail maxFailPos position maxFailExpected []string maxFailInvertExpected bool // max number of expressions to be parsed maxExprCnt uint64 // entrypoint for the parser entrypoint string allowInvalidUTF8 bool *Stats choiceNoMatch string // recovery expression stack, keeps track of the currently available recovery expression, these are traversed in reverse recoveryStack []map[string]any } // push a variable set on the vstack. func (p *parser) pushV() { if cap(p.vstack) == len(p.vstack) { // create new empty slot in the stack p.vstack = append(p.vstack, nil) } else { // slice to 1 more p.vstack = p.vstack[:len(p.vstack)+1] } // get the last args set m := p.vstack[len(p.vstack)-1] if m != nil && len(m) == 0 { // empty map, all good return } m = make(map[string]any) p.vstack[len(p.vstack)-1] = m } // pop a variable set from the vstack. func (p *parser) popV() { // if the map is not empty, clear it m := p.vstack[len(p.vstack)-1] if len(m) > 0 { // GC that map p.vstack[len(p.vstack)-1] = nil } p.vstack = p.vstack[:len(p.vstack)-1] } // push a recovery expression with its labels to the recoveryStack func (p *parser) pushRecovery(labels []string, expr any) { if cap(p.recoveryStack) == len(p.recoveryStack) { // create new empty slot in the stack p.recoveryStack = append(p.recoveryStack, nil) } else { // slice to 1 more p.recoveryStack = p.recoveryStack[:len(p.recoveryStack)+1] } m := make(map[string]any, len(labels)) for _, fl := range labels { m[fl] = expr } p.recoveryStack[len(p.recoveryStack)-1] = m } // pop a recovery expression from the recoveryStack func (p *parser) popRecovery() { // GC that map p.recoveryStack[len(p.recoveryStack)-1] = nil p.recoveryStack = p.recoveryStack[:len(p.recoveryStack)-1] } func (p *parser) addErr(err error) { p.addErrAt(err, p.pt.position, []string{}) } func (p *parser) addErrAt(err error, pos position, expected []string) { var buf bytes.Buffer if p.filename != "" { buf.WriteString(p.filename) } if buf.Len() > 0 { buf.WriteString(":") } buf.WriteString(fmt.Sprintf("%d:%d (%d)", pos.line, pos.col, pos.offset)) if len(p.rstack) > 0 { if buf.Len() > 0 { buf.WriteString(": ") } rule := p.rstack[len(p.rstack)-1] if rule.displayName != "" { buf.WriteString("rule " + rule.displayName) } else { buf.WriteString("rule " + rule.name) } } pe := &parserError{Inner: err, pos: pos, prefix: buf.String(), expected: expected} p.errs.add(pe) } func (p *parser) failAt(fail bool, pos position, want string) { // process fail if parsing fails and not inverted or parsing succeeds and invert is set if fail == p.maxFailInvertExpected { if pos.offset < p.maxFailPos.offset { return } if pos.offset > p.maxFailPos.offset { p.maxFailPos = pos p.maxFailExpected = p.maxFailExpected[:0] } if p.maxFailInvertExpected { want = "!" + want } p.maxFailExpected = append(p.maxFailExpected, want) } } // read advances the parser to the next rune. func (p *parser) read() { p.pt.offset += p.pt.w rn, n := utf8.DecodeRune(p.data[p.pt.offset:]) p.pt.rn = rn p.pt.w = n p.pt.col++ if rn == '\n' { p.pt.line++ p.pt.col = 0 } if rn == utf8.RuneError && n == 1 { // see utf8.DecodeRune if !p.allowInvalidUTF8 { p.addErr(errInvalidEncoding) } } } // restore parser position to the savepoint pt. func (p *parser) restore(pt savepoint) { if pt.offset == p.pt.offset { return } p.pt = pt } // get the slice of bytes from the savepoint start to the current position. func (p *parser) sliceFrom(start savepoint) []byte { return p.data[start.position.offset:p.pt.position.offset] } func (p *parser) buildRulesTable(g *grammar) { p.rules = make(map[string]*rule, len(g.rules)) for _, r := range g.rules { p.rules[r.name] = r } } func (p *parser) parse(g *grammar) (val any, err error) { if len(g.rules) == 0 { p.addErr(errNoRule) return nil, p.errs.err() } // TODO : not super critical but this could be generated p.buildRulesTable(g) if p.recover { // panic can be used in action code to stop parsing immediately // and return the panic as an error. defer func() { if e := recover(); e != nil { val = nil switch e := e.(type) { case error: p.addErr(e) default: p.addErr(fmt.Errorf("%v", e)) } err = p.errs.err() } }() } startRule, ok := p.rules[p.entrypoint] if !ok { p.addErr(errInvalidEntrypoint) return nil, p.errs.err() } p.read() // advance to first rune val, ok = p.parseRuleWrap(startRule) if !ok { if len(*p.errs) == 0 { // If parsing fails, but no errors have been recorded, the expected values // for the farthest parser position are returned as error. maxFailExpectedMap := make(map[string]struct{}, len(p.maxFailExpected)) for _, v := range p.maxFailExpected { maxFailExpectedMap[v] = struct{}{} } expected := make([]string, 0, len(maxFailExpectedMap)) eof := false if _, ok := maxFailExpectedMap["!."]; ok { delete(maxFailExpectedMap, "!.") eof = true } for k := range maxFailExpectedMap { expected = append(expected, k) } sort.Strings(expected) if eof { expected = append(expected, "EOF") } p.addErrAt(errors.New("no match found, expected: "+listJoin(expected, ", ", "or")), p.maxFailPos, expected) } return nil, p.errs.err() } return val, p.errs.err() } func listJoin(list []string, sep string, lastSep string) string { switch len(list) { case 0: return "" case 1: return list[0] default: return strings.Join(list[:len(list)-1], sep) + " " + lastSep + " " + list[len(list)-1] } } func (p *parser) parseRuleWrap(rule *rule) (any, bool) { var ( val any ok bool ) val, ok = p.parseRule(rule) return val, ok } func (p *parser) parseRule(rule *rule) (any, bool) { p.rstack = append(p.rstack, rule) p.pushV() val, ok := p.parseExprWrap(rule.expr) p.popV() p.rstack = p.rstack[:len(p.rstack)-1] return val, ok } func (p *parser) parseExprWrap(expr any) (any, bool) { val, ok := p.parseExpr(expr) return val, ok } func (p *parser) parseExpr(expr any) (any, bool) { p.ExprCnt++ if p.ExprCnt > p.maxExprCnt { panic(errMaxExprCnt) } var val any var ok bool switch expr := expr.(type) { case *actionExpr: val, ok = p.parseActionExpr(expr) case *andCodeExpr: val, ok = p.parseAndCodeExpr(expr) case *andExpr: val, ok = p.parseAndExpr(expr) case *anyMatcher: val, ok = p.parseAnyMatcher(expr) case *charClassMatcher: val, ok = p.parseCharClassMatcher(expr) case *choiceExpr: val, ok = p.parseChoiceExpr(expr) case *labeledExpr: val, ok = p.parseLabeledExpr(expr) case *litMatcher: val, ok = p.parseLitMatcher(expr) case *notCodeExpr: val, ok = p.parseNotCodeExpr(expr) case *notExpr: val, ok = p.parseNotExpr(expr) case *oneOrMoreExpr: val, ok = p.parseOneOrMoreExpr(expr) case *recoveryExpr: val, ok = p.parseRecoveryExpr(expr) case *ruleRefExpr: val, ok = p.parseRuleRefExpr(expr) case *seqExpr: val, ok = p.parseSeqExpr(expr) case *throwExpr: val, ok = p.parseThrowExpr(expr) case *zeroOrMoreExpr: val, ok = p.parseZeroOrMoreExpr(expr) case *zeroOrOneExpr: val, ok = p.parseZeroOrOneExpr(expr) default: panic(fmt.Sprintf("unknown expression type %T", expr)) } return val, ok } func (p *parser) parseActionExpr(act *actionExpr) (any, bool) { start := p.pt val, ok := p.parseExprWrap(act.expr) if ok { p.cur.pos = start.position p.cur.text = p.sliceFrom(start) actVal, err := act.run(p) if err != nil { p.addErrAt(err, start.position, []string{}) } val = actVal } return val, ok } func (p *parser) parseAndCodeExpr(and *andCodeExpr) (any, bool) { ok, err := and.run(p) if err != nil { p.addErr(err) } return nil, ok } func (p *parser) parseAndExpr(and *andExpr) (any, bool) { pt := p.pt p.pushV() _, ok := p.parseExprWrap(and.expr) p.popV() p.restore(pt) return nil, ok } func (p *parser) parseAnyMatcher(any *anyMatcher) (any, bool) { if p.pt.rn == utf8.RuneError && p.pt.w == 0 { // EOF - see utf8.DecodeRune p.failAt(false, p.pt.position, ".") return nil, false } start := p.pt p.read() p.failAt(true, start.position, ".") return p.sliceFrom(start), true } func (p *parser) parseCharClassMatcher(chr *charClassMatcher) (any, bool) { cur := p.pt.rn start := p.pt // can't match EOF if cur == utf8.RuneError && p.pt.w == 0 { // see utf8.DecodeRune p.failAt(false, start.position, chr.val) return nil, false } if chr.ignoreCase { cur = unicode.ToLower(cur) } // try to match in the list of available chars for _, rn := range chr.chars { if rn == cur { if chr.inverted { p.failAt(false, start.position, chr.val) return nil, false } p.read() p.failAt(true, start.position, chr.val) return p.sliceFrom(start), true } } // try to match in the list of ranges for i := 0; i < len(chr.ranges); i += 2 { if cur >= chr.ranges[i] && cur <= chr.ranges[i+1] { if chr.inverted { p.failAt(false, start.position, chr.val) return nil, false } p.read() p.failAt(true, start.position, chr.val) return p.sliceFrom(start), true } } // try to match in the list of Unicode classes for _, cl := range chr.classes { if unicode.Is(cl, cur) { if chr.inverted { p.failAt(false, start.position, chr.val) return nil, false } p.read() p.failAt(true, start.position, chr.val) return p.sliceFrom(start), true } } if chr.inverted { p.read() p.failAt(true, start.position, chr.val) return p.sliceFrom(start), true } p.failAt(false, start.position, chr.val) return nil, false } func (p *parser) parseChoiceExpr(ch *choiceExpr) (any, bool) { for altI, alt := range ch.alternatives { // dummy assignment to prevent compile error if optimized _ = altI p.pushV() val, ok := p.parseExprWrap(alt) p.popV() if ok { return val, ok } } return nil, false } func (p *parser) parseLabeledExpr(lab *labeledExpr) (any, bool) { p.pushV() val, ok := p.parseExprWrap(lab.expr) p.popV() if ok && lab.label != "" { m := p.vstack[len(p.vstack)-1] m[lab.label] = val } return val, ok } func (p *parser) parseLitMatcher(lit *litMatcher) (any, bool) { start := p.pt for _, want := range lit.val { cur := p.pt.rn if lit.ignoreCase { cur = unicode.ToLower(cur) } if cur != want { p.failAt(false, start.position, lit.want) p.restore(start) return nil, false } p.read() } p.failAt(true, start.position, lit.want) return p.sliceFrom(start), true } func (p *parser) parseNotCodeExpr(not *notCodeExpr) (any, bool) { ok, err := not.run(p) if err != nil { p.addErr(err) } return nil, !ok } func (p *parser) parseNotExpr(not *notExpr) (any, bool) { pt := p.pt p.pushV() p.maxFailInvertExpected = !p.maxFailInvertExpected _, ok := p.parseExprWrap(not.expr) p.maxFailInvertExpected = !p.maxFailInvertExpected p.popV() p.restore(pt) return nil, !ok } func (p *parser) parseOneOrMoreExpr(expr *oneOrMoreExpr) (any, bool) { var vals []any for { p.pushV() val, ok := p.parseExprWrap(expr.expr) p.popV() if !ok { if len(vals) == 0 { // did not match once, no match return nil, false } return vals, true } vals = append(vals, val) } } func (p *parser) parseRecoveryExpr(recover *recoveryExpr) (any, bool) { p.pushRecovery(recover.failureLabel, recover.recoverExpr) val, ok := p.parseExprWrap(recover.expr) p.popRecovery() return val, ok } func (p *parser) parseRuleRefExpr(ref *ruleRefExpr) (any, bool) { if ref.name == "" { panic(fmt.Sprintf("%s: invalid rule: missing name", ref.pos)) } rule := p.rules[ref.name] if rule == nil { p.addErr(fmt.Errorf("undefined rule: %s", ref.name)) return nil, false } return p.parseRuleWrap(rule) } func (p *parser) parseSeqExpr(seq *seqExpr) (any, bool) { vals := make([]any, 0, len(seq.exprs)) pt := p.pt for _, expr := range seq.exprs { val, ok := p.parseExprWrap(expr) if !ok { p.restore(pt) return nil, false } vals = append(vals, val) } return vals, true } func (p *parser) parseThrowExpr(expr *throwExpr) (any, bool) { for i := len(p.recoveryStack) - 1; i >= 0; i-- { if recoverExpr, ok := p.recoveryStack[i][expr.label]; ok { if val, ok := p.parseExprWrap(recoverExpr); ok { return val, ok } } } return nil, false } func (p *parser) parseZeroOrMoreExpr(expr *zeroOrMoreExpr) (any, bool) { var vals []any for { p.pushV() val, ok := p.parseExprWrap(expr.expr) p.popV() if !ok { return vals, true } vals = append(vals, val) } } func (p *parser) parseZeroOrOneExpr(expr *zeroOrOneExpr) (any, bool) { p.pushV() val, _ := p.parseExprWrap(expr.expr) p.popV() // whether it matched or not, consider it a match return val, true }