// Package promql implements a promql parser to build flux query specifications from promql.
package promql

import (
	"bytes"
	"errors"
	"fmt"
	"io"
	"io/ioutil"
	"math"
	"os"
	"sort"
	"strconv"
	"strings"
	"time"
	"unicode"
	"unicode/utf8"
)

// DO NOT EDIT: This file is auto generated by the pigeon PEG parser generator.

var reservedWords = map[string]bool{}

var g = &grammar{
	rules: []*rule{
		{
			name: "Grammar",
			pos:  position{line: 11, col: 1, offset: 234},
			expr: &actionExpr{
				pos: position{line: 11, col: 12, offset: 245},
				run: (*parser).callonGrammar1,
				expr: &seqExpr{
					pos: position{line: 11, col: 12, offset: 245},
					exprs: []interface{}{
						&labeledExpr{
							pos:   position{line: 11, col: 12, offset: 245},
							label: "grammar",
							expr: &choiceExpr{
								pos: position{line: 11, col: 22, offset: 255},
								alternatives: []interface{}{
									&ruleRefExpr{
										pos:  position{line: 11, col: 22, offset: 255},
										name: "Comment",
									},
									&ruleRefExpr{
										pos:  position{line: 11, col: 32, offset: 265},
										name: "AggregateExpression",
									},
									&ruleRefExpr{
										pos:  position{line: 11, col: 54, offset: 287},
										name: "VectorSelector",
									},
								},
							},
						},
						&ruleRefExpr{
							pos:  position{line: 11, col: 71, offset: 304},
							name: "EOF",
						},
					},
				},
			},
		},
		{
			name: "SourceChar",
			pos:  position{line: 15, col: 1, offset: 337},
			expr: &anyMatcher{
				line: 15, col: 14, offset: 350,
			},
		},
		{
			name: "Comment",
			pos:  position{line: 17, col: 1, offset: 353},
			expr: &actionExpr{
				pos: position{line: 17, col: 11, offset: 363},
				run: (*parser).callonComment1,
				expr: &seqExpr{
					pos: position{line: 17, col: 11, offset: 363},
					exprs: []interface{}{
						&litMatcher{
							pos:        position{line: 17, col: 11, offset: 363},
							val:        "#",
							ignoreCase: false,
						},
						&zeroOrMoreExpr{
							pos: position{line: 17, col: 15, offset: 367},
							expr: &seqExpr{
								pos: position{line: 17, col: 17, offset: 369},
								exprs: []interface{}{
									&notExpr{
										pos: position{line: 17, col: 17, offset: 369},
										expr: &ruleRefExpr{
											pos:  position{line: 17, col: 18, offset: 370},
											name: "EOL",
										},
									},
									&ruleRefExpr{
										pos:  position{line: 17, col: 22, offset: 374},
										name: "SourceChar",
									},
								},
							},
						},
					},
				},
			},
		},
		{
			name: "Identifier",
			pos:  position{line: 21, col: 1, offset: 434},
			expr: &actionExpr{
				pos: position{line: 21, col: 14, offset: 447},
				run: (*parser).callonIdentifier1,
				expr: &labeledExpr{
					pos:   position{line: 21, col: 14, offset: 447},
					label: "ident",
					expr: &ruleRefExpr{
						pos:  position{line: 21, col: 20, offset: 453},
						name: "IdentifierName",
					},
				},
			},
		},
		{
			name: "IdentifierName",
			pos:  position{line: 29, col: 1, offset: 637},
			expr: &actionExpr{
				pos: position{line: 29, col: 18, offset: 654},
				run: (*parser).callonIdentifierName1,
				expr: &seqExpr{
					pos: position{line: 29, col: 18, offset: 654},
					exprs: []interface{}{
						&ruleRefExpr{
							pos:  position{line: 29, col: 18, offset: 654},
							name: "IdentifierStart",
						},
						&zeroOrMoreExpr{
							pos: position{line: 29, col: 34, offset: 670},
							expr: &ruleRefExpr{
								pos:  position{line: 29, col: 34, offset: 670},
								name: "IdentifierPart",
							},
						},
					},
				},
			},
		},
		{
			name: "IdentifierStart",
			pos:  position{line: 32, col: 1, offset: 721},
			expr: &charClassMatcher{
				pos:        position{line: 32, col: 19, offset: 739},
				val:        "[\\pL_]",
				chars:      []rune{'_'},
				classes:    []*unicode.RangeTable{rangeTable("L")},
				ignoreCase: false,
				inverted:   false,
			},
		},
		{
			name: "IdentifierPart",
			pos:  position{line: 33, col: 1, offset: 746},
			expr: &choiceExpr{
				pos: position{line: 33, col: 18, offset: 763},
				alternatives: []interface{}{
					&ruleRefExpr{
						pos:  position{line: 33, col: 18, offset: 763},
						name: "IdentifierStart",
					},
					&charClassMatcher{
						pos:        position{line: 33, col: 36, offset: 781},
						val:        "[\\p{Nd}]",
						classes:    []*unicode.RangeTable{rangeTable("Nd")},
						ignoreCase: false,
						inverted:   false,
					},
				},
			},
		},
		{
			name: "StringLiteral",
			pos:  position{line: 35, col: 1, offset: 791},
			expr: &choiceExpr{
				pos: position{line: 35, col: 17, offset: 807},
				alternatives: []interface{}{
					&actionExpr{
						pos: position{line: 35, col: 17, offset: 807},
						run: (*parser).callonStringLiteral2,
						expr: &choiceExpr{
							pos: position{line: 35, col: 19, offset: 809},
							alternatives: []interface{}{
								&seqExpr{
									pos: position{line: 35, col: 19, offset: 809},
									exprs: []interface{}{
										&litMatcher{
											pos:        position{line: 35, col: 19, offset: 809},
											val:        "\"",
											ignoreCase: false,
										},
										&zeroOrMoreExpr{
											pos: position{line: 35, col: 23, offset: 813},
											expr: &ruleRefExpr{
												pos:  position{line: 35, col: 23, offset: 813},
												name: "DoubleStringChar",
											},
										},
										&litMatcher{
											pos:        position{line: 35, col: 41, offset: 831},
											val:        "\"",
											ignoreCase: false,
										},
									},
								},
								&seqExpr{
									pos: position{line: 35, col: 47, offset: 837},
									exprs: []interface{}{
										&litMatcher{
											pos:        position{line: 35, col: 47, offset: 837},
											val:        "'",
											ignoreCase: false,
										},
										&ruleRefExpr{
											pos:  position{line: 35, col: 51, offset: 841},
											name: "SingleStringChar",
										},
										&litMatcher{
											pos:        position{line: 35, col: 68, offset: 858},
											val:        "'",
											ignoreCase: false,
										},
									},
								},
								&seqExpr{
									pos: position{line: 35, col: 74, offset: 864},
									exprs: []interface{}{
										&litMatcher{
											pos:        position{line: 35, col: 74, offset: 864},
											val:        "`",
											ignoreCase: false,
										},
										&zeroOrMoreExpr{
											pos: position{line: 35, col: 78, offset: 868},
											expr: &ruleRefExpr{
												pos:  position{line: 35, col: 78, offset: 868},
												name: "RawStringChar",
											},
										},
										&litMatcher{
											pos:        position{line: 35, col: 93, offset: 883},
											val:        "`",
											ignoreCase: false,
										},
									},
								},
							},
						},
					},
					&actionExpr{
						pos: position{line: 41, col: 5, offset: 1029},
						run: (*parser).callonStringLiteral18,
						expr: &choiceExpr{
							pos: position{line: 41, col: 7, offset: 1031},
							alternatives: []interface{}{
								&seqExpr{
									pos: position{line: 41, col: 9, offset: 1033},
									exprs: []interface{}{
										&litMatcher{
											pos:        position{line: 41, col: 9, offset: 1033},
											val:        "\"",
											ignoreCase: false,
										},
										&zeroOrMoreExpr{
											pos: position{line: 41, col: 13, offset: 1037},
											expr: &ruleRefExpr{
												pos:  position{line: 41, col: 13, offset: 1037},
												name: "DoubleStringChar",
											},
										},
										&choiceExpr{
											pos: position{line: 41, col: 33, offset: 1057},
											alternatives: []interface{}{
												&ruleRefExpr{
													pos:  position{line: 41, col: 33, offset: 1057},
													name: "EOL",
												},
												&ruleRefExpr{
													pos:  position{line: 41, col: 39, offset: 1063},
													name: "EOF",
												},
											},
										},
									},
								},
								&seqExpr{
									pos: position{line: 41, col: 51, offset: 1075},
									exprs: []interface{}{
										&litMatcher{
											pos:        position{line: 41, col: 51, offset: 1075},
											val:        "'",
											ignoreCase: false,
										},
										&zeroOrOneExpr{
											pos: position{line: 41, col: 55, offset: 1079},
											expr: &ruleRefExpr{
												pos:  position{line: 41, col: 55, offset: 1079},
												name: "SingleStringChar",
											},
										},
										&choiceExpr{
											pos: position{line: 41, col: 75, offset: 1099},
											alternatives: []interface{}{
												&ruleRefExpr{
													pos:  position{line: 41, col: 75, offset: 1099},
													name: "EOL",
												},
												&ruleRefExpr{
													pos:  position{line: 41, col: 81, offset: 1105},
													name: "EOF",
												},
											},
										},
									},
								},
								&seqExpr{
									pos: position{line: 41, col: 91, offset: 1115},
									exprs: []interface{}{
										&litMatcher{
											pos:        position{line: 41, col: 91, offset: 1115},
											val:        "`",
											ignoreCase: false,
										},
										&zeroOrMoreExpr{
											pos: position{line: 41, col: 95, offset: 1119},
											expr: &ruleRefExpr{
												pos:  position{line: 41, col: 95, offset: 1119},
												name: "RawStringChar",
											},
										},
										&ruleRefExpr{
											pos:  position{line: 41, col: 110, offset: 1134},
											name: "EOF",
										},
									},
								},
							},
						},
					},
				},
			},
		},
		{
			name: "DoubleStringChar",
			pos:  position{line: 45, col: 1, offset: 1205},
			expr: &choiceExpr{
				pos: position{line: 45, col: 20, offset: 1224},
				alternatives: []interface{}{
					&seqExpr{
						pos: position{line: 45, col: 20, offset: 1224},
						exprs: []interface{}{
							&notExpr{
								pos: position{line: 45, col: 20, offset: 1224},
								expr: &choiceExpr{
									pos: position{line: 45, col: 23, offset: 1227},
									alternatives: []interface{}{
										&litMatcher{
											pos:        position{line: 45, col: 23, offset: 1227},
											val:        "\"",
											ignoreCase: false,
										},
										&litMatcher{
											pos:        position{line: 45, col: 29, offset: 1233},
											val:        "\\",
											ignoreCase: false,
										},
										&ruleRefExpr{
											pos:  position{line: 45, col: 36, offset: 1240},
											name: "EOL",
										},
									},
								},
							},
							&ruleRefExpr{
								pos:  position{line: 45, col: 42, offset: 1246},
								name: "SourceChar",
							},
						},
					},
					&seqExpr{
						pos: position{line: 45, col: 55, offset: 1259},
						exprs: []interface{}{
							&litMatcher{
								pos:        position{line: 45, col: 55, offset: 1259},
								val:        "\\",
								ignoreCase: false,
							},
							&ruleRefExpr{
								pos:  position{line: 45, col: 60, offset: 1264},
								name: "DoubleStringEscape",
							},
						},
					},
				},
			},
		},
		{
			name: "SingleStringChar",
			pos:  position{line: 46, col: 1, offset: 1283},
			expr: &choiceExpr{
				pos: position{line: 46, col: 20, offset: 1302},
				alternatives: []interface{}{
					&seqExpr{
						pos: position{line: 46, col: 20, offset: 1302},
						exprs: []interface{}{
							&notExpr{
								pos: position{line: 46, col: 20, offset: 1302},
								expr: &choiceExpr{
									pos: position{line: 46, col: 23, offset: 1305},
									alternatives: []interface{}{
										&litMatcher{
											pos:        position{line: 46, col: 23, offset: 1305},
											val:        "'",
											ignoreCase: false,
										},
										&litMatcher{
											pos:        position{line: 46, col: 29, offset: 1311},
											val:        "\\",
											ignoreCase: false,
										},
										&ruleRefExpr{
											pos:  position{line: 46, col: 36, offset: 1318},
											name: "EOL",
										},
									},
								},
							},
							&ruleRefExpr{
								pos:  position{line: 46, col: 42, offset: 1324},
								name: "SourceChar",
							},
						},
					},
					&seqExpr{
						pos: position{line: 46, col: 55, offset: 1337},
						exprs: []interface{}{
							&litMatcher{
								pos:        position{line: 46, col: 55, offset: 1337},
								val:        "\\",
								ignoreCase: false,
							},
							&ruleRefExpr{
								pos:  position{line: 46, col: 60, offset: 1342},
								name: "SingleStringEscape",
							},
						},
					},
				},
			},
		},
		{
			name: "RawStringChar",
			pos:  position{line: 47, col: 1, offset: 1361},
			expr: &seqExpr{
				pos: position{line: 47, col: 17, offset: 1377},
				exprs: []interface{}{
					&notExpr{
						pos: position{line: 47, col: 17, offset: 1377},
						expr: &litMatcher{
							pos:        position{line: 47, col: 18, offset: 1378},
							val:        "`",
							ignoreCase: false,
						},
					},
					&ruleRefExpr{
						pos:  position{line: 47, col: 22, offset: 1382},
						name: "SourceChar",
					},
				},
			},
		},
		{
			name: "DoubleStringEscape",
			pos:  position{line: 49, col: 1, offset: 1394},
			expr: &choiceExpr{
				pos: position{line: 49, col: 22, offset: 1415},
				alternatives: []interface{}{
					&choiceExpr{
						pos: position{line: 49, col: 24, offset: 1417},
						alternatives: []interface{}{
							&litMatcher{
								pos:        position{line: 49, col: 24, offset: 1417},
								val:        "\"",
								ignoreCase: false,
							},
							&ruleRefExpr{
								pos:  position{line: 49, col: 30, offset: 1423},
								name: "CommonEscapeSequence",
							},
						},
					},
					&actionExpr{
						pos: position{line: 50, col: 7, offset: 1452},
						run: (*parser).callonDoubleStringEscape5,
						expr: &choiceExpr{
							pos: position{line: 50, col: 9, offset: 1454},
							alternatives: []interface{}{
								&ruleRefExpr{
									pos:  position{line: 50, col: 9, offset: 1454},
									name: "SourceChar",
								},
								&ruleRefExpr{
									pos:  position{line: 50, col: 22, offset: 1467},
									name: "EOL",
								},
								&ruleRefExpr{
									pos:  position{line: 50, col: 28, offset: 1473},
									name: "EOF",
								},
							},
						},
					},
				},
			},
		},
		{
			name: "SingleStringEscape",
			pos:  position{line: 53, col: 1, offset: 1538},
			expr: &choiceExpr{
				pos: position{line: 53, col: 22, offset: 1559},
				alternatives: []interface{}{
					&choiceExpr{
						pos: position{line: 53, col: 24, offset: 1561},
						alternatives: []interface{}{
							&litMatcher{
								pos:        position{line: 53, col: 24, offset: 1561},
								val:        "'",
								ignoreCase: false,
							},
							&ruleRefExpr{
								pos:  position{line: 53, col: 30, offset: 1567},
								name: "CommonEscapeSequence",
							},
						},
					},
					&actionExpr{
						pos: position{line: 54, col: 7, offset: 1596},
						run: (*parser).callonSingleStringEscape5,
						expr: &choiceExpr{
							pos: position{line: 54, col: 9, offset: 1598},
							alternatives: []interface{}{
								&ruleRefExpr{
									pos:  position{line: 54, col: 9, offset: 1598},
									name: "SourceChar",
								},
								&ruleRefExpr{
									pos:  position{line: 54, col: 22, offset: 1611},
									name: "EOL",
								},
								&ruleRefExpr{
									pos:  position{line: 54, col: 28, offset: 1617},
									name: "EOF",
								},
							},
						},
					},
				},
			},
		},
		{
			name: "CommonEscapeSequence",
			pos:  position{line: 58, col: 1, offset: 1683},
			expr: &choiceExpr{
				pos: position{line: 58, col: 24, offset: 1706},
				alternatives: []interface{}{
					&ruleRefExpr{
						pos:  position{line: 58, col: 24, offset: 1706},
						name: "SingleCharEscape",
					},
					&ruleRefExpr{
						pos:  position{line: 58, col: 43, offset: 1725},
						name: "OctalEscape",
					},
					&ruleRefExpr{
						pos:  position{line: 58, col: 57, offset: 1739},
						name: "HexEscape",
					},
					&ruleRefExpr{
						pos:  position{line: 58, col: 69, offset: 1751},
						name: "LongUnicodeEscape",
					},
					&ruleRefExpr{
						pos:  position{line: 58, col: 89, offset: 1771},
						name: "ShortUnicodeEscape",
					},
				},
			},
		},
		{
			name: "SingleCharEscape",
			pos:  position{line: 59, col: 1, offset: 1790},
			expr: &choiceExpr{
				pos: position{line: 59, col: 20, offset: 1809},
				alternatives: []interface{}{
					&litMatcher{
						pos:        position{line: 59, col: 20, offset: 1809},
						val:        "a",
						ignoreCase: false,
					},
					&litMatcher{
						pos:        position{line: 59, col: 26, offset: 1815},
						val:        "b",
						ignoreCase: false,
					},
					&litMatcher{
						pos:        position{line: 59, col: 32, offset: 1821},
						val:        "n",
						ignoreCase: false,
					},
					&litMatcher{
						pos:        position{line: 59, col: 38, offset: 1827},
						val:        "f",
						ignoreCase: false,
					},
					&litMatcher{
						pos:        position{line: 59, col: 44, offset: 1833},
						val:        "r",
						ignoreCase: false,
					},
					&litMatcher{
						pos:        position{line: 59, col: 50, offset: 1839},
						val:        "t",
						ignoreCase: false,
					},
					&litMatcher{
						pos:        position{line: 59, col: 56, offset: 1845},
						val:        "v",
						ignoreCase: false,
					},
					&litMatcher{
						pos:        position{line: 59, col: 62, offset: 1851},
						val:        "\\",
						ignoreCase: false,
					},
				},
			},
		},
		{
			name: "OctalEscape",
			pos:  position{line: 60, col: 1, offset: 1856},
			expr: &choiceExpr{
				pos: position{line: 60, col: 15, offset: 1870},
				alternatives: []interface{}{
					&seqExpr{
						pos: position{line: 60, col: 15, offset: 1870},
						exprs: []interface{}{
							&ruleRefExpr{
								pos:  position{line: 60, col: 15, offset: 1870},
								name: "OctalDigit",
							},
							&ruleRefExpr{
								pos:  position{line: 60, col: 26, offset: 1881},
								name: "OctalDigit",
							},
							&ruleRefExpr{
								pos:  position{line: 60, col: 37, offset: 1892},
								name: "OctalDigit",
							},
						},
					},
					&actionExpr{
						pos: position{line: 61, col: 7, offset: 1909},
						run: (*parser).callonOctalEscape6,
						expr: &seqExpr{
							pos: position{line: 61, col: 7, offset: 1909},
							exprs: []interface{}{
								&ruleRefExpr{
									pos:  position{line: 61, col: 7, offset: 1909},
									name: "OctalDigit",
								},
								&choiceExpr{
									pos: position{line: 61, col: 20, offset: 1922},
									alternatives: []interface{}{
										&ruleRefExpr{
											pos:  position{line: 61, col: 20, offset: 1922},
											name: "SourceChar",
										},
										&ruleRefExpr{
											pos:  position{line: 61, col: 33, offset: 1935},
											name: "EOL",
										},
										&ruleRefExpr{
											pos:  position{line: 61, col: 39, offset: 1941},
											name: "EOF",
										},
									},
								},
							},
						},
					},
				},
			},
		},
		{
			name: "HexEscape",
			pos:  position{line: 64, col: 1, offset: 2002},
			expr: &choiceExpr{
				pos: position{line: 64, col: 13, offset: 2014},
				alternatives: []interface{}{
					&seqExpr{
						pos: position{line: 64, col: 13, offset: 2014},
						exprs: []interface{}{
							&litMatcher{
								pos:        position{line: 64, col: 13, offset: 2014},
								val:        "x",
								ignoreCase: false,
							},
							&ruleRefExpr{
								pos:  position{line: 64, col: 17, offset: 2018},
								name: "HexDigit",
							},
							&ruleRefExpr{
								pos:  position{line: 64, col: 26, offset: 2027},
								name: "HexDigit",
							},
						},
					},
					&actionExpr{
						pos: position{line: 65, col: 7, offset: 2042},
						run: (*parser).callonHexEscape6,
						expr: &seqExpr{
							pos: position{line: 65, col: 7, offset: 2042},
							exprs: []interface{}{
								&litMatcher{
									pos:        position{line: 65, col: 7, offset: 2042},
									val:        "x",
									ignoreCase: false,
								},
								&choiceExpr{
									pos: position{line: 65, col: 13, offset: 2048},
									alternatives: []interface{}{
										&ruleRefExpr{
											pos:  position{line: 65, col: 13, offset: 2048},
											name: "SourceChar",
										},
										&ruleRefExpr{
											pos:  position{line: 65, col: 26, offset: 2061},
											name: "EOL",
										},
										&ruleRefExpr{
											pos:  position{line: 65, col: 32, offset: 2067},
											name: "EOF",
										},
									},
								},
							},
						},
					},
				},
			},
		},
		{
			name: "LongUnicodeEscape",
			pos:  position{line: 68, col: 1, offset: 2134},
			expr: &choiceExpr{
				pos: position{line: 69, col: 5, offset: 2159},
				alternatives: []interface{}{
					&actionExpr{
						pos: position{line: 69, col: 5, offset: 2159},
						run: (*parser).callonLongUnicodeEscape2,
						expr: &seqExpr{
							pos: position{line: 69, col: 5, offset: 2159},
							exprs: []interface{}{
								&litMatcher{
									pos:        position{line: 69, col: 5, offset: 2159},
									val:        "U",
									ignoreCase: false,
								},
								&ruleRefExpr{
									pos:  position{line: 69, col: 9, offset: 2163},
									name: "HexDigit",
								},
								&ruleRefExpr{
									pos:  position{line: 69, col: 18, offset: 2172},
									name: "HexDigit",
								},
								&ruleRefExpr{
									pos:  position{line: 69, col: 27, offset: 2181},
									name: "HexDigit",
								},
								&ruleRefExpr{
									pos:  position{line: 69, col: 36, offset: 2190},
									name: "HexDigit",
								},
								&ruleRefExpr{
									pos:  position{line: 69, col: 45, offset: 2199},
									name: "HexDigit",
								},
								&ruleRefExpr{
									pos:  position{line: 69, col: 54, offset: 2208},
									name: "HexDigit",
								},
								&ruleRefExpr{
									pos:  position{line: 69, col: 63, offset: 2217},
									name: "HexDigit",
								},
								&ruleRefExpr{
									pos:  position{line: 69, col: 72, offset: 2226},
									name: "HexDigit",
								},
							},
						},
					},
					&actionExpr{
						pos: position{line: 72, col: 7, offset: 2328},
						run: (*parser).callonLongUnicodeEscape13,
						expr: &seqExpr{
							pos: position{line: 72, col: 7, offset: 2328},
							exprs: []interface{}{
								&litMatcher{
									pos:        position{line: 72, col: 7, offset: 2328},
									val:        "U",
									ignoreCase: false,
								},
								&choiceExpr{
									pos: position{line: 72, col: 13, offset: 2334},
									alternatives: []interface{}{
										&ruleRefExpr{
											pos:  position{line: 72, col: 13, offset: 2334},
											name: "SourceChar",
										},
										&ruleRefExpr{
											pos:  position{line: 72, col: 26, offset: 2347},
											name: "EOL",
										},
										&ruleRefExpr{
											pos:  position{line: 72, col: 32, offset: 2353},
											name: "EOF",
										},
									},
								},
							},
						},
					},
				},
			},
		},
		{
			name: "ShortUnicodeEscape",
			pos:  position{line: 75, col: 1, offset: 2416},
			expr: &choiceExpr{
				pos: position{line: 76, col: 5, offset: 2442},
				alternatives: []interface{}{
					&actionExpr{
						pos: position{line: 76, col: 5, offset: 2442},
						run: (*parser).callonShortUnicodeEscape2,
						expr: &seqExpr{
							pos: position{line: 76, col: 5, offset: 2442},
							exprs: []interface{}{
								&litMatcher{
									pos:        position{line: 76, col: 5, offset: 2442},
									val:        "u",
									ignoreCase: false,
								},
								&ruleRefExpr{
									pos:  position{line: 76, col: 9, offset: 2446},
									name: "HexDigit",
								},
								&ruleRefExpr{
									pos:  position{line: 76, col: 18, offset: 2455},
									name: "HexDigit",
								},
								&ruleRefExpr{
									pos:  position{line: 76, col: 27, offset: 2464},
									name: "HexDigit",
								},
								&ruleRefExpr{
									pos:  position{line: 76, col: 36, offset: 2473},
									name: "HexDigit",
								},
							},
						},
					},
					&actionExpr{
						pos: position{line: 79, col: 7, offset: 2575},
						run: (*parser).callonShortUnicodeEscape9,
						expr: &seqExpr{
							pos: position{line: 79, col: 7, offset: 2575},
							exprs: []interface{}{
								&litMatcher{
									pos:        position{line: 79, col: 7, offset: 2575},
									val:        "u",
									ignoreCase: false,
								},
								&choiceExpr{
									pos: position{line: 79, col: 13, offset: 2581},
									alternatives: []interface{}{
										&ruleRefExpr{
											pos:  position{line: 79, col: 13, offset: 2581},
											name: "SourceChar",
										},
										&ruleRefExpr{
											pos:  position{line: 79, col: 26, offset: 2594},
											name: "EOL",
										},
										&ruleRefExpr{
											pos:  position{line: 79, col: 32, offset: 2600},
											name: "EOF",
										},
									},
								},
							},
						},
					},
				},
			},
		},
		{
			name: "OctalDigit",
			pos:  position{line: 83, col: 1, offset: 2664},
			expr: &charClassMatcher{
				pos:        position{line: 83, col: 14, offset: 2677},
				val:        "[0-7]",
				ranges:     []rune{'0', '7'},
				ignoreCase: false,
				inverted:   false,
			},
		},
		{
			name: "DecimalDigit",
			pos:  position{line: 84, col: 1, offset: 2683},
			expr: &charClassMatcher{
				pos:        position{line: 84, col: 16, offset: 2698},
				val:        "[0-9]",
				ranges:     []rune{'0', '9'},
				ignoreCase: false,
				inverted:   false,
			},
		},
		{
			name: "HexDigit",
			pos:  position{line: 85, col: 1, offset: 2704},
			expr: &charClassMatcher{
				pos:        position{line: 85, col: 12, offset: 2715},
				val:        "[0-9a-f]i",
				ranges:     []rune{'0', '9', 'a', 'f'},
				ignoreCase: true,
				inverted:   false,
			},
		},
		{
			name: "CharClassMatcher",
			pos:  position{line: 87, col: 1, offset: 2726},
			expr: &choiceExpr{
				pos: position{line: 87, col: 20, offset: 2745},
				alternatives: []interface{}{
					&actionExpr{
						pos: position{line: 87, col: 20, offset: 2745},
						run: (*parser).callonCharClassMatcher2,
						expr: &seqExpr{
							pos: position{line: 87, col: 20, offset: 2745},
							exprs: []interface{}{
								&litMatcher{
									pos:        position{line: 87, col: 20, offset: 2745},
									val:        "[",
									ignoreCase: false,
								},
								&zeroOrMoreExpr{
									pos: position{line: 87, col: 24, offset: 2749},
									expr: &choiceExpr{
										pos: position{line: 87, col: 26, offset: 2751},
										alternatives: []interface{}{
											&ruleRefExpr{
												pos:  position{line: 87, col: 26, offset: 2751},
												name: "ClassCharRange",
											},
											&ruleRefExpr{
												pos:  position{line: 87, col: 43, offset: 2768},
												name: "ClassChar",
											},
											&seqExpr{
												pos: position{line: 87, col: 55, offset: 2780},
												exprs: []interface{}{
													&litMatcher{
														pos:        position{line: 87, col: 55, offset: 2780},
														val:        "\\",
														ignoreCase: false,
													},
													&ruleRefExpr{
														pos:  position{line: 87, col: 60, offset: 2785},
														name: "UnicodeClassEscape",
													},
												},
											},
										},
									},
								},
								&litMatcher{
									pos:        position{line: 87, col: 82, offset: 2807},
									val:        "]",
									ignoreCase: false,
								},
								&zeroOrOneExpr{
									pos: position{line: 87, col: 86, offset: 2811},
									expr: &litMatcher{
										pos:        position{line: 87, col: 86, offset: 2811},
										val:        "i",
										ignoreCase: false,
									},
								},
							},
						},
					},
					&actionExpr{
						pos: position{line: 89, col: 5, offset: 2853},
						run: (*parser).callonCharClassMatcher15,
						expr: &seqExpr{
							pos: position{line: 89, col: 5, offset: 2853},
							exprs: []interface{}{
								&litMatcher{
									pos:        position{line: 89, col: 5, offset: 2853},
									val:        "[",
									ignoreCase: false,
								},
								&zeroOrMoreExpr{
									pos: position{line: 89, col: 9, offset: 2857},
									expr: &seqExpr{
										pos: position{line: 89, col: 11, offset: 2859},
										exprs: []interface{}{
											&notExpr{
												pos: position{line: 89, col: 11, offset: 2859},
												expr: &ruleRefExpr{
													pos:  position{line: 89, col: 14, offset: 2862},
													name: "EOL",
												},
											},
											&ruleRefExpr{
												pos:  position{line: 89, col: 20, offset: 2868},
												name: "SourceChar",
											},
										},
									},
								},
								&choiceExpr{
									pos: position{line: 89, col: 36, offset: 2884},
									alternatives: []interface{}{
										&ruleRefExpr{
											pos:  position{line: 89, col: 36, offset: 2884},
											name: "EOL",
										},
										&ruleRefExpr{
											pos:  position{line: 89, col: 42, offset: 2890},
											name: "EOF",
										},
									},
								},
							},
						},
					},
				},
			},
		},
		{
			name: "ClassCharRange",
			pos:  position{line: 93, col: 1, offset: 2962},
			expr: &seqExpr{
				pos: position{line: 93, col: 18, offset: 2979},
				exprs: []interface{}{
					&ruleRefExpr{
						pos:  position{line: 93, col: 18, offset: 2979},
						name: "ClassChar",
					},
					&litMatcher{
						pos:        position{line: 93, col: 28, offset: 2989},
						val:        "-",
						ignoreCase: false,
					},
					&ruleRefExpr{
						pos:  position{line: 93, col: 32, offset: 2993},
						name: "ClassChar",
					},
				},
			},
		},
		{
			name: "ClassChar",
			pos:  position{line: 94, col: 1, offset: 3003},
			expr: &choiceExpr{
				pos: position{line: 94, col: 13, offset: 3015},
				alternatives: []interface{}{
					&seqExpr{
						pos: position{line: 94, col: 13, offset: 3015},
						exprs: []interface{}{
							&notExpr{
								pos: position{line: 94, col: 13, offset: 3015},
								expr: &choiceExpr{
									pos: position{line: 94, col: 16, offset: 3018},
									alternatives: []interface{}{
										&litMatcher{
											pos:        position{line: 94, col: 16, offset: 3018},
											val:        "]",
											ignoreCase: false,
										},
										&litMatcher{
											pos:        position{line: 94, col: 22, offset: 3024},
											val:        "\\",
											ignoreCase: false,
										},
										&ruleRefExpr{
											pos:  position{line: 94, col: 29, offset: 3031},
											name: "EOL",
										},
									},
								},
							},
							&ruleRefExpr{
								pos:  position{line: 94, col: 35, offset: 3037},
								name: "SourceChar",
							},
						},
					},
					&seqExpr{
						pos: position{line: 94, col: 48, offset: 3050},
						exprs: []interface{}{
							&litMatcher{
								pos:        position{line: 94, col: 48, offset: 3050},
								val:        "\\",
								ignoreCase: false,
							},
							&ruleRefExpr{
								pos:  position{line: 94, col: 53, offset: 3055},
								name: "CharClassEscape",
							},
						},
					},
				},
			},
		},
		{
			name: "CharClassEscape",
			pos:  position{line: 95, col: 1, offset: 3071},
			expr: &choiceExpr{
				pos: position{line: 95, col: 19, offset: 3089},
				alternatives: []interface{}{
					&choiceExpr{
						pos: position{line: 95, col: 21, offset: 3091},
						alternatives: []interface{}{
							&litMatcher{
								pos:        position{line: 95, col: 21, offset: 3091},
								val:        "]",
								ignoreCase: false,
							},
							&ruleRefExpr{
								pos:  position{line: 95, col: 27, offset: 3097},
								name: "CommonEscapeSequence",
							},
						},
					},
					&actionExpr{
						pos: position{line: 96, col: 7, offset: 3126},
						run: (*parser).callonCharClassEscape5,
						expr: &seqExpr{
							pos: position{line: 96, col: 7, offset: 3126},
							exprs: []interface{}{
								&notExpr{
									pos: position{line: 96, col: 7, offset: 3126},
									expr: &litMatcher{
										pos:        position{line: 96, col: 8, offset: 3127},
										val:        "p",
										ignoreCase: false,
									},
								},
								&choiceExpr{
									pos: position{line: 96, col: 14, offset: 3133},
									alternatives: []interface{}{
										&ruleRefExpr{
											pos:  position{line: 96, col: 14, offset: 3133},
											name: "SourceChar",
										},
										&ruleRefExpr{
											pos:  position{line: 96, col: 27, offset: 3146},
											name: "EOL",
										},
										&ruleRefExpr{
											pos:  position{line: 96, col: 33, offset: 3152},
											name: "EOF",
										},
									},
								},
							},
						},
					},
				},
			},
		},
		{
			name: "UnicodeClassEscape",
			pos:  position{line: 100, col: 1, offset: 3218},
			expr: &seqExpr{
				pos: position{line: 100, col: 22, offset: 3239},
				exprs: []interface{}{
					&litMatcher{
						pos:        position{line: 100, col: 22, offset: 3239},
						val:        "p",
						ignoreCase: false,
					},
					&choiceExpr{
						pos: position{line: 101, col: 7, offset: 3252},
						alternatives: []interface{}{
							&ruleRefExpr{
								pos:  position{line: 101, col: 7, offset: 3252},
								name: "SingleCharUnicodeClass",
							},
							&actionExpr{
								pos: position{line: 102, col: 7, offset: 3281},
								run: (*parser).callonUnicodeClassEscape5,
								expr: &seqExpr{
									pos: position{line: 102, col: 7, offset: 3281},
									exprs: []interface{}{
										&notExpr{
											pos: position{line: 102, col: 7, offset: 3281},
											expr: &litMatcher{
												pos:        position{line: 102, col: 8, offset: 3282},
												val:        "{",
												ignoreCase: false,
											},
										},
										&choiceExpr{
											pos: position{line: 102, col: 14, offset: 3288},
											alternatives: []interface{}{
												&ruleRefExpr{
													pos:  position{line: 102, col: 14, offset: 3288},
													name: "SourceChar",
												},
												&ruleRefExpr{
													pos:  position{line: 102, col: 27, offset: 3301},
													name: "EOL",
												},
												&ruleRefExpr{
													pos:  position{line: 102, col: 33, offset: 3307},
													name: "EOF",
												},
											},
										},
									},
								},
							},
							&actionExpr{
								pos: position{line: 103, col: 7, offset: 3378},
								run: (*parser).callonUnicodeClassEscape13,
								expr: &seqExpr{
									pos: position{line: 103, col: 7, offset: 3378},
									exprs: []interface{}{
										&litMatcher{
											pos:        position{line: 103, col: 7, offset: 3378},
											val:        "{",
											ignoreCase: false,
										},
										&labeledExpr{
											pos:   position{line: 103, col: 11, offset: 3382},
											label: "ident",
											expr: &ruleRefExpr{
												pos:  position{line: 103, col: 17, offset: 3388},
												name: "IdentifierName",
											},
										},
										&litMatcher{
											pos:        position{line: 103, col: 32, offset: 3403},
											val:        "}",
											ignoreCase: false,
										},
									},
								},
							},
							&actionExpr{
								pos: position{line: 109, col: 7, offset: 3567},
								run: (*parser).callonUnicodeClassEscape19,
								expr: &seqExpr{
									pos: position{line: 109, col: 7, offset: 3567},
									exprs: []interface{}{
										&litMatcher{
											pos:        position{line: 109, col: 7, offset: 3567},
											val:        "{",
											ignoreCase: false,
										},
										&ruleRefExpr{
											pos:  position{line: 109, col: 11, offset: 3571},
											name: "IdentifierName",
										},
										&choiceExpr{
											pos: position{line: 109, col: 28, offset: 3588},
											alternatives: []interface{}{
												&litMatcher{
													pos:        position{line: 109, col: 28, offset: 3588},
													val:        "]",
													ignoreCase: false,
												},
												&ruleRefExpr{
													pos:  position{line: 109, col: 34, offset: 3594},
													name: "EOL",
												},
												&ruleRefExpr{
													pos:  position{line: 109, col: 40, offset: 3600},
													name: "EOF",
												},
											},
										},
									},
								},
							},
						},
					},
				},
			},
		},
		{
			name: "SingleCharUnicodeClass",
			pos:  position{line: 114, col: 1, offset: 3680},
			expr: &charClassMatcher{
				pos:        position{line: 114, col: 26, offset: 3705},
				val:        "[LMNCPZS]",
				chars:      []rune{'L', 'M', 'N', 'C', 'P', 'Z', 'S'},
				ignoreCase: false,
				inverted:   false,
			},
		},
		{
			name: "Number",
			pos:  position{line: 117, col: 1, offset: 3717},
			expr: &actionExpr{
				pos: position{line: 117, col: 10, offset: 3726},
				run: (*parser).callonNumber1,
				expr: &seqExpr{
					pos: position{line: 117, col: 10, offset: 3726},
					exprs: []interface{}{
						&zeroOrOneExpr{
							pos: position{line: 117, col: 10, offset: 3726},
							expr: &litMatcher{
								pos:        position{line: 117, col: 10, offset: 3726},
								val:        "-",
								ignoreCase: false,
							},
						},
						&ruleRefExpr{
							pos:  position{line: 117, col: 15, offset: 3731},
							name: "Integer",
						},
						&zeroOrOneExpr{
							pos: position{line: 117, col: 23, offset: 3739},
							expr: &seqExpr{
								pos: position{line: 117, col: 25, offset: 3741},
								exprs: []interface{}{
									&litMatcher{
										pos:        position{line: 117, col: 25, offset: 3741},
										val:        ".",
										ignoreCase: false,
									},
									&oneOrMoreExpr{
										pos: position{line: 117, col: 29, offset: 3745},
										expr: &ruleRefExpr{
											pos:  position{line: 117, col: 29, offset: 3745},
											name: "Digit",
										},
									},
								},
							},
						},
					},
				},
			},
		},
		{
			name: "Integer",
			pos:  position{line: 121, col: 1, offset: 3797},
			expr: &choiceExpr{
				pos: position{line: 121, col: 11, offset: 3807},
				alternatives: []interface{}{
					&litMatcher{
						pos:        position{line: 121, col: 11, offset: 3807},
						val:        "0",
						ignoreCase: false,
					},
					&actionExpr{
						pos: position{line: 121, col: 17, offset: 3813},
						run: (*parser).callonInteger3,
						expr: &seqExpr{
							pos: position{line: 121, col: 17, offset: 3813},
							exprs: []interface{}{
								&ruleRefExpr{
									pos:  position{line: 121, col: 17, offset: 3813},
									name: "NonZeroDigit",
								},
								&zeroOrMoreExpr{
									pos: position{line: 121, col: 30, offset: 3826},
									expr: &ruleRefExpr{
										pos:  position{line: 121, col: 30, offset: 3826},
										name: "Digit",
									},
								},
							},
						},
					},
				},
			},
		},
		{
			name: "NonZeroDigit",
			pos:  position{line: 125, col: 1, offset: 3890},
			expr: &charClassMatcher{
				pos:        position{line: 125, col: 16, offset: 3905},
				val:        "[1-9]",
				ranges:     []rune{'1', '9'},
				ignoreCase: false,
				inverted:   false,
			},
		},
		{
			name: "Digit",
			pos:  position{line: 126, col: 1, offset: 3911},
			expr: &charClassMatcher{
				pos:        position{line: 126, col: 9, offset: 3919},
				val:        "[0-9]",
				ranges:     []rune{'0', '9'},
				ignoreCase: false,
				inverted:   false,
			},
		},
		{
			name: "LabelBlock",
			pos:  position{line: 128, col: 1, offset: 3926},
			expr: &choiceExpr{
				pos: position{line: 128, col: 14, offset: 3939},
				alternatives: []interface{}{
					&actionExpr{
						pos: position{line: 128, col: 14, offset: 3939},
						run: (*parser).callonLabelBlock2,
						expr: &seqExpr{
							pos: position{line: 128, col: 14, offset: 3939},
							exprs: []interface{}{
								&litMatcher{
									pos:        position{line: 128, col: 14, offset: 3939},
									val:        "{",
									ignoreCase: false,
								},
								&labeledExpr{
									pos:   position{line: 128, col: 18, offset: 3943},
									label: "block",
									expr: &ruleRefExpr{
										pos:  position{line: 128, col: 24, offset: 3949},
										name: "LabelMatches",
									},
								},
								&litMatcher{
									pos:        position{line: 128, col: 37, offset: 3962},
									val:        "}",
									ignoreCase: false,
								},
							},
						},
					},
					&actionExpr{
						pos: position{line: 130, col: 5, offset: 3994},
						run: (*parser).callonLabelBlock8,
						expr: &seqExpr{
							pos: position{line: 130, col: 5, offset: 3994},
							exprs: []interface{}{
								&litMatcher{
									pos:        position{line: 130, col: 5, offset: 3994},
									val:        "{",
									ignoreCase: false,
								},
								&ruleRefExpr{
									pos:  position{line: 130, col: 9, offset: 3998},
									name: "LabelMatches",
								},
								&ruleRefExpr{
									pos:  position{line: 130, col: 22, offset: 4011},
									name: "EOF",
								},
							},
						},
					},
				},
			},
		},
		{
			name: "NanoSecondUnits",
			pos:  position{line: 134, col: 1, offset: 4076},
			expr: &actionExpr{
				pos: position{line: 134, col: 19, offset: 4094},
				run: (*parser).callonNanoSecondUnits1,
				expr: &litMatcher{
					pos:        position{line: 134, col: 19, offset: 4094},
					val:        "ns",
					ignoreCase: false,
				},
			},
		},
		{
			name: "MicroSecondUnits",
			pos:  position{line: 139, col: 1, offset: 4199},
			expr: &actionExpr{
				pos: position{line: 139, col: 20, offset: 4218},
				run: (*parser).callonMicroSecondUnits1,
				expr: &choiceExpr{
					pos: position{line: 139, col: 21, offset: 4219},
					alternatives: []interface{}{
						&litMatcher{
							pos:        position{line: 139, col: 21, offset: 4219},
							val:        "us",
							ignoreCase: false,
						},
						&litMatcher{
							pos:        position{line: 139, col: 28, offset: 4226},
							val:        "µs",
							ignoreCase: false,
						},
						&litMatcher{
							pos:        position{line: 139, col: 35, offset: 4234},
							val:        "μs",
							ignoreCase: false,
						},
					},
				},
			},
		},
		{
			name: "MilliSecondUnits",
			pos:  position{line: 144, col: 1, offset: 4343},
			expr: &actionExpr{
				pos: position{line: 144, col: 20, offset: 4362},
				run: (*parser).callonMilliSecondUnits1,
				expr: &litMatcher{
					pos:        position{line: 144, col: 20, offset: 4362},
					val:        "ms",
					ignoreCase: false,
				},
			},
		},
		{
			name: "SecondUnits",
			pos:  position{line: 149, col: 1, offset: 4469},
			expr: &actionExpr{
				pos: position{line: 149, col: 15, offset: 4483},
				run: (*parser).callonSecondUnits1,
				expr: &litMatcher{
					pos:        position{line: 149, col: 15, offset: 4483},
					val:        "s",
					ignoreCase: false,
				},
			},
		},
		{
			name: "MinuteUnits",
			pos:  position{line: 153, col: 1, offset: 4520},
			expr: &actionExpr{
				pos: position{line: 153, col: 15, offset: 4534},
				run: (*parser).callonMinuteUnits1,
				expr: &litMatcher{
					pos:        position{line: 153, col: 15, offset: 4534},
					val:        "m",
					ignoreCase: false,
				},
			},
		},
		{
			name: "HourUnits",
			pos:  position{line: 157, col: 1, offset: 4571},
			expr: &actionExpr{
				pos: position{line: 157, col: 13, offset: 4583},
				run: (*parser).callonHourUnits1,
				expr: &litMatcher{
					pos:        position{line: 157, col: 13, offset: 4583},
					val:        "h",
					ignoreCase: false,
				},
			},
		},
		{
			name: "DayUnits",
			pos:  position{line: 161, col: 1, offset: 4618},
			expr: &actionExpr{
				pos: position{line: 161, col: 12, offset: 4629},
				run: (*parser).callonDayUnits1,
				expr: &litMatcher{
					pos:        position{line: 161, col: 12, offset: 4629},
					val:        "d",
					ignoreCase: false,
				},
			},
		},
		{
			name: "WeekUnits",
			pos:  position{line: 167, col: 1, offset: 4837},
			expr: &actionExpr{
				pos: position{line: 167, col: 13, offset: 4849},
				run: (*parser).callonWeekUnits1,
				expr: &litMatcher{
					pos:        position{line: 167, col: 13, offset: 4849},
					val:        "w",
					ignoreCase: false,
				},
			},
		},
		{
			name: "YearUnits",
			pos:  position{line: 173, col: 1, offset: 5060},
			expr: &actionExpr{
				pos: position{line: 173, col: 13, offset: 5072},
				run: (*parser).callonYearUnits1,
				expr: &litMatcher{
					pos:        position{line: 173, col: 13, offset: 5072},
					val:        "y",
					ignoreCase: false,
				},
			},
		},
		{
			name: "DurationUnits",
			pos:  position{line: 179, col: 1, offset: 5269},
			expr: &choiceExpr{
				pos: position{line: 179, col: 18, offset: 5286},
				alternatives: []interface{}{
					&ruleRefExpr{
						pos:  position{line: 179, col: 18, offset: 5286},
						name: "NanoSecondUnits",
					},
					&ruleRefExpr{
						pos:  position{line: 179, col: 36, offset: 5304},
						name: "MicroSecondUnits",
					},
					&ruleRefExpr{
						pos:  position{line: 179, col: 55, offset: 5323},
						name: "MilliSecondUnits",
					},
					&ruleRefExpr{
						pos:  position{line: 179, col: 74, offset: 5342},
						name: "SecondUnits",
					},
					&ruleRefExpr{
						pos:  position{line: 179, col: 88, offset: 5356},
						name: "MinuteUnits",
					},
					&ruleRefExpr{
						pos:  position{line: 179, col: 102, offset: 5370},
						name: "HourUnits",
					},
					&ruleRefExpr{
						pos:  position{line: 179, col: 114, offset: 5382},
						name: "DayUnits",
					},
					&ruleRefExpr{
						pos:  position{line: 179, col: 125, offset: 5393},
						name: "WeekUnits",
					},
					&ruleRefExpr{
						pos:  position{line: 179, col: 137, offset: 5405},
						name: "YearUnits",
					},
				},
			},
		},
		{
			name: "Duration",
			pos:  position{line: 181, col: 1, offset: 5417},
			expr: &actionExpr{
				pos: position{line: 181, col: 12, offset: 5428},
				run: (*parser).callonDuration1,
				expr: &seqExpr{
					pos: position{line: 181, col: 12, offset: 5428},
					exprs: []interface{}{
						&labeledExpr{
							pos:   position{line: 181, col: 12, offset: 5428},
							label: "dur",
							expr: &ruleRefExpr{
								pos:  position{line: 181, col: 16, offset: 5432},
								name: "Integer",
							},
						},
						&labeledExpr{
							pos:   position{line: 181, col: 24, offset: 5440},
							label: "units",
							expr: &ruleRefExpr{
								pos:  position{line: 181, col: 30, offset: 5446},
								name: "DurationUnits",
							},
						},
					},
				},
			},
		},
		{
			name: "Operators",
			pos:  position{line: 187, col: 1, offset: 5595},
			expr: &choiceExpr{
				pos: position{line: 187, col: 13, offset: 5607},
				alternatives: []interface{}{
					&litMatcher{
						pos:        position{line: 187, col: 13, offset: 5607},
						val:        "-",
						ignoreCase: false,
					},
					&litMatcher{
						pos:        position{line: 187, col: 19, offset: 5613},
						val:        "+",
						ignoreCase: false,
					},
					&litMatcher{
						pos:        position{line: 187, col: 25, offset: 5619},
						val:        "*",
						ignoreCase: false,
					},
					&litMatcher{
						pos:        position{line: 187, col: 31, offset: 5625},
						val:        "%",
						ignoreCase: false,
					},
					&litMatcher{
						pos:        position{line: 187, col: 37, offset: 5631},
						val:        "/",
						ignoreCase: false,
					},
					&litMatcher{
						pos:        position{line: 187, col: 43, offset: 5637},
						val:        "==",
						ignoreCase: false,
					},
					&litMatcher{
						pos:        position{line: 187, col: 50, offset: 5644},
						val:        "!=",
						ignoreCase: false,
					},
					&litMatcher{
						pos:        position{line: 187, col: 57, offset: 5651},
						val:        "<=",
						ignoreCase: false,
					},
					&litMatcher{
						pos:        position{line: 187, col: 64, offset: 5658},
						val:        "<",
						ignoreCase: false,
					},
					&litMatcher{
						pos:        position{line: 187, col: 70, offset: 5664},
						val:        ">=",
						ignoreCase: false,
					},
					&litMatcher{
						pos:        position{line: 187, col: 77, offset: 5671},
						val:        ">",
						ignoreCase: false,
					},
					&litMatcher{
						pos:        position{line: 187, col: 83, offset: 5677},
						val:        "=~",
						ignoreCase: false,
					},
					&litMatcher{
						pos:        position{line: 187, col: 90, offset: 5684},
						val:        "!~",
						ignoreCase: false,
					},
					&litMatcher{
						pos:        position{line: 187, col: 97, offset: 5691},
						val:        "^",
						ignoreCase: false,
					},
					&litMatcher{
						pos:        position{line: 187, col: 103, offset: 5697},
						val:        "=",
						ignoreCase: false,
					},
				},
			},
		},
		{
			name: "LabelOperators",
			pos:  position{line: 189, col: 1, offset: 5702},
			expr: &choiceExpr{
				pos: position{line: 189, col: 19, offset: 5720},
				alternatives: []interface{}{
					&actionExpr{
						pos: position{line: 189, col: 19, offset: 5720},
						run: (*parser).callonLabelOperators2,
						expr: &litMatcher{
							pos:        position{line: 189, col: 19, offset: 5720},
							val:        "!=",
							ignoreCase: false,
						},
					},
					&actionExpr{
						pos: position{line: 191, col: 5, offset: 5756},
						run: (*parser).callonLabelOperators4,
						expr: &litMatcher{
							pos:        position{line: 191, col: 5, offset: 5756},
							val:        "=~",
							ignoreCase: false,
						},
					},
					&actionExpr{
						pos: position{line: 193, col: 5, offset: 5794},
						run: (*parser).callonLabelOperators6,
						expr: &litMatcher{
							pos:        position{line: 193, col: 5, offset: 5794},
							val:        "!~",
							ignoreCase: false,
						},
					},
					&actionExpr{
						pos: position{line: 195, col: 5, offset: 5834},
						run: (*parser).callonLabelOperators8,
						expr: &litMatcher{
							pos:        position{line: 195, col: 5, offset: 5834},
							val:        "=",
							ignoreCase: false,
						},
					},
				},
			},
		},
		{
			name: "Label",
			pos:  position{line: 199, col: 1, offset: 5865},
			expr: &ruleRefExpr{
				pos:  position{line: 199, col: 9, offset: 5873},
				name: "Identifier",
			},
		},
		{
			name: "LabelMatch",
			pos:  position{line: 200, col: 1, offset: 5884},
			expr: &actionExpr{
				pos: position{line: 200, col: 14, offset: 5897},
				run: (*parser).callonLabelMatch1,
				expr: &seqExpr{
					pos: position{line: 200, col: 14, offset: 5897},
					exprs: []interface{}{
						&labeledExpr{
							pos:   position{line: 200, col: 14, offset: 5897},
							label: "label",
							expr: &ruleRefExpr{
								pos:  position{line: 200, col: 20, offset: 5903},
								name: "Label",
							},
						},
						&ruleRefExpr{
							pos:  position{line: 200, col: 26, offset: 5909},
							name: "__",
						},
						&labeledExpr{
							pos:   position{line: 200, col: 29, offset: 5912},
							label: "op",
							expr: &ruleRefExpr{
								pos:  position{line: 200, col: 32, offset: 5915},
								name: "LabelOperators",
							},
						},
						&ruleRefExpr{
							pos:  position{line: 200, col: 47, offset: 5930},
							name: "__",
						},
						&labeledExpr{
							pos:   position{line: 200, col: 50, offset: 5933},
							label: "match",
							expr: &choiceExpr{
								pos: position{line: 200, col: 58, offset: 5941},
								alternatives: []interface{}{
									&ruleRefExpr{
										pos:  position{line: 200, col: 58, offset: 5941},
										name: "StringLiteral",
									},
									&ruleRefExpr{
										pos:  position{line: 200, col: 74, offset: 5957},
										name: "Number",
									},
								},
							},
						},
					},
				},
			},
		},
		{
			name: "LabelMatches",
			pos:  position{line: 203, col: 1, offset: 6047},
			expr: &actionExpr{
				pos: position{line: 203, col: 16, offset: 6062},
				run: (*parser).callonLabelMatches1,
				expr: &seqExpr{
					pos: position{line: 203, col: 16, offset: 6062},
					exprs: []interface{}{
						&labeledExpr{
							pos:   position{line: 203, col: 16, offset: 6062},
							label: "first",
							expr: &ruleRefExpr{
								pos:  position{line: 203, col: 22, offset: 6068},
								name: "LabelMatch",
							},
						},
						&ruleRefExpr{
							pos:  position{line: 203, col: 33, offset: 6079},
							name: "__",
						},
						&labeledExpr{
							pos:   position{line: 203, col: 36, offset: 6082},
							label: "rest",
							expr: &zeroOrMoreExpr{
								pos: position{line: 203, col: 41, offset: 6087},
								expr: &ruleRefExpr{
									pos:  position{line: 203, col: 41, offset: 6087},
									name: "LabelMatchesRest",
								},
							},
						},
					},
				},
			},
		},
		{
			name: "LabelMatchesRest",
			pos:  position{line: 207, col: 1, offset: 6166},
			expr: &actionExpr{
				pos: position{line: 207, col: 21, offset: 6186},
				run: (*parser).callonLabelMatchesRest1,
				expr: &seqExpr{
					pos: position{line: 207, col: 21, offset: 6186},
					exprs: []interface{}{
						&litMatcher{
							pos:        position{line: 207, col: 21, offset: 6186},
							val:        ",",
							ignoreCase: false,
						},
						&ruleRefExpr{
							pos:  position{line: 207, col: 25, offset: 6190},
							name: "__",
						},
						&labeledExpr{
							pos:   position{line: 207, col: 28, offset: 6193},
							label: "match",
							expr: &ruleRefExpr{
								pos:  position{line: 207, col: 34, offset: 6199},
								name: "LabelMatch",
							},
						},
					},
				},
			},
		},
		{
			name: "LabelList",
			pos:  position{line: 211, col: 1, offset: 6237},
			expr: &choiceExpr{
				pos: position{line: 211, col: 13, offset: 6249},
				alternatives: []interface{}{
					&actionExpr{
						pos: position{line: 211, col: 13, offset: 6249},
						run: (*parser).callonLabelList2,
						expr: &seqExpr{
							pos: position{line: 211, col: 14, offset: 6250},
							exprs: []interface{}{
								&litMatcher{
									pos:        position{line: 211, col: 14, offset: 6250},
									val:        "(",
									ignoreCase: false,
								},
								&ruleRefExpr{
									pos:  position{line: 211, col: 18, offset: 6254},
									name: "__",
								},
								&litMatcher{
									pos:        position{line: 211, col: 21, offset: 6257},
									val:        ")",
									ignoreCase: false,
								},
							},
						},
					},
					&actionExpr{
						pos: position{line: 213, col: 6, offset: 6289},
						run: (*parser).callonLabelList7,
						expr: &seqExpr{
							pos: position{line: 213, col: 6, offset: 6289},
							exprs: []interface{}{
								&litMatcher{
									pos:        position{line: 213, col: 6, offset: 6289},
									val:        "(",
									ignoreCase: false,
								},
								&ruleRefExpr{
									pos:  position{line: 213, col: 10, offset: 6293},
									name: "__",
								},
								&labeledExpr{
									pos:   position{line: 213, col: 13, offset: 6296},
									label: "label",
									expr: &ruleRefExpr{
										pos:  position{line: 213, col: 19, offset: 6302},
										name: "Label",
									},
								},
								&ruleRefExpr{
									pos:  position{line: 213, col: 25, offset: 6308},
									name: "__",
								},
								&labeledExpr{
									pos:   position{line: 213, col: 28, offset: 6311},
									label: "rest",
									expr: &zeroOrMoreExpr{
										pos: position{line: 213, col: 33, offset: 6316},
										expr: &ruleRefExpr{
											pos:  position{line: 213, col: 33, offset: 6316},
											name: "LabelListRest",
										},
									},
								},
								&ruleRefExpr{
									pos:  position{line: 213, col: 48, offset: 6331},
									name: "__",
								},
								&litMatcher{
									pos:        position{line: 213, col: 51, offset: 6334},
									val:        ")",
									ignoreCase: false,
								},
							},
						},
					},
				},
			},
		},
		{
			name: "LabelListRest",
			pos:  position{line: 217, col: 1, offset: 6400},
			expr: &actionExpr{
				pos: position{line: 217, col: 18, offset: 6417},
				run: (*parser).callonLabelListRest1,
				expr: &seqExpr{
					pos: position{line: 217, col: 18, offset: 6417},
					exprs: []interface{}{
						&litMatcher{
							pos:        position{line: 217, col: 18, offset: 6417},
							val:        ",",
							ignoreCase: false,
						},
						&ruleRefExpr{
							pos:  position{line: 217, col: 22, offset: 6421},
							name: "__",
						},
						&labeledExpr{
							pos:   position{line: 217, col: 25, offset: 6424},
							label: "label",
							expr: &ruleRefExpr{
								pos:  position{line: 217, col: 31, offset: 6430},
								name: "Label",
							},
						},
					},
				},
			},
		},
		{
			name: "VectorSelector",
			pos:  position{line: 221, col: 1, offset: 6463},
			expr: &actionExpr{
				pos: position{line: 221, col: 18, offset: 6480},
				run: (*parser).callonVectorSelector1,
				expr: &seqExpr{
					pos: position{line: 221, col: 18, offset: 6480},
					exprs: []interface{}{
						&labeledExpr{
							pos:   position{line: 221, col: 18, offset: 6480},
							label: "metric",
							expr: &ruleRefExpr{
								pos:  position{line: 221, col: 25, offset: 6487},
								name: "Identifier",
							},
						},
						&ruleRefExpr{
							pos:  position{line: 221, col: 36, offset: 6498},
							name: "__",
						},
						&labeledExpr{
							pos:   position{line: 221, col: 40, offset: 6502},
							label: "block",
							expr: &zeroOrOneExpr{
								pos: position{line: 221, col: 46, offset: 6508},
								expr: &ruleRefExpr{
									pos:  position{line: 221, col: 46, offset: 6508},
									name: "LabelBlock",
								},
							},
						},
						&ruleRefExpr{
							pos:  position{line: 221, col: 58, offset: 6520},
							name: "__",
						},
						&labeledExpr{
							pos:   position{line: 221, col: 61, offset: 6523},
							label: "rng",
							expr: &zeroOrOneExpr{
								pos: position{line: 221, col: 65, offset: 6527},
								expr: &ruleRefExpr{
									pos:  position{line: 221, col: 65, offset: 6527},
									name: "Range",
								},
							},
						},
						&ruleRefExpr{
							pos:  position{line: 221, col: 72, offset: 6534},
							name: "__",
						},
						&labeledExpr{
							pos:   position{line: 221, col: 75, offset: 6537},
							label: "offset",
							expr: &zeroOrOneExpr{
								pos: position{line: 221, col: 82, offset: 6544},
								expr: &ruleRefExpr{
									pos:  position{line: 221, col: 82, offset: 6544},
									name: "Offset",
								},
							},
						},
					},
				},
			},
		},
		{
			name: "Range",
			pos:  position{line: 225, col: 1, offset: 6622},
			expr: &actionExpr{
				pos: position{line: 225, col: 9, offset: 6630},
				run: (*parser).callonRange1,
				expr: &seqExpr{
					pos: position{line: 225, col: 9, offset: 6630},
					exprs: []interface{}{
						&litMatcher{
							pos:        position{line: 225, col: 9, offset: 6630},
							val:        "[",
							ignoreCase: false,
						},
						&ruleRefExpr{
							pos:  position{line: 225, col: 13, offset: 6634},
							name: "__",
						},
						&labeledExpr{
							pos:   position{line: 225, col: 16, offset: 6637},
							label: "dur",
							expr: &ruleRefExpr{
								pos:  position{line: 225, col: 20, offset: 6641},
								name: "Duration",
							},
						},
						&ruleRefExpr{
							pos:  position{line: 225, col: 29, offset: 6650},
							name: "__",
						},
						&litMatcher{
							pos:        position{line: 225, col: 32, offset: 6653},
							val:        "]",
							ignoreCase: false,
						},
					},
				},
			},
		},
		{
			name: "Offset",
			pos:  position{line: 229, col: 1, offset: 6682},
			expr: &actionExpr{
				pos: position{line: 229, col: 10, offset: 6691},
				run: (*parser).callonOffset1,
				expr: &seqExpr{
					pos: position{line: 229, col: 10, offset: 6691},
					exprs: []interface{}{
						&litMatcher{
							pos:        position{line: 229, col: 10, offset: 6691},
							val:        "offset",
							ignoreCase: true,
						},
						&ruleRefExpr{
							pos:  position{line: 229, col: 20, offset: 6701},
							name: "__",
						},
						&labeledExpr{
							pos:   position{line: 229, col: 23, offset: 6704},
							label: "dur",
							expr: &ruleRefExpr{
								pos:  position{line: 229, col: 27, offset: 6708},
								name: "Duration",
							},
						},
					},
				},
			},
		},
		{
			name: "CountValueOperator",
			pos:  position{line: 233, col: 1, offset: 6742},
			expr: &actionExpr{
				pos: position{line: 233, col: 22, offset: 6763},
				run: (*parser).callonCountValueOperator1,
				expr: &litMatcher{
					pos:        position{line: 233, col: 22, offset: 6763},
					val:        "count_values",
					ignoreCase: true,
				},
			},
		},
		{
			name: "BinaryAggregateOperators",
			pos:  position{line: 239, col: 1, offset: 6848},
			expr: &actionExpr{
				pos: position{line: 239, col: 29, offset: 6876},
				run: (*parser).callonBinaryAggregateOperators1,
				expr: &labeledExpr{
					pos:   position{line: 239, col: 29, offset: 6876},
					label: "op",
					expr: &choiceExpr{
						pos: position{line: 239, col: 33, offset: 6880},
						alternatives: []interface{}{
							&litMatcher{
								pos:        position{line: 239, col: 33, offset: 6880},
								val:        "topk",
								ignoreCase: true,
							},
							&litMatcher{
								pos:        position{line: 239, col: 43, offset: 6890},
								val:        "bottomk",
								ignoreCase: true,
							},
							&litMatcher{
								pos:        position{line: 239, col: 56, offset: 6903},
								val:        "quantile",
								ignoreCase: true,
							},
						},
					},
				},
			},
		},
		{
			name: "UnaryAggregateOperators",
			pos:  position{line: 245, col: 1, offset: 7005},
			expr: &actionExpr{
				pos: position{line: 245, col: 27, offset: 7031},
				run: (*parser).callonUnaryAggregateOperators1,
				expr: &labeledExpr{
					pos:   position{line: 245, col: 27, offset: 7031},
					label: "op",
					expr: &choiceExpr{
						pos: position{line: 245, col: 31, offset: 7035},
						alternatives: []interface{}{
							&litMatcher{
								pos:        position{line: 245, col: 31, offset: 7035},
								val:        "sum",
								ignoreCase: true,
							},
							&litMatcher{
								pos:        position{line: 245, col: 40, offset: 7044},
								val:        "min",
								ignoreCase: true,
							},
							&litMatcher{
								pos:        position{line: 245, col: 49, offset: 7053},
								val:        "max",
								ignoreCase: true,
							},
							&litMatcher{
								pos:        position{line: 245, col: 58, offset: 7062},
								val:        "avg",
								ignoreCase: true,
							},
							&litMatcher{
								pos:        position{line: 245, col: 67, offset: 7071},
								val:        "stddev",
								ignoreCase: true,
							},
							&litMatcher{
								pos:        position{line: 245, col: 79, offset: 7083},
								val:        "stdvar",
								ignoreCase: true,
							},
							&litMatcher{
								pos:        position{line: 245, col: 91, offset: 7095},
								val:        "count",
								ignoreCase: true,
							},
						},
					},
				},
			},
		},
		{
			name: "AggregateOperators",
			pos:  position{line: 251, col: 1, offset: 7194},
			expr: &choiceExpr{
				pos: position{line: 251, col: 22, offset: 7215},
				alternatives: []interface{}{
					&ruleRefExpr{
						pos:  position{line: 251, col: 22, offset: 7215},
						name: "CountValueOperator",
					},
					&ruleRefExpr{
						pos:  position{line: 251, col: 43, offset: 7236},
						name: "BinaryAggregateOperators",
					},
					&ruleRefExpr{
						pos:  position{line: 251, col: 70, offset: 7263},
						name: "UnaryAggregateOperators",
					},
				},
			},
		},
		{
			name: "AggregateBy",
			pos:  position{line: 253, col: 1, offset: 7288},
			expr: &actionExpr{
				pos: position{line: 253, col: 15, offset: 7302},
				run: (*parser).callonAggregateBy1,
				expr: &seqExpr{
					pos: position{line: 253, col: 15, offset: 7302},
					exprs: []interface{}{
						&litMatcher{
							pos:        position{line: 253, col: 15, offset: 7302},
							val:        "by",
							ignoreCase: true,
						},
						&ruleRefExpr{
							pos:  position{line: 253, col: 21, offset: 7308},
							name: "__",
						},
						&labeledExpr{
							pos:   position{line: 253, col: 24, offset: 7311},
							label: "labels",
							expr: &ruleRefExpr{
								pos:  position{line: 253, col: 31, offset: 7318},
								name: "LabelList",
							},
						},
						&ruleRefExpr{
							pos:  position{line: 253, col: 41, offset: 7328},
							name: "__",
						},
						&labeledExpr{
							pos:   position{line: 253, col: 44, offset: 7331},
							label: "keep",
							expr: &zeroOrOneExpr{
								pos: position{line: 253, col: 49, offset: 7336},
								expr: &litMatcher{
									pos:        position{line: 253, col: 49, offset: 7336},
									val:        "keep_common",
									ignoreCase: true,
								},
							},
						},
					},
				},
			},
		},
		{
			name: "AggregateWithout",
			pos:  position{line: 260, col: 1, offset: 7449},
			expr: &actionExpr{
				pos: position{line: 260, col: 20, offset: 7468},
				run: (*parser).callonAggregateWithout1,
				expr: &seqExpr{
					pos: position{line: 260, col: 20, offset: 7468},
					exprs: []interface{}{
						&litMatcher{
							pos:        position{line: 260, col: 20, offset: 7468},
							val:        "without",
							ignoreCase: true,
						},
						&ruleRefExpr{
							pos:  position{line: 260, col: 31, offset: 7479},
							name: "__",
						},
						&labeledExpr{
							pos:   position{line: 260, col: 34, offset: 7482},
							label: "labels",
							expr: &ruleRefExpr{
								pos:  position{line: 260, col: 41, offset: 7489},
								name: "LabelList",
							},
						},
					},
				},
			},
		},
		{
			name: "AggregateGroup",
			pos:  position{line: 267, col: 1, offset: 7601},
			expr: &choiceExpr{
				pos: position{line: 267, col: 18, offset: 7618},
				alternatives: []interface{}{
					&ruleRefExpr{
						pos:  position{line: 267, col: 18, offset: 7618},
						name: "AggregateBy",
					},
					&ruleRefExpr{
						pos:  position{line: 267, col: 32, offset: 7632},
						name: "AggregateWithout",
					},
				},
			},
		},
		{
			name: "AggregateExpression",
			pos:  position{line: 269, col: 1, offset: 7650},
			expr: &choiceExpr{
				pos: position{line: 270, col: 1, offset: 7672},
				alternatives: []interface{}{
					&actionExpr{
						pos: position{line: 270, col: 1, offset: 7672},
						run: (*parser).callonAggregateExpression2,
						expr: &seqExpr{
							pos: position{line: 270, col: 1, offset: 7672},
							exprs: []interface{}{
								&labeledExpr{
									pos:   position{line: 270, col: 1, offset: 7672},
									label: "op",
									expr: &ruleRefExpr{
										pos:  position{line: 270, col: 4, offset: 7675},
										name: "CountValueOperator",
									},
								},
								&ruleRefExpr{
									pos:  position{line: 270, col: 24, offset: 7695},
									name: "__",
								},
								&litMatcher{
									pos:        position{line: 270, col: 27, offset: 7698},
									val:        "(",
									ignoreCase: false,
								},
								&ruleRefExpr{
									pos:  position{line: 270, col: 31, offset: 7702},
									name: "__",
								},
								&labeledExpr{
									pos:   position{line: 270, col: 34, offset: 7705},
									label: "param",
									expr: &ruleRefExpr{
										pos:  position{line: 270, col: 40, offset: 7711},
										name: "StringLiteral",
									},
								},
								&ruleRefExpr{
									pos:  position{line: 270, col: 54, offset: 7725},
									name: "__",
								},
								&litMatcher{
									pos:        position{line: 270, col: 57, offset: 7728},
									val:        ",",
									ignoreCase: false,
								},
								&ruleRefExpr{
									pos:  position{line: 270, col: 61, offset: 7732},
									name: "__",
								},
								&labeledExpr{
									pos:   position{line: 270, col: 64, offset: 7735},
									label: "vector",
									expr: &ruleRefExpr{
										pos:  position{line: 270, col: 71, offset: 7742},
										name: "VectorSelector",
									},
								},
								&ruleRefExpr{
									pos:  position{line: 270, col: 86, offset: 7757},
									name: "__",
								},
								&litMatcher{
									pos:        position{line: 270, col: 89, offset: 7760},
									val:        ")",
									ignoreCase: false,
								},
								&ruleRefExpr{
									pos:  position{line: 270, col: 93, offset: 7764},
									name: "__",
								},
								&labeledExpr{
									pos:   position{line: 270, col: 96, offset: 7767},
									label: "group",
									expr: &zeroOrOneExpr{
										pos: position{line: 270, col: 102, offset: 7773},
										expr: &ruleRefExpr{
											pos:  position{line: 270, col: 102, offset: 7773},
											name: "AggregateGroup",
										},
									},
								},
							},
						},
					},
					&actionExpr{
						pos: position{line: 276, col: 1, offset: 7921},
						run: (*parser).callonAggregateExpression22,
						expr: &seqExpr{
							pos: position{line: 276, col: 1, offset: 7921},
							exprs: []interface{}{
								&labeledExpr{
									pos:   position{line: 276, col: 1, offset: 7921},
									label: "op",
									expr: &ruleRefExpr{
										pos:  position{line: 276, col: 4, offset: 7924},
										name: "CountValueOperator",
									},
								},
								&ruleRefExpr{
									pos:  position{line: 276, col: 24, offset: 7944},
									name: "__",
								},
								&labeledExpr{
									pos:   position{line: 276, col: 27, offset: 7947},
									label: "group",
									expr: &zeroOrOneExpr{
										pos: position{line: 276, col: 33, offset: 7953},
										expr: &ruleRefExpr{
											pos:  position{line: 276, col: 33, offset: 7953},
											name: "AggregateGroup",
										},
									},
								},
								&ruleRefExpr{
									pos:  position{line: 276, col: 49, offset: 7969},
									name: "__",
								},
								&litMatcher{
									pos:        position{line: 276, col: 52, offset: 7972},
									val:        "(",
									ignoreCase: false,
								},
								&ruleRefExpr{
									pos:  position{line: 276, col: 56, offset: 7976},
									name: "__",
								},
								&labeledExpr{
									pos:   position{line: 276, col: 59, offset: 7979},
									label: "param",
									expr: &ruleRefExpr{
										pos:  position{line: 276, col: 65, offset: 7985},
										name: "StringLiteral",
									},
								},
								&ruleRefExpr{
									pos:  position{line: 276, col: 79, offset: 7999},
									name: "__",
								},
								&litMatcher{
									pos:        position{line: 276, col: 82, offset: 8002},
									val:        ",",
									ignoreCase: false,
								},
								&ruleRefExpr{
									pos:  position{line: 276, col: 86, offset: 8006},
									name: "__",
								},
								&labeledExpr{
									pos:   position{line: 276, col: 89, offset: 8009},
									label: "vector",
									expr: &ruleRefExpr{
										pos:  position{line: 276, col: 96, offset: 8016},
										name: "VectorSelector",
									},
								},
								&ruleRefExpr{
									pos:  position{line: 276, col: 111, offset: 8031},
									name: "__",
								},
								&litMatcher{
									pos:        position{line: 276, col: 114, offset: 8034},
									val:        ")",
									ignoreCase: false,
								},
							},
						},
					},
					&actionExpr{
						pos: position{line: 282, col: 1, offset: 8170},
						run: (*parser).callonAggregateExpression42,
						expr: &seqExpr{
							pos: position{line: 282, col: 1, offset: 8170},
							exprs: []interface{}{
								&labeledExpr{
									pos:   position{line: 282, col: 1, offset: 8170},
									label: "op",
									expr: &ruleRefExpr{
										pos:  position{line: 282, col: 4, offset: 8173},
										name: "BinaryAggregateOperators",
									},
								},
								&ruleRefExpr{
									pos:  position{line: 282, col: 30, offset: 8199},
									name: "__",
								},
								&litMatcher{
									pos:        position{line: 282, col: 33, offset: 8202},
									val:        "(",
									ignoreCase: false,
								},
								&ruleRefExpr{
									pos:  position{line: 282, col: 37, offset: 8206},
									name: "__",
								},
								&labeledExpr{
									pos:   position{line: 282, col: 41, offset: 8210},
									label: "param",
									expr: &ruleRefExpr{
										pos:  position{line: 282, col: 47, offset: 8216},
										name: "Number",
									},
								},
								&ruleRefExpr{
									pos:  position{line: 282, col: 54, offset: 8223},
									name: "__",
								},
								&litMatcher{
									pos:        position{line: 282, col: 57, offset: 8226},
									val:        ",",
									ignoreCase: false,
								},
								&ruleRefExpr{
									pos:  position{line: 282, col: 61, offset: 8230},
									name: "__",
								},
								&labeledExpr{
									pos:   position{line: 282, col: 64, offset: 8233},
									label: "vector",
									expr: &ruleRefExpr{
										pos:  position{line: 282, col: 71, offset: 8240},
										name: "VectorSelector",
									},
								},
								&ruleRefExpr{
									pos:  position{line: 282, col: 86, offset: 8255},
									name: "__",
								},
								&litMatcher{
									pos:        position{line: 282, col: 89, offset: 8258},
									val:        ")",
									ignoreCase: false,
								},
								&ruleRefExpr{
									pos:  position{line: 282, col: 93, offset: 8262},
									name: "__",
								},
								&labeledExpr{
									pos:   position{line: 282, col: 96, offset: 8265},
									label: "group",
									expr: &zeroOrOneExpr{
										pos: position{line: 282, col: 102, offset: 8271},
										expr: &ruleRefExpr{
											pos:  position{line: 282, col: 102, offset: 8271},
											name: "AggregateGroup",
										},
									},
								},
							},
						},
					},
					&actionExpr{
						pos: position{line: 288, col: 1, offset: 8412},
						run: (*parser).callonAggregateExpression62,
						expr: &seqExpr{
							pos: position{line: 288, col: 1, offset: 8412},
							exprs: []interface{}{
								&labeledExpr{
									pos:   position{line: 288, col: 1, offset: 8412},
									label: "op",
									expr: &ruleRefExpr{
										pos:  position{line: 288, col: 4, offset: 8415},
										name: "BinaryAggregateOperators",
									},
								},
								&ruleRefExpr{
									pos:  position{line: 288, col: 30, offset: 8441},
									name: "__",
								},
								&labeledExpr{
									pos:   position{line: 288, col: 33, offset: 8444},
									label: "group",
									expr: &zeroOrOneExpr{
										pos: position{line: 288, col: 39, offset: 8450},
										expr: &ruleRefExpr{
											pos:  position{line: 288, col: 39, offset: 8450},
											name: "AggregateGroup",
										},
									},
								},
								&ruleRefExpr{
									pos:  position{line: 288, col: 55, offset: 8466},
									name: "__",
								},
								&litMatcher{
									pos:        position{line: 288, col: 58, offset: 8469},
									val:        "(",
									ignoreCase: false,
								},
								&ruleRefExpr{
									pos:  position{line: 288, col: 62, offset: 8473},
									name: "__",
								},
								&labeledExpr{
									pos:   position{line: 288, col: 66, offset: 8477},
									label: "param",
									expr: &ruleRefExpr{
										pos:  position{line: 288, col: 72, offset: 8483},
										name: "Number",
									},
								},
								&ruleRefExpr{
									pos:  position{line: 288, col: 79, offset: 8490},
									name: "__",
								},
								&litMatcher{
									pos:        position{line: 288, col: 82, offset: 8493},
									val:        ",",
									ignoreCase: false,
								},
								&ruleRefExpr{
									pos:  position{line: 288, col: 86, offset: 8497},
									name: "__",
								},
								&labeledExpr{
									pos:   position{line: 288, col: 89, offset: 8500},
									label: "vector",
									expr: &ruleRefExpr{
										pos:  position{line: 288, col: 96, offset: 8507},
										name: "VectorSelector",
									},
								},
								&ruleRefExpr{
									pos:  position{line: 288, col: 111, offset: 8522},
									name: "__",
								},
								&litMatcher{
									pos:        position{line: 288, col: 114, offset: 8525},
									val:        ")",
									ignoreCase: false,
								},
							},
						},
					},
					&actionExpr{
						pos: position{line: 294, col: 1, offset: 8654},
						run: (*parser).callonAggregateExpression82,
						expr: &seqExpr{
							pos: position{line: 294, col: 1, offset: 8654},
							exprs: []interface{}{
								&labeledExpr{
									pos:   position{line: 294, col: 1, offset: 8654},
									label: "op",
									expr: &ruleRefExpr{
										pos:  position{line: 294, col: 4, offset: 8657},
										name: "UnaryAggregateOperators",
									},
								},
								&ruleRefExpr{
									pos:  position{line: 294, col: 29, offset: 8682},
									name: "__",
								},
								&litMatcher{
									pos:        position{line: 294, col: 32, offset: 8685},
									val:        "(",
									ignoreCase: false,
								},
								&ruleRefExpr{
									pos:  position{line: 294, col: 36, offset: 8689},
									name: "__",
								},
								&labeledExpr{
									pos:   position{line: 294, col: 39, offset: 8692},
									label: "vector",
									expr: &ruleRefExpr{
										pos:  position{line: 294, col: 46, offset: 8699},
										name: "VectorSelector",
									},
								},
								&ruleRefExpr{
									pos:  position{line: 294, col: 61, offset: 8714},
									name: "__",
								},
								&litMatcher{
									pos:        position{line: 294, col: 64, offset: 8717},
									val:        ")",
									ignoreCase: false,
								},
								&ruleRefExpr{
									pos:  position{line: 294, col: 68, offset: 8721},
									name: "__",
								},
								&labeledExpr{
									pos:   position{line: 294, col: 71, offset: 8724},
									label: "group",
									expr: &zeroOrOneExpr{
										pos: position{line: 294, col: 77, offset: 8730},
										expr: &ruleRefExpr{
											pos:  position{line: 294, col: 77, offset: 8730},
											name: "AggregateGroup",
										},
									},
								},
							},
						},
					},
					&actionExpr{
						pos: position{line: 298, col: 1, offset: 8823},
						run: (*parser).callonAggregateExpression97,
						expr: &seqExpr{
							pos: position{line: 298, col: 1, offset: 8823},
							exprs: []interface{}{
								&labeledExpr{
									pos:   position{line: 298, col: 1, offset: 8823},
									label: "op",
									expr: &ruleRefExpr{
										pos:  position{line: 298, col: 4, offset: 8826},
										name: "UnaryAggregateOperators",
									},
								},
								&ruleRefExpr{
									pos:  position{line: 298, col: 29, offset: 8851},
									name: "__",
								},
								&labeledExpr{
									pos:   position{line: 298, col: 32, offset: 8854},
									label: "group",
									expr: &zeroOrOneExpr{
										pos: position{line: 298, col: 38, offset: 8860},
										expr: &ruleRefExpr{
											pos:  position{line: 298, col: 38, offset: 8860},
											name: "AggregateGroup",
										},
									},
								},
								&ruleRefExpr{
									pos:  position{line: 298, col: 54, offset: 8876},
									name: "__",
								},
								&litMatcher{
									pos:        position{line: 298, col: 57, offset: 8879},
									val:        "(",
									ignoreCase: false,
								},
								&ruleRefExpr{
									pos:  position{line: 298, col: 61, offset: 8883},
									name: "__",
								},
								&labeledExpr{
									pos:   position{line: 298, col: 64, offset: 8886},
									label: "vector",
									expr: &ruleRefExpr{
										pos:  position{line: 298, col: 71, offset: 8893},
										name: "VectorSelector",
									},
								},
								&ruleRefExpr{
									pos:  position{line: 298, col: 86, offset: 8908},
									name: "__",
								},
								&litMatcher{
									pos:        position{line: 298, col: 89, offset: 8911},
									val:        ")",
									ignoreCase: false,
								},
							},
						},
					},
				},
			},
		},
		{
			name: "__",
			pos:  position{line: 302, col: 1, offset: 8991},
			expr: &zeroOrMoreExpr{
				pos: position{line: 302, col: 6, offset: 8996},
				expr: &choiceExpr{
					pos: position{line: 302, col: 8, offset: 8998},
					alternatives: []interface{}{
						&ruleRefExpr{
							pos:  position{line: 302, col: 8, offset: 8998},
							name: "Whitespace",
						},
						&ruleRefExpr{
							pos:  position{line: 302, col: 21, offset: 9011},
							name: "EOL",
						},
						&ruleRefExpr{
							pos:  position{line: 302, col: 27, offset: 9017},
							name: "Comment",
						},
					},
				},
			},
		},
		{
			name: "_",
			pos:  position{line: 303, col: 1, offset: 9028},
			expr: &zeroOrMoreExpr{
				pos: position{line: 303, col: 5, offset: 9032},
				expr: &ruleRefExpr{
					pos:  position{line: 303, col: 5, offset: 9032},
					name: "Whitespace",
				},
			},
		},
		{
			name: "Whitespace",
			pos:  position{line: 305, col: 1, offset: 9045},
			expr: &charClassMatcher{
				pos:        position{line: 305, col: 14, offset: 9058},
				val:        "[ \\t\\r]",
				chars:      []rune{' ', '\t', '\r'},
				ignoreCase: false,
				inverted:   false,
			},
		},
		{
			name: "EOL",
			pos:  position{line: 306, col: 1, offset: 9066},
			expr: &litMatcher{
				pos:        position{line: 306, col: 7, offset: 9072},
				val:        "\n",
				ignoreCase: false,
			},
		},
		{
			name: "EOS",
			pos:  position{line: 307, col: 1, offset: 9077},
			expr: &choiceExpr{
				pos: position{line: 307, col: 7, offset: 9083},
				alternatives: []interface{}{
					&seqExpr{
						pos: position{line: 307, col: 7, offset: 9083},
						exprs: []interface{}{
							&ruleRefExpr{
								pos:  position{line: 307, col: 7, offset: 9083},
								name: "__",
							},
							&litMatcher{
								pos:        position{line: 307, col: 10, offset: 9086},
								val:        ";",
								ignoreCase: false,
							},
						},
					},
					&seqExpr{
						pos: position{line: 307, col: 16, offset: 9092},
						exprs: []interface{}{
							&ruleRefExpr{
								pos:  position{line: 307, col: 16, offset: 9092},
								name: "_",
							},
							&zeroOrOneExpr{
								pos: position{line: 307, col: 18, offset: 9094},
								expr: &ruleRefExpr{
									pos:  position{line: 307, col: 18, offset: 9094},
									name: "SingleLineComment",
								},
							},
							&ruleRefExpr{
								pos:  position{line: 307, col: 37, offset: 9113},
								name: "EOL",
							},
						},
					},
					&seqExpr{
						pos: position{line: 307, col: 43, offset: 9119},
						exprs: []interface{}{
							&ruleRefExpr{
								pos:  position{line: 307, col: 43, offset: 9119},
								name: "__",
							},
							&ruleRefExpr{
								pos:  position{line: 307, col: 46, offset: 9122},
								name: "EOF",
							},
						},
					},
				},
			},
		},
		{
			name: "EOF",
			pos:  position{line: 309, col: 1, offset: 9127},
			expr: &notExpr{
				pos: position{line: 309, col: 7, offset: 9133},
				expr: &anyMatcher{
					line: 309, col: 8, offset: 9134,
				},
			},
		},
	},
}

