consul/vendor/github.com/hashicorp/go-bexpr/grammar.go

2904 lines
74 KiB
Go

// Code generated by pigeon; DO NOT EDIT.
package bexpr
import (
"bytes"
"errors"
"fmt"
"io"
"io/ioutil"
"math"
"os"
"sort"
"strconv"
"strings"
"unicode"
"unicode/utf8"
)
var g = &grammar{
rules: []*rule{
{
name: "Input",
pos: position{line: 10, col: 1, offset: 57},
expr: &choiceExpr{
pos: position{line: 10, col: 10, offset: 66},
alternatives: []interface{}{
&actionExpr{
pos: position{line: 10, col: 10, offset: 66},
run: (*parser).callonInput2,
expr: &seqExpr{
pos: position{line: 10, col: 10, offset: 66},
exprs: []interface{}{
&zeroOrOneExpr{
pos: position{line: 10, col: 10, offset: 66},
expr: &ruleRefExpr{
pos: position{line: 10, col: 10, offset: 66},
name: "_",
},
},
&litMatcher{
pos: position{line: 10, col: 13, offset: 69},
val: "(",
ignoreCase: false,
},
&zeroOrOneExpr{
pos: position{line: 10, col: 17, offset: 73},
expr: &ruleRefExpr{
pos: position{line: 10, col: 17, offset: 73},
name: "_",
},
},
&labeledExpr{
pos: position{line: 10, col: 20, offset: 76},
label: "expr",
expr: &ruleRefExpr{
pos: position{line: 10, col: 25, offset: 81},
name: "OrExpression",
},
},
&zeroOrOneExpr{
pos: position{line: 10, col: 38, offset: 94},
expr: &ruleRefExpr{
pos: position{line: 10, col: 38, offset: 94},
name: "_",
},
},
&litMatcher{
pos: position{line: 10, col: 41, offset: 97},
val: ")",
ignoreCase: false,
},
&zeroOrOneExpr{
pos: position{line: 10, col: 45, offset: 101},
expr: &ruleRefExpr{
pos: position{line: 10, col: 45, offset: 101},
name: "_",
},
},
&ruleRefExpr{
pos: position{line: 10, col: 48, offset: 104},
name: "EOF",
},
},
},
},
&actionExpr{
pos: position{line: 12, col: 5, offset: 134},
run: (*parser).callonInput17,
expr: &seqExpr{
pos: position{line: 12, col: 5, offset: 134},
exprs: []interface{}{
&zeroOrOneExpr{
pos: position{line: 12, col: 5, offset: 134},
expr: &ruleRefExpr{
pos: position{line: 12, col: 5, offset: 134},
name: "_",
},
},
&labeledExpr{
pos: position{line: 12, col: 8, offset: 137},
label: "expr",
expr: &ruleRefExpr{
pos: position{line: 12, col: 13, offset: 142},
name: "OrExpression",
},
},
&zeroOrOneExpr{
pos: position{line: 12, col: 26, offset: 155},
expr: &ruleRefExpr{
pos: position{line: 12, col: 26, offset: 155},
name: "_",
},
},
&ruleRefExpr{
pos: position{line: 12, col: 29, offset: 158},
name: "EOF",
},
},
},
},
},
},
},
{
name: "OrExpression",
pos: position{line: 16, col: 1, offset: 187},
expr: &choiceExpr{
pos: position{line: 16, col: 17, offset: 203},
alternatives: []interface{}{
&actionExpr{
pos: position{line: 16, col: 17, offset: 203},
run: (*parser).callonOrExpression2,
expr: &seqExpr{
pos: position{line: 16, col: 17, offset: 203},
exprs: []interface{}{
&labeledExpr{
pos: position{line: 16, col: 17, offset: 203},
label: "left",
expr: &ruleRefExpr{
pos: position{line: 16, col: 22, offset: 208},
name: "AndExpression",
},
},
&ruleRefExpr{
pos: position{line: 16, col: 36, offset: 222},
name: "_",
},
&litMatcher{
pos: position{line: 16, col: 38, offset: 224},
val: "or",
ignoreCase: false,
},
&ruleRefExpr{
pos: position{line: 16, col: 43, offset: 229},
name: "_",
},
&labeledExpr{
pos: position{line: 16, col: 45, offset: 231},
label: "right",
expr: &ruleRefExpr{
pos: position{line: 16, col: 51, offset: 237},
name: "OrExpression",
},
},
},
},
},
&actionExpr{
pos: position{line: 22, col: 5, offset: 387},
run: (*parser).callonOrExpression11,
expr: &labeledExpr{
pos: position{line: 22, col: 5, offset: 387},
label: "expr",
expr: &ruleRefExpr{
pos: position{line: 22, col: 10, offset: 392},
name: "AndExpression",
},
},
},
},
},
},
{
name: "AndExpression",
pos: position{line: 26, col: 1, offset: 431},
expr: &choiceExpr{
pos: position{line: 26, col: 18, offset: 448},
alternatives: []interface{}{
&actionExpr{
pos: position{line: 26, col: 18, offset: 448},
run: (*parser).callonAndExpression2,
expr: &seqExpr{
pos: position{line: 26, col: 18, offset: 448},
exprs: []interface{}{
&labeledExpr{
pos: position{line: 26, col: 18, offset: 448},
label: "left",
expr: &ruleRefExpr{
pos: position{line: 26, col: 23, offset: 453},
name: "NotExpression",
},
},
&ruleRefExpr{
pos: position{line: 26, col: 37, offset: 467},
name: "_",
},
&litMatcher{
pos: position{line: 26, col: 39, offset: 469},
val: "and",
ignoreCase: false,
},
&ruleRefExpr{
pos: position{line: 26, col: 45, offset: 475},
name: "_",
},
&labeledExpr{
pos: position{line: 26, col: 47, offset: 477},
label: "right",
expr: &ruleRefExpr{
pos: position{line: 26, col: 53, offset: 483},
name: "AndExpression",
},
},
},
},
},
&actionExpr{
pos: position{line: 32, col: 5, offset: 635},
run: (*parser).callonAndExpression11,
expr: &labeledExpr{
pos: position{line: 32, col: 5, offset: 635},
label: "expr",
expr: &ruleRefExpr{
pos: position{line: 32, col: 10, offset: 640},
name: "NotExpression",
},
},
},
},
},
},
{
name: "NotExpression",
pos: position{line: 36, col: 1, offset: 679},
expr: &choiceExpr{
pos: position{line: 36, col: 18, offset: 696},
alternatives: []interface{}{
&actionExpr{
pos: position{line: 36, col: 18, offset: 696},
run: (*parser).callonNotExpression2,
expr: &seqExpr{
pos: position{line: 36, col: 18, offset: 696},
exprs: []interface{}{
&litMatcher{
pos: position{line: 36, col: 18, offset: 696},
val: "not",
ignoreCase: false,
},
&ruleRefExpr{
pos: position{line: 36, col: 24, offset: 702},
name: "_",
},
&labeledExpr{
pos: position{line: 36, col: 26, offset: 704},
label: "expr",
expr: &ruleRefExpr{
pos: position{line: 36, col: 31, offset: 709},
name: "NotExpression",
},
},
},
},
},
&actionExpr{
pos: position{line: 47, col: 5, offset: 1096},
run: (*parser).callonNotExpression8,
expr: &labeledExpr{
pos: position{line: 47, col: 5, offset: 1096},
label: "expr",
expr: &ruleRefExpr{
pos: position{line: 47, col: 10, offset: 1101},
name: "ParenthesizedExpression",
},
},
},
},
},
},
{
name: "ParenthesizedExpression",
displayName: "\"grouping\"",
pos: position{line: 51, col: 1, offset: 1150},
expr: &choiceExpr{
pos: position{line: 51, col: 39, offset: 1188},
alternatives: []interface{}{
&actionExpr{
pos: position{line: 51, col: 39, offset: 1188},
run: (*parser).callonParenthesizedExpression2,
expr: &seqExpr{
pos: position{line: 51, col: 39, offset: 1188},
exprs: []interface{}{
&litMatcher{
pos: position{line: 51, col: 39, offset: 1188},
val: "(",
ignoreCase: false,
},
&zeroOrOneExpr{
pos: position{line: 51, col: 43, offset: 1192},
expr: &ruleRefExpr{
pos: position{line: 51, col: 43, offset: 1192},
name: "_",
},
},
&labeledExpr{
pos: position{line: 51, col: 46, offset: 1195},
label: "expr",
expr: &ruleRefExpr{
pos: position{line: 51, col: 51, offset: 1200},
name: "OrExpression",
},
},
&zeroOrOneExpr{
pos: position{line: 51, col: 64, offset: 1213},
expr: &ruleRefExpr{
pos: position{line: 51, col: 64, offset: 1213},
name: "_",
},
},
&litMatcher{
pos: position{line: 51, col: 67, offset: 1216},
val: ")",
ignoreCase: false,
},
},
},
},
&actionExpr{
pos: position{line: 53, col: 5, offset: 1246},
run: (*parser).callonParenthesizedExpression12,
expr: &labeledExpr{
pos: position{line: 53, col: 5, offset: 1246},
label: "expr",
expr: &ruleRefExpr{
pos: position{line: 53, col: 10, offset: 1251},
name: "MatchExpression",
},
},
},
&seqExpr{
pos: position{line: 55, col: 5, offset: 1293},
exprs: []interface{}{
&litMatcher{
pos: position{line: 55, col: 5, offset: 1293},
val: "(",
ignoreCase: false,
},
&zeroOrOneExpr{
pos: position{line: 55, col: 9, offset: 1297},
expr: &ruleRefExpr{
pos: position{line: 55, col: 9, offset: 1297},
name: "_",
},
},
&ruleRefExpr{
pos: position{line: 55, col: 12, offset: 1300},
name: "OrExpression",
},
&zeroOrOneExpr{
pos: position{line: 55, col: 25, offset: 1313},
expr: &ruleRefExpr{
pos: position{line: 55, col: 25, offset: 1313},
name: "_",
},
},
&notExpr{
pos: position{line: 55, col: 28, offset: 1316},
expr: &litMatcher{
pos: position{line: 55, col: 29, offset: 1317},
val: ")",
ignoreCase: false,
},
},
&andCodeExpr{
pos: position{line: 55, col: 33, offset: 1321},
run: (*parser).callonParenthesizedExpression24,
},
},
},
},
},
},
{
name: "MatchExpression",
displayName: "\"match\"",
pos: position{line: 59, col: 1, offset: 1380},
expr: &choiceExpr{
pos: position{line: 59, col: 28, offset: 1407},
alternatives: []interface{}{
&ruleRefExpr{
pos: position{line: 59, col: 28, offset: 1407},
name: "MatchSelectorOpValue",
},
&ruleRefExpr{
pos: position{line: 59, col: 51, offset: 1430},
name: "MatchSelectorOp",
},
&ruleRefExpr{
pos: position{line: 59, col: 69, offset: 1448},
name: "MatchValueOpSelector",
},
},
},
},
{
name: "MatchSelectorOpValue",
displayName: "\"match\"",
pos: position{line: 61, col: 1, offset: 1470},
expr: &actionExpr{
pos: position{line: 61, col: 33, offset: 1502},
run: (*parser).callonMatchSelectorOpValue1,
expr: &seqExpr{
pos: position{line: 61, col: 33, offset: 1502},
exprs: []interface{}{
&labeledExpr{
pos: position{line: 61, col: 33, offset: 1502},
label: "selector",
expr: &ruleRefExpr{
pos: position{line: 61, col: 42, offset: 1511},
name: "Selector",
},
},
&labeledExpr{
pos: position{line: 61, col: 51, offset: 1520},
label: "operator",
expr: &choiceExpr{
pos: position{line: 61, col: 61, offset: 1530},
alternatives: []interface{}{
&ruleRefExpr{
pos: position{line: 61, col: 61, offset: 1530},
name: "MatchEqual",
},
&ruleRefExpr{
pos: position{line: 61, col: 74, offset: 1543},
name: "MatchNotEqual",
},
&ruleRefExpr{
pos: position{line: 61, col: 90, offset: 1559},
name: "MatchContains",
},
&ruleRefExpr{
pos: position{line: 61, col: 106, offset: 1575},
name: "MatchNotContains",
},
&ruleRefExpr{
pos: position{line: 61, col: 125, offset: 1594},
name: "MatchMatches",
},
&ruleRefExpr{
pos: position{line: 61, col: 140, offset: 1609},
name: "MatchNotMatches",
},
},
},
},
&labeledExpr{
pos: position{line: 61, col: 157, offset: 1626},
label: "value",
expr: &ruleRefExpr{
pos: position{line: 61, col: 163, offset: 1632},
name: "Value",
},
},
},
},
},
},
{
name: "MatchSelectorOp",
displayName: "\"match\"",
pos: position{line: 65, col: 1, offset: 1770},
expr: &actionExpr{
pos: position{line: 65, col: 28, offset: 1797},
run: (*parser).callonMatchSelectorOp1,
expr: &seqExpr{
pos: position{line: 65, col: 28, offset: 1797},
exprs: []interface{}{
&labeledExpr{
pos: position{line: 65, col: 28, offset: 1797},
label: "selector",
expr: &ruleRefExpr{
pos: position{line: 65, col: 37, offset: 1806},
name: "Selector",
},
},
&labeledExpr{
pos: position{line: 65, col: 46, offset: 1815},
label: "operator",
expr: &choiceExpr{
pos: position{line: 65, col: 56, offset: 1825},
alternatives: []interface{}{
&ruleRefExpr{
pos: position{line: 65, col: 56, offset: 1825},
name: "MatchIsEmpty",
},
&ruleRefExpr{
pos: position{line: 65, col: 71, offset: 1840},
name: "MatchIsNotEmpty",
},
},
},
},
},
},
},
},
{
name: "MatchValueOpSelector",
displayName: "\"match\"",
pos: position{line: 69, col: 1, offset: 1973},
expr: &choiceExpr{
pos: position{line: 69, col: 33, offset: 2005},
alternatives: []interface{}{
&actionExpr{
pos: position{line: 69, col: 33, offset: 2005},
run: (*parser).callonMatchValueOpSelector2,
expr: &seqExpr{
pos: position{line: 69, col: 33, offset: 2005},
exprs: []interface{}{
&labeledExpr{
pos: position{line: 69, col: 33, offset: 2005},
label: "value",
expr: &ruleRefExpr{
pos: position{line: 69, col: 39, offset: 2011},
name: "Value",
},
},
&labeledExpr{
pos: position{line: 69, col: 45, offset: 2017},
label: "operator",
expr: &choiceExpr{
pos: position{line: 69, col: 55, offset: 2027},
alternatives: []interface{}{
&ruleRefExpr{
pos: position{line: 69, col: 55, offset: 2027},
name: "MatchIn",
},
&ruleRefExpr{
pos: position{line: 69, col: 65, offset: 2037},
name: "MatchNotIn",
},
},
},
},
&labeledExpr{
pos: position{line: 69, col: 77, offset: 2049},
label: "selector",
expr: &ruleRefExpr{
pos: position{line: 69, col: 86, offset: 2058},
name: "Selector",
},
},
},
},
},
&seqExpr{
pos: position{line: 71, col: 5, offset: 2200},
exprs: []interface{}{
&ruleRefExpr{
pos: position{line: 71, col: 5, offset: 2200},
name: "Value",
},
&labeledExpr{
pos: position{line: 71, col: 11, offset: 2206},
label: "operator",
expr: &choiceExpr{
pos: position{line: 71, col: 21, offset: 2216},
alternatives: []interface{}{
&ruleRefExpr{
pos: position{line: 71, col: 21, offset: 2216},
name: "MatchIn",
},
&ruleRefExpr{
pos: position{line: 71, col: 31, offset: 2226},
name: "MatchNotIn",
},
},
},
},
&notExpr{
pos: position{line: 71, col: 43, offset: 2238},
expr: &ruleRefExpr{
pos: position{line: 71, col: 44, offset: 2239},
name: "Selector",
},
},
&andCodeExpr{
pos: position{line: 71, col: 53, offset: 2248},
run: (*parser).callonMatchValueOpSelector20,
},
},
},
},
},
},
{
name: "MatchEqual",
pos: position{line: 75, col: 1, offset: 2302},
expr: &actionExpr{
pos: position{line: 75, col: 15, offset: 2316},
run: (*parser).callonMatchEqual1,
expr: &seqExpr{
pos: position{line: 75, col: 15, offset: 2316},
exprs: []interface{}{
&zeroOrOneExpr{
pos: position{line: 75, col: 15, offset: 2316},
expr: &ruleRefExpr{
pos: position{line: 75, col: 15, offset: 2316},
name: "_",
},
},
&litMatcher{
pos: position{line: 75, col: 18, offset: 2319},
val: "==",
ignoreCase: false,
},
&zeroOrOneExpr{
pos: position{line: 75, col: 23, offset: 2324},
expr: &ruleRefExpr{
pos: position{line: 75, col: 23, offset: 2324},
name: "_",
},
},
},
},
},
},
{
name: "MatchNotEqual",
pos: position{line: 78, col: 1, offset: 2357},
expr: &actionExpr{
pos: position{line: 78, col: 18, offset: 2374},
run: (*parser).callonMatchNotEqual1,
expr: &seqExpr{
pos: position{line: 78, col: 18, offset: 2374},
exprs: []interface{}{
&zeroOrOneExpr{
pos: position{line: 78, col: 18, offset: 2374},
expr: &ruleRefExpr{
pos: position{line: 78, col: 18, offset: 2374},
name: "_",
},
},
&litMatcher{
pos: position{line: 78, col: 21, offset: 2377},
val: "!=",
ignoreCase: false,
},
&zeroOrOneExpr{
pos: position{line: 78, col: 26, offset: 2382},
expr: &ruleRefExpr{
pos: position{line: 78, col: 26, offset: 2382},
name: "_",
},
},
},
},
},
},
{
name: "MatchIsEmpty",
pos: position{line: 81, col: 1, offset: 2418},
expr: &actionExpr{
pos: position{line: 81, col: 17, offset: 2434},
run: (*parser).callonMatchIsEmpty1,
expr: &seqExpr{
pos: position{line: 81, col: 17, offset: 2434},
exprs: []interface{}{
&ruleRefExpr{
pos: position{line: 81, col: 17, offset: 2434},
name: "_",
},
&litMatcher{
pos: position{line: 81, col: 19, offset: 2436},
val: "is",
ignoreCase: false,
},
&ruleRefExpr{
pos: position{line: 81, col: 24, offset: 2441},
name: "_",
},
&litMatcher{
pos: position{line: 81, col: 26, offset: 2443},
val: "empty",
ignoreCase: false,
},
},
},
},
},
{
name: "MatchIsNotEmpty",
pos: position{line: 84, col: 1, offset: 2483},
expr: &actionExpr{
pos: position{line: 84, col: 20, offset: 2502},
run: (*parser).callonMatchIsNotEmpty1,
expr: &seqExpr{
pos: position{line: 84, col: 20, offset: 2502},
exprs: []interface{}{
&ruleRefExpr{
pos: position{line: 84, col: 20, offset: 2502},
name: "_",
},
&litMatcher{
pos: position{line: 84, col: 21, offset: 2503},
val: "is",
ignoreCase: false,
},
&ruleRefExpr{
pos: position{line: 84, col: 26, offset: 2508},
name: "_",
},
&litMatcher{
pos: position{line: 84, col: 28, offset: 2510},
val: "not",
ignoreCase: false,
},
&ruleRefExpr{
pos: position{line: 84, col: 34, offset: 2516},
name: "_",
},
&litMatcher{
pos: position{line: 84, col: 36, offset: 2518},
val: "empty",
ignoreCase: false,
},
},
},
},
},
{
name: "MatchIn",
pos: position{line: 87, col: 1, offset: 2561},
expr: &actionExpr{
pos: position{line: 87, col: 12, offset: 2572},
run: (*parser).callonMatchIn1,
expr: &seqExpr{
pos: position{line: 87, col: 12, offset: 2572},
exprs: []interface{}{
&ruleRefExpr{
pos: position{line: 87, col: 12, offset: 2572},
name: "_",
},
&litMatcher{
pos: position{line: 87, col: 14, offset: 2574},
val: "in",
ignoreCase: false,
},
&ruleRefExpr{
pos: position{line: 87, col: 19, offset: 2579},
name: "_",
},
},
},
},
},
{
name: "MatchNotIn",
pos: position{line: 90, col: 1, offset: 2608},
expr: &actionExpr{
pos: position{line: 90, col: 15, offset: 2622},
run: (*parser).callonMatchNotIn1,
expr: &seqExpr{
pos: position{line: 90, col: 15, offset: 2622},
exprs: []interface{}{
&ruleRefExpr{
pos: position{line: 90, col: 15, offset: 2622},
name: "_",
},
&litMatcher{
pos: position{line: 90, col: 17, offset: 2624},
val: "not",
ignoreCase: false,
},
&ruleRefExpr{
pos: position{line: 90, col: 23, offset: 2630},
name: "_",
},
&litMatcher{
pos: position{line: 90, col: 25, offset: 2632},
val: "in",
ignoreCase: false,
},
&ruleRefExpr{
pos: position{line: 90, col: 30, offset: 2637},
name: "_",
},
},
},
},
},
{
name: "MatchContains",
pos: position{line: 93, col: 1, offset: 2669},
expr: &actionExpr{
pos: position{line: 93, col: 18, offset: 2686},
run: (*parser).callonMatchContains1,
expr: &seqExpr{
pos: position{line: 93, col: 18, offset: 2686},
exprs: []interface{}{
&ruleRefExpr{
pos: position{line: 93, col: 18, offset: 2686},
name: "_",
},
&litMatcher{
pos: position{line: 93, col: 20, offset: 2688},
val: "contains",
ignoreCase: false,
},
&ruleRefExpr{
pos: position{line: 93, col: 31, offset: 2699},
name: "_",
},
},
},
},
},
{
name: "MatchNotContains",
pos: position{line: 96, col: 1, offset: 2728},
expr: &actionExpr{
pos: position{line: 96, col: 21, offset: 2748},
run: (*parser).callonMatchNotContains1,
expr: &seqExpr{
pos: position{line: 96, col: 21, offset: 2748},
exprs: []interface{}{
&ruleRefExpr{
pos: position{line: 96, col: 21, offset: 2748},
name: "_",
},
&litMatcher{
pos: position{line: 96, col: 23, offset: 2750},
val: "not",
ignoreCase: false,
},
&ruleRefExpr{
pos: position{line: 96, col: 29, offset: 2756},
name: "_",
},
&litMatcher{
pos: position{line: 96, col: 31, offset: 2758},
val: "contains",
ignoreCase: false,
},
&ruleRefExpr{
pos: position{line: 96, col: 42, offset: 2769},
name: "_",
},
},
},
},
},
{
name: "MatchMatches",
pos: position{line: 99, col: 1, offset: 2801},
expr: &actionExpr{
pos: position{line: 99, col: 17, offset: 2817},
run: (*parser).callonMatchMatches1,
expr: &seqExpr{
pos: position{line: 99, col: 17, offset: 2817},
exprs: []interface{}{
&ruleRefExpr{
pos: position{line: 99, col: 17, offset: 2817},
name: "_",
},
&litMatcher{
pos: position{line: 99, col: 19, offset: 2819},
val: "matches",
ignoreCase: false,
},
&ruleRefExpr{
pos: position{line: 99, col: 29, offset: 2829},
name: "_",
},
},
},
},
},
{
name: "MatchNotMatches",
pos: position{line: 102, col: 1, offset: 2863},
expr: &actionExpr{
pos: position{line: 102, col: 20, offset: 2882},
run: (*parser).callonMatchNotMatches1,
expr: &seqExpr{
pos: position{line: 102, col: 20, offset: 2882},
exprs: []interface{}{
&ruleRefExpr{
pos: position{line: 102, col: 20, offset: 2882},
name: "_",
},
&litMatcher{
pos: position{line: 102, col: 22, offset: 2884},
val: "not",
ignoreCase: false,
},
&ruleRefExpr{
pos: position{line: 102, col: 28, offset: 2890},
name: "_",
},
&litMatcher{
pos: position{line: 102, col: 30, offset: 2892},
val: "matches",
ignoreCase: false,
},
&ruleRefExpr{
pos: position{line: 102, col: 40, offset: 2902},
name: "_",
},
},
},
},
},
{
name: "Selector",
displayName: "\"selector\"",
pos: position{line: 106, col: 1, offset: 2940},
expr: &actionExpr{
pos: position{line: 106, col: 24, offset: 2963},
run: (*parser).callonSelector1,
expr: &seqExpr{
pos: position{line: 106, col: 24, offset: 2963},
exprs: []interface{}{
&labeledExpr{
pos: position{line: 106, col: 24, offset: 2963},
label: "first",
expr: &ruleRefExpr{
pos: position{line: 106, col: 30, offset: 2969},
name: "Identifier",
},
},
&labeledExpr{
pos: position{line: 106, col: 41, offset: 2980},
label: "rest",
expr: &zeroOrMoreExpr{
pos: position{line: 106, col: 46, offset: 2985},
expr: &ruleRefExpr{
pos: position{line: 106, col: 46, offset: 2985},
name: "SelectorOrIndex",
},
},
},
},
},
},
},
{
name: "Identifier",
pos: position{line: 119, col: 1, offset: 3192},
expr: &actionExpr{
pos: position{line: 119, col: 15, offset: 3206},
run: (*parser).callonIdentifier1,
expr: &seqExpr{
pos: position{line: 119, col: 15, offset: 3206},
exprs: []interface{}{
&charClassMatcher{
pos: position{line: 119, col: 15, offset: 3206},
val: "[a-zA-Z]",
ranges: []rune{'a', 'z', 'A', 'Z'},
ignoreCase: false,
inverted: false,
},
&zeroOrMoreExpr{
pos: position{line: 119, col: 24, offset: 3215},
expr: &charClassMatcher{
pos: position{line: 119, col: 24, offset: 3215},
val: "[a-zA-Z0-9_]",
chars: []rune{'_'},
ranges: []rune{'a', 'z', 'A', 'Z', '0', '9'},
ignoreCase: false,
inverted: false,
},
},
},
},
},
},
{
name: "SelectorOrIndex",
pos: position{line: 123, col: 1, offset: 3264},
expr: &choiceExpr{
pos: position{line: 123, col: 20, offset: 3283},
alternatives: []interface{}{
&actionExpr{
pos: position{line: 123, col: 20, offset: 3283},
run: (*parser).callonSelectorOrIndex2,
expr: &seqExpr{
pos: position{line: 123, col: 20, offset: 3283},
exprs: []interface{}{
&litMatcher{
pos: position{line: 123, col: 20, offset: 3283},
val: ".",
ignoreCase: false,
},
&labeledExpr{
pos: position{line: 123, col: 24, offset: 3287},
label: "ident",
expr: &ruleRefExpr{
pos: position{line: 123, col: 30, offset: 3293},
name: "Identifier",
},
},
},
},
},
&actionExpr{
pos: position{line: 125, col: 5, offset: 3331},
run: (*parser).callonSelectorOrIndex7,
expr: &labeledExpr{
pos: position{line: 125, col: 5, offset: 3331},
label: "expr",
expr: &ruleRefExpr{
pos: position{line: 125, col: 10, offset: 3336},
name: "IndexExpression",
},
},
},
},
},
},
{
name: "IndexExpression",
displayName: "\"index\"",
pos: position{line: 129, col: 1, offset: 3377},
expr: &choiceExpr{
pos: position{line: 129, col: 28, offset: 3404},
alternatives: []interface{}{
&actionExpr{
pos: position{line: 129, col: 28, offset: 3404},
run: (*parser).callonIndexExpression2,
expr: &seqExpr{
pos: position{line: 129, col: 28, offset: 3404},
exprs: []interface{}{
&litMatcher{
pos: position{line: 129, col: 28, offset: 3404},
val: "[",
ignoreCase: false,
},
&zeroOrOneExpr{
pos: position{line: 129, col: 32, offset: 3408},
expr: &ruleRefExpr{
pos: position{line: 129, col: 32, offset: 3408},
name: "_",
},
},
&labeledExpr{
pos: position{line: 129, col: 35, offset: 3411},
label: "lit",
expr: &ruleRefExpr{
pos: position{line: 129, col: 39, offset: 3415},
name: "StringLiteral",
},
},
&zeroOrOneExpr{
pos: position{line: 129, col: 53, offset: 3429},
expr: &ruleRefExpr{
pos: position{line: 129, col: 53, offset: 3429},
name: "_",
},
},
&litMatcher{
pos: position{line: 129, col: 56, offset: 3432},
val: "]",
ignoreCase: false,
},
},
},
},
&seqExpr{
pos: position{line: 131, col: 5, offset: 3461},
exprs: []interface{}{
&litMatcher{
pos: position{line: 131, col: 5, offset: 3461},
val: "[",
ignoreCase: false,
},
&zeroOrOneExpr{
pos: position{line: 131, col: 9, offset: 3465},
expr: &ruleRefExpr{
pos: position{line: 131, col: 9, offset: 3465},
name: "_",
},
},
&notExpr{
pos: position{line: 131, col: 12, offset: 3468},
expr: &ruleRefExpr{
pos: position{line: 131, col: 13, offset: 3469},
name: "StringLiteral",
},
},
&andCodeExpr{
pos: position{line: 131, col: 27, offset: 3483},
run: (*parser).callonIndexExpression18,
},
},
},
&seqExpr{
pos: position{line: 133, col: 5, offset: 3535},
exprs: []interface{}{
&litMatcher{
pos: position{line: 133, col: 5, offset: 3535},
val: "[",
ignoreCase: false,
},
&zeroOrOneExpr{
pos: position{line: 133, col: 9, offset: 3539},
expr: &ruleRefExpr{
pos: position{line: 133, col: 9, offset: 3539},
name: "_",
},
},
&ruleRefExpr{
pos: position{line: 133, col: 12, offset: 3542},
name: "StringLiteral",
},
&zeroOrOneExpr{
pos: position{line: 133, col: 26, offset: 3556},
expr: &ruleRefExpr{
pos: position{line: 133, col: 26, offset: 3556},
name: "_",
},
},
&notExpr{
pos: position{line: 133, col: 29, offset: 3559},
expr: &litMatcher{
pos: position{line: 133, col: 30, offset: 3560},
val: "]",
ignoreCase: false,
},
},
&andCodeExpr{
pos: position{line: 133, col: 34, offset: 3564},
run: (*parser).callonIndexExpression28,
},
},
},
},
},
},
{
name: "Value",
displayName: "\"value\"",
pos: position{line: 137, col: 1, offset: 3627},
expr: &choiceExpr{
pos: position{line: 137, col: 18, offset: 3644},
alternatives: []interface{}{
&actionExpr{
pos: position{line: 137, col: 18, offset: 3644},
run: (*parser).callonValue2,
expr: &labeledExpr{
pos: position{line: 137, col: 18, offset: 3644},
label: "selector",
expr: &ruleRefExpr{
pos: position{line: 137, col: 27, offset: 3653},
name: "Selector",
},
},
},
&actionExpr{
pos: position{line: 138, col: 10, offset: 3743},
run: (*parser).callonValue5,
expr: &labeledExpr{
pos: position{line: 138, col: 10, offset: 3743},
label: "n",
expr: &ruleRefExpr{
pos: position{line: 138, col: 12, offset: 3745},
name: "NumberLiteral",
},
},
},
&actionExpr{
pos: position{line: 139, col: 10, offset: 3813},
run: (*parser).callonValue8,
expr: &labeledExpr{
pos: position{line: 139, col: 10, offset: 3813},
label: "s",
expr: &ruleRefExpr{
pos: position{line: 139, col: 12, offset: 3815},
name: "StringLiteral",
},
},
},
},
},
},
{
name: "NumberLiteral",
displayName: "\"number\"",
pos: position{line: 141, col: 1, offset: 3874},
expr: &choiceExpr{
pos: position{line: 141, col: 27, offset: 3900},
alternatives: []interface{}{
&actionExpr{
pos: position{line: 141, col: 27, offset: 3900},
run: (*parser).callonNumberLiteral2,
expr: &seqExpr{
pos: position{line: 141, col: 27, offset: 3900},
exprs: []interface{}{
&zeroOrOneExpr{
pos: position{line: 141, col: 27, offset: 3900},
expr: &litMatcher{
pos: position{line: 141, col: 27, offset: 3900},
val: "-",
ignoreCase: false,
},
},
&ruleRefExpr{
pos: position{line: 141, col: 32, offset: 3905},
name: "IntegerOrFloat",
},
&andExpr{
pos: position{line: 141, col: 47, offset: 3920},
expr: &ruleRefExpr{
pos: position{line: 141, col: 48, offset: 3921},
name: "AfterNumbers",
},
},
},
},
},
&seqExpr{
pos: position{line: 143, col: 5, offset: 3970},
exprs: []interface{}{
&zeroOrOneExpr{
pos: position{line: 143, col: 5, offset: 3970},
expr: &litMatcher{
pos: position{line: 143, col: 5, offset: 3970},
val: "-",
ignoreCase: false,
},
},
&ruleRefExpr{
pos: position{line: 143, col: 10, offset: 3975},
name: "IntegerOrFloat",
},
&notExpr{
pos: position{line: 143, col: 25, offset: 3990},
expr: &ruleRefExpr{
pos: position{line: 143, col: 26, offset: 3991},
name: "AfterNumbers",
},
},
&andCodeExpr{
pos: position{line: 143, col: 39, offset: 4004},
run: (*parser).callonNumberLiteral15,
},
},
},
},
},
},
{
name: "AfterNumbers",
pos: position{line: 147, col: 1, offset: 4064},
expr: &andExpr{
pos: position{line: 147, col: 17, offset: 4080},
expr: &choiceExpr{
pos: position{line: 147, col: 19, offset: 4082},
alternatives: []interface{}{
&ruleRefExpr{
pos: position{line: 147, col: 19, offset: 4082},
name: "_",
},
&ruleRefExpr{
pos: position{line: 147, col: 23, offset: 4086},
name: "EOF",
},
&litMatcher{
pos: position{line: 147, col: 29, offset: 4092},
val: ")",
ignoreCase: false,
},
},
},
},
},
{
name: "IntegerOrFloat",
pos: position{line: 149, col: 1, offset: 4098},
expr: &seqExpr{
pos: position{line: 149, col: 19, offset: 4116},
exprs: []interface{}{
&choiceExpr{
pos: position{line: 149, col: 20, offset: 4117},
alternatives: []interface{}{
&litMatcher{
pos: position{line: 149, col: 20, offset: 4117},
val: "0",
ignoreCase: false,
},
&seqExpr{
pos: position{line: 149, col: 26, offset: 4123},
exprs: []interface{}{
&charClassMatcher{
pos: position{line: 149, col: 26, offset: 4123},
val: "[1-9]",
ranges: []rune{'1', '9'},
ignoreCase: false,
inverted: false,
},
&zeroOrMoreExpr{
pos: position{line: 149, col: 31, offset: 4128},
expr: &charClassMatcher{
pos: position{line: 149, col: 31, offset: 4128},
val: "[0-9]",
ranges: []rune{'0', '9'},
ignoreCase: false,
inverted: false,
},
},
},
},
},
},
&zeroOrOneExpr{
pos: position{line: 149, col: 39, offset: 4136},
expr: &seqExpr{
pos: position{line: 149, col: 40, offset: 4137},
exprs: []interface{}{
&litMatcher{
pos: position{line: 149, col: 40, offset: 4137},
val: ".",
ignoreCase: false,
},
&oneOrMoreExpr{
pos: position{line: 149, col: 44, offset: 4141},
expr: &charClassMatcher{
pos: position{line: 149, col: 44, offset: 4141},
val: "[0-9]",
ranges: []rune{'0', '9'},
ignoreCase: false,
inverted: false,
},
},
},
},
},
},
},
},
{
name: "StringLiteral",
displayName: "\"string\"",
pos: position{line: 151, col: 1, offset: 4151},
expr: &choiceExpr{
pos: position{line: 151, col: 27, offset: 4177},
alternatives: []interface{}{
&actionExpr{
pos: position{line: 151, col: 27, offset: 4177},
run: (*parser).callonStringLiteral2,
expr: &choiceExpr{
pos: position{line: 151, col: 28, offset: 4178},
alternatives: []interface{}{
&seqExpr{
pos: position{line: 151, col: 28, offset: 4178},
exprs: []interface{}{
&litMatcher{
pos: position{line: 151, col: 28, offset: 4178},
val: "`",
ignoreCase: false,
},
&zeroOrMoreExpr{
pos: position{line: 151, col: 32, offset: 4182},
expr: &ruleRefExpr{
pos: position{line: 151, col: 32, offset: 4182},
name: "RawStringChar",
},
},
&litMatcher{
pos: position{line: 151, col: 47, offset: 4197},
val: "`",
ignoreCase: false,
},
},
},
&seqExpr{
pos: position{line: 151, col: 53, offset: 4203},
exprs: []interface{}{
&litMatcher{
pos: position{line: 151, col: 53, offset: 4203},
val: "\"",
ignoreCase: false,
},
&zeroOrMoreExpr{
pos: position{line: 151, col: 57, offset: 4207},
expr: &ruleRefExpr{
pos: position{line: 151, col: 57, offset: 4207},
name: "DoubleStringChar",
},
},
&litMatcher{
pos: position{line: 151, col: 75, offset: 4225},
val: "\"",
ignoreCase: false,
},
},
},
},
},
},
&seqExpr{
pos: position{line: 153, col: 5, offset: 4277},
exprs: []interface{}{
&choiceExpr{
pos: position{line: 153, col: 6, offset: 4278},
alternatives: []interface{}{
&seqExpr{
pos: position{line: 153, col: 6, offset: 4278},
exprs: []interface{}{
&litMatcher{
pos: position{line: 153, col: 6, offset: 4278},
val: "`",
ignoreCase: false,
},
&zeroOrMoreExpr{
pos: position{line: 153, col: 10, offset: 4282},
expr: &ruleRefExpr{
pos: position{line: 153, col: 10, offset: 4282},
name: "RawStringChar",
},
},
},
},
&seqExpr{
pos: position{line: 153, col: 27, offset: 4299},
exprs: []interface{}{
&litMatcher{
pos: position{line: 153, col: 27, offset: 4299},
val: "\"",
ignoreCase: false,
},
&zeroOrMoreExpr{
pos: position{line: 153, col: 31, offset: 4303},
expr: &ruleRefExpr{
pos: position{line: 153, col: 31, offset: 4303},
name: "DoubleStringChar",
},
},
},
},
},
},
&ruleRefExpr{
pos: position{line: 153, col: 50, offset: 4322},
name: "EOF",
},
&andCodeExpr{
pos: position{line: 153, col: 54, offset: 4326},
run: (*parser).callonStringLiteral25,
},
},
},
},
},
},
{
name: "RawStringChar",
pos: position{line: 157, col: 1, offset: 4390},
expr: &seqExpr{
pos: position{line: 157, col: 18, offset: 4407},
exprs: []interface{}{
&notExpr{
pos: position{line: 157, col: 18, offset: 4407},
expr: &litMatcher{
pos: position{line: 157, col: 19, offset: 4408},
val: "`",
ignoreCase: false,
},
},
&anyMatcher{
line: 157, col: 23, offset: 4412,
},
},
},
},
{
name: "DoubleStringChar",
pos: position{line: 158, col: 1, offset: 4414},
expr: &seqExpr{
pos: position{line: 158, col: 21, offset: 4434},
exprs: []interface{}{
&notExpr{
pos: position{line: 158, col: 21, offset: 4434},
expr: &litMatcher{
pos: position{line: 158, col: 22, offset: 4435},
val: "\"",
ignoreCase: false,
},
},
&anyMatcher{
line: 158, col: 26, offset: 4439,
},
},
},
},
{
name: "_",
displayName: "\"whitespace\"",
pos: position{line: 160, col: 1, offset: 4442},
expr: &oneOrMoreExpr{
pos: position{line: 160, col: 19, offset: 4460},
expr: &charClassMatcher{
pos: position{line: 160, col: 19, offset: 4460},
val: "[ \\t\\r\\n]",
chars: []rune{' ', '\t', '\r', '\n'},
ignoreCase: false,
inverted: false,
},
},
},
{
name: "EOF",
pos: position{line: 162, col: 1, offset: 4472},
expr: &notExpr{
pos: position{line: 162, col: 8, offset: 4479},
expr: &anyMatcher{
line: 162, col: 9, offset: 4480,
},
},
},
},
}
func (c *current) onInput2(expr interface{}) (interface{}, error) {
return expr, nil
}
func (p *parser) callonInput2() (interface{}, error) {
stack := p.vstack[len(p.vstack)-1]
_ = stack
return p.cur.onInput2(stack["expr"])
}
func (c *current) onInput17(expr interface{}) (interface{}, error) {
return expr, nil
}
func (p *parser) callonInput17() (interface{}, error) {
stack := p.vstack[len(p.vstack)-1]
_ = stack
return p.cur.onInput17(stack["expr"])
}
func (c *current) onOrExpression2(left, right interface{}) (interface{}, error) {
return &BinaryExpression{
Operator: BinaryOpOr,
Left: left.(Expression),
Right: right.(Expression),
}, nil
}
func (p *parser) callonOrExpression2() (interface{}, error) {
stack := p.vstack[len(p.vstack)-1]
_ = stack
return p.cur.onOrExpression2(stack["left"], stack["right"])
}
func (c *current) onOrExpression11(expr interface{}) (interface{}, error) {
return expr, nil
}
func (p *parser) callonOrExpression11() (interface{}, error) {
stack := p.vstack[len(p.vstack)-1]
_ = stack
return p.cur.onOrExpression11(stack["expr"])
}
func (c *current) onAndExpression2(left, right interface{}) (interface{}, error) {
return &BinaryExpression{
Operator: BinaryOpAnd,
Left: left.(Expression),
Right: right.(Expression),
}, nil
}
func (p *parser) callonAndExpression2() (interface{}, error) {
stack := p.vstack[len(p.vstack)-1]
_ = stack
return p.cur.onAndExpression2(stack["left"], stack["right"])
}
func (c *current) onAndExpression11(expr interface{}) (interface{}, error) {
return expr, nil
}
func (p *parser) callonAndExpression11() (interface{}, error) {
stack := p.vstack[len(p.vstack)-1]
_ = stack
return p.cur.onAndExpression11(stack["expr"])
}
func (c *current) onNotExpression2(expr interface{}) (interface{}, error) {
if unary, ok := expr.(*UnaryExpression); ok && unary.Operator == UnaryOpNot {
// small optimization to get rid unnecessary levels of AST nodes
// for things like: not not foo == 3 which is equivalent to foo == 3
return unary.Operand, nil
}
return &UnaryExpression{
Operator: UnaryOpNot,
Operand: expr.(Expression),
}, nil
}
func (p *parser) callonNotExpression2() (interface{}, error) {
stack := p.vstack[len(p.vstack)-1]
_ = stack
return p.cur.onNotExpression2(stack["expr"])
}
func (c *current) onNotExpression8(expr interface{}) (interface{}, error) {
return expr, nil
}
func (p *parser) callonNotExpression8() (interface{}, error) {
stack := p.vstack[len(p.vstack)-1]
_ = stack
return p.cur.onNotExpression8(stack["expr"])
}
func (c *current) onParenthesizedExpression2(expr interface{}) (interface{}, error) {
return expr, nil
}
func (p *parser) callonParenthesizedExpression2() (interface{}, error) {
stack := p.vstack[len(p.vstack)-1]
_ = stack
return p.cur.onParenthesizedExpression2(stack["expr"])
}
func (c *current) onParenthesizedExpression12(expr interface{}) (interface{}, error) {
return expr, nil
}
func (p *parser) callonParenthesizedExpression12() (interface{}, error) {
stack := p.vstack[len(p.vstack)-1]
_ = stack
return p.cur.onParenthesizedExpression12(stack["expr"])
}
func (c *current) onParenthesizedExpression24() (bool, error) {
return false, errors.New("Unmatched parentheses")
}
func (p *parser) callonParenthesizedExpression24() (bool, error) {
stack := p.vstack[len(p.vstack)-1]
_ = stack
return p.cur.onParenthesizedExpression24()
}
func (c *current) onMatchSelectorOpValue1(selector, operator, value interface{}) (interface{}, error) {
return &MatchExpression{Selector: selector.(Selector), Operator: operator.(MatchOperator), Value: value.(*MatchValue)}, nil
}
func (p *parser) callonMatchSelectorOpValue1() (interface{}, error) {
stack := p.vstack[len(p.vstack)-1]
_ = stack
return p.cur.onMatchSelectorOpValue1(stack["selector"], stack["operator"], stack["value"])
}
func (c *current) onMatchSelectorOp1(selector, operator interface{}) (interface{}, error) {
return &MatchExpression{Selector: selector.(Selector), Operator: operator.(MatchOperator), Value: nil}, nil
}
func (p *parser) callonMatchSelectorOp1() (interface{}, error) {
stack := p.vstack[len(p.vstack)-1]
_ = stack
return p.cur.onMatchSelectorOp1(stack["selector"], stack["operator"])
}
func (c *current) onMatchValueOpSelector2(value, operator, selector interface{}) (interface{}, error) {
return &MatchExpression{Selector: selector.(Selector), Operator: operator.(MatchOperator), Value: value.(*MatchValue)}, nil
}
func (p *parser) callonMatchValueOpSelector2() (interface{}, error) {
stack := p.vstack[len(p.vstack)-1]
_ = stack
return p.cur.onMatchValueOpSelector2(stack["value"], stack["operator"], stack["selector"])
}
func (c *current) onMatchValueOpSelector20(operator interface{}) (bool, error) {
return false, errors.New("Invalid selector")
}
func (p *parser) callonMatchValueOpSelector20() (bool, error) {
stack := p.vstack[len(p.vstack)-1]
_ = stack
return p.cur.onMatchValueOpSelector20(stack["operator"])
}
func (c *current) onMatchEqual1() (interface{}, error) {
return MatchEqual, nil
}
func (p *parser) callonMatchEqual1() (interface{}, error) {
stack := p.vstack[len(p.vstack)-1]
_ = stack
return p.cur.onMatchEqual1()
}
func (c *current) onMatchNotEqual1() (interface{}, error) {
return MatchNotEqual, nil
}
func (p *parser) callonMatchNotEqual1() (interface{}, error) {
stack := p.vstack[len(p.vstack)-1]
_ = stack
return p.cur.onMatchNotEqual1()
}
func (c *current) onMatchIsEmpty1() (interface{}, error) {
return MatchIsEmpty, nil
}
func (p *parser) callonMatchIsEmpty1() (interface{}, error) {
stack := p.vstack[len(p.vstack)-1]
_ = stack
return p.cur.onMatchIsEmpty1()
}
func (c *current) onMatchIsNotEmpty1() (interface{}, error) {
return MatchIsNotEmpty, nil
}
func (p *parser) callonMatchIsNotEmpty1() (interface{}, error) {
stack := p.vstack[len(p.vstack)-1]
_ = stack
return p.cur.onMatchIsNotEmpty1()
}
func (c *current) onMatchIn1() (interface{}, error) {
return MatchIn, nil
}
func (p *parser) callonMatchIn1() (interface{}, error) {
stack := p.vstack[len(p.vstack)-1]
_ = stack
return p.cur.onMatchIn1()
}
func (c *current) onMatchNotIn1() (interface{}, error) {
return MatchNotIn, nil
}
func (p *parser) callonMatchNotIn1() (interface{}, error) {
stack := p.vstack[len(p.vstack)-1]
_ = stack
return p.cur.onMatchNotIn1()
}
func (c *current) onMatchContains1() (interface{}, error) {
return MatchIn, nil
}
func (p *parser) callonMatchContains1() (interface{}, error) {
stack := p.vstack[len(p.vstack)-1]
_ = stack
return p.cur.onMatchContains1()
}
func (c *current) onMatchNotContains1() (interface{}, error) {
return MatchNotIn, nil
}
func (p *parser) callonMatchNotContains1() (interface{}, error) {
stack := p.vstack[len(p.vstack)-1]
_ = stack
return p.cur.onMatchNotContains1()
}
func (c *current) onMatchMatches1() (interface{}, error) {
return MatchMatches, nil
}
func (p *parser) callonMatchMatches1() (interface{}, error) {
stack := p.vstack[len(p.vstack)-1]
_ = stack
return p.cur.onMatchMatches1()
}
func (c *current) onMatchNotMatches1() (interface{}, error) {
return MatchNotMatches, nil
}
func (p *parser) callonMatchNotMatches1() (interface{}, error) {
stack := p.vstack[len(p.vstack)-1]
_ = stack
return p.cur.onMatchNotMatches1()
}
func (c *current) onSelector1(first, rest interface{}) (interface{}, error) {
sel := Selector{
first.(string),
}
if rest != nil {
for _, v := range rest.([]interface{}) {
sel = append(sel, v.(string))
}
}
return sel, nil
}
func (p *parser) callonSelector1() (interface{}, error) {
stack := p.vstack[len(p.vstack)-1]
_ = stack
return p.cur.onSelector1(stack["first"], stack["rest"])
}
func (c *current) onIdentifier1() (interface{}, error) {
return string(c.text), nil
}
func (p *parser) callonIdentifier1() (interface{}, error) {
stack := p.vstack[len(p.vstack)-1]
_ = stack
return p.cur.onIdentifier1()
}
func (c *current) onSelectorOrIndex2(ident interface{}) (interface{}, error) {
return ident, nil
}
func (p *parser) callonSelectorOrIndex2() (interface{}, error) {
stack := p.vstack[len(p.vstack)-1]
_ = stack
return p.cur.onSelectorOrIndex2(stack["ident"])
}
func (c *current) onSelectorOrIndex7(expr interface{}) (interface{}, error) {
return expr, nil
}
func (p *parser) callonSelectorOrIndex7() (interface{}, error) {
stack := p.vstack[len(p.vstack)-1]
_ = stack
return p.cur.onSelectorOrIndex7(stack["expr"])
}
func (c *current) onIndexExpression2(lit interface{}) (interface{}, error) {
return lit, nil
}
func (p *parser) callonIndexExpression2() (interface{}, error) {
stack := p.vstack[len(p.vstack)-1]
_ = stack
return p.cur.onIndexExpression2(stack["lit"])
}
func (c *current) onIndexExpression18() (bool, error) {
return false, errors.New("Invalid index")
}
func (p *parser) callonIndexExpression18() (bool, error) {
stack := p.vstack[len(p.vstack)-1]
_ = stack
return p.cur.onIndexExpression18()
}
func (c *current) onIndexExpression28() (bool, error) {
return false, errors.New("Unclosed index expression")
}
func (p *parser) callonIndexExpression28() (bool, error) {
stack := p.vstack[len(p.vstack)-1]
_ = stack
return p.cur.onIndexExpression28()
}
func (c *current) onValue2(selector interface{}) (interface{}, error) {
return &MatchValue{Raw: strings.Join(selector.(Selector), ".")}, nil
}
func (p *parser) callonValue2() (interface{}, error) {
stack := p.vstack[len(p.vstack)-1]
_ = stack
return p.cur.onValue2(stack["selector"])
}
func (c *current) onValue5(n interface{}) (interface{}, error) {
return &MatchValue{Raw: n.(string)}, nil
}
func (p *parser) callonValue5() (interface{}, error) {
stack := p.vstack[len(p.vstack)-1]
_ = stack
return p.cur.onValue5(stack["n"])
}
func (c *current) onValue8(s interface{}) (interface{}, error) {
return &MatchValue{Raw: s.(string)}, nil
}
func (p *parser) callonValue8() (interface{}, error) {
stack := p.vstack[len(p.vstack)-1]
_ = stack
return p.cur.onValue8(stack["s"])
}
func (c *current) onNumberLiteral2() (interface{}, error) {
return string(c.text), nil
}
func (p *parser) callonNumberLiteral2() (interface{}, error) {
stack := p.vstack[len(p.vstack)-1]
_ = stack
return p.cur.onNumberLiteral2()
}
func (c *current) onNumberLiteral15() (bool, error) {
return false, errors.New("Invalid number literal")
}
func (p *parser) callonNumberLiteral15() (bool, error) {
stack := p.vstack[len(p.vstack)-1]
_ = stack
return p.cur.onNumberLiteral15()
}
func (c *current) onStringLiteral2() (interface{}, error) {
return strconv.Unquote(string(c.text))
}
func (p *parser) callonStringLiteral2() (interface{}, error) {
stack := p.vstack[len(p.vstack)-1]
_ = stack
return p.cur.onStringLiteral2()
}
func (c *current) onStringLiteral25() (bool, error) {
return false, errors.New("Unterminated string literal")
}
func (p *parser) callonStringLiteral25() (bool, error) {
stack := p.vstack[len(p.vstack)-1]
_ = stack
return p.cur.onStringLiteral25()
}
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)
}
}
// 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)
}
}
// 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
// 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 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{
globalStore: make(storeDict),
},
maxFailPos: position{col: 1, line: 1},
maxFailExpected: make([]string, 0, 20),
Stats: &stats,
// start rule is rule [0] unless an alternate entrypoint is specified
entrypoint: g.rules[0].name,
}
p.setOptions(opts)
if p.maxExprCnt == 0 {
p.maxExprCnt = math.MaxUint64
}
return p
}
// setOptions applies the options to the parser.
func (p *parser) setOptions(opts []Option) {
for _, opt := range opts {
opt(p)
}
}
type resultTuple struct {
v 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
// 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{}
}
// 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) addErr(err error) {
p.addErrAt(err, p.pt.position, []string{})
}
func (p *parser) addErrAt(err error, pos position, expected []string) {
var buf bytes.Buffer
if p.filename != "" {
buf.WriteString(p.filename)
}
if buf.Len() > 0 {
buf.WriteString(":")
}
buf.WriteString(fmt.Sprintf("%d:%d (%d)", pos.line, pos.col, pos.offset))
if len(p.rstack) > 0 {
if buf.Len() > 0 {
buf.WriteString(": ")
}
rule := p.rstack[len(p.rstack)-1]
if rule.displayName != "" {
buf.WriteString("rule " + rule.displayName)
} else {
buf.WriteString("rule " + rule.name)
}
}
pe := &parserError{Inner: err, pos: pos, prefix: buf.String(), expected: expected}
p.errs.add(pe)
}
func (p *parser) failAt(fail bool, pos position, want string) {
// process fail if parsing fails and not inverted or parsing succeeds and invert is set
if fail == p.maxFailInvertExpected {
if pos.offset < p.maxFailPos.offset {
return
}
if pos.offset > p.maxFailPos.offset {
p.maxFailPos = pos
p.maxFailExpected = p.maxFailExpected[:0]
}
if p.maxFailInvertExpected {
want = "!" + want
}
p.maxFailExpected = append(p.maxFailExpected, want)
}
}
// read advances the parser to the next rune.
func (p *parser) read() {
p.pt.offset += p.pt.w
rn, n := utf8.DecodeRune(p.data[p.pt.offset:])
p.pt.rn = rn
p.pt.w = n
p.pt.col++
if rn == '\n' {
p.pt.line++
p.pt.col = 0
}
if rn == utf8.RuneError && n == 1 { // see utf8.DecodeRune
if !p.allowInvalidUTF8 {
p.addErr(errInvalidEncoding)
}
}
}
// restore parser position to the savepoint pt.
func (p *parser) restore(pt savepoint) {
if pt.offset == p.pt.offset {
return
}
p.pt = pt
}
// get the slice of bytes from the savepoint start to the current position.
func (p *parser) sliceFrom(start savepoint) []byte {
return p.data[start.position.offset:p.pt.position.offset]
}
func (p *parser) buildRulesTable(g *grammar) {
p.rules = make(map[string]*rule, len(g.rules))
for _, r := range g.rules {
p.rules[r.name] = r
}
}
func (p *parser) parse(g *grammar) (val 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 {
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) {
p.rstack = append(p.rstack, rule)
p.pushV()
val, ok := p.parseExpr(rule.expr)
p.popV()
p.rstack = p.rstack[:len(p.rstack)-1]
return val, ok
}
func (p *parser) parseExpr(expr interface{}) (interface{}, bool) {
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 *throwExpr:
val, ok = p.parseThrowExpr(expr)
case *zeroOrMoreExpr:
val, ok = p.parseZeroOrMoreExpr(expr)
case *zeroOrOneExpr:
val, ok = p.parseZeroOrOneExpr(expr)
default:
panic(fmt.Sprintf("unknown expression type %T", expr))
}
return val, ok
}
func (p *parser) parseActionExpr(act *actionExpr) (interface{}, bool) {
start := p.pt
val, ok := p.parseExpr(act.expr)
if ok {
p.cur.pos = start.position
p.cur.text = p.sliceFrom(start)
actVal, err := act.run(p)
if err != nil {
p.addErrAt(err, start.position, []string{})
}
val = actVal
}
return val, ok
}
func (p *parser) parseAndCodeExpr(and *andCodeExpr) (interface{}, bool) {
ok, err := and.run(p)
if err != nil {
p.addErr(err)
}
return nil, ok
}
func (p *parser) parseAndExpr(and *andExpr) (interface{}, bool) {
pt := p.pt
p.pushV()
_, ok := p.parseExpr(and.expr)
p.popV()
p.restore(pt)
return nil, ok
}
func (p *parser) parseAnyMatcher(any *anyMatcher) (interface{}, bool) {
if p.pt.rn == utf8.RuneError && p.pt.w == 0 {
// EOF - see utf8.DecodeRune
p.failAt(false, p.pt.position, ".")
return nil, false
}
start := p.pt
p.read()
p.failAt(true, start.position, ".")
return p.sliceFrom(start), true
}
func (p *parser) parseCharClassMatcher(chr *charClassMatcher) (interface{}, bool) {
cur := p.pt.rn
start := p.pt
// can't match EOF
if cur == utf8.RuneError && p.pt.w == 0 { // see utf8.DecodeRune
p.failAt(false, start.position, chr.val)
return nil, false
}
if chr.ignoreCase {
cur = unicode.ToLower(cur)
}
// try to match in the list of available chars
for _, rn := range chr.chars {
if rn == cur {
if chr.inverted {
p.failAt(false, start.position, chr.val)
return nil, false
}
p.read()
p.failAt(true, start.position, chr.val)
return p.sliceFrom(start), true
}
}
// try to match in the list of ranges
for i := 0; i < len(chr.ranges); i += 2 {
if cur >= chr.ranges[i] && cur <= chr.ranges[i+1] {
if chr.inverted {
p.failAt(false, start.position, chr.val)
return nil, false
}
p.read()
p.failAt(true, start.position, chr.val)
return p.sliceFrom(start), true
}
}
// try to match in the list of Unicode classes
for _, cl := range chr.classes {
if unicode.Is(cl, cur) {
if chr.inverted {
p.failAt(false, start.position, chr.val)
return nil, false
}
p.read()
p.failAt(true, start.position, chr.val)
return p.sliceFrom(start), true
}
}
if chr.inverted {
p.read()
p.failAt(true, start.position, chr.val)
return p.sliceFrom(start), true
}
p.failAt(false, start.position, chr.val)
return nil, false
}
func (p *parser) parseChoiceExpr(ch *choiceExpr) (interface{}, bool) {
for altI, alt := range ch.alternatives {
// dummy assignment to prevent compile error if optimized
_ = altI
p.pushV()
val, ok := p.parseExpr(alt)
p.popV()
if ok {
return val, ok
}
}
return nil, false
}
func (p *parser) parseLabeledExpr(lab *labeledExpr) (interface{}, bool) {
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) {
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) {
ok, err := not.run(p)
if err != nil {
p.addErr(err)
}
return nil, !ok
}
func (p *parser) parseNotExpr(not *notExpr) (interface{}, bool) {
pt := p.pt
p.pushV()
p.maxFailInvertExpected = !p.maxFailInvertExpected
_, ok := p.parseExpr(not.expr)
p.maxFailInvertExpected = !p.maxFailInvertExpected
p.popV()
p.restore(pt)
return nil, !ok
}
func (p *parser) parseOneOrMoreExpr(expr *oneOrMoreExpr) (interface{}, bool) {
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) {
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 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) {
vals := make([]interface{}, 0, len(seq.exprs))
pt := p.pt
for _, expr := range seq.exprs {
val, ok := p.parseExpr(expr)
if !ok {
p.restore(pt)
return nil, false
}
vals = append(vals, val)
}
return vals, true
}
func (p *parser) parseThrowExpr(expr *throwExpr) (interface{}, bool) {
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) {
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) {
p.pushV()
val, _ := p.parseExpr(expr.expr)
p.popV()
// whether it matched or not, consider it a match
return val, true
}