mirror of https://github.com/hashicorp/consul
2815 lines
72 KiB
Go
2815 lines
72 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: "_",
|
|
},
|
|
},
|
|
¬Expr{
|
|
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",
|
|
},
|
|
},
|
|
},
|
|
},
|
|
&labeledExpr{
|
|
pos: position{line: 61, col: 124, offset: 1593},
|
|
label: "value",
|
|
expr: &ruleRefExpr{
|
|
pos: position{line: 61, col: 130, offset: 1599},
|
|
name: "Value",
|
|
},
|
|
},
|
|
},
|
|
},
|
|
},
|
|
},
|
|
{
|
|
name: "MatchSelectorOp",
|
|
displayName: "\"match\"",
|
|
pos: position{line: 65, col: 1, offset: 1737},
|
|
expr: &actionExpr{
|
|
pos: position{line: 65, col: 28, offset: 1764},
|
|
run: (*parser).callonMatchSelectorOp1,
|
|
expr: &seqExpr{
|
|
pos: position{line: 65, col: 28, offset: 1764},
|
|
exprs: []interface{}{
|
|
&labeledExpr{
|
|
pos: position{line: 65, col: 28, offset: 1764},
|
|
label: "selector",
|
|
expr: &ruleRefExpr{
|
|
pos: position{line: 65, col: 37, offset: 1773},
|
|
name: "Selector",
|
|
},
|
|
},
|
|
&labeledExpr{
|
|
pos: position{line: 65, col: 46, offset: 1782},
|
|
label: "operator",
|
|
expr: &choiceExpr{
|
|
pos: position{line: 65, col: 56, offset: 1792},
|
|
alternatives: []interface{}{
|
|
&ruleRefExpr{
|
|
pos: position{line: 65, col: 56, offset: 1792},
|
|
name: "MatchIsEmpty",
|
|
},
|
|
&ruleRefExpr{
|
|
pos: position{line: 65, col: 71, offset: 1807},
|
|
name: "MatchIsNotEmpty",
|
|
},
|
|
},
|
|
},
|
|
},
|
|
},
|
|
},
|
|
},
|
|
},
|
|
{
|
|
name: "MatchValueOpSelector",
|
|
displayName: "\"match\"",
|
|
pos: position{line: 69, col: 1, offset: 1940},
|
|
expr: &choiceExpr{
|
|
pos: position{line: 69, col: 33, offset: 1972},
|
|
alternatives: []interface{}{
|
|
&actionExpr{
|
|
pos: position{line: 69, col: 33, offset: 1972},
|
|
run: (*parser).callonMatchValueOpSelector2,
|
|
expr: &seqExpr{
|
|
pos: position{line: 69, col: 33, offset: 1972},
|
|
exprs: []interface{}{
|
|
&labeledExpr{
|
|
pos: position{line: 69, col: 33, offset: 1972},
|
|
label: "value",
|
|
expr: &ruleRefExpr{
|
|
pos: position{line: 69, col: 39, offset: 1978},
|
|
name: "Value",
|
|
},
|
|
},
|
|
&labeledExpr{
|
|
pos: position{line: 69, col: 45, offset: 1984},
|
|
label: "operator",
|
|
expr: &choiceExpr{
|
|
pos: position{line: 69, col: 55, offset: 1994},
|
|
alternatives: []interface{}{
|
|
&ruleRefExpr{
|
|
pos: position{line: 69, col: 55, offset: 1994},
|
|
name: "MatchIn",
|
|
},
|
|
&ruleRefExpr{
|
|
pos: position{line: 69, col: 65, offset: 2004},
|
|
name: "MatchNotIn",
|
|
},
|
|
},
|
|
},
|
|
},
|
|
&labeledExpr{
|
|
pos: position{line: 69, col: 77, offset: 2016},
|
|
label: "selector",
|
|
expr: &ruleRefExpr{
|
|
pos: position{line: 69, col: 86, offset: 2025},
|
|
name: "Selector",
|
|
},
|
|
},
|
|
},
|
|
},
|
|
},
|
|
&seqExpr{
|
|
pos: position{line: 71, col: 5, offset: 2167},
|
|
exprs: []interface{}{
|
|
&ruleRefExpr{
|
|
pos: position{line: 71, col: 5, offset: 2167},
|
|
name: "Value",
|
|
},
|
|
&labeledExpr{
|
|
pos: position{line: 71, col: 11, offset: 2173},
|
|
label: "operator",
|
|
expr: &choiceExpr{
|
|
pos: position{line: 71, col: 21, offset: 2183},
|
|
alternatives: []interface{}{
|
|
&ruleRefExpr{
|
|
pos: position{line: 71, col: 21, offset: 2183},
|
|
name: "MatchIn",
|
|
},
|
|
&ruleRefExpr{
|
|
pos: position{line: 71, col: 31, offset: 2193},
|
|
name: "MatchNotIn",
|
|
},
|
|
},
|
|
},
|
|
},
|
|
¬Expr{
|
|
pos: position{line: 71, col: 43, offset: 2205},
|
|
expr: &ruleRefExpr{
|
|
pos: position{line: 71, col: 44, offset: 2206},
|
|
name: "Selector",
|
|
},
|
|
},
|
|
&andCodeExpr{
|
|
pos: position{line: 71, col: 53, offset: 2215},
|
|
run: (*parser).callonMatchValueOpSelector20,
|
|
},
|
|
},
|
|
},
|
|
},
|
|
},
|
|
},
|
|
{
|
|
name: "MatchEqual",
|
|
pos: position{line: 75, col: 1, offset: 2269},
|
|
expr: &actionExpr{
|
|
pos: position{line: 75, col: 15, offset: 2283},
|
|
run: (*parser).callonMatchEqual1,
|
|
expr: &seqExpr{
|
|
pos: position{line: 75, col: 15, offset: 2283},
|
|
exprs: []interface{}{
|
|
&zeroOrOneExpr{
|
|
pos: position{line: 75, col: 15, offset: 2283},
|
|
expr: &ruleRefExpr{
|
|
pos: position{line: 75, col: 15, offset: 2283},
|
|
name: "_",
|
|
},
|
|
},
|
|
&litMatcher{
|
|
pos: position{line: 75, col: 18, offset: 2286},
|
|
val: "==",
|
|
ignoreCase: false,
|
|
},
|
|
&zeroOrOneExpr{
|
|
pos: position{line: 75, col: 23, offset: 2291},
|
|
expr: &ruleRefExpr{
|
|
pos: position{line: 75, col: 23, offset: 2291},
|
|
name: "_",
|
|
},
|
|
},
|
|
},
|
|
},
|
|
},
|
|
},
|
|
{
|
|
name: "MatchNotEqual",
|
|
pos: position{line: 78, col: 1, offset: 2324},
|
|
expr: &actionExpr{
|
|
pos: position{line: 78, col: 18, offset: 2341},
|
|
run: (*parser).callonMatchNotEqual1,
|
|
expr: &seqExpr{
|
|
pos: position{line: 78, col: 18, offset: 2341},
|
|
exprs: []interface{}{
|
|
&zeroOrOneExpr{
|
|
pos: position{line: 78, col: 18, offset: 2341},
|
|
expr: &ruleRefExpr{
|
|
pos: position{line: 78, col: 18, offset: 2341},
|
|
name: "_",
|
|
},
|
|
},
|
|
&litMatcher{
|
|
pos: position{line: 78, col: 21, offset: 2344},
|
|
val: "!=",
|
|
ignoreCase: false,
|
|
},
|
|
&zeroOrOneExpr{
|
|
pos: position{line: 78, col: 26, offset: 2349},
|
|
expr: &ruleRefExpr{
|
|
pos: position{line: 78, col: 26, offset: 2349},
|
|
name: "_",
|
|
},
|
|
},
|
|
},
|
|
},
|
|
},
|
|
},
|
|
{
|
|
name: "MatchIsEmpty",
|
|
pos: position{line: 81, col: 1, offset: 2385},
|
|
expr: &actionExpr{
|
|
pos: position{line: 81, col: 17, offset: 2401},
|
|
run: (*parser).callonMatchIsEmpty1,
|
|
expr: &seqExpr{
|
|
pos: position{line: 81, col: 17, offset: 2401},
|
|
exprs: []interface{}{
|
|
&ruleRefExpr{
|
|
pos: position{line: 81, col: 17, offset: 2401},
|
|
name: "_",
|
|
},
|
|
&litMatcher{
|
|
pos: position{line: 81, col: 19, offset: 2403},
|
|
val: "is",
|
|
ignoreCase: false,
|
|
},
|
|
&ruleRefExpr{
|
|
pos: position{line: 81, col: 24, offset: 2408},
|
|
name: "_",
|
|
},
|
|
&litMatcher{
|
|
pos: position{line: 81, col: 26, offset: 2410},
|
|
val: "empty",
|
|
ignoreCase: false,
|
|
},
|
|
},
|
|
},
|
|
},
|
|
},
|
|
{
|
|
name: "MatchIsNotEmpty",
|
|
pos: position{line: 84, col: 1, offset: 2450},
|
|
expr: &actionExpr{
|
|
pos: position{line: 84, col: 20, offset: 2469},
|
|
run: (*parser).callonMatchIsNotEmpty1,
|
|
expr: &seqExpr{
|
|
pos: position{line: 84, col: 20, offset: 2469},
|
|
exprs: []interface{}{
|
|
&ruleRefExpr{
|
|
pos: position{line: 84, col: 20, offset: 2469},
|
|
name: "_",
|
|
},
|
|
&litMatcher{
|
|
pos: position{line: 84, col: 21, offset: 2470},
|
|
val: "is",
|
|
ignoreCase: false,
|
|
},
|
|
&ruleRefExpr{
|
|
pos: position{line: 84, col: 26, offset: 2475},
|
|
name: "_",
|
|
},
|
|
&litMatcher{
|
|
pos: position{line: 84, col: 28, offset: 2477},
|
|
val: "not",
|
|
ignoreCase: false,
|
|
},
|
|
&ruleRefExpr{
|
|
pos: position{line: 84, col: 34, offset: 2483},
|
|
name: "_",
|
|
},
|
|
&litMatcher{
|
|
pos: position{line: 84, col: 36, offset: 2485},
|
|
val: "empty",
|
|
ignoreCase: false,
|
|
},
|
|
},
|
|
},
|
|
},
|
|
},
|
|
{
|
|
name: "MatchIn",
|
|
pos: position{line: 87, col: 1, offset: 2528},
|
|
expr: &actionExpr{
|
|
pos: position{line: 87, col: 12, offset: 2539},
|
|
run: (*parser).callonMatchIn1,
|
|
expr: &seqExpr{
|
|
pos: position{line: 87, col: 12, offset: 2539},
|
|
exprs: []interface{}{
|
|
&ruleRefExpr{
|
|
pos: position{line: 87, col: 12, offset: 2539},
|
|
name: "_",
|
|
},
|
|
&litMatcher{
|
|
pos: position{line: 87, col: 14, offset: 2541},
|
|
val: "in",
|
|
ignoreCase: false,
|
|
},
|
|
&ruleRefExpr{
|
|
pos: position{line: 87, col: 19, offset: 2546},
|
|
name: "_",
|
|
},
|
|
},
|
|
},
|
|
},
|
|
},
|
|
{
|
|
name: "MatchNotIn",
|
|
pos: position{line: 90, col: 1, offset: 2575},
|
|
expr: &actionExpr{
|
|
pos: position{line: 90, col: 15, offset: 2589},
|
|
run: (*parser).callonMatchNotIn1,
|
|
expr: &seqExpr{
|
|
pos: position{line: 90, col: 15, offset: 2589},
|
|
exprs: []interface{}{
|
|
&ruleRefExpr{
|
|
pos: position{line: 90, col: 15, offset: 2589},
|
|
name: "_",
|
|
},
|
|
&litMatcher{
|
|
pos: position{line: 90, col: 17, offset: 2591},
|
|
val: "not",
|
|
ignoreCase: false,
|
|
},
|
|
&ruleRefExpr{
|
|
pos: position{line: 90, col: 23, offset: 2597},
|
|
name: "_",
|
|
},
|
|
&litMatcher{
|
|
pos: position{line: 90, col: 25, offset: 2599},
|
|
val: "in",
|
|
ignoreCase: false,
|
|
},
|
|
&ruleRefExpr{
|
|
pos: position{line: 90, col: 30, offset: 2604},
|
|
name: "_",
|
|
},
|
|
},
|
|
},
|
|
},
|
|
},
|
|
{
|
|
name: "MatchContains",
|
|
pos: position{line: 93, col: 1, offset: 2636},
|
|
expr: &actionExpr{
|
|
pos: position{line: 93, col: 18, offset: 2653},
|
|
run: (*parser).callonMatchContains1,
|
|
expr: &seqExpr{
|
|
pos: position{line: 93, col: 18, offset: 2653},
|
|
exprs: []interface{}{
|
|
&ruleRefExpr{
|
|
pos: position{line: 93, col: 18, offset: 2653},
|
|
name: "_",
|
|
},
|
|
&litMatcher{
|
|
pos: position{line: 93, col: 20, offset: 2655},
|
|
val: "contains",
|
|
ignoreCase: false,
|
|
},
|
|
&ruleRefExpr{
|
|
pos: position{line: 93, col: 31, offset: 2666},
|
|
name: "_",
|
|
},
|
|
},
|
|
},
|
|
},
|
|
},
|
|
{
|
|
name: "MatchNotContains",
|
|
pos: position{line: 96, col: 1, offset: 2695},
|
|
expr: &actionExpr{
|
|
pos: position{line: 96, col: 21, offset: 2715},
|
|
run: (*parser).callonMatchNotContains1,
|
|
expr: &seqExpr{
|
|
pos: position{line: 96, col: 21, offset: 2715},
|
|
exprs: []interface{}{
|
|
&ruleRefExpr{
|
|
pos: position{line: 96, col: 21, offset: 2715},
|
|
name: "_",
|
|
},
|
|
&litMatcher{
|
|
pos: position{line: 96, col: 23, offset: 2717},
|
|
val: "not",
|
|
ignoreCase: false,
|
|
},
|
|
&ruleRefExpr{
|
|
pos: position{line: 96, col: 29, offset: 2723},
|
|
name: "_",
|
|
},
|
|
&litMatcher{
|
|
pos: position{line: 96, col: 31, offset: 2725},
|
|
val: "contains",
|
|
ignoreCase: false,
|
|
},
|
|
&ruleRefExpr{
|
|
pos: position{line: 96, col: 42, offset: 2736},
|
|
name: "_",
|
|
},
|
|
},
|
|
},
|
|
},
|
|
},
|
|
{
|
|
name: "Selector",
|
|
displayName: "\"selector\"",
|
|
pos: position{line: 101, col: 1, offset: 2770},
|
|
expr: &actionExpr{
|
|
pos: position{line: 101, col: 24, offset: 2793},
|
|
run: (*parser).callonSelector1,
|
|
expr: &seqExpr{
|
|
pos: position{line: 101, col: 24, offset: 2793},
|
|
exprs: []interface{}{
|
|
&labeledExpr{
|
|
pos: position{line: 101, col: 24, offset: 2793},
|
|
label: "first",
|
|
expr: &ruleRefExpr{
|
|
pos: position{line: 101, col: 30, offset: 2799},
|
|
name: "Identifier",
|
|
},
|
|
},
|
|
&labeledExpr{
|
|
pos: position{line: 101, col: 41, offset: 2810},
|
|
label: "rest",
|
|
expr: &zeroOrMoreExpr{
|
|
pos: position{line: 101, col: 46, offset: 2815},
|
|
expr: &ruleRefExpr{
|
|
pos: position{line: 101, col: 46, offset: 2815},
|
|
name: "SelectorOrIndex",
|
|
},
|
|
},
|
|
},
|
|
},
|
|
},
|
|
},
|
|
},
|
|
{
|
|
name: "Identifier",
|
|
pos: position{line: 114, col: 1, offset: 3022},
|
|
expr: &actionExpr{
|
|
pos: position{line: 114, col: 15, offset: 3036},
|
|
run: (*parser).callonIdentifier1,
|
|
expr: &seqExpr{
|
|
pos: position{line: 114, col: 15, offset: 3036},
|
|
exprs: []interface{}{
|
|
&charClassMatcher{
|
|
pos: position{line: 114, col: 15, offset: 3036},
|
|
val: "[a-zA-Z]",
|
|
ranges: []rune{'a', 'z', 'A', 'Z'},
|
|
ignoreCase: false,
|
|
inverted: false,
|
|
},
|
|
&zeroOrMoreExpr{
|
|
pos: position{line: 114, col: 24, offset: 3045},
|
|
expr: &charClassMatcher{
|
|
pos: position{line: 114, col: 24, offset: 3045},
|
|
val: "[a-zA-Z0-9_]",
|
|
chars: []rune{'_'},
|
|
ranges: []rune{'a', 'z', 'A', 'Z', '0', '9'},
|
|
ignoreCase: false,
|
|
inverted: false,
|
|
},
|
|
},
|
|
},
|
|
},
|
|
},
|
|
},
|
|
{
|
|
name: "SelectorOrIndex",
|
|
pos: position{line: 118, col: 1, offset: 3094},
|
|
expr: &choiceExpr{
|
|
pos: position{line: 118, col: 20, offset: 3113},
|
|
alternatives: []interface{}{
|
|
&actionExpr{
|
|
pos: position{line: 118, col: 20, offset: 3113},
|
|
run: (*parser).callonSelectorOrIndex2,
|
|
expr: &seqExpr{
|
|
pos: position{line: 118, col: 20, offset: 3113},
|
|
exprs: []interface{}{
|
|
&litMatcher{
|
|
pos: position{line: 118, col: 20, offset: 3113},
|
|
val: ".",
|
|
ignoreCase: false,
|
|
},
|
|
&labeledExpr{
|
|
pos: position{line: 118, col: 24, offset: 3117},
|
|
label: "ident",
|
|
expr: &ruleRefExpr{
|
|
pos: position{line: 118, col: 30, offset: 3123},
|
|
name: "Identifier",
|
|
},
|
|
},
|
|
},
|
|
},
|
|
},
|
|
&actionExpr{
|
|
pos: position{line: 120, col: 5, offset: 3161},
|
|
run: (*parser).callonSelectorOrIndex7,
|
|
expr: &labeledExpr{
|
|
pos: position{line: 120, col: 5, offset: 3161},
|
|
label: "expr",
|
|
expr: &ruleRefExpr{
|
|
pos: position{line: 120, col: 10, offset: 3166},
|
|
name: "IndexExpression",
|
|
},
|
|
},
|
|
},
|
|
},
|
|
},
|
|
},
|
|
{
|
|
name: "IndexExpression",
|
|
displayName: "\"index\"",
|
|
pos: position{line: 124, col: 1, offset: 3207},
|
|
expr: &choiceExpr{
|
|
pos: position{line: 124, col: 28, offset: 3234},
|
|
alternatives: []interface{}{
|
|
&actionExpr{
|
|
pos: position{line: 124, col: 28, offset: 3234},
|
|
run: (*parser).callonIndexExpression2,
|
|
expr: &seqExpr{
|
|
pos: position{line: 124, col: 28, offset: 3234},
|
|
exprs: []interface{}{
|
|
&litMatcher{
|
|
pos: position{line: 124, col: 28, offset: 3234},
|
|
val: "[",
|
|
ignoreCase: false,
|
|
},
|
|
&zeroOrOneExpr{
|
|
pos: position{line: 124, col: 32, offset: 3238},
|
|
expr: &ruleRefExpr{
|
|
pos: position{line: 124, col: 32, offset: 3238},
|
|
name: "_",
|
|
},
|
|
},
|
|
&labeledExpr{
|
|
pos: position{line: 124, col: 35, offset: 3241},
|
|
label: "lit",
|
|
expr: &ruleRefExpr{
|
|
pos: position{line: 124, col: 39, offset: 3245},
|
|
name: "StringLiteral",
|
|
},
|
|
},
|
|
&zeroOrOneExpr{
|
|
pos: position{line: 124, col: 53, offset: 3259},
|
|
expr: &ruleRefExpr{
|
|
pos: position{line: 124, col: 53, offset: 3259},
|
|
name: "_",
|
|
},
|
|
},
|
|
&litMatcher{
|
|
pos: position{line: 124, col: 56, offset: 3262},
|
|
val: "]",
|
|
ignoreCase: false,
|
|
},
|
|
},
|
|
},
|
|
},
|
|
&seqExpr{
|
|
pos: position{line: 126, col: 5, offset: 3291},
|
|
exprs: []interface{}{
|
|
&litMatcher{
|
|
pos: position{line: 126, col: 5, offset: 3291},
|
|
val: "[",
|
|
ignoreCase: false,
|
|
},
|
|
&zeroOrOneExpr{
|
|
pos: position{line: 126, col: 9, offset: 3295},
|
|
expr: &ruleRefExpr{
|
|
pos: position{line: 126, col: 9, offset: 3295},
|
|
name: "_",
|
|
},
|
|
},
|
|
¬Expr{
|
|
pos: position{line: 126, col: 12, offset: 3298},
|
|
expr: &ruleRefExpr{
|
|
pos: position{line: 126, col: 13, offset: 3299},
|
|
name: "StringLiteral",
|
|
},
|
|
},
|
|
&andCodeExpr{
|
|
pos: position{line: 126, col: 27, offset: 3313},
|
|
run: (*parser).callonIndexExpression18,
|
|
},
|
|
},
|
|
},
|
|
&seqExpr{
|
|
pos: position{line: 128, col: 5, offset: 3365},
|
|
exprs: []interface{}{
|
|
&litMatcher{
|
|
pos: position{line: 128, col: 5, offset: 3365},
|
|
val: "[",
|
|
ignoreCase: false,
|
|
},
|
|
&zeroOrOneExpr{
|
|
pos: position{line: 128, col: 9, offset: 3369},
|
|
expr: &ruleRefExpr{
|
|
pos: position{line: 128, col: 9, offset: 3369},
|
|
name: "_",
|
|
},
|
|
},
|
|
&ruleRefExpr{
|
|
pos: position{line: 128, col: 12, offset: 3372},
|
|
name: "StringLiteral",
|
|
},
|
|
&zeroOrOneExpr{
|
|
pos: position{line: 128, col: 26, offset: 3386},
|
|
expr: &ruleRefExpr{
|
|
pos: position{line: 128, col: 26, offset: 3386},
|
|
name: "_",
|
|
},
|
|
},
|
|
¬Expr{
|
|
pos: position{line: 128, col: 29, offset: 3389},
|
|
expr: &litMatcher{
|
|
pos: position{line: 128, col: 30, offset: 3390},
|
|
val: "]",
|
|
ignoreCase: false,
|
|
},
|
|
},
|
|
&andCodeExpr{
|
|
pos: position{line: 128, col: 34, offset: 3394},
|
|
run: (*parser).callonIndexExpression28,
|
|
},
|
|
},
|
|
},
|
|
},
|
|
},
|
|
},
|
|
{
|
|
name: "Value",
|
|
displayName: "\"value\"",
|
|
pos: position{line: 132, col: 1, offset: 3457},
|
|
expr: &choiceExpr{
|
|
pos: position{line: 132, col: 18, offset: 3474},
|
|
alternatives: []interface{}{
|
|
&actionExpr{
|
|
pos: position{line: 132, col: 18, offset: 3474},
|
|
run: (*parser).callonValue2,
|
|
expr: &labeledExpr{
|
|
pos: position{line: 132, col: 18, offset: 3474},
|
|
label: "selector",
|
|
expr: &ruleRefExpr{
|
|
pos: position{line: 132, col: 27, offset: 3483},
|
|
name: "Selector",
|
|
},
|
|
},
|
|
},
|
|
&actionExpr{
|
|
pos: position{line: 133, col: 10, offset: 3573},
|
|
run: (*parser).callonValue5,
|
|
expr: &labeledExpr{
|
|
pos: position{line: 133, col: 10, offset: 3573},
|
|
label: "n",
|
|
expr: &ruleRefExpr{
|
|
pos: position{line: 133, col: 12, offset: 3575},
|
|
name: "NumberLiteral",
|
|
},
|
|
},
|
|
},
|
|
&actionExpr{
|
|
pos: position{line: 134, col: 10, offset: 3643},
|
|
run: (*parser).callonValue8,
|
|
expr: &labeledExpr{
|
|
pos: position{line: 134, col: 10, offset: 3643},
|
|
label: "s",
|
|
expr: &ruleRefExpr{
|
|
pos: position{line: 134, col: 12, offset: 3645},
|
|
name: "StringLiteral",
|
|
},
|
|
},
|
|
},
|
|
},
|
|
},
|
|
},
|
|
{
|
|
name: "NumberLiteral",
|
|
displayName: "\"number\"",
|
|
pos: position{line: 136, col: 1, offset: 3704},
|
|
expr: &choiceExpr{
|
|
pos: position{line: 136, col: 27, offset: 3730},
|
|
alternatives: []interface{}{
|
|
&actionExpr{
|
|
pos: position{line: 136, col: 27, offset: 3730},
|
|
run: (*parser).callonNumberLiteral2,
|
|
expr: &seqExpr{
|
|
pos: position{line: 136, col: 27, offset: 3730},
|
|
exprs: []interface{}{
|
|
&zeroOrOneExpr{
|
|
pos: position{line: 136, col: 27, offset: 3730},
|
|
expr: &litMatcher{
|
|
pos: position{line: 136, col: 27, offset: 3730},
|
|
val: "-",
|
|
ignoreCase: false,
|
|
},
|
|
},
|
|
&ruleRefExpr{
|
|
pos: position{line: 136, col: 32, offset: 3735},
|
|
name: "IntegerOrFloat",
|
|
},
|
|
&andExpr{
|
|
pos: position{line: 136, col: 47, offset: 3750},
|
|
expr: &ruleRefExpr{
|
|
pos: position{line: 136, col: 48, offset: 3751},
|
|
name: "AfterNumbers",
|
|
},
|
|
},
|
|
},
|
|
},
|
|
},
|
|
&seqExpr{
|
|
pos: position{line: 138, col: 5, offset: 3800},
|
|
exprs: []interface{}{
|
|
&zeroOrOneExpr{
|
|
pos: position{line: 138, col: 5, offset: 3800},
|
|
expr: &litMatcher{
|
|
pos: position{line: 138, col: 5, offset: 3800},
|
|
val: "-",
|
|
ignoreCase: false,
|
|
},
|
|
},
|
|
&ruleRefExpr{
|
|
pos: position{line: 138, col: 10, offset: 3805},
|
|
name: "IntegerOrFloat",
|
|
},
|
|
¬Expr{
|
|
pos: position{line: 138, col: 25, offset: 3820},
|
|
expr: &ruleRefExpr{
|
|
pos: position{line: 138, col: 26, offset: 3821},
|
|
name: "AfterNumbers",
|
|
},
|
|
},
|
|
&andCodeExpr{
|
|
pos: position{line: 138, col: 39, offset: 3834},
|
|
run: (*parser).callonNumberLiteral15,
|
|
},
|
|
},
|
|
},
|
|
},
|
|
},
|
|
},
|
|
{
|
|
name: "AfterNumbers",
|
|
pos: position{line: 142, col: 1, offset: 3894},
|
|
expr: &andExpr{
|
|
pos: position{line: 142, col: 17, offset: 3910},
|
|
expr: &choiceExpr{
|
|
pos: position{line: 142, col: 19, offset: 3912},
|
|
alternatives: []interface{}{
|
|
&ruleRefExpr{
|
|
pos: position{line: 142, col: 19, offset: 3912},
|
|
name: "_",
|
|
},
|
|
&ruleRefExpr{
|
|
pos: position{line: 142, col: 23, offset: 3916},
|
|
name: "EOF",
|
|
},
|
|
&litMatcher{
|
|
pos: position{line: 142, col: 29, offset: 3922},
|
|
val: ")",
|
|
ignoreCase: false,
|
|
},
|
|
},
|
|
},
|
|
},
|
|
},
|
|
{
|
|
name: "IntegerOrFloat",
|
|
pos: position{line: 144, col: 1, offset: 3928},
|
|
expr: &seqExpr{
|
|
pos: position{line: 144, col: 19, offset: 3946},
|
|
exprs: []interface{}{
|
|
&choiceExpr{
|
|
pos: position{line: 144, col: 20, offset: 3947},
|
|
alternatives: []interface{}{
|
|
&litMatcher{
|
|
pos: position{line: 144, col: 20, offset: 3947},
|
|
val: "0",
|
|
ignoreCase: false,
|
|
},
|
|
&seqExpr{
|
|
pos: position{line: 144, col: 26, offset: 3953},
|
|
exprs: []interface{}{
|
|
&charClassMatcher{
|
|
pos: position{line: 144, col: 26, offset: 3953},
|
|
val: "[1-9]",
|
|
ranges: []rune{'1', '9'},
|
|
ignoreCase: false,
|
|
inverted: false,
|
|
},
|
|
&zeroOrMoreExpr{
|
|
pos: position{line: 144, col: 31, offset: 3958},
|
|
expr: &charClassMatcher{
|
|
pos: position{line: 144, col: 31, offset: 3958},
|
|
val: "[0-9]",
|
|
ranges: []rune{'0', '9'},
|
|
ignoreCase: false,
|
|
inverted: false,
|
|
},
|
|
},
|
|
},
|
|
},
|
|
},
|
|
},
|
|
&zeroOrOneExpr{
|
|
pos: position{line: 144, col: 39, offset: 3966},
|
|
expr: &seqExpr{
|
|
pos: position{line: 144, col: 40, offset: 3967},
|
|
exprs: []interface{}{
|
|
&litMatcher{
|
|
pos: position{line: 144, col: 40, offset: 3967},
|
|
val: ".",
|
|
ignoreCase: false,
|
|
},
|
|
&oneOrMoreExpr{
|
|
pos: position{line: 144, col: 44, offset: 3971},
|
|
expr: &charClassMatcher{
|
|
pos: position{line: 144, col: 44, offset: 3971},
|
|
val: "[0-9]",
|
|
ranges: []rune{'0', '9'},
|
|
ignoreCase: false,
|
|
inverted: false,
|
|
},
|
|
},
|
|
},
|
|
},
|
|
},
|
|
},
|
|
},
|
|
},
|
|
{
|
|
name: "StringLiteral",
|
|
displayName: "\"string\"",
|
|
pos: position{line: 146, col: 1, offset: 3981},
|
|
expr: &choiceExpr{
|
|
pos: position{line: 146, col: 27, offset: 4007},
|
|
alternatives: []interface{}{
|
|
&actionExpr{
|
|
pos: position{line: 146, col: 27, offset: 4007},
|
|
run: (*parser).callonStringLiteral2,
|
|
expr: &choiceExpr{
|
|
pos: position{line: 146, col: 28, offset: 4008},
|
|
alternatives: []interface{}{
|
|
&seqExpr{
|
|
pos: position{line: 146, col: 28, offset: 4008},
|
|
exprs: []interface{}{
|
|
&litMatcher{
|
|
pos: position{line: 146, col: 28, offset: 4008},
|
|
val: "`",
|
|
ignoreCase: false,
|
|
},
|
|
&zeroOrMoreExpr{
|
|
pos: position{line: 146, col: 32, offset: 4012},
|
|
expr: &ruleRefExpr{
|
|
pos: position{line: 146, col: 32, offset: 4012},
|
|
name: "RawStringChar",
|
|
},
|
|
},
|
|
&litMatcher{
|
|
pos: position{line: 146, col: 47, offset: 4027},
|
|
val: "`",
|
|
ignoreCase: false,
|
|
},
|
|
},
|
|
},
|
|
&seqExpr{
|
|
pos: position{line: 146, col: 53, offset: 4033},
|
|
exprs: []interface{}{
|
|
&litMatcher{
|
|
pos: position{line: 146, col: 53, offset: 4033},
|
|
val: "\"",
|
|
ignoreCase: false,
|
|
},
|
|
&zeroOrMoreExpr{
|
|
pos: position{line: 146, col: 57, offset: 4037},
|
|
expr: &ruleRefExpr{
|
|
pos: position{line: 146, col: 57, offset: 4037},
|
|
name: "DoubleStringChar",
|
|
},
|
|
},
|
|
&litMatcher{
|
|
pos: position{line: 146, col: 75, offset: 4055},
|
|
val: "\"",
|
|
ignoreCase: false,
|
|
},
|
|
},
|
|
},
|
|
},
|
|
},
|
|
},
|
|
&seqExpr{
|
|
pos: position{line: 148, col: 5, offset: 4107},
|
|
exprs: []interface{}{
|
|
&choiceExpr{
|
|
pos: position{line: 148, col: 6, offset: 4108},
|
|
alternatives: []interface{}{
|
|
&seqExpr{
|
|
pos: position{line: 148, col: 6, offset: 4108},
|
|
exprs: []interface{}{
|
|
&litMatcher{
|
|
pos: position{line: 148, col: 6, offset: 4108},
|
|
val: "`",
|
|
ignoreCase: false,
|
|
},
|
|
&zeroOrMoreExpr{
|
|
pos: position{line: 148, col: 10, offset: 4112},
|
|
expr: &ruleRefExpr{
|
|
pos: position{line: 148, col: 10, offset: 4112},
|
|
name: "RawStringChar",
|
|
},
|
|
},
|
|
},
|
|
},
|
|
&seqExpr{
|
|
pos: position{line: 148, col: 27, offset: 4129},
|
|
exprs: []interface{}{
|
|
&litMatcher{
|
|
pos: position{line: 148, col: 27, offset: 4129},
|
|
val: "\"",
|
|
ignoreCase: false,
|
|
},
|
|
&zeroOrMoreExpr{
|
|
pos: position{line: 148, col: 31, offset: 4133},
|
|
expr: &ruleRefExpr{
|
|
pos: position{line: 148, col: 31, offset: 4133},
|
|
name: "DoubleStringChar",
|
|
},
|
|
},
|
|
},
|
|
},
|
|
},
|
|
},
|
|
&ruleRefExpr{
|
|
pos: position{line: 148, col: 50, offset: 4152},
|
|
name: "EOF",
|
|
},
|
|
&andCodeExpr{
|
|
pos: position{line: 148, col: 54, offset: 4156},
|
|
run: (*parser).callonStringLiteral25,
|
|
},
|
|
},
|
|
},
|
|
},
|
|
},
|
|
},
|
|
{
|
|
name: "RawStringChar",
|
|
pos: position{line: 152, col: 1, offset: 4220},
|
|
expr: &seqExpr{
|
|
pos: position{line: 152, col: 18, offset: 4237},
|
|
exprs: []interface{}{
|
|
¬Expr{
|
|
pos: position{line: 152, col: 18, offset: 4237},
|
|
expr: &litMatcher{
|
|
pos: position{line: 152, col: 19, offset: 4238},
|
|
val: "`",
|
|
ignoreCase: false,
|
|
},
|
|
},
|
|
&anyMatcher{
|
|
line: 152, col: 23, offset: 4242,
|
|
},
|
|
},
|
|
},
|
|
},
|
|
{
|
|
name: "DoubleStringChar",
|
|
pos: position{line: 153, col: 1, offset: 4244},
|
|
expr: &seqExpr{
|
|
pos: position{line: 153, col: 21, offset: 4264},
|
|
exprs: []interface{}{
|
|
¬Expr{
|
|
pos: position{line: 153, col: 21, offset: 4264},
|
|
expr: &litMatcher{
|
|
pos: position{line: 153, col: 22, offset: 4265},
|
|
val: "\"",
|
|
ignoreCase: false,
|
|
},
|
|
},
|
|
&anyMatcher{
|
|
line: 153, col: 26, offset: 4269,
|
|
},
|
|
},
|
|
},
|
|
},
|
|
{
|
|
name: "_",
|
|
displayName: "\"whitespace\"",
|
|
pos: position{line: 155, col: 1, offset: 4272},
|
|
expr: &oneOrMoreExpr{
|
|
pos: position{line: 155, col: 19, offset: 4290},
|
|
expr: &charClassMatcher{
|
|
pos: position{line: 155, col: 19, offset: 4290},
|
|
val: "[ \\t\\r\\n]",
|
|
chars: []rune{' ', '\t', '\r', '\n'},
|
|
ignoreCase: false,
|
|
inverted: false,
|
|
},
|
|
},
|
|
},
|
|
{
|
|
name: "EOF",
|
|
pos: position{line: 157, col: 1, offset: 4302},
|
|
expr: ¬Expr{
|
|
pos: position{line: 157, col: 8, offset: 4309},
|
|
expr: &anyMatcher{
|
|
line: 157, col: 9, offset: 4310,
|
|
},
|
|
},
|
|
},
|
|
},
|
|
}
|
|
|
|
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) 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
|
|
}
|