func (c *current) onGrammar1(grammar interface{}) (interface{}, error) {
	return grammar, nil
}

func (p *parser) callonGrammar1() (interface{}, error) {
	stack := p.vstack[len(p.vstack)-1]
	_ = stack
	return p.cur.onGrammar1(stack["grammar"])
}

func (c *current) onComment1() (interface{}, error) {
	return &Comment{string(c.text)}, nil
}

func (p *parser) callonComment1() (interface{}, error) {
	stack := p.vstack[len(p.vstack)-1]
	_ = stack
	return p.cur.onComment1()
}

func (c *current) onIdentifier1(ident interface{}) (interface{}, error) {
	i := string(c.text)
	if reservedWords[i] {
		return nil, errors.New("identifier is a reserved word")
	}
	return &Identifier{ident.(string)}, nil
}

func (p *parser) callonIdentifier1() (interface{}, error) {
	stack := p.vstack[len(p.vstack)-1]
	_ = stack
	return p.cur.onIdentifier1(stack["ident"])
}

func (c *current) onIdentifierName1() (interface{}, error) {
	return string(c.text), nil
}

func (p *parser) callonIdentifierName1() (interface{}, error) {
	stack := p.vstack[len(p.vstack)-1]
	_ = stack
	return p.cur.onIdentifierName1()
}

func (c *current) onStringLiteral2() (interface{}, error) {
	str, err := strconv.Unquote(string(c.text))
	if err != nil {
		return nil, err
	}
	return &StringLiteral{str}, nil
}

func (p *parser) callonStringLiteral2() (interface{}, error) {
	stack := p.vstack[len(p.vstack)-1]
	_ = stack
	return p.cur.onStringLiteral2()
}

func (c *current) onStringLiteral18() (interface{}, error) {
	return nil, errors.New("string literal not terminated")
}

func (p *parser) callonStringLiteral18() (interface{}, error) {
	stack := p.vstack[len(p.vstack)-1]
	_ = stack
	return p.cur.onStringLiteral18()
}

func (c *current) onDoubleStringEscape5() (interface{}, error) {
	return nil, errors.New("invalid escape character")
}

func (p *parser) callonDoubleStringEscape5() (interface{}, error) {
	stack := p.vstack[len(p.vstack)-1]
	_ = stack
	return p.cur.onDoubleStringEscape5()
}

func (c *current) onSingleStringEscape5() (interface{}, error) {
	return nil, errors.New("invalid escape character")
}

func (p *parser) callonSingleStringEscape5() (interface{}, error) {
	stack := p.vstack[len(p.vstack)-1]
	_ = stack
	return p.cur.onSingleStringEscape5()
}

func (c *current) onOctalEscape6() (interface{}, error) {
	return nil, errors.New("invalid octal escape")
}

func (p *parser) callonOctalEscape6() (interface{}, error) {
	stack := p.vstack[len(p.vstack)-1]
	_ = stack
	return p.cur.onOctalEscape6()
}

func (c *current) onHexEscape6() (interface{}, error) {
	return nil, errors.New("invalid hexadecimal escape")
}

func (p *parser) callonHexEscape6() (interface{}, error) {
	stack := p.vstack[len(p.vstack)-1]
	_ = stack
	return p.cur.onHexEscape6()
}

func (c *current) onLongUnicodeEscape2() (interface{}, error) {
	return validateUnicodeEscape(string(c.text), "invalid Unicode escape")

}

func (p *parser) callonLongUnicodeEscape2() (interface{}, error) {
	stack := p.vstack[len(p.vstack)-1]
	_ = stack
	return p.cur.onLongUnicodeEscape2()
}

func (c *current) onLongUnicodeEscape13() (interface{}, error) {
	return nil, errors.New("invalid Unicode escape")
}

func (p *parser) callonLongUnicodeEscape13() (interface{}, error) {
	stack := p.vstack[len(p.vstack)-1]
	_ = stack
	return p.cur.onLongUnicodeEscape13()
}

func (c *current) onShortUnicodeEscape2() (interface{}, error) {
	return validateUnicodeEscape(string(c.text), "invalid Unicode escape")

}

func (p *parser) callonShortUnicodeEscape2() (interface{}, error) {
	stack := p.vstack[len(p.vstack)-1]
	_ = stack
	return p.cur.onShortUnicodeEscape2()
}

func (c *current) onShortUnicodeEscape9() (interface{}, error) {
	return nil, errors.New("invalid Unicode escape")
}

func (p *parser) callonShortUnicodeEscape9() (interface{}, error) {
	stack := p.vstack[len(p.vstack)-1]
	_ = stack
	return p.cur.onShortUnicodeEscape9()
}

func (c *current) onCharClassMatcher2() (interface{}, error) {
	return string(c.text), nil
}

func (p *parser) callonCharClassMatcher2() (interface{}, error) {
	stack := p.vstack[len(p.vstack)-1]
	_ = stack
	return p.cur.onCharClassMatcher2()
}

func (c *current) onCharClassMatcher15() (interface{}, error) {
	return nil, errors.New("character class not terminated")
}

func (p *parser) callonCharClassMatcher15() (interface{}, error) {
	stack := p.vstack[len(p.vstack)-1]
	_ = stack
	return p.cur.onCharClassMatcher15()
}

func (c *current) onCharClassEscape5() (interface{}, error) {
	return nil, errors.New("invalid escape character")
}

func (p *parser) callonCharClassEscape5() (interface{}, error) {
	stack := p.vstack[len(p.vstack)-1]
	_ = stack
	return p.cur.onCharClassEscape5()
}

func (c *current) onUnicodeClassEscape5() (interface{}, error) {
	return nil, errors.New("invalid Unicode class escape")
}

func (p *parser) callonUnicodeClassEscape5() (interface{}, error) {
	stack := p.vstack[len(p.vstack)-1]
	_ = stack
	return p.cur.onUnicodeClassEscape5()
}

func (c *current) onUnicodeClassEscape13(ident interface{}) (interface{}, error) {
	if !unicodeClasses[ident.(string)] {
		return nil, errors.New("invalid Unicode class escape")
	}
	return nil, nil

}

func (p *parser) callonUnicodeClassEscape13() (interface{}, error) {
	stack := p.vstack[len(p.vstack)-1]
	_ = stack
	return p.cur.onUnicodeClassEscape13(stack["ident"])
}

func (c *current) onUnicodeClassEscape19() (interface{}, error) {
	return nil, errors.New("Unicode class not terminated")

}

func (p *parser) callonUnicodeClassEscape19() (interface{}, error) {
	stack := p.vstack[len(p.vstack)-1]
	_ = stack
	return p.cur.onUnicodeClassEscape19()
}

func (c *current) onNumber1() (interface{}, error) {
	return NewNumber(string(c.text))
}

func (p *parser) callonNumber1() (interface{}, error) {
	stack := p.vstack[len(p.vstack)-1]
	_ = stack
	return p.cur.onNumber1()
}

func (c *current) onInteger3() (interface{}, error) {
	return strconv.ParseInt(string(c.text), 10, 64)
}

func (p *parser) callonInteger3() (interface{}, error) {
	stack := p.vstack[len(p.vstack)-1]
	_ = stack
	return p.cur.onInteger3()
}

func (c *current) onLabelBlock2(block interface{}) (interface{}, error) {
	return block, nil
}

func (p *parser) callonLabelBlock2() (interface{}, error) {
	stack := p.vstack[len(p.vstack)-1]
	_ = stack
	return p.cur.onLabelBlock2(stack["block"])
}

func (c *current) onLabelBlock8() (interface{}, error) {
	return nil, errors.New("code block not terminated")
}

func (p *parser) callonLabelBlock8() (interface{}, error) {
	stack := p.vstack[len(p.vstack)-1]
	_ = stack
	return p.cur.onLabelBlock8()
}

func (c *current) onNanoSecondUnits1() (interface{}, error) {
	// Prometheus doesn't support nanoseconds, but, influx does
	return time.Nanosecond, nil
}

func (p *parser) callonNanoSecondUnits1() (interface{}, error) {
	stack := p.vstack[len(p.vstack)-1]
	_ = stack
	return p.cur.onNanoSecondUnits1()
}

func (c *current) onMicroSecondUnits1() (interface{}, error) {
	// Prometheus doesn't support nanoseconds, but, influx does
	return time.Microsecond, nil
}

func (p *parser) callonMicroSecondUnits1() (interface{}, error) {
	stack := p.vstack[len(p.vstack)-1]
	_ = stack
	return p.cur.onMicroSecondUnits1()
}

func (c *current) onMilliSecondUnits1() (interface{}, error) {
	// Prometheus doesn't support nanoseconds, but, influx does
	return time.Millisecond, nil
}

func (p *parser) callonMilliSecondUnits1() (interface{}, error) {
	stack := p.vstack[len(p.vstack)-1]
	_ = stack
	return p.cur.onMilliSecondUnits1()
}

func (c *current) onSecondUnits1() (interface{}, error) {
	return time.Second, nil
}

func (p *parser) callonSecondUnits1() (interface{}, error) {
	stack := p.vstack[len(p.vstack)-1]
	_ = stack
	return p.cur.onSecondUnits1()
}

func (c *current) onMinuteUnits1() (interface{}, error) {
	return time.Minute, nil
}

func (p *parser) callonMinuteUnits1() (interface{}, error) {
	stack := p.vstack[len(p.vstack)-1]
	_ = stack
	return p.cur.onMinuteUnits1()
}

func (c *current) onHourUnits1() (interface{}, error) {
	return time.Hour, nil
}

func (p *parser) callonHourUnits1() (interface{}, error) {
	stack := p.vstack[len(p.vstack)-1]
	_ = stack
	return p.cur.onHourUnits1()
}

func (c *current) onDayUnits1() (interface{}, error) {
	// Prometheus always assumes exactly 24 hours in a day
	// https://github.com/prometheus/common/blob/61f87aac8082fa8c3c5655c7608d7478d46ac2ad/model/time.go#L180
	return time.Hour * 24, nil
}

func (p *parser) callonDayUnits1() (interface{}, error) {
	stack := p.vstack[len(p.vstack)-1]
	_ = stack
	return p.cur.onDayUnits1()
}

func (c *current) onWeekUnits1() (interface{}, error) {
	// Prometheus always assumes exactly 7 days in a week
	// https://github.com/prometheus/common/blob/61f87aac8082fa8c3c5655c7608d7478d46ac2ad/model/time.go#L180
	return time.Hour * 24 * 7, nil
}

func (p *parser) callonWeekUnits1() (interface{}, error) {
	stack := p.vstack[len(p.vstack)-1]
	_ = stack
	return p.cur.onWeekUnits1()
}

func (c *current) onYearUnits1() (interface{}, error) {
	// Prometheus always assumes 365 days
	// https://github.com/prometheus/common/blob/61f87aac8082fa8c3c5655c7608d7478d46ac2ad/model/time.go#L180
	return time.Hour * 24 * 365, nil
}

func (p *parser) callonYearUnits1() (interface{}, error) {
	stack := p.vstack[len(p.vstack)-1]
	_ = stack
	return p.cur.onYearUnits1()
}

func (c *current) onDuration1(dur, units interface{}) (interface{}, error) {
	nanos := time.Duration(dur.(int64))
	conversion := units.(time.Duration)
	return time.Duration(nanos) * conversion, nil
}

func (p *parser) callonDuration1() (interface{}, error) {
	stack := p.vstack[len(p.vstack)-1]
	_ = stack
	return p.cur.onDuration1(stack["dur"], stack["units"])
}

func (c *current) onLabelOperators2() (interface{}, error) {
	return NotEqual, nil
}

func (p *parser) callonLabelOperators2() (interface{}, error) {
	stack := p.vstack[len(p.vstack)-1]
	_ = stack
	return p.cur.onLabelOperators2()
}

func (c *current) onLabelOperators4() (interface{}, error) {
	return RegexMatch, nil
}

func (p *parser) callonLabelOperators4() (interface{}, error) {
	stack := p.vstack[len(p.vstack)-1]
	_ = stack
	return p.cur.onLabelOperators4()
}

func (c *current) onLabelOperators6() (interface{}, error) {
	return RegexNoMatch, nil
}

func (p *parser) callonLabelOperators6() (interface{}, error) {
	stack := p.vstack[len(p.vstack)-1]
	_ = stack
	return p.cur.onLabelOperators6()
}

func (c *current) onLabelOperators8() (interface{}, error) {
	return Equal, nil
}

func (p *parser) callonLabelOperators8() (interface{}, error) {
	stack := p.vstack[len(p.vstack)-1]
	_ = stack
	return p.cur.onLabelOperators8()
}

func (c *current) onLabelMatch1(label, op, match interface{}) (interface{}, error) {
	return NewLabelMatcher(label.(*Identifier), op.(MatchKind), match.(Arg))
}

func (p *parser) callonLabelMatch1() (interface{}, error) {
	stack := p.vstack[len(p.vstack)-1]
	_ = stack
	return p.cur.onLabelMatch1(stack["label"], stack["op"], stack["match"])
}

func (c *current) onLabelMatches1(first, rest interface{}) (interface{}, error) {
	return NewLabelMatches(first.(*LabelMatcher), rest)
}

func (p *parser) callonLabelMatches1() (interface{}, error) {
	stack := p.vstack[len(p.vstack)-1]
	_ = stack
	return p.cur.onLabelMatches1(stack["first"], stack["rest"])
}

func (c *current) onLabelMatchesRest1(match interface{}) (interface{}, error) {
	return match, nil
}

func (p *parser) callonLabelMatchesRest1() (interface{}, error) {
	stack := p.vstack[len(p.vstack)-1]
	_ = stack
	return p.cur.onLabelMatchesRest1(stack["match"])
}

func (c *current) onLabelList2() (interface{}, error) {
	return nil, nil
}

func (p *parser) callonLabelList2() (interface{}, error) {
	stack := p.vstack[len(p.vstack)-1]
	_ = stack
	return p.cur.onLabelList2()
}

func (c *current) onLabelList7(label, rest interface{}) (interface{}, error) {
	return NewIdentifierList(label.(*Identifier), rest)
}

func (p *parser) callonLabelList7() (interface{}, error) {
	stack := p.vstack[len(p.vstack)-1]
	_ = stack
	return p.cur.onLabelList7(stack["label"], stack["rest"])
}

func (c *current) onLabelListRest1(label interface{}) (interface{}, error) {
	return label, nil
}

func (p *parser) callonLabelListRest1() (interface{}, error) {
	stack := p.vstack[len(p.vstack)-1]
	_ = stack
	return p.cur.onLabelListRest1(stack["label"])
}

func (c *current) onVectorSelector1(metric, block, rng, offset interface{}) (interface{}, error) {
	return NewSelector(metric.(*Identifier), block, rng, offset)
}

func (p *parser) callonVectorSelector1() (interface{}, error) {
	stack := p.vstack[len(p.vstack)-1]
	_ = stack
	return p.cur.onVectorSelector1(stack["metric"], stack["block"], stack["rng"], stack["offset"])
}

func (c *current) onRange1(dur interface{}) (interface{}, error) {
	return dur, nil
}

func (p *parser) callonRange1() (interface{}, error) {
	stack := p.vstack[len(p.vstack)-1]
	_ = stack
	return p.cur.onRange1(stack["dur"])
}

func (c *current) onOffset1(dur interface{}) (interface{}, error) {
	return dur, nil
}

func (p *parser) callonOffset1() (interface{}, error) {
	stack := p.vstack[len(p.vstack)-1]
	_ = stack
	return p.cur.onOffset1(stack["dur"])
}

func (c *current) onCountValueOperator1() (interface{}, error) {
	return &Operator{
		Kind: CountValuesKind,
	}, nil
}

func (p *parser) callonCountValueOperator1() (interface{}, error) {
	stack := p.vstack[len(p.vstack)-1]
	_ = stack
	return p.cur.onCountValueOperator1()
}

func (c *current) onBinaryAggregateOperators1(op interface{}) (interface{}, error) {
	return &Operator{
		Kind: ToOperatorKind(string(op.([]byte))),
	}, nil
}

func (p *parser) callonBinaryAggregateOperators1() (interface{}, error) {
	stack := p.vstack[len(p.vstack)-1]
	_ = stack
	return p.cur.onBinaryAggregateOperators1(stack["op"])
}

func (c *current) onUnaryAggregateOperators1(op interface{}) (interface{}, error) {
	return &Operator{
		Kind: ToOperatorKind(string(op.([]byte))),
	}, nil
}

func (p *parser) callonUnaryAggregateOperators1() (interface{}, error) {
	stack := p.vstack[len(p.vstack)-1]
	_ = stack
	return p.cur.onUnaryAggregateOperators1(stack["op"])
}

func (c *current) onAggregateBy1(labels, keep interface{}) (interface{}, error) {
	return &Aggregate{
		By:     true,
		Labels: labels.([]*Identifier),
	}, nil
}

func (p *parser) callonAggregateBy1() (interface{}, error) {
	stack := p.vstack[len(p.vstack)-1]
	_ = stack
	return p.cur.onAggregateBy1(stack["labels"], stack["keep"])
}

func (c *current) onAggregateWithout1(labels interface{}) (interface{}, error) {
	return &Aggregate{
		Without: true,
		Labels:  labels.([]*Identifier),
	}, nil
}

func (p *parser) callonAggregateWithout1() (interface{}, error) {
	stack := p.vstack[len(p.vstack)-1]
	_ = stack
	return p.cur.onAggregateWithout1(stack["labels"])
}

func (c *current) onAggregateExpression2(op, param, vector, group interface{}) (interface{}, error) {
	oper := op.(*Operator)
	oper.Arg = param.(*StringLiteral)
	return NewAggregateExpr(oper, vector.(*Selector), group)
}

func (p *parser) callonAggregateExpression2() (interface{}, error) {
	stack := p.vstack[len(p.vstack)-1]
	_ = stack
	return p.cur.onAggregateExpression2(stack["op"], stack["param"], stack["vector"], stack["group"])
}

func (c *current) onAggregateExpression22(op, group, param, vector interface{}) (interface{}, error) {
	oper := op.(*Operator)
	oper.Arg = param.(*StringLiteral)
	return NewAggregateExpr(oper, vector.(*Selector), group)
}

func (p *parser) callonAggregateExpression22() (interface{}, error) {
	stack := p.vstack[len(p.vstack)-1]
	_ = stack
	return p.cur.onAggregateExpression22(stack["op"], stack["group"], stack["param"], stack["vector"])
}

func (c *current) onAggregateExpression42(op, param, vector, group interface{}) (interface{}, error) {
	oper := op.(*Operator)
	oper.Arg = param.(*Number)
	return NewAggregateExpr(oper, vector.(*Selector), group)
}

func (p *parser) callonAggregateExpression42() (interface{}, error) {
	stack := p.vstack[len(p.vstack)-1]
	_ = stack
	return p.cur.onAggregateExpression42(stack["op"], stack["param"], stack["vector"], stack["group"])
}

func (c *current) onAggregateExpression62(op, group, param, vector interface{}) (interface{}, error) {
	oper := op.(*Operator)
	oper.Arg = param.(*Number)
	return NewAggregateExpr(oper, vector.(*Selector), group)
}

func (p *parser) callonAggregateExpression62() (interface{}, error) {
	stack := p.vstack[len(p.vstack)-1]
	_ = stack
	return p.cur.onAggregateExpression62(stack["op"], stack["group"], stack["param"], stack["vector"])
}

func (c *current) onAggregateExpression82(op, vector, group interface{}) (interface{}, error) {
	return NewAggregateExpr(op.(*Operator), vector.(*Selector), group)
}

func (p *parser) callonAggregateExpression82() (interface{}, error) {
	stack := p.vstack[len(p.vstack)-1]
	_ = stack
	return p.cur.onAggregateExpression82(stack["op"], stack["vector"], stack["group"])
}

func (c *current) onAggregateExpression97(op, group, vector interface{}) (interface{}, error) {
	return NewAggregateExpr(op.(*Operator), vector.(*Selector), group)
}

func (p *parser) callonAggregateExpression97() (interface{}, error) {
	stack := p.vstack[len(p.vstack)-1]
	_ = stack
	return p.cur.onAggregateExpression97(stack["op"], stack["group"], stack["vector"])
}

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 expresssions 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)
	}
}

// Statistics adds a user provided Stats struct to the parser to allow
// the user to process the results after the parsing has finished.
// Also the key for the "no match" counter is set.
//
// Example usage:
//
//     input := "input"
//     stats := Stats{}
//     _, err := Parse("input-file", []byte(input), Statistics(&stats, "no match"))
//     if err != nil {
//         log.Panicln(err)
//     }
//     b, err := json.MarshalIndent(stats.ChoiceAltCnt, "", "  ")
//     if err != nil {
//         log.Panicln(err)
//     }
//     fmt.Println(string(b))
//
func Statistics(stats *Stats, choiceNoMatch string) Option {
	return func(p *parser) Option {
		oldStats := p.Stats
		p.Stats = stats
		oldChoiceNoMatch := p.choiceNoMatch
		p.choiceNoMatch = choiceNoMatch
		if p.Stats.ChoiceAltCnt == nil {
			p.Stats.ChoiceAltCnt = make(map[string]map[string]int)
		}
		return Statistics(oldStats, oldChoiceNoMatch)
	}
}

// Debug creates an Option to set the debug flag to b. When set to true,
// debugging information is printed to stdout while parsing.
//
// The default is false.
func Debug(b bool) Option {
	return func(p *parser) Option {
		old := p.debug
		p.debug = b
		return Debug(old)
	}
}

// Memoize creates an Option to set the memoize flag to b. When set to true,
// the parser will cache all results so each expression is evaluated only
// once. This guarantees linear parsing time even for pathological cases,
// at the expense of more memory and slower times for typical cases.
//
// The default is false.
func Memoize(b bool) Option {
	return func(p *parser) Option {
		old := p.memoize
		p.memoize = b
		return Memoize(old)
	}
}

// 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 interface{}) Option {
	return func(p *parser) Option {
		old := p.cur.globalStore[key]
		p.cur.globalStore[key] = value
		return GlobalStore(key, old)
	}
}

// InitState creates an Option to set a key to a certain value in
// the global "state" store.
func InitState(key string, value interface{}) Option {
	return func(p *parser) Option {
		old := p.cur.state[key]
		p.cur.state[key] = value
		return InitState(key, old)
	}
}

// ParseFile parses the file identified by filename.
func ParseFile(filename string, opts ...Option) (i interface{}, 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) (interface{}, error) {
	b, err := ioutil.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) (interface{}, 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 fmt.Sprintf("%d:%d [%d]", p.line, p.col, 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

	// state is a store for arbitrary key,value pairs that the user wants to be
	// tied to the backtracking of the parser.
	// This is always rolled back if a parsing rule fails.
	state storeDict

	// 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]interface{}

// the AST types...

type grammar struct {
	pos   position
	rules []*rule
}

type rule struct {
	pos         position
	name        string
	displayName string
	expr        interface{}
}

type choiceExpr struct {
	pos          position
	alternatives []interface{}
}

type actionExpr struct {
	pos  position
	expr interface{}
	run  func(*parser) (interface{}, error)
}

type recoveryExpr struct {
	pos          position
	expr         interface{}
	recoverExpr  interface{}
	failureLabel []string
}

type seqExpr struct {
	pos   position
	exprs []interface{}
}

type throwExpr struct {
	pos   position
	label string
}

type labeledExpr struct {
	pos   position
	label string
	expr  interface{}
}

type expr struct {
	pos  position
	expr interface{}
}

type andExpr expr
type notExpr expr
type zeroOrOneExpr expr
type zeroOrMoreExpr expr
type oneOrMoreExpr expr

type ruleRefExpr struct {
	pos  position
	name string
}

type stateCodeExpr struct {
	pos position
	run func(*parser) error
}

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
}

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{
			state:       make(storeDict),
			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,
		emptyState: make(storeDict),
	}
	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   interface{}
	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
	debug   bool

	memoize bool
	// memoization table for the packrat algorithm:
	// map[offset in source] map[expression or rule] {value, match}
	memo map[int]map[interface{}]resultTuple

	// rules table, maps the rule identifier to the rule node
	rules map[string]*rule
	// variables stack, map of label to value
	vstack []map[string]interface{}
	// 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]interface{}

	// emptyState contains an empty storeDict, which is used to optimize cloneState if global "state" store is not used.
	emptyState storeDict
}

// 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]interface{})
	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 interface{}) {
	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]interface{}, 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) print(prefix, s string) string {
	if !p.debug {
		return s
	}

	fmt.Printf("%s %d:%d:%d: %s [%#U]\n",
		prefix, p.pt.line, p.pt.col, p.pt.offset, s, p.pt.rn)
	return s
}

func (p *parser) in(s string) string {
	p.depth++
	return p.print(strings.Repeat(" ", p.depth)+">", s)
}

func (p *parser) out(s string) string {
	p.depth--
	return p.print(strings.Repeat(" ", p.depth)+"<", s)
}

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 p.debug {
		defer p.out(p.in("restore"))
	}
	if pt.offset == p.pt.offset {
		return
	}
	p.pt = pt
}

// Cloner is implemented by any value that has a Clone method, which returns a
// copy of the value. This is mainly used for types which are not passed by
// value (e.g map, slice, chan) or structs that contain such types.
//
// This is used in conjunction with the global state feature to create proper
// copies of the state to allow the parser to properly restore the state in
// the case of backtracking.
type Cloner interface {
	Clone() interface{}
}

// clone and return parser current state.
func (p *parser) cloneState() storeDict {
	if p.debug {
		defer p.out(p.in("cloneState"))
	}

	if len(p.cur.state) == 0 {
		if len(p.emptyState) > 0 {
			p.emptyState = make(storeDict)
		}
		return p.emptyState
	}

	state := make(storeDict, len(p.cur.state))
	for k, v := range p.cur.state {
		if c, ok := v.(Cloner); ok {
			state[k] = c.Clone()
		} else {
			state[k] = v
		}
	}
	return state
}

// restore parser current state to the state storeDict.
// every restoreState should applied only one time for every cloned state
func (p *parser) restoreState(state storeDict) {
	if p.debug {
		defer p.out(p.in("restoreState"))
	}
	p.cur.state = state
}

// 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) getMemoized(node interface{}) (resultTuple, bool) {
	if len(p.memo) == 0 {
		return resultTuple{}, false
	}
	m := p.memo[p.pt.offset]
	if len(m) == 0 {
		return resultTuple{}, false
	}
	res, ok := m[node]
	return res, ok
}

func (p *parser) setMemoized(pt savepoint, node interface{}, tuple resultTuple) {
	if p.memo == nil {
		p.memo = make(map[int]map[interface{}]resultTuple)
	}
	m := p.memo[pt.offset]
	if m == nil {
		m = make(map[interface{}]resultTuple)
		p.memo[pt.offset] = m
	}
	m[node] = tuple
}

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 interface{}, 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 {
				if p.debug {
					defer p.out(p.in("panic handler"))
				}
				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.parseRule(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 fmt.Sprintf("%s %s %s", strings.Join(list[:len(list)-1], sep), lastSep, list[len(list)-1])
	}
}

func (p *parser) parseRule(rule *rule) (interface{}, bool) {
	if p.debug {
		defer p.out(p.in("parseRule " + rule.name))
	}

	if p.memoize {
		res, ok := p.getMemoized(rule)
		if ok {
			p.restore(res.end)
			return res.v, res.b
		}
	}

	start := p.pt
	p.rstack = append(p.rstack, rule)
	p.pushV()
	val, ok := p.parseExpr(rule.expr)
	p.popV()
	p.rstack = p.rstack[:len(p.rstack)-1]
	if ok && p.debug {
		p.print(strings.Repeat(" ", p.depth)+"MATCH", string(p.sliceFrom(start)))
	}

	if p.memoize {
		p.setMemoized(start, rule, resultTuple{val, ok, p.pt})
	}
	return val, ok
}

func (p *parser) parseExpr(expr interface{}) (interface{}, bool) {
	var pt savepoint

	if p.memoize {
		res, ok := p.getMemoized(expr)
		if ok {
			p.restore(res.end)
			return res.v, res.b
		}
		pt = p.pt
	}

	p.ExprCnt++
	if p.ExprCnt > p.maxExprCnt {
		panic(errMaxExprCnt)
	}

	var val interface{}
	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 *stateCodeExpr:
		val, ok = p.parseStateCodeExpr(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))
	}
	if p.memoize {
		p.setMemoized(pt, expr, resultTuple{val, ok, p.pt})
	}
	return val, ok
}

func (p *parser) parseActionExpr(act *actionExpr) (interface{}, bool) {
	if p.debug {
		defer p.out(p.in("parseActionExpr"))
	}

	start := p.pt
	val, ok := p.parseExpr(act.expr)
	if ok {
		p.cur.pos = start.position
		p.cur.text = p.sliceFrom(start)
		state := p.cloneState()
		actVal, err := act.run(p)
		if err != nil {
			p.addErrAt(err, start.position, []string{})
		}
		p.restoreState(state)

		val = actVal
	}
	if ok && p.debug {
		p.print(strings.Repeat(" ", p.depth)+"MATCH", string(p.sliceFrom(start)))
	}
	return val, ok
}

func (p *parser) parseAndCodeExpr(and *andCodeExpr) (interface{}, bool) {
	if p.debug {
		defer p.out(p.in("parseAndCodeExpr"))
	}

	state := p.cloneState()

	ok, err := and.run(p)
	if err != nil {
		p.addErr(err)
	}
	p.restoreState(state)

	return nil, ok
}

func (p *parser) parseAndExpr(and *andExpr) (interface{}, bool) {
	if p.debug {
		defer p.out(p.in("parseAndExpr"))
	}

	pt := p.pt
	state := p.cloneState()
	p.pushV()
	_, ok := p.parseExpr(and.expr)
	p.popV()
	p.restoreState(state)
	p.restore(pt)

	return nil, ok
}

func (p *parser) parseAnyMatcher(any *anyMatcher) (interface{}, bool) {
	if p.debug {
		defer p.out(p.in("parseAnyMatcher"))
	}

	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) (interface{}, bool) {
	if p.debug {
		defer p.out(p.in("parseCharClassMatcher"))
	}

	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) incChoiceAltCnt(ch *choiceExpr, altI int) {
	choiceIdent := fmt.Sprintf("%s %d:%d", p.rstack[len(p.rstack)-1].name, ch.pos.line, ch.pos.col)
	m := p.ChoiceAltCnt[choiceIdent]
	if m == nil {
		m = make(map[string]int)
		p.ChoiceAltCnt[choiceIdent] = m
	}
	// We increment altI by 1, so the keys do not start at 0
	alt := strconv.Itoa(altI + 1)
	if altI == choiceNoMatch {
		alt = p.choiceNoMatch
	}
	m[alt]++
}

func (p *parser) parseChoiceExpr(ch *choiceExpr) (interface{}, bool) {
	if p.debug {
		defer p.out(p.in("parseChoiceExpr"))
	}

	for altI, alt := range ch.alternatives {
		// dummy assignment to prevent compile error if optimized
		_ = altI

		state := p.cloneState()

		p.pushV()
		val, ok := p.parseExpr(alt)
		p.popV()
		if ok {
			p.incChoiceAltCnt(ch, altI)
			return val, ok
		}
		p.restoreState(state)
	}
	p.incChoiceAltCnt(ch, choiceNoMatch)
	return nil, false
}

func (p *parser) parseLabeledExpr(lab *labeledExpr) (interface{}, bool) {
	if p.debug {
		defer p.out(p.in("parseLabeledExpr"))
	}

	p.pushV()
	val, ok := p.parseExpr(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) (interface{}, bool) {
	if p.debug {
		defer p.out(p.in("parseLitMatcher"))
	}

	ignoreCase := ""
	if lit.ignoreCase {
		ignoreCase = "i"
	}
	val := fmt.Sprintf("%q%s", lit.val, ignoreCase)
	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, val)
			p.restore(start)
			return nil, false
		}
		p.read()
	}
	p.failAt(true, start.position, val)
	return p.sliceFrom(start), true
}

func (p *parser) parseNotCodeExpr(not *notCodeExpr) (interface{}, bool) {
	if p.debug {
		defer p.out(p.in("parseNotCodeExpr"))
	}

	state := p.cloneState()

	ok, err := not.run(p)
	if err != nil {
		p.addErr(err)
	}
	p.restoreState(state)

	return nil, !ok
}

func (p *parser) parseNotExpr(not *notExpr) (interface{}, bool) {
	if p.debug {
		defer p.out(p.in("parseNotExpr"))
	}

	pt := p.pt
	state := p.cloneState()
	p.pushV()
	p.maxFailInvertExpected = !p.maxFailInvertExpected
	_, ok := p.parseExpr(not.expr)
	p.maxFailInvertExpected = !p.maxFailInvertExpected
	p.popV()
	p.restoreState(state)
	p.restore(pt)

	return nil, !ok
}

func (p *parser) parseOneOrMoreExpr(expr *oneOrMoreExpr) (interface{}, bool) {
	if p.debug {
		defer p.out(p.in("parseOneOrMoreExpr"))
	}

	var vals []interface{}

	for {
		p.pushV()
		val, ok := p.parseExpr(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) (interface{}, bool) {
	if p.debug {
		defer p.out(p.in("parseRecoveryExpr (" + strings.Join(recover.failureLabel, ",") + ")"))
	}

	p.pushRecovery(recover.failureLabel, recover.recoverExpr)
	val, ok := p.parseExpr(recover.expr)
	p.popRecovery()

	return val, ok
}

func (p *parser) parseRuleRefExpr(ref *ruleRefExpr) (interface{}, bool) {
	if p.debug {
		defer p.out(p.in("parseRuleRefExpr " + ref.name))
	}

	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.parseRule(rule)
}

func (p *parser) parseSeqExpr(seq *seqExpr) (interface{}, bool) {
	if p.debug {
		defer p.out(p.in("parseSeqExpr"))
	}

	vals := make([]interface{}, 0, len(seq.exprs))

	pt := p.pt
	state := p.cloneState()
	for _, expr := range seq.exprs {
		val, ok := p.parseExpr(expr)
		if !ok {
			p.restoreState(state)
			p.restore(pt)
			return nil, false
		}
		vals = append(vals, val)
	}
	return vals, true
}

func (p *parser) parseStateCodeExpr(state *stateCodeExpr) (interface{}, bool) {
	if p.debug {
		defer p.out(p.in("parseStateCodeExpr"))
	}

	err := state.run(p)
	if err != nil {
		p.addErr(err)
	}
	return nil, true
}

func (p *parser) parseThrowExpr(expr *throwExpr) (interface{}, bool) {
	if p.debug {
		defer p.out(p.in("parseThrowExpr"))
	}

	for i := len(p.recoveryStack) - 1; i >= 0; i-- {
		if recoverExpr, ok := p.recoveryStack[i][expr.label]; ok {
			if val, ok := p.parseExpr(recoverExpr); ok {
				return val, ok
			}
		}
	}

	return nil, false
}

func (p *parser) parseZeroOrMoreExpr(expr *zeroOrMoreExpr) (interface{}, bool) {
	if p.debug {
		defer p.out(p.in("parseZeroOrMoreExpr"))
	}

	var vals []interface{}

	for {
		p.pushV()
		val, ok := p.parseExpr(expr.expr)
		p.popV()
		if !ok {
			return vals, true
		}
		vals = append(vals, val)
	}
}

func (p *parser) parseZeroOrOneExpr(expr *zeroOrOneExpr) (interface{}, bool) {
	if p.debug {
		defer p.out(p.in("parseZeroOrOneExpr"))
	}

	p.pushV()
	val, _ := p.parseExpr(expr.expr)
	p.popV()
	// whether it matched or not, consider it a match
	return val, true
}

func rangeTable(class string) *unicode.RangeTable {
	if rt, ok := unicode.Categories[class]; ok {
		return rt
	}
	if rt, ok := unicode.Properties[class]; ok {
		return rt
	}
	if rt, ok := unicode.Scripts[class]; ok {
		return rt
	}

	// cannot happen
	panic(fmt.Sprintf("invalid Unicode class: %s", class))
}