mirror of
https://github.com/opencloud-eu/opencloud.git
synced 2026-05-07 20:15:31 -05:00
d836423a0b
Bumps [github.com/mna/pigeon](https://github.com/mna/pigeon) from 1.2.1 to 1.3.0. - [Release notes](https://github.com/mna/pigeon/releases) - [Changelog](https://github.com/mna/pigeon/blob/master/.goreleaser.yml) - [Commits](https://github.com/mna/pigeon/compare/v1.2.1...v1.3.0) --- updated-dependencies: - dependency-name: github.com/mna/pigeon dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] <support@github.com>
4682 lines
119 KiB
Go
4682 lines
119 KiB
Go
// Code generated by pigeon; DO NOT EDIT.
|
|
|
|
package main
|
|
|
|
import (
|
|
"bytes"
|
|
"errors"
|
|
"fmt"
|
|
"io"
|
|
"math"
|
|
"os"
|
|
"sort"
|
|
"strconv"
|
|
"strings"
|
|
"sync"
|
|
"unicode"
|
|
"unicode/utf8"
|
|
|
|
"github.com/mna/pigeon/ast"
|
|
)
|
|
|
|
var g = &grammar{
|
|
rules: []*rule{
|
|
{
|
|
name: "Grammar",
|
|
pos: position{line: 5, col: 1, offset: 18},
|
|
expr: &actionExpr{
|
|
pos: position{line: 5, col: 11, offset: 30},
|
|
run: (*parser).callonGrammar1,
|
|
expr: &seqExpr{
|
|
pos: position{line: 5, col: 11, offset: 30},
|
|
exprs: []any{
|
|
&ruleRefExpr{
|
|
pos: position{line: 5, col: 11, offset: 30},
|
|
name: "__",
|
|
},
|
|
&labeledExpr{
|
|
pos: position{line: 5, col: 14, offset: 33},
|
|
label: "initializer",
|
|
expr: &zeroOrOneExpr{
|
|
pos: position{line: 5, col: 26, offset: 45},
|
|
expr: &seqExpr{
|
|
pos: position{line: 5, col: 28, offset: 47},
|
|
exprs: []any{
|
|
&ruleRefExpr{
|
|
pos: position{line: 5, col: 28, offset: 47},
|
|
name: "Initializer",
|
|
},
|
|
&ruleRefExpr{
|
|
pos: position{line: 5, col: 40, offset: 59},
|
|
name: "__",
|
|
},
|
|
},
|
|
},
|
|
},
|
|
},
|
|
&labeledExpr{
|
|
pos: position{line: 5, col: 46, offset: 65},
|
|
label: "rules",
|
|
expr: &oneOrMoreExpr{
|
|
pos: position{line: 5, col: 52, offset: 71},
|
|
expr: &seqExpr{
|
|
pos: position{line: 5, col: 54, offset: 73},
|
|
exprs: []any{
|
|
&ruleRefExpr{
|
|
pos: position{line: 5, col: 54, offset: 73},
|
|
name: "Rule",
|
|
},
|
|
&ruleRefExpr{
|
|
pos: position{line: 5, col: 59, offset: 78},
|
|
name: "__",
|
|
},
|
|
},
|
|
},
|
|
},
|
|
},
|
|
&ruleRefExpr{
|
|
pos: position{line: 5, col: 65, offset: 84},
|
|
name: "EOF",
|
|
},
|
|
},
|
|
},
|
|
},
|
|
},
|
|
{
|
|
name: "Initializer",
|
|
pos: position{line: 24, col: 1, offset: 513},
|
|
expr: &actionExpr{
|
|
pos: position{line: 24, col: 15, offset: 529},
|
|
run: (*parser).callonInitializer1,
|
|
expr: &seqExpr{
|
|
pos: position{line: 24, col: 15, offset: 529},
|
|
exprs: []any{
|
|
&labeledExpr{
|
|
pos: position{line: 24, col: 15, offset: 529},
|
|
label: "code",
|
|
expr: &ruleRefExpr{
|
|
pos: position{line: 24, col: 20, offset: 534},
|
|
name: "CodeBlock",
|
|
},
|
|
},
|
|
&ruleRefExpr{
|
|
pos: position{line: 24, col: 30, offset: 544},
|
|
name: "EOS",
|
|
},
|
|
},
|
|
},
|
|
},
|
|
},
|
|
{
|
|
name: "Rule",
|
|
pos: position{line: 28, col: 1, offset: 574},
|
|
expr: &actionExpr{
|
|
pos: position{line: 28, col: 8, offset: 583},
|
|
run: (*parser).callonRule1,
|
|
expr: &seqExpr{
|
|
pos: position{line: 28, col: 8, offset: 583},
|
|
exprs: []any{
|
|
&labeledExpr{
|
|
pos: position{line: 28, col: 8, offset: 583},
|
|
label: "name",
|
|
expr: &ruleRefExpr{
|
|
pos: position{line: 28, col: 13, offset: 588},
|
|
name: "IdentifierName",
|
|
},
|
|
},
|
|
&ruleRefExpr{
|
|
pos: position{line: 28, col: 28, offset: 603},
|
|
name: "__",
|
|
},
|
|
&labeledExpr{
|
|
pos: position{line: 28, col: 31, offset: 606},
|
|
label: "display",
|
|
expr: &zeroOrOneExpr{
|
|
pos: position{line: 28, col: 39, offset: 614},
|
|
expr: &seqExpr{
|
|
pos: position{line: 28, col: 41, offset: 616},
|
|
exprs: []any{
|
|
&ruleRefExpr{
|
|
pos: position{line: 28, col: 41, offset: 616},
|
|
name: "StringLiteral",
|
|
},
|
|
&ruleRefExpr{
|
|
pos: position{line: 28, col: 55, offset: 630},
|
|
name: "__",
|
|
},
|
|
},
|
|
},
|
|
},
|
|
},
|
|
&ruleRefExpr{
|
|
pos: position{line: 28, col: 61, offset: 636},
|
|
name: "RuleDefOp",
|
|
},
|
|
&ruleRefExpr{
|
|
pos: position{line: 28, col: 71, offset: 646},
|
|
name: "__",
|
|
},
|
|
&labeledExpr{
|
|
pos: position{line: 28, col: 74, offset: 649},
|
|
label: "expr",
|
|
expr: &ruleRefExpr{
|
|
pos: position{line: 28, col: 79, offset: 654},
|
|
name: "Expression",
|
|
},
|
|
},
|
|
&ruleRefExpr{
|
|
pos: position{line: 28, col: 90, offset: 665},
|
|
name: "EOS",
|
|
},
|
|
},
|
|
},
|
|
},
|
|
},
|
|
{
|
|
name: "Expression",
|
|
pos: position{line: 41, col: 1, offset: 947},
|
|
expr: &ruleRefExpr{
|
|
pos: position{line: 41, col: 14, offset: 962},
|
|
name: "RecoveryExpr",
|
|
},
|
|
},
|
|
{
|
|
name: "RecoveryExpr",
|
|
pos: position{line: 43, col: 1, offset: 976},
|
|
expr: &actionExpr{
|
|
pos: position{line: 43, col: 16, offset: 993},
|
|
run: (*parser).callonRecoveryExpr1,
|
|
expr: &seqExpr{
|
|
pos: position{line: 43, col: 16, offset: 993},
|
|
exprs: []any{
|
|
&labeledExpr{
|
|
pos: position{line: 43, col: 16, offset: 993},
|
|
label: "expr",
|
|
expr: &ruleRefExpr{
|
|
pos: position{line: 43, col: 21, offset: 998},
|
|
name: "ChoiceExpr",
|
|
},
|
|
},
|
|
&labeledExpr{
|
|
pos: position{line: 43, col: 32, offset: 1009},
|
|
label: "recoverExprs",
|
|
expr: &zeroOrMoreExpr{
|
|
pos: position{line: 43, col: 45, offset: 1022},
|
|
expr: &seqExpr{
|
|
pos: position{line: 43, col: 47, offset: 1024},
|
|
exprs: []any{
|
|
&ruleRefExpr{
|
|
pos: position{line: 43, col: 47, offset: 1024},
|
|
name: "__",
|
|
},
|
|
&litMatcher{
|
|
pos: position{line: 43, col: 50, offset: 1027},
|
|
val: "//{",
|
|
ignoreCase: false,
|
|
want: "\"//{\"",
|
|
},
|
|
&ruleRefExpr{
|
|
pos: position{line: 43, col: 56, offset: 1033},
|
|
name: "__",
|
|
},
|
|
&ruleRefExpr{
|
|
pos: position{line: 43, col: 59, offset: 1036},
|
|
name: "Labels",
|
|
},
|
|
&ruleRefExpr{
|
|
pos: position{line: 43, col: 66, offset: 1043},
|
|
name: "__",
|
|
},
|
|
&litMatcher{
|
|
pos: position{line: 43, col: 69, offset: 1046},
|
|
val: "}",
|
|
ignoreCase: false,
|
|
want: "\"}\"",
|
|
},
|
|
&ruleRefExpr{
|
|
pos: position{line: 43, col: 73, offset: 1050},
|
|
name: "__",
|
|
},
|
|
&ruleRefExpr{
|
|
pos: position{line: 43, col: 76, offset: 1053},
|
|
name: "ChoiceExpr",
|
|
},
|
|
},
|
|
},
|
|
},
|
|
},
|
|
},
|
|
},
|
|
},
|
|
},
|
|
{
|
|
name: "Labels",
|
|
pos: position{line: 58, col: 1, offset: 1449},
|
|
expr: &actionExpr{
|
|
pos: position{line: 58, col: 10, offset: 1460},
|
|
run: (*parser).callonLabels1,
|
|
expr: &seqExpr{
|
|
pos: position{line: 58, col: 10, offset: 1460},
|
|
exprs: []any{
|
|
&labeledExpr{
|
|
pos: position{line: 58, col: 10, offset: 1460},
|
|
label: "label",
|
|
expr: &ruleRefExpr{
|
|
pos: position{line: 58, col: 16, offset: 1466},
|
|
name: "IdentifierName",
|
|
},
|
|
},
|
|
&labeledExpr{
|
|
pos: position{line: 58, col: 31, offset: 1481},
|
|
label: "labels",
|
|
expr: &zeroOrMoreExpr{
|
|
pos: position{line: 58, col: 38, offset: 1488},
|
|
expr: &seqExpr{
|
|
pos: position{line: 58, col: 40, offset: 1490},
|
|
exprs: []any{
|
|
&ruleRefExpr{
|
|
pos: position{line: 58, col: 40, offset: 1490},
|
|
name: "__",
|
|
},
|
|
&litMatcher{
|
|
pos: position{line: 58, col: 43, offset: 1493},
|
|
val: ",",
|
|
ignoreCase: false,
|
|
want: "\",\"",
|
|
},
|
|
&ruleRefExpr{
|
|
pos: position{line: 58, col: 47, offset: 1497},
|
|
name: "__",
|
|
},
|
|
&ruleRefExpr{
|
|
pos: position{line: 58, col: 50, offset: 1500},
|
|
name: "IdentifierName",
|
|
},
|
|
},
|
|
},
|
|
},
|
|
},
|
|
},
|
|
},
|
|
},
|
|
},
|
|
{
|
|
name: "ChoiceExpr",
|
|
pos: position{line: 67, col: 1, offset: 1819},
|
|
expr: &actionExpr{
|
|
pos: position{line: 67, col: 14, offset: 1834},
|
|
run: (*parser).callonChoiceExpr1,
|
|
expr: &seqExpr{
|
|
pos: position{line: 67, col: 14, offset: 1834},
|
|
exprs: []any{
|
|
&labeledExpr{
|
|
pos: position{line: 67, col: 14, offset: 1834},
|
|
label: "first",
|
|
expr: &ruleRefExpr{
|
|
pos: position{line: 67, col: 20, offset: 1840},
|
|
name: "ActionExpr",
|
|
},
|
|
},
|
|
&labeledExpr{
|
|
pos: position{line: 67, col: 31, offset: 1851},
|
|
label: "rest",
|
|
expr: &zeroOrMoreExpr{
|
|
pos: position{line: 67, col: 36, offset: 1856},
|
|
expr: &seqExpr{
|
|
pos: position{line: 67, col: 38, offset: 1858},
|
|
exprs: []any{
|
|
&ruleRefExpr{
|
|
pos: position{line: 67, col: 38, offset: 1858},
|
|
name: "__",
|
|
},
|
|
&litMatcher{
|
|
pos: position{line: 67, col: 41, offset: 1861},
|
|
val: "/",
|
|
ignoreCase: false,
|
|
want: "\"/\"",
|
|
},
|
|
&ruleRefExpr{
|
|
pos: position{line: 67, col: 45, offset: 1865},
|
|
name: "__",
|
|
},
|
|
&ruleRefExpr{
|
|
pos: position{line: 67, col: 48, offset: 1868},
|
|
name: "ActionExpr",
|
|
},
|
|
},
|
|
},
|
|
},
|
|
},
|
|
},
|
|
},
|
|
},
|
|
},
|
|
{
|
|
name: "ActionExpr",
|
|
pos: position{line: 82, col: 1, offset: 2263},
|
|
expr: &actionExpr{
|
|
pos: position{line: 82, col: 14, offset: 2278},
|
|
run: (*parser).callonActionExpr1,
|
|
expr: &seqExpr{
|
|
pos: position{line: 82, col: 14, offset: 2278},
|
|
exprs: []any{
|
|
&labeledExpr{
|
|
pos: position{line: 82, col: 14, offset: 2278},
|
|
label: "expr",
|
|
expr: &ruleRefExpr{
|
|
pos: position{line: 82, col: 19, offset: 2283},
|
|
name: "SeqExpr",
|
|
},
|
|
},
|
|
&labeledExpr{
|
|
pos: position{line: 82, col: 27, offset: 2291},
|
|
label: "code",
|
|
expr: &zeroOrOneExpr{
|
|
pos: position{line: 82, col: 32, offset: 2296},
|
|
expr: &seqExpr{
|
|
pos: position{line: 82, col: 34, offset: 2298},
|
|
exprs: []any{
|
|
&ruleRefExpr{
|
|
pos: position{line: 82, col: 34, offset: 2298},
|
|
name: "__",
|
|
},
|
|
&ruleRefExpr{
|
|
pos: position{line: 82, col: 37, offset: 2301},
|
|
name: "CodeBlock",
|
|
},
|
|
},
|
|
},
|
|
},
|
|
},
|
|
},
|
|
},
|
|
},
|
|
},
|
|
{
|
|
name: "SeqExpr",
|
|
pos: position{line: 96, col: 1, offset: 2565},
|
|
expr: &actionExpr{
|
|
pos: position{line: 96, col: 11, offset: 2577},
|
|
run: (*parser).callonSeqExpr1,
|
|
expr: &seqExpr{
|
|
pos: position{line: 96, col: 11, offset: 2577},
|
|
exprs: []any{
|
|
&labeledExpr{
|
|
pos: position{line: 96, col: 11, offset: 2577},
|
|
label: "first",
|
|
expr: &ruleRefExpr{
|
|
pos: position{line: 96, col: 17, offset: 2583},
|
|
name: "LabeledExpr",
|
|
},
|
|
},
|
|
&labeledExpr{
|
|
pos: position{line: 96, col: 29, offset: 2595},
|
|
label: "rest",
|
|
expr: &zeroOrMoreExpr{
|
|
pos: position{line: 96, col: 34, offset: 2600},
|
|
expr: &seqExpr{
|
|
pos: position{line: 96, col: 36, offset: 2602},
|
|
exprs: []any{
|
|
&ruleRefExpr{
|
|
pos: position{line: 96, col: 36, offset: 2602},
|
|
name: "__",
|
|
},
|
|
&ruleRefExpr{
|
|
pos: position{line: 96, col: 39, offset: 2605},
|
|
name: "LabeledExpr",
|
|
},
|
|
},
|
|
},
|
|
},
|
|
},
|
|
},
|
|
},
|
|
},
|
|
},
|
|
{
|
|
name: "LabeledExpr",
|
|
pos: position{line: 109, col: 1, offset: 2946},
|
|
expr: &choiceExpr{
|
|
pos: position{line: 109, col: 15, offset: 2962},
|
|
alternatives: []any{
|
|
&actionExpr{
|
|
pos: position{line: 109, col: 15, offset: 2962},
|
|
run: (*parser).callonLabeledExpr2,
|
|
expr: &seqExpr{
|
|
pos: position{line: 109, col: 15, offset: 2962},
|
|
exprs: []any{
|
|
&labeledExpr{
|
|
pos: position{line: 109, col: 15, offset: 2962},
|
|
label: "label",
|
|
expr: &ruleRefExpr{
|
|
pos: position{line: 109, col: 21, offset: 2968},
|
|
name: "Identifier",
|
|
},
|
|
},
|
|
&ruleRefExpr{
|
|
pos: position{line: 109, col: 32, offset: 2979},
|
|
name: "__",
|
|
},
|
|
&litMatcher{
|
|
pos: position{line: 109, col: 35, offset: 2982},
|
|
val: ":",
|
|
ignoreCase: false,
|
|
want: "\":\"",
|
|
},
|
|
&ruleRefExpr{
|
|
pos: position{line: 109, col: 39, offset: 2986},
|
|
name: "__",
|
|
},
|
|
&labeledExpr{
|
|
pos: position{line: 109, col: 42, offset: 2989},
|
|
label: "expr",
|
|
expr: &ruleRefExpr{
|
|
pos: position{line: 109, col: 47, offset: 2994},
|
|
name: "PrefixedExpr",
|
|
},
|
|
},
|
|
},
|
|
},
|
|
},
|
|
&ruleRefExpr{
|
|
pos: position{line: 115, col: 5, offset: 3167},
|
|
name: "PrefixedExpr",
|
|
},
|
|
&ruleRefExpr{
|
|
pos: position{line: 115, col: 20, offset: 3182},
|
|
name: "ThrowExpr",
|
|
},
|
|
},
|
|
},
|
|
},
|
|
{
|
|
name: "PrefixedExpr",
|
|
pos: position{line: 117, col: 1, offset: 3193},
|
|
expr: &choiceExpr{
|
|
pos: position{line: 117, col: 16, offset: 3210},
|
|
alternatives: []any{
|
|
&actionExpr{
|
|
pos: position{line: 117, col: 16, offset: 3210},
|
|
run: (*parser).callonPrefixedExpr2,
|
|
expr: &seqExpr{
|
|
pos: position{line: 117, col: 16, offset: 3210},
|
|
exprs: []any{
|
|
&labeledExpr{
|
|
pos: position{line: 117, col: 16, offset: 3210},
|
|
label: "op",
|
|
expr: &ruleRefExpr{
|
|
pos: position{line: 117, col: 19, offset: 3213},
|
|
name: "PrefixedOp",
|
|
},
|
|
},
|
|
&ruleRefExpr{
|
|
pos: position{line: 117, col: 30, offset: 3224},
|
|
name: "__",
|
|
},
|
|
&labeledExpr{
|
|
pos: position{line: 117, col: 33, offset: 3227},
|
|
label: "expr",
|
|
expr: &ruleRefExpr{
|
|
pos: position{line: 117, col: 38, offset: 3232},
|
|
name: "SuffixedExpr",
|
|
},
|
|
},
|
|
},
|
|
},
|
|
},
|
|
&ruleRefExpr{
|
|
pos: position{line: 128, col: 5, offset: 3514},
|
|
name: "SuffixedExpr",
|
|
},
|
|
},
|
|
},
|
|
},
|
|
{
|
|
name: "PrefixedOp",
|
|
pos: position{line: 130, col: 1, offset: 3528},
|
|
expr: &actionExpr{
|
|
pos: position{line: 130, col: 14, offset: 3543},
|
|
run: (*parser).callonPrefixedOp1,
|
|
expr: &choiceExpr{
|
|
pos: position{line: 130, col: 16, offset: 3545},
|
|
alternatives: []any{
|
|
&litMatcher{
|
|
pos: position{line: 130, col: 16, offset: 3545},
|
|
val: "&",
|
|
ignoreCase: false,
|
|
want: "\"&\"",
|
|
},
|
|
&litMatcher{
|
|
pos: position{line: 130, col: 22, offset: 3551},
|
|
val: "!",
|
|
ignoreCase: false,
|
|
want: "\"!\"",
|
|
},
|
|
},
|
|
},
|
|
},
|
|
},
|
|
{
|
|
name: "SuffixedExpr",
|
|
pos: position{line: 134, col: 1, offset: 3593},
|
|
expr: &choiceExpr{
|
|
pos: position{line: 134, col: 16, offset: 3610},
|
|
alternatives: []any{
|
|
&actionExpr{
|
|
pos: position{line: 134, col: 16, offset: 3610},
|
|
run: (*parser).callonSuffixedExpr2,
|
|
expr: &seqExpr{
|
|
pos: position{line: 134, col: 16, offset: 3610},
|
|
exprs: []any{
|
|
&labeledExpr{
|
|
pos: position{line: 134, col: 16, offset: 3610},
|
|
label: "expr",
|
|
expr: &ruleRefExpr{
|
|
pos: position{line: 134, col: 21, offset: 3615},
|
|
name: "PrimaryExpr",
|
|
},
|
|
},
|
|
&ruleRefExpr{
|
|
pos: position{line: 134, col: 33, offset: 3627},
|
|
name: "__",
|
|
},
|
|
&labeledExpr{
|
|
pos: position{line: 134, col: 36, offset: 3630},
|
|
label: "op",
|
|
expr: &ruleRefExpr{
|
|
pos: position{line: 134, col: 39, offset: 3633},
|
|
name: "SuffixedOp",
|
|
},
|
|
},
|
|
},
|
|
},
|
|
},
|
|
&ruleRefExpr{
|
|
pos: position{line: 153, col: 5, offset: 4163},
|
|
name: "PrimaryExpr",
|
|
},
|
|
},
|
|
},
|
|
},
|
|
{
|
|
name: "SuffixedOp",
|
|
pos: position{line: 155, col: 1, offset: 4176},
|
|
expr: &actionExpr{
|
|
pos: position{line: 155, col: 14, offset: 4191},
|
|
run: (*parser).callonSuffixedOp1,
|
|
expr: &choiceExpr{
|
|
pos: position{line: 155, col: 16, offset: 4193},
|
|
alternatives: []any{
|
|
&litMatcher{
|
|
pos: position{line: 155, col: 16, offset: 4193},
|
|
val: "?",
|
|
ignoreCase: false,
|
|
want: "\"?\"",
|
|
},
|
|
&litMatcher{
|
|
pos: position{line: 155, col: 22, offset: 4199},
|
|
val: "*",
|
|
ignoreCase: false,
|
|
want: "\"*\"",
|
|
},
|
|
&litMatcher{
|
|
pos: position{line: 155, col: 28, offset: 4205},
|
|
val: "+",
|
|
ignoreCase: false,
|
|
want: "\"+\"",
|
|
},
|
|
},
|
|
},
|
|
},
|
|
},
|
|
{
|
|
name: "PrimaryExpr",
|
|
pos: position{line: 159, col: 1, offset: 4247},
|
|
expr: &choiceExpr{
|
|
pos: position{line: 159, col: 15, offset: 4263},
|
|
alternatives: []any{
|
|
&ruleRefExpr{
|
|
pos: position{line: 159, col: 15, offset: 4263},
|
|
name: "LitMatcher",
|
|
},
|
|
&ruleRefExpr{
|
|
pos: position{line: 159, col: 28, offset: 4276},
|
|
name: "CharClassMatcher",
|
|
},
|
|
&ruleRefExpr{
|
|
pos: position{line: 159, col: 47, offset: 4295},
|
|
name: "AnyMatcher",
|
|
},
|
|
&ruleRefExpr{
|
|
pos: position{line: 159, col: 60, offset: 4308},
|
|
name: "RuleRefExpr",
|
|
},
|
|
&ruleRefExpr{
|
|
pos: position{line: 159, col: 74, offset: 4322},
|
|
name: "SemanticPredExpr",
|
|
},
|
|
&actionExpr{
|
|
pos: position{line: 159, col: 93, offset: 4341},
|
|
run: (*parser).callonPrimaryExpr7,
|
|
expr: &seqExpr{
|
|
pos: position{line: 159, col: 93, offset: 4341},
|
|
exprs: []any{
|
|
&litMatcher{
|
|
pos: position{line: 159, col: 93, offset: 4341},
|
|
val: "(",
|
|
ignoreCase: false,
|
|
want: "\"(\"",
|
|
},
|
|
&ruleRefExpr{
|
|
pos: position{line: 159, col: 97, offset: 4345},
|
|
name: "__",
|
|
},
|
|
&labeledExpr{
|
|
pos: position{line: 159, col: 100, offset: 4348},
|
|
label: "expr",
|
|
expr: &ruleRefExpr{
|
|
pos: position{line: 159, col: 105, offset: 4353},
|
|
name: "Expression",
|
|
},
|
|
},
|
|
&ruleRefExpr{
|
|
pos: position{line: 159, col: 116, offset: 4364},
|
|
name: "__",
|
|
},
|
|
&litMatcher{
|
|
pos: position{line: 159, col: 119, offset: 4367},
|
|
val: ")",
|
|
ignoreCase: false,
|
|
want: "\")\"",
|
|
},
|
|
},
|
|
},
|
|
},
|
|
},
|
|
},
|
|
},
|
|
{
|
|
name: "RuleRefExpr",
|
|
pos: position{line: 162, col: 1, offset: 4396},
|
|
expr: &actionExpr{
|
|
pos: position{line: 162, col: 15, offset: 4412},
|
|
run: (*parser).callonRuleRefExpr1,
|
|
expr: &seqExpr{
|
|
pos: position{line: 162, col: 15, offset: 4412},
|
|
exprs: []any{
|
|
&labeledExpr{
|
|
pos: position{line: 162, col: 15, offset: 4412},
|
|
label: "name",
|
|
expr: &ruleRefExpr{
|
|
pos: position{line: 162, col: 20, offset: 4417},
|
|
name: "IdentifierName",
|
|
},
|
|
},
|
|
¬Expr{
|
|
pos: position{line: 162, col: 35, offset: 4432},
|
|
expr: &seqExpr{
|
|
pos: position{line: 162, col: 38, offset: 4435},
|
|
exprs: []any{
|
|
&ruleRefExpr{
|
|
pos: position{line: 162, col: 38, offset: 4435},
|
|
name: "__",
|
|
},
|
|
&zeroOrOneExpr{
|
|
pos: position{line: 162, col: 41, offset: 4438},
|
|
expr: &seqExpr{
|
|
pos: position{line: 162, col: 43, offset: 4440},
|
|
exprs: []any{
|
|
&ruleRefExpr{
|
|
pos: position{line: 162, col: 43, offset: 4440},
|
|
name: "StringLiteral",
|
|
},
|
|
&ruleRefExpr{
|
|
pos: position{line: 162, col: 57, offset: 4454},
|
|
name: "__",
|
|
},
|
|
},
|
|
},
|
|
},
|
|
&ruleRefExpr{
|
|
pos: position{line: 162, col: 63, offset: 4460},
|
|
name: "RuleDefOp",
|
|
},
|
|
},
|
|
},
|
|
},
|
|
},
|
|
},
|
|
},
|
|
},
|
|
{
|
|
name: "SemanticPredExpr",
|
|
pos: position{line: 167, col: 1, offset: 4576},
|
|
expr: &actionExpr{
|
|
pos: position{line: 167, col: 20, offset: 4597},
|
|
run: (*parser).callonSemanticPredExpr1,
|
|
expr: &seqExpr{
|
|
pos: position{line: 167, col: 20, offset: 4597},
|
|
exprs: []any{
|
|
&labeledExpr{
|
|
pos: position{line: 167, col: 20, offset: 4597},
|
|
label: "op",
|
|
expr: &ruleRefExpr{
|
|
pos: position{line: 167, col: 23, offset: 4600},
|
|
name: "SemanticPredOp",
|
|
},
|
|
},
|
|
&ruleRefExpr{
|
|
pos: position{line: 167, col: 38, offset: 4615},
|
|
name: "__",
|
|
},
|
|
&labeledExpr{
|
|
pos: position{line: 167, col: 41, offset: 4618},
|
|
label: "code",
|
|
expr: &ruleRefExpr{
|
|
pos: position{line: 167, col: 46, offset: 4623},
|
|
name: "CodeBlock",
|
|
},
|
|
},
|
|
},
|
|
},
|
|
},
|
|
},
|
|
{
|
|
name: "SemanticPredOp",
|
|
pos: position{line: 187, col: 1, offset: 5070},
|
|
expr: &actionExpr{
|
|
pos: position{line: 187, col: 18, offset: 5089},
|
|
run: (*parser).callonSemanticPredOp1,
|
|
expr: &choiceExpr{
|
|
pos: position{line: 187, col: 20, offset: 5091},
|
|
alternatives: []any{
|
|
&litMatcher{
|
|
pos: position{line: 187, col: 20, offset: 5091},
|
|
val: "#",
|
|
ignoreCase: false,
|
|
want: "\"#\"",
|
|
},
|
|
&litMatcher{
|
|
pos: position{line: 187, col: 26, offset: 5097},
|
|
val: "&",
|
|
ignoreCase: false,
|
|
want: "\"&\"",
|
|
},
|
|
&litMatcher{
|
|
pos: position{line: 187, col: 32, offset: 5103},
|
|
val: "!",
|
|
ignoreCase: false,
|
|
want: "\"!\"",
|
|
},
|
|
},
|
|
},
|
|
},
|
|
},
|
|
{
|
|
name: "RuleDefOp",
|
|
pos: position{line: 191, col: 1, offset: 5145},
|
|
expr: &choiceExpr{
|
|
pos: position{line: 191, col: 13, offset: 5159},
|
|
alternatives: []any{
|
|
&litMatcher{
|
|
pos: position{line: 191, col: 13, offset: 5159},
|
|
val: "=",
|
|
ignoreCase: false,
|
|
want: "\"=\"",
|
|
},
|
|
&litMatcher{
|
|
pos: position{line: 191, col: 19, offset: 5165},
|
|
val: "<-",
|
|
ignoreCase: false,
|
|
want: "\"<-\"",
|
|
},
|
|
&litMatcher{
|
|
pos: position{line: 191, col: 26, offset: 5172},
|
|
val: "←",
|
|
ignoreCase: false,
|
|
want: "\"←\"",
|
|
},
|
|
&litMatcher{
|
|
pos: position{line: 191, col: 37, offset: 5183},
|
|
val: "⟵",
|
|
ignoreCase: false,
|
|
want: "\"⟵\"",
|
|
},
|
|
},
|
|
},
|
|
},
|
|
{
|
|
name: "SourceChar",
|
|
pos: position{line: 193, col: 1, offset: 5193},
|
|
expr: &anyMatcher{
|
|
line: 193, col: 14, offset: 5208,
|
|
},
|
|
},
|
|
{
|
|
name: "Comment",
|
|
pos: position{line: 194, col: 1, offset: 5210},
|
|
expr: &choiceExpr{
|
|
pos: position{line: 194, col: 11, offset: 5222},
|
|
alternatives: []any{
|
|
&ruleRefExpr{
|
|
pos: position{line: 194, col: 11, offset: 5222},
|
|
name: "MultiLineComment",
|
|
},
|
|
&ruleRefExpr{
|
|
pos: position{line: 194, col: 30, offset: 5241},
|
|
name: "SingleLineComment",
|
|
},
|
|
},
|
|
},
|
|
},
|
|
{
|
|
name: "MultiLineComment",
|
|
pos: position{line: 195, col: 1, offset: 5259},
|
|
expr: &seqExpr{
|
|
pos: position{line: 195, col: 20, offset: 5280},
|
|
exprs: []any{
|
|
&litMatcher{
|
|
pos: position{line: 195, col: 20, offset: 5280},
|
|
val: "/*",
|
|
ignoreCase: false,
|
|
want: "\"/*\"",
|
|
},
|
|
&zeroOrMoreExpr{
|
|
pos: position{line: 195, col: 25, offset: 5285},
|
|
expr: &seqExpr{
|
|
pos: position{line: 195, col: 27, offset: 5287},
|
|
exprs: []any{
|
|
¬Expr{
|
|
pos: position{line: 195, col: 27, offset: 5287},
|
|
expr: &litMatcher{
|
|
pos: position{line: 195, col: 28, offset: 5288},
|
|
val: "*/",
|
|
ignoreCase: false,
|
|
want: "\"*/\"",
|
|
},
|
|
},
|
|
&ruleRefExpr{
|
|
pos: position{line: 195, col: 33, offset: 5293},
|
|
name: "SourceChar",
|
|
},
|
|
},
|
|
},
|
|
},
|
|
&litMatcher{
|
|
pos: position{line: 195, col: 47, offset: 5307},
|
|
val: "*/",
|
|
ignoreCase: false,
|
|
want: "\"*/\"",
|
|
},
|
|
},
|
|
},
|
|
},
|
|
{
|
|
name: "MultiLineCommentNoLineTerminator",
|
|
pos: position{line: 196, col: 1, offset: 5312},
|
|
expr: &seqExpr{
|
|
pos: position{line: 196, col: 36, offset: 5349},
|
|
exprs: []any{
|
|
&litMatcher{
|
|
pos: position{line: 196, col: 36, offset: 5349},
|
|
val: "/*",
|
|
ignoreCase: false,
|
|
want: "\"/*\"",
|
|
},
|
|
&zeroOrMoreExpr{
|
|
pos: position{line: 196, col: 41, offset: 5354},
|
|
expr: &seqExpr{
|
|
pos: position{line: 196, col: 43, offset: 5356},
|
|
exprs: []any{
|
|
¬Expr{
|
|
pos: position{line: 196, col: 43, offset: 5356},
|
|
expr: &choiceExpr{
|
|
pos: position{line: 196, col: 46, offset: 5359},
|
|
alternatives: []any{
|
|
&litMatcher{
|
|
pos: position{line: 196, col: 46, offset: 5359},
|
|
val: "*/",
|
|
ignoreCase: false,
|
|
want: "\"*/\"",
|
|
},
|
|
&ruleRefExpr{
|
|
pos: position{line: 196, col: 53, offset: 5366},
|
|
name: "EOL",
|
|
},
|
|
},
|
|
},
|
|
},
|
|
&ruleRefExpr{
|
|
pos: position{line: 196, col: 59, offset: 5372},
|
|
name: "SourceChar",
|
|
},
|
|
},
|
|
},
|
|
},
|
|
&litMatcher{
|
|
pos: position{line: 196, col: 73, offset: 5386},
|
|
val: "*/",
|
|
ignoreCase: false,
|
|
want: "\"*/\"",
|
|
},
|
|
},
|
|
},
|
|
},
|
|
{
|
|
name: "SingleLineComment",
|
|
pos: position{line: 197, col: 1, offset: 5391},
|
|
expr: &seqExpr{
|
|
pos: position{line: 197, col: 21, offset: 5413},
|
|
exprs: []any{
|
|
¬Expr{
|
|
pos: position{line: 197, col: 21, offset: 5413},
|
|
expr: &litMatcher{
|
|
pos: position{line: 197, col: 23, offset: 5415},
|
|
val: "//{",
|
|
ignoreCase: false,
|
|
want: "\"//{\"",
|
|
},
|
|
},
|
|
&litMatcher{
|
|
pos: position{line: 197, col: 30, offset: 5422},
|
|
val: "//",
|
|
ignoreCase: false,
|
|
want: "\"//\"",
|
|
},
|
|
&zeroOrMoreExpr{
|
|
pos: position{line: 197, col: 35, offset: 5427},
|
|
expr: &seqExpr{
|
|
pos: position{line: 197, col: 37, offset: 5429},
|
|
exprs: []any{
|
|
¬Expr{
|
|
pos: position{line: 197, col: 37, offset: 5429},
|
|
expr: &ruleRefExpr{
|
|
pos: position{line: 197, col: 38, offset: 5430},
|
|
name: "EOL",
|
|
},
|
|
},
|
|
&ruleRefExpr{
|
|
pos: position{line: 197, col: 42, offset: 5434},
|
|
name: "SourceChar",
|
|
},
|
|
},
|
|
},
|
|
},
|
|
},
|
|
},
|
|
},
|
|
{
|
|
name: "Identifier",
|
|
pos: position{line: 199, col: 1, offset: 5449},
|
|
expr: &actionExpr{
|
|
pos: position{line: 199, col: 14, offset: 5464},
|
|
run: (*parser).callonIdentifier1,
|
|
expr: &labeledExpr{
|
|
pos: position{line: 199, col: 14, offset: 5464},
|
|
label: "ident",
|
|
expr: &ruleRefExpr{
|
|
pos: position{line: 199, col: 20, offset: 5470},
|
|
name: "IdentifierName",
|
|
},
|
|
},
|
|
},
|
|
},
|
|
{
|
|
name: "IdentifierName",
|
|
pos: position{line: 207, col: 1, offset: 5689},
|
|
expr: &actionExpr{
|
|
pos: position{line: 207, col: 18, offset: 5708},
|
|
run: (*parser).callonIdentifierName1,
|
|
expr: &seqExpr{
|
|
pos: position{line: 207, col: 18, offset: 5708},
|
|
exprs: []any{
|
|
&ruleRefExpr{
|
|
pos: position{line: 207, col: 18, offset: 5708},
|
|
name: "IdentifierStart",
|
|
},
|
|
&zeroOrMoreExpr{
|
|
pos: position{line: 207, col: 34, offset: 5724},
|
|
expr: &ruleRefExpr{
|
|
pos: position{line: 207, col: 34, offset: 5724},
|
|
name: "IdentifierPart",
|
|
},
|
|
},
|
|
},
|
|
},
|
|
},
|
|
},
|
|
{
|
|
name: "IdentifierStart",
|
|
pos: position{line: 210, col: 1, offset: 5806},
|
|
expr: &charClassMatcher{
|
|
pos: position{line: 210, col: 19, offset: 5826},
|
|
val: "[\\pL_]",
|
|
chars: []rune{'_'},
|
|
classes: []*unicode.RangeTable{rangeTable("L")},
|
|
ignoreCase: false,
|
|
inverted: false,
|
|
},
|
|
},
|
|
{
|
|
name: "IdentifierPart",
|
|
pos: position{line: 211, col: 1, offset: 5833},
|
|
expr: &choiceExpr{
|
|
pos: position{line: 211, col: 18, offset: 5852},
|
|
alternatives: []any{
|
|
&ruleRefExpr{
|
|
pos: position{line: 211, col: 18, offset: 5852},
|
|
name: "IdentifierStart",
|
|
},
|
|
&charClassMatcher{
|
|
pos: position{line: 211, col: 36, offset: 5870},
|
|
val: "[\\p{Nd}]",
|
|
classes: []*unicode.RangeTable{rangeTable("Nd")},
|
|
ignoreCase: false,
|
|
inverted: false,
|
|
},
|
|
},
|
|
},
|
|
},
|
|
{
|
|
name: "LitMatcher",
|
|
pos: position{line: 213, col: 1, offset: 5880},
|
|
expr: &actionExpr{
|
|
pos: position{line: 213, col: 14, offset: 5895},
|
|
run: (*parser).callonLitMatcher1,
|
|
expr: &seqExpr{
|
|
pos: position{line: 213, col: 14, offset: 5895},
|
|
exprs: []any{
|
|
&labeledExpr{
|
|
pos: position{line: 213, col: 14, offset: 5895},
|
|
label: "lit",
|
|
expr: &ruleRefExpr{
|
|
pos: position{line: 213, col: 18, offset: 5899},
|
|
name: "StringLiteral",
|
|
},
|
|
},
|
|
&labeledExpr{
|
|
pos: position{line: 213, col: 32, offset: 5913},
|
|
label: "ignore",
|
|
expr: &zeroOrOneExpr{
|
|
pos: position{line: 213, col: 39, offset: 5920},
|
|
expr: &litMatcher{
|
|
pos: position{line: 213, col: 39, offset: 5920},
|
|
val: "i",
|
|
ignoreCase: false,
|
|
want: "\"i\"",
|
|
},
|
|
},
|
|
},
|
|
},
|
|
},
|
|
},
|
|
},
|
|
{
|
|
name: "StringLiteral",
|
|
pos: position{line: 226, col: 1, offset: 6319},
|
|
expr: &choiceExpr{
|
|
pos: position{line: 226, col: 17, offset: 6337},
|
|
alternatives: []any{
|
|
&actionExpr{
|
|
pos: position{line: 226, col: 17, offset: 6337},
|
|
run: (*parser).callonStringLiteral2,
|
|
expr: &choiceExpr{
|
|
pos: position{line: 226, col: 19, offset: 6339},
|
|
alternatives: []any{
|
|
&seqExpr{
|
|
pos: position{line: 226, col: 19, offset: 6339},
|
|
exprs: []any{
|
|
&litMatcher{
|
|
pos: position{line: 226, col: 19, offset: 6339},
|
|
val: "\"",
|
|
ignoreCase: false,
|
|
want: "\"\\\"\"",
|
|
},
|
|
&zeroOrMoreExpr{
|
|
pos: position{line: 226, col: 23, offset: 6343},
|
|
expr: &ruleRefExpr{
|
|
pos: position{line: 226, col: 23, offset: 6343},
|
|
name: "DoubleStringChar",
|
|
},
|
|
},
|
|
&litMatcher{
|
|
pos: position{line: 226, col: 41, offset: 6361},
|
|
val: "\"",
|
|
ignoreCase: false,
|
|
want: "\"\\\"\"",
|
|
},
|
|
},
|
|
},
|
|
&seqExpr{
|
|
pos: position{line: 226, col: 47, offset: 6367},
|
|
exprs: []any{
|
|
&litMatcher{
|
|
pos: position{line: 226, col: 47, offset: 6367},
|
|
val: "'",
|
|
ignoreCase: false,
|
|
want: "\"'\"",
|
|
},
|
|
&ruleRefExpr{
|
|
pos: position{line: 226, col: 51, offset: 6371},
|
|
name: "SingleStringChar",
|
|
},
|
|
&litMatcher{
|
|
pos: position{line: 226, col: 68, offset: 6388},
|
|
val: "'",
|
|
ignoreCase: false,
|
|
want: "\"'\"",
|
|
},
|
|
},
|
|
},
|
|
&seqExpr{
|
|
pos: position{line: 226, col: 74, offset: 6394},
|
|
exprs: []any{
|
|
&litMatcher{
|
|
pos: position{line: 226, col: 74, offset: 6394},
|
|
val: "`",
|
|
ignoreCase: false,
|
|
want: "\"`\"",
|
|
},
|
|
&zeroOrMoreExpr{
|
|
pos: position{line: 226, col: 78, offset: 6398},
|
|
expr: &ruleRefExpr{
|
|
pos: position{line: 226, col: 78, offset: 6398},
|
|
name: "RawStringChar",
|
|
},
|
|
},
|
|
&litMatcher{
|
|
pos: position{line: 226, col: 93, offset: 6413},
|
|
val: "`",
|
|
ignoreCase: false,
|
|
want: "\"`\"",
|
|
},
|
|
},
|
|
},
|
|
},
|
|
},
|
|
},
|
|
&actionExpr{
|
|
pos: position{line: 228, col: 5, offset: 6486},
|
|
run: (*parser).callonStringLiteral18,
|
|
expr: &choiceExpr{
|
|
pos: position{line: 228, col: 7, offset: 6488},
|
|
alternatives: []any{
|
|
&seqExpr{
|
|
pos: position{line: 228, col: 9, offset: 6490},
|
|
exprs: []any{
|
|
&litMatcher{
|
|
pos: position{line: 228, col: 9, offset: 6490},
|
|
val: "\"",
|
|
ignoreCase: false,
|
|
want: "\"\\\"\"",
|
|
},
|
|
&zeroOrMoreExpr{
|
|
pos: position{line: 228, col: 13, offset: 6494},
|
|
expr: &ruleRefExpr{
|
|
pos: position{line: 228, col: 13, offset: 6494},
|
|
name: "DoubleStringChar",
|
|
},
|
|
},
|
|
&choiceExpr{
|
|
pos: position{line: 228, col: 33, offset: 6514},
|
|
alternatives: []any{
|
|
&ruleRefExpr{
|
|
pos: position{line: 228, col: 33, offset: 6514},
|
|
name: "EOL",
|
|
},
|
|
&ruleRefExpr{
|
|
pos: position{line: 228, col: 39, offset: 6520},
|
|
name: "EOF",
|
|
},
|
|
},
|
|
},
|
|
},
|
|
},
|
|
&seqExpr{
|
|
pos: position{line: 228, col: 51, offset: 6532},
|
|
exprs: []any{
|
|
&litMatcher{
|
|
pos: position{line: 228, col: 51, offset: 6532},
|
|
val: "'",
|
|
ignoreCase: false,
|
|
want: "\"'\"",
|
|
},
|
|
&zeroOrOneExpr{
|
|
pos: position{line: 228, col: 55, offset: 6536},
|
|
expr: &ruleRefExpr{
|
|
pos: position{line: 228, col: 55, offset: 6536},
|
|
name: "SingleStringChar",
|
|
},
|
|
},
|
|
&choiceExpr{
|
|
pos: position{line: 228, col: 75, offset: 6556},
|
|
alternatives: []any{
|
|
&ruleRefExpr{
|
|
pos: position{line: 228, col: 75, offset: 6556},
|
|
name: "EOL",
|
|
},
|
|
&ruleRefExpr{
|
|
pos: position{line: 228, col: 81, offset: 6562},
|
|
name: "EOF",
|
|
},
|
|
},
|
|
},
|
|
},
|
|
},
|
|
&seqExpr{
|
|
pos: position{line: 228, col: 91, offset: 6572},
|
|
exprs: []any{
|
|
&litMatcher{
|
|
pos: position{line: 228, col: 91, offset: 6572},
|
|
val: "`",
|
|
ignoreCase: false,
|
|
want: "\"`\"",
|
|
},
|
|
&zeroOrMoreExpr{
|
|
pos: position{line: 228, col: 95, offset: 6576},
|
|
expr: &ruleRefExpr{
|
|
pos: position{line: 228, col: 95, offset: 6576},
|
|
name: "RawStringChar",
|
|
},
|
|
},
|
|
&ruleRefExpr{
|
|
pos: position{line: 228, col: 110, offset: 6591},
|
|
name: "EOF",
|
|
},
|
|
},
|
|
},
|
|
},
|
|
},
|
|
},
|
|
},
|
|
},
|
|
},
|
|
{
|
|
name: "DoubleStringChar",
|
|
pos: position{line: 232, col: 1, offset: 6693},
|
|
expr: &choiceExpr{
|
|
pos: position{line: 232, col: 20, offset: 6714},
|
|
alternatives: []any{
|
|
&seqExpr{
|
|
pos: position{line: 232, col: 20, offset: 6714},
|
|
exprs: []any{
|
|
¬Expr{
|
|
pos: position{line: 232, col: 20, offset: 6714},
|
|
expr: &choiceExpr{
|
|
pos: position{line: 232, col: 23, offset: 6717},
|
|
alternatives: []any{
|
|
&litMatcher{
|
|
pos: position{line: 232, col: 23, offset: 6717},
|
|
val: "\"",
|
|
ignoreCase: false,
|
|
want: "\"\\\"\"",
|
|
},
|
|
&litMatcher{
|
|
pos: position{line: 232, col: 29, offset: 6723},
|
|
val: "\\",
|
|
ignoreCase: false,
|
|
want: "\"\\\\\"",
|
|
},
|
|
&ruleRefExpr{
|
|
pos: position{line: 232, col: 36, offset: 6730},
|
|
name: "EOL",
|
|
},
|
|
},
|
|
},
|
|
},
|
|
&ruleRefExpr{
|
|
pos: position{line: 232, col: 42, offset: 6736},
|
|
name: "SourceChar",
|
|
},
|
|
},
|
|
},
|
|
&seqExpr{
|
|
pos: position{line: 232, col: 55, offset: 6749},
|
|
exprs: []any{
|
|
&litMatcher{
|
|
pos: position{line: 232, col: 55, offset: 6749},
|
|
val: "\\",
|
|
ignoreCase: false,
|
|
want: "\"\\\\\"",
|
|
},
|
|
&ruleRefExpr{
|
|
pos: position{line: 232, col: 60, offset: 6754},
|
|
name: "DoubleStringEscape",
|
|
},
|
|
},
|
|
},
|
|
},
|
|
},
|
|
},
|
|
{
|
|
name: "SingleStringChar",
|
|
pos: position{line: 233, col: 1, offset: 6773},
|
|
expr: &choiceExpr{
|
|
pos: position{line: 233, col: 20, offset: 6794},
|
|
alternatives: []any{
|
|
&seqExpr{
|
|
pos: position{line: 233, col: 20, offset: 6794},
|
|
exprs: []any{
|
|
¬Expr{
|
|
pos: position{line: 233, col: 20, offset: 6794},
|
|
expr: &choiceExpr{
|
|
pos: position{line: 233, col: 23, offset: 6797},
|
|
alternatives: []any{
|
|
&litMatcher{
|
|
pos: position{line: 233, col: 23, offset: 6797},
|
|
val: "'",
|
|
ignoreCase: false,
|
|
want: "\"'\"",
|
|
},
|
|
&litMatcher{
|
|
pos: position{line: 233, col: 29, offset: 6803},
|
|
val: "\\",
|
|
ignoreCase: false,
|
|
want: "\"\\\\\"",
|
|
},
|
|
&ruleRefExpr{
|
|
pos: position{line: 233, col: 36, offset: 6810},
|
|
name: "EOL",
|
|
},
|
|
},
|
|
},
|
|
},
|
|
&ruleRefExpr{
|
|
pos: position{line: 233, col: 42, offset: 6816},
|
|
name: "SourceChar",
|
|
},
|
|
},
|
|
},
|
|
&seqExpr{
|
|
pos: position{line: 233, col: 55, offset: 6829},
|
|
exprs: []any{
|
|
&litMatcher{
|
|
pos: position{line: 233, col: 55, offset: 6829},
|
|
val: "\\",
|
|
ignoreCase: false,
|
|
want: "\"\\\\\"",
|
|
},
|
|
&ruleRefExpr{
|
|
pos: position{line: 233, col: 60, offset: 6834},
|
|
name: "SingleStringEscape",
|
|
},
|
|
},
|
|
},
|
|
},
|
|
},
|
|
},
|
|
{
|
|
name: "RawStringChar",
|
|
pos: position{line: 234, col: 1, offset: 6853},
|
|
expr: &seqExpr{
|
|
pos: position{line: 234, col: 17, offset: 6871},
|
|
exprs: []any{
|
|
¬Expr{
|
|
pos: position{line: 234, col: 17, offset: 6871},
|
|
expr: &litMatcher{
|
|
pos: position{line: 234, col: 18, offset: 6872},
|
|
val: "`",
|
|
ignoreCase: false,
|
|
want: "\"`\"",
|
|
},
|
|
},
|
|
&ruleRefExpr{
|
|
pos: position{line: 234, col: 22, offset: 6876},
|
|
name: "SourceChar",
|
|
},
|
|
},
|
|
},
|
|
},
|
|
{
|
|
name: "DoubleStringEscape",
|
|
pos: position{line: 236, col: 1, offset: 6888},
|
|
expr: &choiceExpr{
|
|
pos: position{line: 236, col: 22, offset: 6911},
|
|
alternatives: []any{
|
|
&choiceExpr{
|
|
pos: position{line: 236, col: 24, offset: 6913},
|
|
alternatives: []any{
|
|
&litMatcher{
|
|
pos: position{line: 236, col: 24, offset: 6913},
|
|
val: "\"",
|
|
ignoreCase: false,
|
|
want: "\"\\\"\"",
|
|
},
|
|
&ruleRefExpr{
|
|
pos: position{line: 236, col: 30, offset: 6919},
|
|
name: "CommonEscapeSequence",
|
|
},
|
|
},
|
|
},
|
|
&actionExpr{
|
|
pos: position{line: 237, col: 7, offset: 6948},
|
|
run: (*parser).callonDoubleStringEscape5,
|
|
expr: &choiceExpr{
|
|
pos: position{line: 237, col: 9, offset: 6950},
|
|
alternatives: []any{
|
|
&ruleRefExpr{
|
|
pos: position{line: 237, col: 9, offset: 6950},
|
|
name: "SourceChar",
|
|
},
|
|
&ruleRefExpr{
|
|
pos: position{line: 237, col: 22, offset: 6963},
|
|
name: "EOL",
|
|
},
|
|
&ruleRefExpr{
|
|
pos: position{line: 237, col: 28, offset: 6969},
|
|
name: "EOF",
|
|
},
|
|
},
|
|
},
|
|
},
|
|
},
|
|
},
|
|
},
|
|
{
|
|
name: "SingleStringEscape",
|
|
pos: position{line: 240, col: 1, offset: 7034},
|
|
expr: &choiceExpr{
|
|
pos: position{line: 240, col: 22, offset: 7057},
|
|
alternatives: []any{
|
|
&choiceExpr{
|
|
pos: position{line: 240, col: 24, offset: 7059},
|
|
alternatives: []any{
|
|
&litMatcher{
|
|
pos: position{line: 240, col: 24, offset: 7059},
|
|
val: "'",
|
|
ignoreCase: false,
|
|
want: "\"'\"",
|
|
},
|
|
&ruleRefExpr{
|
|
pos: position{line: 240, col: 30, offset: 7065},
|
|
name: "CommonEscapeSequence",
|
|
},
|
|
},
|
|
},
|
|
&actionExpr{
|
|
pos: position{line: 241, col: 7, offset: 7094},
|
|
run: (*parser).callonSingleStringEscape5,
|
|
expr: &choiceExpr{
|
|
pos: position{line: 241, col: 9, offset: 7096},
|
|
alternatives: []any{
|
|
&ruleRefExpr{
|
|
pos: position{line: 241, col: 9, offset: 7096},
|
|
name: "SourceChar",
|
|
},
|
|
&ruleRefExpr{
|
|
pos: position{line: 241, col: 22, offset: 7109},
|
|
name: "EOL",
|
|
},
|
|
&ruleRefExpr{
|
|
pos: position{line: 241, col: 28, offset: 7115},
|
|
name: "EOF",
|
|
},
|
|
},
|
|
},
|
|
},
|
|
},
|
|
},
|
|
},
|
|
{
|
|
name: "CommonEscapeSequence",
|
|
pos: position{line: 245, col: 1, offset: 7181},
|
|
expr: &choiceExpr{
|
|
pos: position{line: 245, col: 24, offset: 7206},
|
|
alternatives: []any{
|
|
&ruleRefExpr{
|
|
pos: position{line: 245, col: 24, offset: 7206},
|
|
name: "SingleCharEscape",
|
|
},
|
|
&ruleRefExpr{
|
|
pos: position{line: 245, col: 43, offset: 7225},
|
|
name: "OctalEscape",
|
|
},
|
|
&ruleRefExpr{
|
|
pos: position{line: 245, col: 57, offset: 7239},
|
|
name: "HexEscape",
|
|
},
|
|
&ruleRefExpr{
|
|
pos: position{line: 245, col: 69, offset: 7251},
|
|
name: "LongUnicodeEscape",
|
|
},
|
|
&ruleRefExpr{
|
|
pos: position{line: 245, col: 89, offset: 7271},
|
|
name: "ShortUnicodeEscape",
|
|
},
|
|
},
|
|
},
|
|
},
|
|
{
|
|
name: "SingleCharEscape",
|
|
pos: position{line: 246, col: 1, offset: 7290},
|
|
expr: &choiceExpr{
|
|
pos: position{line: 246, col: 20, offset: 7311},
|
|
alternatives: []any{
|
|
&litMatcher{
|
|
pos: position{line: 246, col: 20, offset: 7311},
|
|
val: "a",
|
|
ignoreCase: false,
|
|
want: "\"a\"",
|
|
},
|
|
&litMatcher{
|
|
pos: position{line: 246, col: 26, offset: 7317},
|
|
val: "b",
|
|
ignoreCase: false,
|
|
want: "\"b\"",
|
|
},
|
|
&litMatcher{
|
|
pos: position{line: 246, col: 32, offset: 7323},
|
|
val: "n",
|
|
ignoreCase: false,
|
|
want: "\"n\"",
|
|
},
|
|
&litMatcher{
|
|
pos: position{line: 246, col: 38, offset: 7329},
|
|
val: "f",
|
|
ignoreCase: false,
|
|
want: "\"f\"",
|
|
},
|
|
&litMatcher{
|
|
pos: position{line: 246, col: 44, offset: 7335},
|
|
val: "r",
|
|
ignoreCase: false,
|
|
want: "\"r\"",
|
|
},
|
|
&litMatcher{
|
|
pos: position{line: 246, col: 50, offset: 7341},
|
|
val: "t",
|
|
ignoreCase: false,
|
|
want: "\"t\"",
|
|
},
|
|
&litMatcher{
|
|
pos: position{line: 246, col: 56, offset: 7347},
|
|
val: "v",
|
|
ignoreCase: false,
|
|
want: "\"v\"",
|
|
},
|
|
&litMatcher{
|
|
pos: position{line: 246, col: 62, offset: 7353},
|
|
val: "\\",
|
|
ignoreCase: false,
|
|
want: "\"\\\\\"",
|
|
},
|
|
},
|
|
},
|
|
},
|
|
{
|
|
name: "OctalEscape",
|
|
pos: position{line: 247, col: 1, offset: 7358},
|
|
expr: &choiceExpr{
|
|
pos: position{line: 247, col: 15, offset: 7374},
|
|
alternatives: []any{
|
|
&seqExpr{
|
|
pos: position{line: 247, col: 15, offset: 7374},
|
|
exprs: []any{
|
|
&ruleRefExpr{
|
|
pos: position{line: 247, col: 15, offset: 7374},
|
|
name: "OctalDigit",
|
|
},
|
|
&ruleRefExpr{
|
|
pos: position{line: 247, col: 26, offset: 7385},
|
|
name: "OctalDigit",
|
|
},
|
|
&ruleRefExpr{
|
|
pos: position{line: 247, col: 37, offset: 7396},
|
|
name: "OctalDigit",
|
|
},
|
|
},
|
|
},
|
|
&actionExpr{
|
|
pos: position{line: 248, col: 7, offset: 7413},
|
|
run: (*parser).callonOctalEscape6,
|
|
expr: &seqExpr{
|
|
pos: position{line: 248, col: 7, offset: 7413},
|
|
exprs: []any{
|
|
&ruleRefExpr{
|
|
pos: position{line: 248, col: 7, offset: 7413},
|
|
name: "OctalDigit",
|
|
},
|
|
&choiceExpr{
|
|
pos: position{line: 248, col: 20, offset: 7426},
|
|
alternatives: []any{
|
|
&ruleRefExpr{
|
|
pos: position{line: 248, col: 20, offset: 7426},
|
|
name: "SourceChar",
|
|
},
|
|
&ruleRefExpr{
|
|
pos: position{line: 248, col: 33, offset: 7439},
|
|
name: "EOL",
|
|
},
|
|
&ruleRefExpr{
|
|
pos: position{line: 248, col: 39, offset: 7445},
|
|
name: "EOF",
|
|
},
|
|
},
|
|
},
|
|
},
|
|
},
|
|
},
|
|
},
|
|
},
|
|
},
|
|
{
|
|
name: "HexEscape",
|
|
pos: position{line: 251, col: 1, offset: 7506},
|
|
expr: &choiceExpr{
|
|
pos: position{line: 251, col: 13, offset: 7520},
|
|
alternatives: []any{
|
|
&seqExpr{
|
|
pos: position{line: 251, col: 13, offset: 7520},
|
|
exprs: []any{
|
|
&litMatcher{
|
|
pos: position{line: 251, col: 13, offset: 7520},
|
|
val: "x",
|
|
ignoreCase: false,
|
|
want: "\"x\"",
|
|
},
|
|
&ruleRefExpr{
|
|
pos: position{line: 251, col: 17, offset: 7524},
|
|
name: "HexDigit",
|
|
},
|
|
&ruleRefExpr{
|
|
pos: position{line: 251, col: 26, offset: 7533},
|
|
name: "HexDigit",
|
|
},
|
|
},
|
|
},
|
|
&actionExpr{
|
|
pos: position{line: 252, col: 7, offset: 7548},
|
|
run: (*parser).callonHexEscape6,
|
|
expr: &seqExpr{
|
|
pos: position{line: 252, col: 7, offset: 7548},
|
|
exprs: []any{
|
|
&litMatcher{
|
|
pos: position{line: 252, col: 7, offset: 7548},
|
|
val: "x",
|
|
ignoreCase: false,
|
|
want: "\"x\"",
|
|
},
|
|
&choiceExpr{
|
|
pos: position{line: 252, col: 13, offset: 7554},
|
|
alternatives: []any{
|
|
&ruleRefExpr{
|
|
pos: position{line: 252, col: 13, offset: 7554},
|
|
name: "SourceChar",
|
|
},
|
|
&ruleRefExpr{
|
|
pos: position{line: 252, col: 26, offset: 7567},
|
|
name: "EOL",
|
|
},
|
|
&ruleRefExpr{
|
|
pos: position{line: 252, col: 32, offset: 7573},
|
|
name: "EOF",
|
|
},
|
|
},
|
|
},
|
|
},
|
|
},
|
|
},
|
|
},
|
|
},
|
|
},
|
|
{
|
|
name: "LongUnicodeEscape",
|
|
pos: position{line: 255, col: 1, offset: 7640},
|
|
expr: &choiceExpr{
|
|
pos: position{line: 256, col: 5, offset: 7666},
|
|
alternatives: []any{
|
|
&actionExpr{
|
|
pos: position{line: 256, col: 5, offset: 7666},
|
|
run: (*parser).callonLongUnicodeEscape2,
|
|
expr: &seqExpr{
|
|
pos: position{line: 256, col: 5, offset: 7666},
|
|
exprs: []any{
|
|
&litMatcher{
|
|
pos: position{line: 256, col: 5, offset: 7666},
|
|
val: "U",
|
|
ignoreCase: false,
|
|
want: "\"U\"",
|
|
},
|
|
&ruleRefExpr{
|
|
pos: position{line: 256, col: 9, offset: 7670},
|
|
name: "HexDigit",
|
|
},
|
|
&ruleRefExpr{
|
|
pos: position{line: 256, col: 18, offset: 7679},
|
|
name: "HexDigit",
|
|
},
|
|
&ruleRefExpr{
|
|
pos: position{line: 256, col: 27, offset: 7688},
|
|
name: "HexDigit",
|
|
},
|
|
&ruleRefExpr{
|
|
pos: position{line: 256, col: 36, offset: 7697},
|
|
name: "HexDigit",
|
|
},
|
|
&ruleRefExpr{
|
|
pos: position{line: 256, col: 45, offset: 7706},
|
|
name: "HexDigit",
|
|
},
|
|
&ruleRefExpr{
|
|
pos: position{line: 256, col: 54, offset: 7715},
|
|
name: "HexDigit",
|
|
},
|
|
&ruleRefExpr{
|
|
pos: position{line: 256, col: 63, offset: 7724},
|
|
name: "HexDigit",
|
|
},
|
|
&ruleRefExpr{
|
|
pos: position{line: 256, col: 72, offset: 7733},
|
|
name: "HexDigit",
|
|
},
|
|
},
|
|
},
|
|
},
|
|
&actionExpr{
|
|
pos: position{line: 259, col: 7, offset: 7835},
|
|
run: (*parser).callonLongUnicodeEscape13,
|
|
expr: &seqExpr{
|
|
pos: position{line: 259, col: 7, offset: 7835},
|
|
exprs: []any{
|
|
&litMatcher{
|
|
pos: position{line: 259, col: 7, offset: 7835},
|
|
val: "U",
|
|
ignoreCase: false,
|
|
want: "\"U\"",
|
|
},
|
|
&choiceExpr{
|
|
pos: position{line: 259, col: 13, offset: 7841},
|
|
alternatives: []any{
|
|
&ruleRefExpr{
|
|
pos: position{line: 259, col: 13, offset: 7841},
|
|
name: "SourceChar",
|
|
},
|
|
&ruleRefExpr{
|
|
pos: position{line: 259, col: 26, offset: 7854},
|
|
name: "EOL",
|
|
},
|
|
&ruleRefExpr{
|
|
pos: position{line: 259, col: 32, offset: 7860},
|
|
name: "EOF",
|
|
},
|
|
},
|
|
},
|
|
},
|
|
},
|
|
},
|
|
},
|
|
},
|
|
},
|
|
{
|
|
name: "ShortUnicodeEscape",
|
|
pos: position{line: 262, col: 1, offset: 7923},
|
|
expr: &choiceExpr{
|
|
pos: position{line: 263, col: 5, offset: 7950},
|
|
alternatives: []any{
|
|
&actionExpr{
|
|
pos: position{line: 263, col: 5, offset: 7950},
|
|
run: (*parser).callonShortUnicodeEscape2,
|
|
expr: &seqExpr{
|
|
pos: position{line: 263, col: 5, offset: 7950},
|
|
exprs: []any{
|
|
&litMatcher{
|
|
pos: position{line: 263, col: 5, offset: 7950},
|
|
val: "u",
|
|
ignoreCase: false,
|
|
want: "\"u\"",
|
|
},
|
|
&ruleRefExpr{
|
|
pos: position{line: 263, col: 9, offset: 7954},
|
|
name: "HexDigit",
|
|
},
|
|
&ruleRefExpr{
|
|
pos: position{line: 263, col: 18, offset: 7963},
|
|
name: "HexDigit",
|
|
},
|
|
&ruleRefExpr{
|
|
pos: position{line: 263, col: 27, offset: 7972},
|
|
name: "HexDigit",
|
|
},
|
|
&ruleRefExpr{
|
|
pos: position{line: 263, col: 36, offset: 7981},
|
|
name: "HexDigit",
|
|
},
|
|
},
|
|
},
|
|
},
|
|
&actionExpr{
|
|
pos: position{line: 266, col: 7, offset: 8083},
|
|
run: (*parser).callonShortUnicodeEscape9,
|
|
expr: &seqExpr{
|
|
pos: position{line: 266, col: 7, offset: 8083},
|
|
exprs: []any{
|
|
&litMatcher{
|
|
pos: position{line: 266, col: 7, offset: 8083},
|
|
val: "u",
|
|
ignoreCase: false,
|
|
want: "\"u\"",
|
|
},
|
|
&choiceExpr{
|
|
pos: position{line: 266, col: 13, offset: 8089},
|
|
alternatives: []any{
|
|
&ruleRefExpr{
|
|
pos: position{line: 266, col: 13, offset: 8089},
|
|
name: "SourceChar",
|
|
},
|
|
&ruleRefExpr{
|
|
pos: position{line: 266, col: 26, offset: 8102},
|
|
name: "EOL",
|
|
},
|
|
&ruleRefExpr{
|
|
pos: position{line: 266, col: 32, offset: 8108},
|
|
name: "EOF",
|
|
},
|
|
},
|
|
},
|
|
},
|
|
},
|
|
},
|
|
},
|
|
},
|
|
},
|
|
{
|
|
name: "OctalDigit",
|
|
pos: position{line: 270, col: 1, offset: 8172},
|
|
expr: &charClassMatcher{
|
|
pos: position{line: 270, col: 14, offset: 8187},
|
|
val: "[0-7]",
|
|
ranges: []rune{'0', '7'},
|
|
ignoreCase: false,
|
|
inverted: false,
|
|
},
|
|
},
|
|
{
|
|
name: "DecimalDigit",
|
|
pos: position{line: 271, col: 1, offset: 8193},
|
|
expr: &charClassMatcher{
|
|
pos: position{line: 271, col: 16, offset: 8210},
|
|
val: "[0-9]",
|
|
ranges: []rune{'0', '9'},
|
|
ignoreCase: false,
|
|
inverted: false,
|
|
},
|
|
},
|
|
{
|
|
name: "HexDigit",
|
|
pos: position{line: 272, col: 1, offset: 8216},
|
|
expr: &charClassMatcher{
|
|
pos: position{line: 272, col: 12, offset: 8229},
|
|
val: "[0-9a-f]i",
|
|
ranges: []rune{'0', '9', 'a', 'f'},
|
|
ignoreCase: true,
|
|
inverted: false,
|
|
},
|
|
},
|
|
{
|
|
name: "CharClassMatcher",
|
|
pos: position{line: 274, col: 1, offset: 8240},
|
|
expr: &choiceExpr{
|
|
pos: position{line: 274, col: 20, offset: 8261},
|
|
alternatives: []any{
|
|
&actionExpr{
|
|
pos: position{line: 274, col: 20, offset: 8261},
|
|
run: (*parser).callonCharClassMatcher2,
|
|
expr: &seqExpr{
|
|
pos: position{line: 274, col: 20, offset: 8261},
|
|
exprs: []any{
|
|
&litMatcher{
|
|
pos: position{line: 274, col: 20, offset: 8261},
|
|
val: "[",
|
|
ignoreCase: false,
|
|
want: "\"[\"",
|
|
},
|
|
&zeroOrMoreExpr{
|
|
pos: position{line: 274, col: 24, offset: 8265},
|
|
expr: &choiceExpr{
|
|
pos: position{line: 274, col: 26, offset: 8267},
|
|
alternatives: []any{
|
|
&ruleRefExpr{
|
|
pos: position{line: 274, col: 26, offset: 8267},
|
|
name: "ClassCharRange",
|
|
},
|
|
&ruleRefExpr{
|
|
pos: position{line: 274, col: 43, offset: 8284},
|
|
name: "ClassChar",
|
|
},
|
|
&seqExpr{
|
|
pos: position{line: 274, col: 55, offset: 8296},
|
|
exprs: []any{
|
|
&litMatcher{
|
|
pos: position{line: 274, col: 55, offset: 8296},
|
|
val: "\\",
|
|
ignoreCase: false,
|
|
want: "\"\\\\\"",
|
|
},
|
|
&ruleRefExpr{
|
|
pos: position{line: 274, col: 60, offset: 8301},
|
|
name: "UnicodeClassEscape",
|
|
},
|
|
},
|
|
},
|
|
},
|
|
},
|
|
},
|
|
&litMatcher{
|
|
pos: position{line: 274, col: 82, offset: 8323},
|
|
val: "]",
|
|
ignoreCase: false,
|
|
want: "\"]\"",
|
|
},
|
|
&zeroOrOneExpr{
|
|
pos: position{line: 274, col: 86, offset: 8327},
|
|
expr: &litMatcher{
|
|
pos: position{line: 274, col: 86, offset: 8327},
|
|
val: "i",
|
|
ignoreCase: false,
|
|
want: "\"i\"",
|
|
},
|
|
},
|
|
},
|
|
},
|
|
},
|
|
&actionExpr{
|
|
pos: position{line: 278, col: 5, offset: 8434},
|
|
run: (*parser).callonCharClassMatcher15,
|
|
expr: &seqExpr{
|
|
pos: position{line: 278, col: 5, offset: 8434},
|
|
exprs: []any{
|
|
&litMatcher{
|
|
pos: position{line: 278, col: 5, offset: 8434},
|
|
val: "[",
|
|
ignoreCase: false,
|
|
want: "\"[\"",
|
|
},
|
|
&zeroOrMoreExpr{
|
|
pos: position{line: 278, col: 9, offset: 8438},
|
|
expr: &seqExpr{
|
|
pos: position{line: 278, col: 11, offset: 8440},
|
|
exprs: []any{
|
|
¬Expr{
|
|
pos: position{line: 278, col: 11, offset: 8440},
|
|
expr: &ruleRefExpr{
|
|
pos: position{line: 278, col: 14, offset: 8443},
|
|
name: "EOL",
|
|
},
|
|
},
|
|
&ruleRefExpr{
|
|
pos: position{line: 278, col: 20, offset: 8449},
|
|
name: "SourceChar",
|
|
},
|
|
},
|
|
},
|
|
},
|
|
&choiceExpr{
|
|
pos: position{line: 278, col: 36, offset: 8465},
|
|
alternatives: []any{
|
|
&ruleRefExpr{
|
|
pos: position{line: 278, col: 36, offset: 8465},
|
|
name: "EOL",
|
|
},
|
|
&ruleRefExpr{
|
|
pos: position{line: 278, col: 42, offset: 8471},
|
|
name: "EOF",
|
|
},
|
|
},
|
|
},
|
|
},
|
|
},
|
|
},
|
|
},
|
|
},
|
|
},
|
|
{
|
|
name: "ClassCharRange",
|
|
pos: position{line: 282, col: 1, offset: 8581},
|
|
expr: &seqExpr{
|
|
pos: position{line: 282, col: 18, offset: 8600},
|
|
exprs: []any{
|
|
&ruleRefExpr{
|
|
pos: position{line: 282, col: 18, offset: 8600},
|
|
name: "ClassChar",
|
|
},
|
|
&litMatcher{
|
|
pos: position{line: 282, col: 28, offset: 8610},
|
|
val: "-",
|
|
ignoreCase: false,
|
|
want: "\"-\"",
|
|
},
|
|
&ruleRefExpr{
|
|
pos: position{line: 282, col: 32, offset: 8614},
|
|
name: "ClassChar",
|
|
},
|
|
},
|
|
},
|
|
},
|
|
{
|
|
name: "ClassChar",
|
|
pos: position{line: 283, col: 1, offset: 8624},
|
|
expr: &choiceExpr{
|
|
pos: position{line: 283, col: 13, offset: 8638},
|
|
alternatives: []any{
|
|
&seqExpr{
|
|
pos: position{line: 283, col: 13, offset: 8638},
|
|
exprs: []any{
|
|
¬Expr{
|
|
pos: position{line: 283, col: 13, offset: 8638},
|
|
expr: &choiceExpr{
|
|
pos: position{line: 283, col: 16, offset: 8641},
|
|
alternatives: []any{
|
|
&litMatcher{
|
|
pos: position{line: 283, col: 16, offset: 8641},
|
|
val: "]",
|
|
ignoreCase: false,
|
|
want: "\"]\"",
|
|
},
|
|
&litMatcher{
|
|
pos: position{line: 283, col: 22, offset: 8647},
|
|
val: "\\",
|
|
ignoreCase: false,
|
|
want: "\"\\\\\"",
|
|
},
|
|
&ruleRefExpr{
|
|
pos: position{line: 283, col: 29, offset: 8654},
|
|
name: "EOL",
|
|
},
|
|
},
|
|
},
|
|
},
|
|
&ruleRefExpr{
|
|
pos: position{line: 283, col: 35, offset: 8660},
|
|
name: "SourceChar",
|
|
},
|
|
},
|
|
},
|
|
&seqExpr{
|
|
pos: position{line: 283, col: 48, offset: 8673},
|
|
exprs: []any{
|
|
&litMatcher{
|
|
pos: position{line: 283, col: 48, offset: 8673},
|
|
val: "\\",
|
|
ignoreCase: false,
|
|
want: "\"\\\\\"",
|
|
},
|
|
&ruleRefExpr{
|
|
pos: position{line: 283, col: 53, offset: 8678},
|
|
name: "CharClassEscape",
|
|
},
|
|
},
|
|
},
|
|
},
|
|
},
|
|
},
|
|
{
|
|
name: "CharClassEscape",
|
|
pos: position{line: 284, col: 1, offset: 8694},
|
|
expr: &choiceExpr{
|
|
pos: position{line: 284, col: 19, offset: 8714},
|
|
alternatives: []any{
|
|
&choiceExpr{
|
|
pos: position{line: 284, col: 21, offset: 8716},
|
|
alternatives: []any{
|
|
&litMatcher{
|
|
pos: position{line: 284, col: 21, offset: 8716},
|
|
val: "]",
|
|
ignoreCase: false,
|
|
want: "\"]\"",
|
|
},
|
|
&ruleRefExpr{
|
|
pos: position{line: 284, col: 27, offset: 8722},
|
|
name: "CommonEscapeSequence",
|
|
},
|
|
},
|
|
},
|
|
&actionExpr{
|
|
pos: position{line: 285, col: 7, offset: 8751},
|
|
run: (*parser).callonCharClassEscape5,
|
|
expr: &seqExpr{
|
|
pos: position{line: 285, col: 7, offset: 8751},
|
|
exprs: []any{
|
|
¬Expr{
|
|
pos: position{line: 285, col: 7, offset: 8751},
|
|
expr: &litMatcher{
|
|
pos: position{line: 285, col: 8, offset: 8752},
|
|
val: "p",
|
|
ignoreCase: false,
|
|
want: "\"p\"",
|
|
},
|
|
},
|
|
&choiceExpr{
|
|
pos: position{line: 285, col: 14, offset: 8758},
|
|
alternatives: []any{
|
|
&ruleRefExpr{
|
|
pos: position{line: 285, col: 14, offset: 8758},
|
|
name: "SourceChar",
|
|
},
|
|
&ruleRefExpr{
|
|
pos: position{line: 285, col: 27, offset: 8771},
|
|
name: "EOL",
|
|
},
|
|
&ruleRefExpr{
|
|
pos: position{line: 285, col: 33, offset: 8777},
|
|
name: "EOF",
|
|
},
|
|
},
|
|
},
|
|
},
|
|
},
|
|
},
|
|
},
|
|
},
|
|
},
|
|
{
|
|
name: "UnicodeClassEscape",
|
|
pos: position{line: 289, col: 1, offset: 8843},
|
|
expr: &seqExpr{
|
|
pos: position{line: 289, col: 22, offset: 8866},
|
|
exprs: []any{
|
|
&litMatcher{
|
|
pos: position{line: 289, col: 22, offset: 8866},
|
|
val: "p",
|
|
ignoreCase: false,
|
|
want: "\"p\"",
|
|
},
|
|
&choiceExpr{
|
|
pos: position{line: 290, col: 7, offset: 8878},
|
|
alternatives: []any{
|
|
&ruleRefExpr{
|
|
pos: position{line: 290, col: 7, offset: 8878},
|
|
name: "SingleCharUnicodeClass",
|
|
},
|
|
&actionExpr{
|
|
pos: position{line: 291, col: 7, offset: 8907},
|
|
run: (*parser).callonUnicodeClassEscape5,
|
|
expr: &seqExpr{
|
|
pos: position{line: 291, col: 7, offset: 8907},
|
|
exprs: []any{
|
|
¬Expr{
|
|
pos: position{line: 291, col: 7, offset: 8907},
|
|
expr: &litMatcher{
|
|
pos: position{line: 291, col: 8, offset: 8908},
|
|
val: "{",
|
|
ignoreCase: false,
|
|
want: "\"{\"",
|
|
},
|
|
},
|
|
&choiceExpr{
|
|
pos: position{line: 291, col: 14, offset: 8914},
|
|
alternatives: []any{
|
|
&ruleRefExpr{
|
|
pos: position{line: 291, col: 14, offset: 8914},
|
|
name: "SourceChar",
|
|
},
|
|
&ruleRefExpr{
|
|
pos: position{line: 291, col: 27, offset: 8927},
|
|
name: "EOL",
|
|
},
|
|
&ruleRefExpr{
|
|
pos: position{line: 291, col: 33, offset: 8933},
|
|
name: "EOF",
|
|
},
|
|
},
|
|
},
|
|
},
|
|
},
|
|
},
|
|
&actionExpr{
|
|
pos: position{line: 292, col: 7, offset: 9004},
|
|
run: (*parser).callonUnicodeClassEscape13,
|
|
expr: &seqExpr{
|
|
pos: position{line: 292, col: 7, offset: 9004},
|
|
exprs: []any{
|
|
&litMatcher{
|
|
pos: position{line: 292, col: 7, offset: 9004},
|
|
val: "{",
|
|
ignoreCase: false,
|
|
want: "\"{\"",
|
|
},
|
|
&labeledExpr{
|
|
pos: position{line: 292, col: 11, offset: 9008},
|
|
label: "ident",
|
|
expr: &ruleRefExpr{
|
|
pos: position{line: 292, col: 17, offset: 9014},
|
|
name: "IdentifierName",
|
|
},
|
|
},
|
|
&litMatcher{
|
|
pos: position{line: 292, col: 32, offset: 9029},
|
|
val: "}",
|
|
ignoreCase: false,
|
|
want: "\"}\"",
|
|
},
|
|
},
|
|
},
|
|
},
|
|
&actionExpr{
|
|
pos: position{line: 298, col: 7, offset: 9206},
|
|
run: (*parser).callonUnicodeClassEscape19,
|
|
expr: &seqExpr{
|
|
pos: position{line: 298, col: 7, offset: 9206},
|
|
exprs: []any{
|
|
&litMatcher{
|
|
pos: position{line: 298, col: 7, offset: 9206},
|
|
val: "{",
|
|
ignoreCase: false,
|
|
want: "\"{\"",
|
|
},
|
|
&ruleRefExpr{
|
|
pos: position{line: 298, col: 11, offset: 9210},
|
|
name: "IdentifierName",
|
|
},
|
|
&choiceExpr{
|
|
pos: position{line: 298, col: 28, offset: 9227},
|
|
alternatives: []any{
|
|
&litMatcher{
|
|
pos: position{line: 298, col: 28, offset: 9227},
|
|
val: "]",
|
|
ignoreCase: false,
|
|
want: "\"]\"",
|
|
},
|
|
&ruleRefExpr{
|
|
pos: position{line: 298, col: 34, offset: 9233},
|
|
name: "EOL",
|
|
},
|
|
&ruleRefExpr{
|
|
pos: position{line: 298, col: 40, offset: 9239},
|
|
name: "EOF",
|
|
},
|
|
},
|
|
},
|
|
},
|
|
},
|
|
},
|
|
},
|
|
},
|
|
},
|
|
},
|
|
},
|
|
{
|
|
name: "SingleCharUnicodeClass",
|
|
pos: position{line: 302, col: 1, offset: 9322},
|
|
expr: &charClassMatcher{
|
|
pos: position{line: 302, col: 26, offset: 9349},
|
|
val: "[LMNCPZS]",
|
|
chars: []rune{'L', 'M', 'N', 'C', 'P', 'Z', 'S'},
|
|
ignoreCase: false,
|
|
inverted: false,
|
|
},
|
|
},
|
|
{
|
|
name: "AnyMatcher",
|
|
pos: position{line: 304, col: 1, offset: 9360},
|
|
expr: &actionExpr{
|
|
pos: position{line: 304, col: 14, offset: 9375},
|
|
run: (*parser).callonAnyMatcher1,
|
|
expr: &litMatcher{
|
|
pos: position{line: 304, col: 14, offset: 9375},
|
|
val: ".",
|
|
ignoreCase: false,
|
|
want: "\".\"",
|
|
},
|
|
},
|
|
},
|
|
{
|
|
name: "ThrowExpr",
|
|
pos: position{line: 309, col: 1, offset: 9450},
|
|
expr: &choiceExpr{
|
|
pos: position{line: 309, col: 13, offset: 9464},
|
|
alternatives: []any{
|
|
&actionExpr{
|
|
pos: position{line: 309, col: 13, offset: 9464},
|
|
run: (*parser).callonThrowExpr2,
|
|
expr: &seqExpr{
|
|
pos: position{line: 309, col: 13, offset: 9464},
|
|
exprs: []any{
|
|
&litMatcher{
|
|
pos: position{line: 309, col: 13, offset: 9464},
|
|
val: "%",
|
|
ignoreCase: false,
|
|
want: "\"%\"",
|
|
},
|
|
&litMatcher{
|
|
pos: position{line: 309, col: 17, offset: 9468},
|
|
val: "{",
|
|
ignoreCase: false,
|
|
want: "\"{\"",
|
|
},
|
|
&labeledExpr{
|
|
pos: position{line: 309, col: 21, offset: 9472},
|
|
label: "label",
|
|
expr: &ruleRefExpr{
|
|
pos: position{line: 309, col: 27, offset: 9478},
|
|
name: "IdentifierName",
|
|
},
|
|
},
|
|
&litMatcher{
|
|
pos: position{line: 309, col: 42, offset: 9493},
|
|
val: "}",
|
|
ignoreCase: false,
|
|
want: "\"}\"",
|
|
},
|
|
},
|
|
},
|
|
},
|
|
&actionExpr{
|
|
pos: position{line: 313, col: 5, offset: 9601},
|
|
run: (*parser).callonThrowExpr9,
|
|
expr: &seqExpr{
|
|
pos: position{line: 313, col: 5, offset: 9601},
|
|
exprs: []any{
|
|
&litMatcher{
|
|
pos: position{line: 313, col: 5, offset: 9601},
|
|
val: "%",
|
|
ignoreCase: false,
|
|
want: "\"%\"",
|
|
},
|
|
&litMatcher{
|
|
pos: position{line: 313, col: 9, offset: 9605},
|
|
val: "{",
|
|
ignoreCase: false,
|
|
want: "\"{\"",
|
|
},
|
|
&ruleRefExpr{
|
|
pos: position{line: 313, col: 13, offset: 9609},
|
|
name: "IdentifierName",
|
|
},
|
|
&ruleRefExpr{
|
|
pos: position{line: 313, col: 28, offset: 9624},
|
|
name: "EOF",
|
|
},
|
|
},
|
|
},
|
|
},
|
|
},
|
|
},
|
|
},
|
|
{
|
|
name: "CodeBlock",
|
|
pos: position{line: 317, col: 1, offset: 9695},
|
|
expr: &choiceExpr{
|
|
pos: position{line: 317, col: 13, offset: 9709},
|
|
alternatives: []any{
|
|
&actionExpr{
|
|
pos: position{line: 317, col: 13, offset: 9709},
|
|
run: (*parser).callonCodeBlock2,
|
|
expr: &seqExpr{
|
|
pos: position{line: 317, col: 13, offset: 9709},
|
|
exprs: []any{
|
|
&litMatcher{
|
|
pos: position{line: 317, col: 13, offset: 9709},
|
|
val: "{",
|
|
ignoreCase: false,
|
|
want: "\"{\"",
|
|
},
|
|
&ruleRefExpr{
|
|
pos: position{line: 317, col: 17, offset: 9713},
|
|
name: "Code",
|
|
},
|
|
&litMatcher{
|
|
pos: position{line: 317, col: 22, offset: 9718},
|
|
val: "}",
|
|
ignoreCase: false,
|
|
want: "\"}\"",
|
|
},
|
|
},
|
|
},
|
|
},
|
|
&actionExpr{
|
|
pos: position{line: 321, col: 5, offset: 9817},
|
|
run: (*parser).callonCodeBlock7,
|
|
expr: &seqExpr{
|
|
pos: position{line: 321, col: 5, offset: 9817},
|
|
exprs: []any{
|
|
&litMatcher{
|
|
pos: position{line: 321, col: 5, offset: 9817},
|
|
val: "{",
|
|
ignoreCase: false,
|
|
want: "\"{\"",
|
|
},
|
|
&ruleRefExpr{
|
|
pos: position{line: 321, col: 9, offset: 9821},
|
|
name: "Code",
|
|
},
|
|
&ruleRefExpr{
|
|
pos: position{line: 321, col: 14, offset: 9826},
|
|
name: "EOF",
|
|
},
|
|
},
|
|
},
|
|
},
|
|
},
|
|
},
|
|
},
|
|
{
|
|
name: "Code",
|
|
pos: position{line: 325, col: 1, offset: 9891},
|
|
expr: &zeroOrMoreExpr{
|
|
pos: position{line: 325, col: 8, offset: 9900},
|
|
expr: &choiceExpr{
|
|
pos: position{line: 325, col: 10, offset: 9902},
|
|
alternatives: []any{
|
|
&oneOrMoreExpr{
|
|
pos: position{line: 325, col: 10, offset: 9902},
|
|
expr: &choiceExpr{
|
|
pos: position{line: 325, col: 12, offset: 9904},
|
|
alternatives: []any{
|
|
&ruleRefExpr{
|
|
pos: position{line: 325, col: 12, offset: 9904},
|
|
name: "Comment",
|
|
},
|
|
&ruleRefExpr{
|
|
pos: position{line: 325, col: 22, offset: 9914},
|
|
name: "CodeStringLiteral",
|
|
},
|
|
&seqExpr{
|
|
pos: position{line: 325, col: 42, offset: 9934},
|
|
exprs: []any{
|
|
¬Expr{
|
|
pos: position{line: 325, col: 42, offset: 9934},
|
|
expr: &charClassMatcher{
|
|
pos: position{line: 325, col: 43, offset: 9935},
|
|
val: "[{}]",
|
|
chars: []rune{'{', '}'},
|
|
ignoreCase: false,
|
|
inverted: false,
|
|
},
|
|
},
|
|
&ruleRefExpr{
|
|
pos: position{line: 325, col: 48, offset: 9940},
|
|
name: "SourceChar",
|
|
},
|
|
},
|
|
},
|
|
},
|
|
},
|
|
},
|
|
&seqExpr{
|
|
pos: position{line: 325, col: 64, offset: 9956},
|
|
exprs: []any{
|
|
&litMatcher{
|
|
pos: position{line: 325, col: 64, offset: 9956},
|
|
val: "{",
|
|
ignoreCase: false,
|
|
want: "\"{\"",
|
|
},
|
|
&ruleRefExpr{
|
|
pos: position{line: 325, col: 68, offset: 9960},
|
|
name: "Code",
|
|
},
|
|
&litMatcher{
|
|
pos: position{line: 325, col: 73, offset: 9965},
|
|
val: "}",
|
|
ignoreCase: false,
|
|
want: "\"}\"",
|
|
},
|
|
},
|
|
},
|
|
},
|
|
},
|
|
},
|
|
},
|
|
{
|
|
name: "CodeStringLiteral",
|
|
pos: position{line: 327, col: 1, offset: 9973},
|
|
expr: &choiceExpr{
|
|
pos: position{line: 327, col: 21, offset: 9995},
|
|
alternatives: []any{
|
|
&seqExpr{
|
|
pos: position{line: 327, col: 21, offset: 9995},
|
|
exprs: []any{
|
|
&litMatcher{
|
|
pos: position{line: 327, col: 21, offset: 9995},
|
|
val: "\"",
|
|
ignoreCase: false,
|
|
want: "\"\\\"\"",
|
|
},
|
|
&zeroOrMoreExpr{
|
|
pos: position{line: 327, col: 25, offset: 9999},
|
|
expr: &choiceExpr{
|
|
pos: position{line: 327, col: 26, offset: 10000},
|
|
alternatives: []any{
|
|
&litMatcher{
|
|
pos: position{line: 327, col: 26, offset: 10000},
|
|
val: "\\\"",
|
|
ignoreCase: false,
|
|
want: "\"\\\\\\\"\"",
|
|
},
|
|
&litMatcher{
|
|
pos: position{line: 327, col: 33, offset: 10007},
|
|
val: "\\\\",
|
|
ignoreCase: false,
|
|
want: "\"\\\\\\\\\"",
|
|
},
|
|
&charClassMatcher{
|
|
pos: position{line: 327, col: 40, offset: 10014},
|
|
val: "[^\"\\r\\n]",
|
|
chars: []rune{'"', '\r', '\n'},
|
|
ignoreCase: false,
|
|
inverted: true,
|
|
},
|
|
},
|
|
},
|
|
},
|
|
&litMatcher{
|
|
pos: position{line: 327, col: 51, offset: 10025},
|
|
val: "\"",
|
|
ignoreCase: false,
|
|
want: "\"\\\"\"",
|
|
},
|
|
},
|
|
},
|
|
&seqExpr{
|
|
pos: position{line: 328, col: 21, offset: 10051},
|
|
exprs: []any{
|
|
&litMatcher{
|
|
pos: position{line: 328, col: 21, offset: 10051},
|
|
val: "`",
|
|
ignoreCase: false,
|
|
want: "\"`\"",
|
|
},
|
|
&zeroOrMoreExpr{
|
|
pos: position{line: 328, col: 25, offset: 10055},
|
|
expr: &charClassMatcher{
|
|
pos: position{line: 328, col: 25, offset: 10055},
|
|
val: "[^`]",
|
|
chars: []rune{'`'},
|
|
ignoreCase: false,
|
|
inverted: true,
|
|
},
|
|
},
|
|
&litMatcher{
|
|
pos: position{line: 328, col: 31, offset: 10061},
|
|
val: "`",
|
|
ignoreCase: false,
|
|
want: "\"`\"",
|
|
},
|
|
},
|
|
},
|
|
&seqExpr{
|
|
pos: position{line: 329, col: 21, offset: 10087},
|
|
exprs: []any{
|
|
&litMatcher{
|
|
pos: position{line: 329, col: 21, offset: 10087},
|
|
val: "'",
|
|
ignoreCase: false,
|
|
want: "\"'\"",
|
|
},
|
|
&choiceExpr{
|
|
pos: position{line: 329, col: 27, offset: 10093},
|
|
alternatives: []any{
|
|
&litMatcher{
|
|
pos: position{line: 329, col: 27, offset: 10093},
|
|
val: "\\'",
|
|
ignoreCase: false,
|
|
want: "\"\\\\'\"",
|
|
},
|
|
&litMatcher{
|
|
pos: position{line: 329, col: 34, offset: 10100},
|
|
val: "\\\\",
|
|
ignoreCase: false,
|
|
want: "\"\\\\\\\\\"",
|
|
},
|
|
&oneOrMoreExpr{
|
|
pos: position{line: 329, col: 41, offset: 10107},
|
|
expr: &charClassMatcher{
|
|
pos: position{line: 329, col: 41, offset: 10107},
|
|
val: "[^']",
|
|
chars: []rune{'\''},
|
|
ignoreCase: false,
|
|
inverted: true,
|
|
},
|
|
},
|
|
},
|
|
},
|
|
&litMatcher{
|
|
pos: position{line: 329, col: 48, offset: 10114},
|
|
val: "'",
|
|
ignoreCase: false,
|
|
want: "\"'\"",
|
|
},
|
|
},
|
|
},
|
|
},
|
|
},
|
|
},
|
|
{
|
|
name: "__",
|
|
pos: position{line: 331, col: 1, offset: 10120},
|
|
expr: &zeroOrMoreExpr{
|
|
pos: position{line: 331, col: 6, offset: 10127},
|
|
expr: &choiceExpr{
|
|
pos: position{line: 331, col: 8, offset: 10129},
|
|
alternatives: []any{
|
|
&ruleRefExpr{
|
|
pos: position{line: 331, col: 8, offset: 10129},
|
|
name: "Whitespace",
|
|
},
|
|
&ruleRefExpr{
|
|
pos: position{line: 331, col: 21, offset: 10142},
|
|
name: "EOL",
|
|
},
|
|
&ruleRefExpr{
|
|
pos: position{line: 331, col: 27, offset: 10148},
|
|
name: "Comment",
|
|
},
|
|
},
|
|
},
|
|
},
|
|
},
|
|
{
|
|
name: "_",
|
|
pos: position{line: 332, col: 1, offset: 10159},
|
|
expr: &zeroOrMoreExpr{
|
|
pos: position{line: 332, col: 5, offset: 10165},
|
|
expr: &choiceExpr{
|
|
pos: position{line: 332, col: 7, offset: 10167},
|
|
alternatives: []any{
|
|
&ruleRefExpr{
|
|
pos: position{line: 332, col: 7, offset: 10167},
|
|
name: "Whitespace",
|
|
},
|
|
&ruleRefExpr{
|
|
pos: position{line: 332, col: 20, offset: 10180},
|
|
name: "MultiLineCommentNoLineTerminator",
|
|
},
|
|
},
|
|
},
|
|
},
|
|
},
|
|
{
|
|
name: "Whitespace",
|
|
pos: position{line: 334, col: 1, offset: 10217},
|
|
expr: &charClassMatcher{
|
|
pos: position{line: 334, col: 14, offset: 10232},
|
|
val: "[ \\t\\r]",
|
|
chars: []rune{' ', '\t', '\r'},
|
|
ignoreCase: false,
|
|
inverted: false,
|
|
},
|
|
},
|
|
{
|
|
name: "EOL",
|
|
pos: position{line: 335, col: 1, offset: 10240},
|
|
expr: &litMatcher{
|
|
pos: position{line: 335, col: 7, offset: 10248},
|
|
val: "\n",
|
|
ignoreCase: false,
|
|
want: "\"\\n\"",
|
|
},
|
|
},
|
|
{
|
|
name: "EOS",
|
|
pos: position{line: 336, col: 1, offset: 10253},
|
|
expr: &choiceExpr{
|
|
pos: position{line: 336, col: 7, offset: 10261},
|
|
alternatives: []any{
|
|
&seqExpr{
|
|
pos: position{line: 336, col: 7, offset: 10261},
|
|
exprs: []any{
|
|
&ruleRefExpr{
|
|
pos: position{line: 336, col: 7, offset: 10261},
|
|
name: "__",
|
|
},
|
|
&litMatcher{
|
|
pos: position{line: 336, col: 10, offset: 10264},
|
|
val: ";",
|
|
ignoreCase: false,
|
|
want: "\";\"",
|
|
},
|
|
},
|
|
},
|
|
&seqExpr{
|
|
pos: position{line: 336, col: 16, offset: 10270},
|
|
exprs: []any{
|
|
&ruleRefExpr{
|
|
pos: position{line: 336, col: 16, offset: 10270},
|
|
name: "_",
|
|
},
|
|
&zeroOrOneExpr{
|
|
pos: position{line: 336, col: 18, offset: 10272},
|
|
expr: &ruleRefExpr{
|
|
pos: position{line: 336, col: 18, offset: 10272},
|
|
name: "SingleLineComment",
|
|
},
|
|
},
|
|
&ruleRefExpr{
|
|
pos: position{line: 336, col: 37, offset: 10291},
|
|
name: "EOL",
|
|
},
|
|
},
|
|
},
|
|
&seqExpr{
|
|
pos: position{line: 336, col: 43, offset: 10297},
|
|
exprs: []any{
|
|
&ruleRefExpr{
|
|
pos: position{line: 336, col: 43, offset: 10297},
|
|
name: "__",
|
|
},
|
|
&ruleRefExpr{
|
|
pos: position{line: 336, col: 46, offset: 10300},
|
|
name: "EOF",
|
|
},
|
|
},
|
|
},
|
|
},
|
|
},
|
|
},
|
|
{
|
|
name: "EOF",
|
|
pos: position{line: 338, col: 1, offset: 10305},
|
|
expr: ¬Expr{
|
|
pos: position{line: 338, col: 7, offset: 10313},
|
|
expr: &anyMatcher{
|
|
line: 338, col: 8, offset: 10314,
|
|
},
|
|
},
|
|
},
|
|
},
|
|
}
|
|
|
|
func (c *current) onGrammar1(initializer, rules any) (any, error) {
|
|
pos := c.astPos()
|
|
|
|
// create the grammar, assign its initializer
|
|
g := ast.NewGrammar(pos)
|
|
initSlice := toAnySlice(initializer)
|
|
if len(initSlice) > 0 {
|
|
g.Init = initSlice[0].(*ast.CodeBlock)
|
|
}
|
|
|
|
rulesSlice := toAnySlice(rules)
|
|
g.Rules = make([]*ast.Rule, len(rulesSlice))
|
|
for i, duo := range rulesSlice {
|
|
g.Rules[i] = duo.([]any)[0].(*ast.Rule)
|
|
}
|
|
|
|
return g, nil
|
|
}
|
|
|
|
func (p *parser) callonGrammar1() (any, error) {
|
|
stack := p.vstack[len(p.vstack)-1]
|
|
_ = stack
|
|
return p.cur.onGrammar1(stack["initializer"], stack["rules"])
|
|
}
|
|
|
|
func (c *current) onInitializer1(code any) (any, error) {
|
|
return code, nil
|
|
}
|
|
|
|
func (p *parser) callonInitializer1() (any, error) {
|
|
stack := p.vstack[len(p.vstack)-1]
|
|
_ = stack
|
|
return p.cur.onInitializer1(stack["code"])
|
|
}
|
|
|
|
func (c *current) onRule1(name, display, expr any) (any, error) {
|
|
pos := c.astPos()
|
|
|
|
rule := ast.NewRule(pos, name.(*ast.Identifier))
|
|
displaySlice := toAnySlice(display)
|
|
if len(displaySlice) > 0 {
|
|
rule.DisplayName = displaySlice[0].(*ast.StringLit)
|
|
}
|
|
rule.Expr = expr.(ast.Expression)
|
|
|
|
return rule, nil
|
|
}
|
|
|
|
func (p *parser) callonRule1() (any, error) {
|
|
stack := p.vstack[len(p.vstack)-1]
|
|
_ = stack
|
|
return p.cur.onRule1(stack["name"], stack["display"], stack["expr"])
|
|
}
|
|
|
|
func (c *current) onRecoveryExpr1(expr, recoverExprs any) (any, error) {
|
|
recoverExprSlice := toAnySlice(recoverExprs)
|
|
recover := expr.(ast.Expression)
|
|
for _, sl := range recoverExprSlice {
|
|
pos := c.astPos()
|
|
r := ast.NewRecoveryExpr(pos)
|
|
r.Expr = recover
|
|
r.RecoverExpr = sl.([]any)[7].(ast.Expression)
|
|
r.Labels = sl.([]any)[3].([]ast.FailureLabel)
|
|
|
|
recover = r
|
|
}
|
|
return recover, nil
|
|
}
|
|
|
|
func (p *parser) callonRecoveryExpr1() (any, error) {
|
|
stack := p.vstack[len(p.vstack)-1]
|
|
_ = stack
|
|
return p.cur.onRecoveryExpr1(stack["expr"], stack["recoverExprs"])
|
|
}
|
|
|
|
func (c *current) onLabels1(label, labels any) (any, error) {
|
|
failureLabels := []ast.FailureLabel{ast.FailureLabel(label.(*ast.Identifier).Val)}
|
|
labelSlice := toAnySlice(labels)
|
|
for _, fl := range labelSlice {
|
|
failureLabels = append(failureLabels, ast.FailureLabel(fl.([]any)[3].(*ast.Identifier).Val))
|
|
}
|
|
return failureLabels, nil
|
|
}
|
|
|
|
func (p *parser) callonLabels1() (any, error) {
|
|
stack := p.vstack[len(p.vstack)-1]
|
|
_ = stack
|
|
return p.cur.onLabels1(stack["label"], stack["labels"])
|
|
}
|
|
|
|
func (c *current) onChoiceExpr1(first, rest any) (any, error) {
|
|
restSlice := toAnySlice(rest)
|
|
if len(restSlice) == 0 {
|
|
return first, nil
|
|
}
|
|
|
|
pos := c.astPos()
|
|
choice := ast.NewChoiceExpr(pos)
|
|
choice.Alternatives = []ast.Expression{first.(ast.Expression)}
|
|
for _, sl := range restSlice {
|
|
choice.Alternatives = append(choice.Alternatives, sl.([]any)[3].(ast.Expression))
|
|
}
|
|
return choice, nil
|
|
}
|
|
|
|
func (p *parser) callonChoiceExpr1() (any, error) {
|
|
stack := p.vstack[len(p.vstack)-1]
|
|
_ = stack
|
|
return p.cur.onChoiceExpr1(stack["first"], stack["rest"])
|
|
}
|
|
|
|
func (c *current) onActionExpr1(expr, code any) (any, error) {
|
|
if code == nil {
|
|
return expr, nil
|
|
}
|
|
|
|
pos := c.astPos()
|
|
act := ast.NewActionExpr(pos)
|
|
act.Expr = expr.(ast.Expression)
|
|
codeSlice := toAnySlice(code)
|
|
act.Code = codeSlice[1].(*ast.CodeBlock)
|
|
|
|
return act, nil
|
|
}
|
|
|
|
func (p *parser) callonActionExpr1() (any, error) {
|
|
stack := p.vstack[len(p.vstack)-1]
|
|
_ = stack
|
|
return p.cur.onActionExpr1(stack["expr"], stack["code"])
|
|
}
|
|
|
|
func (c *current) onSeqExpr1(first, rest any) (any, error) {
|
|
restSlice := toAnySlice(rest)
|
|
if len(restSlice) == 0 {
|
|
return first, nil
|
|
}
|
|
seq := ast.NewSeqExpr(c.astPos())
|
|
seq.Exprs = []ast.Expression{first.(ast.Expression)}
|
|
for _, sl := range restSlice {
|
|
seq.Exprs = append(seq.Exprs, sl.([]any)[1].(ast.Expression))
|
|
}
|
|
return seq, nil
|
|
}
|
|
|
|
func (p *parser) callonSeqExpr1() (any, error) {
|
|
stack := p.vstack[len(p.vstack)-1]
|
|
_ = stack
|
|
return p.cur.onSeqExpr1(stack["first"], stack["rest"])
|
|
}
|
|
|
|
func (c *current) onLabeledExpr2(label, expr any) (any, error) {
|
|
pos := c.astPos()
|
|
lab := ast.NewLabeledExpr(pos)
|
|
lab.Label = label.(*ast.Identifier)
|
|
lab.Expr = expr.(ast.Expression)
|
|
return lab, nil
|
|
}
|
|
|
|
func (p *parser) callonLabeledExpr2() (any, error) {
|
|
stack := p.vstack[len(p.vstack)-1]
|
|
_ = stack
|
|
return p.cur.onLabeledExpr2(stack["label"], stack["expr"])
|
|
}
|
|
|
|
func (c *current) onPrefixedExpr2(op, expr any) (any, error) {
|
|
pos := c.astPos()
|
|
opStr := op.(string)
|
|
if opStr == "&" {
|
|
and := ast.NewAndExpr(pos)
|
|
and.Expr = expr.(ast.Expression)
|
|
return and, nil
|
|
}
|
|
not := ast.NewNotExpr(pos)
|
|
not.Expr = expr.(ast.Expression)
|
|
return not, nil
|
|
}
|
|
|
|
func (p *parser) callonPrefixedExpr2() (any, error) {
|
|
stack := p.vstack[len(p.vstack)-1]
|
|
_ = stack
|
|
return p.cur.onPrefixedExpr2(stack["op"], stack["expr"])
|
|
}
|
|
|
|
func (c *current) onPrefixedOp1() (any, error) {
|
|
return string(c.text), nil
|
|
}
|
|
|
|
func (p *parser) callonPrefixedOp1() (any, error) {
|
|
stack := p.vstack[len(p.vstack)-1]
|
|
_ = stack
|
|
return p.cur.onPrefixedOp1()
|
|
}
|
|
|
|
func (c *current) onSuffixedExpr2(expr, op any) (any, error) {
|
|
pos := c.astPos()
|
|
opStr := op.(string)
|
|
switch opStr {
|
|
case "?":
|
|
zero := ast.NewZeroOrOneExpr(pos)
|
|
zero.Expr = expr.(ast.Expression)
|
|
return zero, nil
|
|
case "*":
|
|
zero := ast.NewZeroOrMoreExpr(pos)
|
|
zero.Expr = expr.(ast.Expression)
|
|
return zero, nil
|
|
case "+":
|
|
one := ast.NewOneOrMoreExpr(pos)
|
|
one.Expr = expr.(ast.Expression)
|
|
return one, nil
|
|
default:
|
|
return nil, errors.New("unknown operator: " + opStr)
|
|
}
|
|
}
|
|
|
|
func (p *parser) callonSuffixedExpr2() (any, error) {
|
|
stack := p.vstack[len(p.vstack)-1]
|
|
_ = stack
|
|
return p.cur.onSuffixedExpr2(stack["expr"], stack["op"])
|
|
}
|
|
|
|
func (c *current) onSuffixedOp1() (any, error) {
|
|
return string(c.text), nil
|
|
}
|
|
|
|
func (p *parser) callonSuffixedOp1() (any, error) {
|
|
stack := p.vstack[len(p.vstack)-1]
|
|
_ = stack
|
|
return p.cur.onSuffixedOp1()
|
|
}
|
|
|
|
func (c *current) onPrimaryExpr7(expr any) (any, error) {
|
|
return expr, nil
|
|
}
|
|
|
|
func (p *parser) callonPrimaryExpr7() (any, error) {
|
|
stack := p.vstack[len(p.vstack)-1]
|
|
_ = stack
|
|
return p.cur.onPrimaryExpr7(stack["expr"])
|
|
}
|
|
|
|
func (c *current) onRuleRefExpr1(name any) (any, error) {
|
|
ref := ast.NewRuleRefExpr(c.astPos())
|
|
ref.Name = name.(*ast.Identifier)
|
|
return ref, nil
|
|
}
|
|
|
|
func (p *parser) callonRuleRefExpr1() (any, error) {
|
|
stack := p.vstack[len(p.vstack)-1]
|
|
_ = stack
|
|
return p.cur.onRuleRefExpr1(stack["name"])
|
|
}
|
|
|
|
func (c *current) onSemanticPredExpr1(op, code any) (any, error) {
|
|
switch op.(string) {
|
|
case "#":
|
|
state := ast.NewStateCodeExpr(c.astPos())
|
|
state.Code = code.(*ast.CodeBlock)
|
|
return state, nil
|
|
|
|
case "&":
|
|
and := ast.NewAndCodeExpr(c.astPos())
|
|
and.Code = code.(*ast.CodeBlock)
|
|
return and, nil
|
|
|
|
// case "!":
|
|
default:
|
|
not := ast.NewNotCodeExpr(c.astPos())
|
|
not.Code = code.(*ast.CodeBlock)
|
|
return not, nil
|
|
|
|
}
|
|
}
|
|
|
|
func (p *parser) callonSemanticPredExpr1() (any, error) {
|
|
stack := p.vstack[len(p.vstack)-1]
|
|
_ = stack
|
|
return p.cur.onSemanticPredExpr1(stack["op"], stack["code"])
|
|
}
|
|
|
|
func (c *current) onSemanticPredOp1() (any, error) {
|
|
return string(c.text), nil
|
|
}
|
|
|
|
func (p *parser) callonSemanticPredOp1() (any, error) {
|
|
stack := p.vstack[len(p.vstack)-1]
|
|
_ = stack
|
|
return p.cur.onSemanticPredOp1()
|
|
}
|
|
|
|
func (c *current) onIdentifier1(ident any) (any, error) {
|
|
astIdent := ast.NewIdentifier(c.astPos(), string(c.text))
|
|
if reservedWords[astIdent.Val] {
|
|
return astIdent, errors.New("identifier is a reserved word")
|
|
}
|
|
return astIdent, nil
|
|
}
|
|
|
|
func (p *parser) callonIdentifier1() (any, error) {
|
|
stack := p.vstack[len(p.vstack)-1]
|
|
_ = stack
|
|
return p.cur.onIdentifier1(stack["ident"])
|
|
}
|
|
|
|
func (c *current) onIdentifierName1() (any, error) {
|
|
return ast.NewIdentifier(c.astPos(), string(c.text)), nil
|
|
}
|
|
|
|
func (p *parser) callonIdentifierName1() (any, error) {
|
|
stack := p.vstack[len(p.vstack)-1]
|
|
_ = stack
|
|
return p.cur.onIdentifierName1()
|
|
}
|
|
|
|
func (c *current) onLitMatcher1(lit, ignore any) (any, error) {
|
|
rawStr := lit.(*ast.StringLit).Val
|
|
s, err := strconv.Unquote(rawStr)
|
|
if err != nil {
|
|
// an invalid string literal raises an error in the escape rules,
|
|
// so simply replace the literal with an empty string here to
|
|
// avoid a cascade of errors.
|
|
s = ""
|
|
}
|
|
m := ast.NewLitMatcher(c.astPos(), s)
|
|
m.IgnoreCase = ignore != nil
|
|
return m, nil
|
|
}
|
|
|
|
func (p *parser) callonLitMatcher1() (any, error) {
|
|
stack := p.vstack[len(p.vstack)-1]
|
|
_ = stack
|
|
return p.cur.onLitMatcher1(stack["lit"], stack["ignore"])
|
|
}
|
|
|
|
func (c *current) onStringLiteral2() (any, error) {
|
|
return ast.NewStringLit(c.astPos(), string(c.text)), nil
|
|
}
|
|
|
|
func (p *parser) callonStringLiteral2() (any, error) {
|
|
stack := p.vstack[len(p.vstack)-1]
|
|
_ = stack
|
|
return p.cur.onStringLiteral2()
|
|
}
|
|
|
|
func (c *current) onStringLiteral18() (any, error) {
|
|
return ast.NewStringLit(c.astPos(), "``"), errors.New("string literal not terminated")
|
|
}
|
|
|
|
func (p *parser) callonStringLiteral18() (any, error) {
|
|
stack := p.vstack[len(p.vstack)-1]
|
|
_ = stack
|
|
return p.cur.onStringLiteral18()
|
|
}
|
|
|
|
func (c *current) onDoubleStringEscape5() (any, error) {
|
|
return nil, errors.New("invalid escape character")
|
|
}
|
|
|
|
func (p *parser) callonDoubleStringEscape5() (any, error) {
|
|
stack := p.vstack[len(p.vstack)-1]
|
|
_ = stack
|
|
return p.cur.onDoubleStringEscape5()
|
|
}
|
|
|
|
func (c *current) onSingleStringEscape5() (any, error) {
|
|
return nil, errors.New("invalid escape character")
|
|
}
|
|
|
|
func (p *parser) callonSingleStringEscape5() (any, error) {
|
|
stack := p.vstack[len(p.vstack)-1]
|
|
_ = stack
|
|
return p.cur.onSingleStringEscape5()
|
|
}
|
|
|
|
func (c *current) onOctalEscape6() (any, error) {
|
|
return nil, errors.New("invalid octal escape")
|
|
}
|
|
|
|
func (p *parser) callonOctalEscape6() (any, error) {
|
|
stack := p.vstack[len(p.vstack)-1]
|
|
_ = stack
|
|
return p.cur.onOctalEscape6()
|
|
}
|
|
|
|
func (c *current) onHexEscape6() (any, error) {
|
|
return nil, errors.New("invalid hexadecimal escape")
|
|
}
|
|
|
|
func (p *parser) callonHexEscape6() (any, error) {
|
|
stack := p.vstack[len(p.vstack)-1]
|
|
_ = stack
|
|
return p.cur.onHexEscape6()
|
|
}
|
|
|
|
func (c *current) onLongUnicodeEscape2() (any, error) {
|
|
return validateUnicodeEscape(string(c.text), "invalid Unicode escape")
|
|
|
|
}
|
|
|
|
func (p *parser) callonLongUnicodeEscape2() (any, error) {
|
|
stack := p.vstack[len(p.vstack)-1]
|
|
_ = stack
|
|
return p.cur.onLongUnicodeEscape2()
|
|
}
|
|
|
|
func (c *current) onLongUnicodeEscape13() (any, error) {
|
|
return nil, errors.New("invalid Unicode escape")
|
|
}
|
|
|
|
func (p *parser) callonLongUnicodeEscape13() (any, error) {
|
|
stack := p.vstack[len(p.vstack)-1]
|
|
_ = stack
|
|
return p.cur.onLongUnicodeEscape13()
|
|
}
|
|
|
|
func (c *current) onShortUnicodeEscape2() (any, error) {
|
|
return validateUnicodeEscape(string(c.text), "invalid Unicode escape")
|
|
|
|
}
|
|
|
|
func (p *parser) callonShortUnicodeEscape2() (any, error) {
|
|
stack := p.vstack[len(p.vstack)-1]
|
|
_ = stack
|
|
return p.cur.onShortUnicodeEscape2()
|
|
}
|
|
|
|
func (c *current) onShortUnicodeEscape9() (any, error) {
|
|
return nil, errors.New("invalid Unicode escape")
|
|
}
|
|
|
|
func (p *parser) callonShortUnicodeEscape9() (any, error) {
|
|
stack := p.vstack[len(p.vstack)-1]
|
|
_ = stack
|
|
return p.cur.onShortUnicodeEscape9()
|
|
}
|
|
|
|
func (c *current) onCharClassMatcher2() (any, error) {
|
|
pos := c.astPos()
|
|
cc := ast.NewCharClassMatcher(pos, string(c.text))
|
|
return cc, nil
|
|
}
|
|
|
|
func (p *parser) callonCharClassMatcher2() (any, error) {
|
|
stack := p.vstack[len(p.vstack)-1]
|
|
_ = stack
|
|
return p.cur.onCharClassMatcher2()
|
|
}
|
|
|
|
func (c *current) onCharClassMatcher15() (any, error) {
|
|
return ast.NewCharClassMatcher(c.astPos(), "[]"), errors.New("character class not terminated")
|
|
}
|
|
|
|
func (p *parser) callonCharClassMatcher15() (any, error) {
|
|
stack := p.vstack[len(p.vstack)-1]
|
|
_ = stack
|
|
return p.cur.onCharClassMatcher15()
|
|
}
|
|
|
|
func (c *current) onCharClassEscape5() (any, error) {
|
|
return nil, errors.New("invalid escape character")
|
|
}
|
|
|
|
func (p *parser) callonCharClassEscape5() (any, error) {
|
|
stack := p.vstack[len(p.vstack)-1]
|
|
_ = stack
|
|
return p.cur.onCharClassEscape5()
|
|
}
|
|
|
|
func (c *current) onUnicodeClassEscape5() (any, error) {
|
|
return nil, errors.New("invalid Unicode class escape")
|
|
}
|
|
|
|
func (p *parser) callonUnicodeClassEscape5() (any, error) {
|
|
stack := p.vstack[len(p.vstack)-1]
|
|
_ = stack
|
|
return p.cur.onUnicodeClassEscape5()
|
|
}
|
|
|
|
func (c *current) onUnicodeClassEscape13(ident any) (any, error) {
|
|
if !unicodeClasses[ident.(*ast.Identifier).Val] {
|
|
return nil, errors.New("invalid Unicode class escape")
|
|
}
|
|
return nil, nil
|
|
|
|
}
|
|
|
|
func (p *parser) callonUnicodeClassEscape13() (any, error) {
|
|
stack := p.vstack[len(p.vstack)-1]
|
|
_ = stack
|
|
return p.cur.onUnicodeClassEscape13(stack["ident"])
|
|
}
|
|
|
|
func (c *current) onUnicodeClassEscape19() (any, error) {
|
|
return nil, errors.New("Unicode class not terminated")
|
|
|
|
}
|
|
|
|
func (p *parser) callonUnicodeClassEscape19() (any, error) {
|
|
stack := p.vstack[len(p.vstack)-1]
|
|
_ = stack
|
|
return p.cur.onUnicodeClassEscape19()
|
|
}
|
|
|
|
func (c *current) onAnyMatcher1() (any, error) {
|
|
any := ast.NewAnyMatcher(c.astPos(), ".")
|
|
return any, nil
|
|
}
|
|
|
|
func (p *parser) callonAnyMatcher1() (any, error) {
|
|
stack := p.vstack[len(p.vstack)-1]
|
|
_ = stack
|
|
return p.cur.onAnyMatcher1()
|
|
}
|
|
|
|
func (c *current) onThrowExpr2(label any) (any, error) {
|
|
t := ast.NewThrowExpr(c.astPos())
|
|
t.Label = label.(*ast.Identifier).Val
|
|
return t, nil
|
|
}
|
|
|
|
func (p *parser) callonThrowExpr2() (any, error) {
|
|
stack := p.vstack[len(p.vstack)-1]
|
|
_ = stack
|
|
return p.cur.onThrowExpr2(stack["label"])
|
|
}
|
|
|
|
func (c *current) onThrowExpr9() (any, error) {
|
|
return nil, errors.New("throw expression not terminated")
|
|
}
|
|
|
|
func (p *parser) callonThrowExpr9() (any, error) {
|
|
stack := p.vstack[len(p.vstack)-1]
|
|
_ = stack
|
|
return p.cur.onThrowExpr9()
|
|
}
|
|
|
|
func (c *current) onCodeBlock2() (any, error) {
|
|
pos := c.astPos()
|
|
cb := ast.NewCodeBlock(pos, string(c.text))
|
|
return cb, nil
|
|
}
|
|
|
|
func (p *parser) callonCodeBlock2() (any, error) {
|
|
stack := p.vstack[len(p.vstack)-1]
|
|
_ = stack
|
|
return p.cur.onCodeBlock2()
|
|
}
|
|
|
|
func (c *current) onCodeBlock7() (any, error) {
|
|
return nil, errors.New("code block not terminated")
|
|
}
|
|
|
|
func (p *parser) callonCodeBlock7() (any, error) {
|
|
stack := p.vstack[len(p.vstack)-1]
|
|
_ = stack
|
|
return p.cur.onCodeBlock7()
|
|
}
|
|
|
|
var (
|
|
// errNoRule is returned when the grammar to parse has no rule.
|
|
errNoRule = errors.New("grammar has no rule")
|
|
|
|
// errInvalidEntrypoint is returned when the specified entrypoint rule
|
|
// does not exit.
|
|
errInvalidEntrypoint = errors.New("invalid entrypoint")
|
|
|
|
// errInvalidEncoding is returned when the source is not properly
|
|
// utf8-encoded.
|
|
errInvalidEncoding = errors.New("invalid encoding")
|
|
|
|
// errMaxExprCnt is used to signal that the maximum number of
|
|
// expressions have been parsed.
|
|
errMaxExprCnt = errors.New("max number of expressions parsed")
|
|
)
|
|
|
|
// Option is a function that can set an option on the parser. It returns
|
|
// the previous setting as an Option.
|
|
type Option func(*parser) Option
|
|
|
|
// MaxExpressions creates an Option to stop parsing after the provided
|
|
// number of expressions have been parsed, if the value is 0 then the parser will
|
|
// parse for as many steps as needed (possibly an infinite number).
|
|
//
|
|
// The default for maxExprCnt is 0.
|
|
func MaxExpressions(maxExprCnt uint64) Option {
|
|
return func(p *parser) Option {
|
|
oldMaxExprCnt := p.maxExprCnt
|
|
p.maxExprCnt = maxExprCnt
|
|
return MaxExpressions(oldMaxExprCnt)
|
|
}
|
|
}
|
|
|
|
// Entrypoint creates an Option to set the rule name to use as entrypoint.
|
|
// The rule name must have been specified in the -alternate-entrypoints
|
|
// if generating the parser with the -optimize-grammar flag, otherwise
|
|
// it may have been optimized out. Passing an empty string sets the
|
|
// entrypoint to the first rule in the grammar.
|
|
//
|
|
// The default is to start parsing at the first rule in the grammar.
|
|
func Entrypoint(ruleName string) Option {
|
|
return func(p *parser) Option {
|
|
oldEntrypoint := p.entrypoint
|
|
p.entrypoint = ruleName
|
|
if ruleName == "" {
|
|
p.entrypoint = g.rules[0].name
|
|
}
|
|
return Entrypoint(oldEntrypoint)
|
|
}
|
|
}
|
|
|
|
// Statistics adds a user provided Stats struct to the parser to allow
|
|
// the user to process the results after the parsing has finished.
|
|
// Also the key for the "no match" counter is set.
|
|
//
|
|
// Example usage:
|
|
//
|
|
// input := "input"
|
|
// stats := Stats{}
|
|
// _, err := Parse("input-file", []byte(input), Statistics(&stats, "no match"))
|
|
// if err != nil {
|
|
// log.Panicln(err)
|
|
// }
|
|
// b, err := json.MarshalIndent(stats.ChoiceAltCnt, "", " ")
|
|
// if err != nil {
|
|
// log.Panicln(err)
|
|
// }
|
|
// fmt.Println(string(b))
|
|
func Statistics(stats *Stats, choiceNoMatch string) Option {
|
|
return func(p *parser) Option {
|
|
oldStats := p.Stats
|
|
p.Stats = stats
|
|
oldChoiceNoMatch := p.choiceNoMatch
|
|
p.choiceNoMatch = choiceNoMatch
|
|
if p.Stats.ChoiceAltCnt == nil {
|
|
p.Stats.ChoiceAltCnt = make(map[string]map[string]int)
|
|
}
|
|
return Statistics(oldStats, oldChoiceNoMatch)
|
|
}
|
|
}
|
|
|
|
// Debug creates an Option to set the debug flag to b. When set to true,
|
|
// debugging information is printed to stdout while parsing.
|
|
//
|
|
// The default is false.
|
|
func Debug(b bool) Option {
|
|
return func(p *parser) Option {
|
|
old := p.debug
|
|
p.debug = b
|
|
return Debug(old)
|
|
}
|
|
}
|
|
|
|
// Memoize creates an Option to set the memoize flag to b. When set to true,
|
|
// the parser will cache all results so each expression is evaluated only
|
|
// once. This guarantees linear parsing time even for pathological cases,
|
|
// at the expense of more memory and slower times for typical cases.
|
|
//
|
|
// The default is false.
|
|
func Memoize(b bool) Option {
|
|
return func(p *parser) Option {
|
|
old := p.memoize
|
|
p.memoize = b
|
|
return Memoize(old)
|
|
}
|
|
}
|
|
|
|
// AllowInvalidUTF8 creates an Option to allow invalid UTF-8 bytes.
|
|
// Every invalid UTF-8 byte is treated as a utf8.RuneError (U+FFFD)
|
|
// by character class matchers and is matched by the any matcher.
|
|
// The returned matched value, c.text and c.offset are NOT affected.
|
|
//
|
|
// The default is false.
|
|
func AllowInvalidUTF8(b bool) Option {
|
|
return func(p *parser) Option {
|
|
old := p.allowInvalidUTF8
|
|
p.allowInvalidUTF8 = b
|
|
return AllowInvalidUTF8(old)
|
|
}
|
|
}
|
|
|
|
// Recover creates an Option to set the recover flag to b. When set to
|
|
// true, this causes the parser to recover from panics and convert it
|
|
// to an error. Setting it to false can be useful while debugging to
|
|
// access the full stack trace.
|
|
//
|
|
// The default is true.
|
|
func Recover(b bool) Option {
|
|
return func(p *parser) Option {
|
|
old := p.recover
|
|
p.recover = b
|
|
return Recover(old)
|
|
}
|
|
}
|
|
|
|
// GlobalStore creates an Option to set a key to a certain value in
|
|
// the globalStore.
|
|
func GlobalStore(key string, value any) Option {
|
|
return func(p *parser) Option {
|
|
old := p.cur.globalStore[key]
|
|
p.cur.globalStore[key] = value
|
|
return GlobalStore(key, old)
|
|
}
|
|
}
|
|
|
|
// InitState creates an Option to set a key to a certain value in
|
|
// the global "state" store.
|
|
func InitState(key string, value any) Option {
|
|
return func(p *parser) Option {
|
|
old := p.cur.state[key]
|
|
p.cur.state[key] = value
|
|
return InitState(key, old)
|
|
}
|
|
}
|
|
|
|
// ParseFile parses the file identified by filename.
|
|
func ParseFile(filename string, opts ...Option) (i any, err error) { // nolint: deadcode
|
|
f, err := os.Open(filename)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
defer func() {
|
|
if closeErr := f.Close(); closeErr != nil {
|
|
err = closeErr
|
|
}
|
|
}()
|
|
return ParseReader(filename, f, opts...)
|
|
}
|
|
|
|
// ParseReader parses the data from r using filename as information in the
|
|
// error messages.
|
|
func ParseReader(filename string, r io.Reader, opts ...Option) (any, error) { // nolint: deadcode
|
|
b, err := io.ReadAll(r)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
return Parse(filename, b, opts...)
|
|
}
|
|
|
|
// Parse parses the data from b using filename as information in the
|
|
// error messages.
|
|
func Parse(filename string, b []byte, opts ...Option) (any, error) {
|
|
return newParser(filename, b, opts...).parse(g)
|
|
}
|
|
|
|
// position records a position in the text.
|
|
type position struct {
|
|
line, col, offset int
|
|
}
|
|
|
|
func (p position) String() string {
|
|
return strconv.Itoa(p.line) + ":" + strconv.Itoa(p.col) + " [" + strconv.Itoa(p.offset) + "]"
|
|
}
|
|
|
|
// savepoint stores all state required to go back to this point in the
|
|
// parser.
|
|
type savepoint struct {
|
|
position
|
|
rn rune
|
|
w int
|
|
}
|
|
|
|
type current struct {
|
|
pos position // start position of the match
|
|
text []byte // raw text of the match
|
|
|
|
// state is a store for arbitrary key,value pairs that the user wants to be
|
|
// tied to the backtracking of the parser.
|
|
// This is always rolled back if a parsing rule fails.
|
|
state storeDict
|
|
|
|
// globalStore is a general store for the user to store arbitrary key-value
|
|
// pairs that they need to manage and that they do not want tied to the
|
|
// backtracking of the parser. This is only modified by the user and never
|
|
// rolled back by the parser. It is always up to the user to keep this in a
|
|
// consistent state.
|
|
globalStore storeDict
|
|
}
|
|
|
|
type storeDict map[string]any
|
|
|
|
// the AST types...
|
|
|
|
// nolint: structcheck
|
|
type grammar struct {
|
|
pos position
|
|
rules []*rule
|
|
}
|
|
|
|
// nolint: structcheck
|
|
type rule struct {
|
|
pos position
|
|
name string
|
|
displayName string
|
|
expr any
|
|
}
|
|
|
|
// nolint: structcheck
|
|
type choiceExpr struct {
|
|
pos position
|
|
alternatives []any
|
|
}
|
|
|
|
// nolint: structcheck
|
|
type actionExpr struct {
|
|
pos position
|
|
expr any
|
|
run func(*parser) (any, error)
|
|
}
|
|
|
|
// nolint: structcheck
|
|
type recoveryExpr struct {
|
|
pos position
|
|
expr any
|
|
recoverExpr any
|
|
failureLabel []string
|
|
}
|
|
|
|
// nolint: structcheck
|
|
type seqExpr struct {
|
|
pos position
|
|
exprs []any
|
|
}
|
|
|
|
// nolint: structcheck
|
|
type throwExpr struct {
|
|
pos position
|
|
label string
|
|
}
|
|
|
|
// nolint: structcheck
|
|
type labeledExpr struct {
|
|
pos position
|
|
label string
|
|
expr any
|
|
}
|
|
|
|
// nolint: structcheck
|
|
type expr struct {
|
|
pos position
|
|
expr any
|
|
}
|
|
|
|
type (
|
|
andExpr expr // nolint: structcheck
|
|
notExpr expr // nolint: structcheck
|
|
zeroOrOneExpr expr // nolint: structcheck
|
|
zeroOrMoreExpr expr // nolint: structcheck
|
|
oneOrMoreExpr expr // nolint: structcheck
|
|
)
|
|
|
|
// nolint: structcheck
|
|
type ruleRefExpr struct {
|
|
pos position
|
|
name string
|
|
}
|
|
|
|
// nolint: structcheck
|
|
type stateCodeExpr struct {
|
|
pos position
|
|
run func(*parser) error
|
|
}
|
|
|
|
// nolint: structcheck
|
|
type andCodeExpr struct {
|
|
pos position
|
|
run func(*parser) (bool, error)
|
|
}
|
|
|
|
// nolint: structcheck
|
|
type notCodeExpr struct {
|
|
pos position
|
|
run func(*parser) (bool, error)
|
|
}
|
|
|
|
// nolint: structcheck
|
|
type litMatcher struct {
|
|
pos position
|
|
val string
|
|
ignoreCase bool
|
|
want string
|
|
}
|
|
|
|
// nolint: structcheck
|
|
type charClassMatcher struct {
|
|
pos position
|
|
val string
|
|
basicLatinChars [128]bool
|
|
chars []rune
|
|
ranges []rune
|
|
classes []*unicode.RangeTable
|
|
ignoreCase bool
|
|
inverted bool
|
|
}
|
|
|
|
type anyMatcher position // nolint: structcheck
|
|
|
|
// errList cumulates the errors found by the parser.
|
|
type errList []error
|
|
|
|
func (e *errList) add(err error) {
|
|
*e = append(*e, err)
|
|
}
|
|
|
|
func (e errList) err() error {
|
|
if len(e) == 0 {
|
|
return nil
|
|
}
|
|
e.dedupe()
|
|
return e
|
|
}
|
|
|
|
func (e *errList) dedupe() {
|
|
var cleaned []error
|
|
set := make(map[string]bool)
|
|
for _, err := range *e {
|
|
if msg := err.Error(); !set[msg] {
|
|
set[msg] = true
|
|
cleaned = append(cleaned, err)
|
|
}
|
|
}
|
|
*e = cleaned
|
|
}
|
|
|
|
func (e errList) Error() string {
|
|
switch len(e) {
|
|
case 0:
|
|
return ""
|
|
case 1:
|
|
return e[0].Error()
|
|
default:
|
|
var buf bytes.Buffer
|
|
|
|
for i, err := range e {
|
|
if i > 0 {
|
|
buf.WriteRune('\n')
|
|
}
|
|
buf.WriteString(err.Error())
|
|
}
|
|
return buf.String()
|
|
}
|
|
}
|
|
|
|
// parserError wraps an error with a prefix indicating the rule in which
|
|
// the error occurred. The original error is stored in the Inner field.
|
|
type parserError struct {
|
|
Inner error
|
|
pos position
|
|
prefix string
|
|
expected []string
|
|
}
|
|
|
|
// Error returns the error message.
|
|
func (p *parserError) Error() string {
|
|
return p.prefix + ": " + p.Inner.Error()
|
|
}
|
|
|
|
// newParser creates a parser with the specified input source and options.
|
|
func newParser(filename string, b []byte, opts ...Option) *parser {
|
|
stats := Stats{
|
|
ChoiceAltCnt: make(map[string]map[string]int),
|
|
}
|
|
|
|
p := &parser{
|
|
filename: filename,
|
|
errs: new(errList),
|
|
data: b,
|
|
pt: savepoint{position: position{line: 1}},
|
|
recover: true,
|
|
cur: current{
|
|
state: make(storeDict),
|
|
globalStore: make(storeDict),
|
|
},
|
|
maxFailPos: position{col: 1, line: 1},
|
|
maxFailExpected: make([]string, 0, 20),
|
|
Stats: &stats,
|
|
// start rule is rule [0] unless an alternate entrypoint is specified
|
|
entrypoint: g.rules[0].name,
|
|
}
|
|
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)
|
|
}
|
|
}
|
|
|
|
// nolint: structcheck,deadcode
|
|
type resultTuple struct {
|
|
v any
|
|
b bool
|
|
end savepoint
|
|
}
|
|
|
|
// nolint: varcheck
|
|
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
|
|
}
|
|
|
|
// nolint: structcheck,maligned
|
|
type parser struct {
|
|
filename string
|
|
pt savepoint
|
|
cur current
|
|
|
|
data []byte
|
|
errs *errList
|
|
|
|
depth int
|
|
recover bool
|
|
debug bool
|
|
|
|
memoize bool
|
|
// memoization table for the packrat algorithm:
|
|
// map[offset in source] map[expression or rule] {value, match}
|
|
memo map[int]map[any]resultTuple
|
|
|
|
// rules table, maps the rule identifier to the rule node
|
|
rules map[string]*rule
|
|
// variables stack, map of label to value
|
|
vstack []map[string]any
|
|
// rule stack, allows identification of the current rule in errors
|
|
rstack []*rule
|
|
|
|
// parse fail
|
|
maxFailPos position
|
|
maxFailExpected []string
|
|
maxFailInvertExpected bool
|
|
|
|
// max number of expressions to be parsed
|
|
maxExprCnt uint64
|
|
// entrypoint for the parser
|
|
entrypoint string
|
|
|
|
allowInvalidUTF8 bool
|
|
|
|
*Stats
|
|
|
|
choiceNoMatch string
|
|
// recovery expression stack, keeps track of the currently available recovery expression, these are traversed in reverse
|
|
recoveryStack []map[string]any
|
|
}
|
|
|
|
// push a variable set on the vstack.
|
|
func (p *parser) pushV() {
|
|
if cap(p.vstack) == len(p.vstack) {
|
|
// create new empty slot in the stack
|
|
p.vstack = append(p.vstack, nil)
|
|
} else {
|
|
// slice to 1 more
|
|
p.vstack = p.vstack[:len(p.vstack)+1]
|
|
}
|
|
|
|
// get the last args set
|
|
m := p.vstack[len(p.vstack)-1]
|
|
if m != nil && len(m) == 0 {
|
|
// empty map, all good
|
|
return
|
|
}
|
|
|
|
m = make(map[string]any)
|
|
p.vstack[len(p.vstack)-1] = m
|
|
}
|
|
|
|
// pop a variable set from the vstack.
|
|
func (p *parser) popV() {
|
|
// if the map is not empty, clear it
|
|
m := p.vstack[len(p.vstack)-1]
|
|
if len(m) > 0 {
|
|
// GC that map
|
|
p.vstack[len(p.vstack)-1] = nil
|
|
}
|
|
p.vstack = p.vstack[:len(p.vstack)-1]
|
|
}
|
|
|
|
// push a recovery expression with its labels to the recoveryStack
|
|
func (p *parser) pushRecovery(labels []string, expr any) {
|
|
if cap(p.recoveryStack) == len(p.recoveryStack) {
|
|
// create new empty slot in the stack
|
|
p.recoveryStack = append(p.recoveryStack, nil)
|
|
} else {
|
|
// slice to 1 more
|
|
p.recoveryStack = p.recoveryStack[:len(p.recoveryStack)+1]
|
|
}
|
|
|
|
m := make(map[string]any, len(labels))
|
|
for _, fl := range labels {
|
|
m[fl] = expr
|
|
}
|
|
p.recoveryStack[len(p.recoveryStack)-1] = m
|
|
}
|
|
|
|
// pop a recovery expression from the recoveryStack
|
|
func (p *parser) popRecovery() {
|
|
// GC that map
|
|
p.recoveryStack[len(p.recoveryStack)-1] = nil
|
|
|
|
p.recoveryStack = p.recoveryStack[:len(p.recoveryStack)-1]
|
|
}
|
|
|
|
func (p *parser) print(prefix, s string) string {
|
|
if !p.debug {
|
|
return s
|
|
}
|
|
|
|
fmt.Printf("%s %d:%d:%d: %s [%#U]\n",
|
|
prefix, p.pt.line, p.pt.col, p.pt.offset, s, p.pt.rn)
|
|
return s
|
|
}
|
|
|
|
func (p *parser) printIndent(mark string, s string) string {
|
|
return p.print(strings.Repeat(" ", p.depth)+mark, s)
|
|
}
|
|
|
|
func (p *parser) in(s string) string {
|
|
res := p.printIndent(">", s)
|
|
p.depth++
|
|
return res
|
|
}
|
|
|
|
func (p *parser) out(s string) string {
|
|
p.depth--
|
|
return p.printIndent("<", s)
|
|
}
|
|
|
|
func (p *parser) addErr(err error) {
|
|
p.addErrAt(err, p.pt.position, []string{})
|
|
}
|
|
|
|
func (p *parser) addErrAt(err error, pos position, expected []string) {
|
|
var buf bytes.Buffer
|
|
if p.filename != "" {
|
|
buf.WriteString(p.filename)
|
|
}
|
|
if buf.Len() > 0 {
|
|
buf.WriteString(":")
|
|
}
|
|
buf.WriteString(fmt.Sprintf("%d:%d (%d)", pos.line, pos.col, pos.offset))
|
|
if len(p.rstack) > 0 {
|
|
if buf.Len() > 0 {
|
|
buf.WriteString(": ")
|
|
}
|
|
rule := p.rstack[len(p.rstack)-1]
|
|
if rule.displayName != "" {
|
|
buf.WriteString("rule " + rule.displayName)
|
|
} else {
|
|
buf.WriteString("rule " + rule.name)
|
|
}
|
|
}
|
|
pe := &parserError{Inner: err, pos: pos, prefix: buf.String(), expected: expected}
|
|
p.errs.add(pe)
|
|
}
|
|
|
|
func (p *parser) failAt(fail bool, pos position, want string) {
|
|
// process fail if parsing fails and not inverted or parsing succeeds and invert is set
|
|
if fail == p.maxFailInvertExpected {
|
|
if pos.offset < p.maxFailPos.offset {
|
|
return
|
|
}
|
|
|
|
if pos.offset > p.maxFailPos.offset {
|
|
p.maxFailPos = pos
|
|
p.maxFailExpected = p.maxFailExpected[:0]
|
|
}
|
|
|
|
if p.maxFailInvertExpected {
|
|
want = "!" + want
|
|
}
|
|
p.maxFailExpected = append(p.maxFailExpected, want)
|
|
}
|
|
}
|
|
|
|
// read advances the parser to the next rune.
|
|
func (p *parser) read() {
|
|
p.pt.offset += p.pt.w
|
|
rn, n := utf8.DecodeRune(p.data[p.pt.offset:])
|
|
p.pt.rn = rn
|
|
p.pt.w = n
|
|
p.pt.col++
|
|
if rn == '\n' {
|
|
p.pt.line++
|
|
p.pt.col = 0
|
|
}
|
|
|
|
if rn == utf8.RuneError && n == 1 { // see utf8.DecodeRune
|
|
if !p.allowInvalidUTF8 {
|
|
p.addErr(errInvalidEncoding)
|
|
}
|
|
}
|
|
}
|
|
|
|
// restore parser position to the savepoint pt.
|
|
func (p *parser) restore(pt savepoint) {
|
|
if p.debug {
|
|
defer p.out(p.in("restore"))
|
|
}
|
|
if pt.offset == p.pt.offset {
|
|
return
|
|
}
|
|
p.pt = pt
|
|
}
|
|
|
|
// Cloner is implemented by any value that has a Clone method, which returns a
|
|
// copy of the value. This is mainly used for types which are not passed by
|
|
// value (e.g map, slice, chan) or structs that contain such types.
|
|
//
|
|
// This is used in conjunction with the global state feature to create proper
|
|
// copies of the state to allow the parser to properly restore the state in
|
|
// the case of backtracking.
|
|
type Cloner interface {
|
|
Clone() any
|
|
}
|
|
|
|
var statePool = &sync.Pool{
|
|
New: func() any { return make(storeDict) },
|
|
}
|
|
|
|
func (sd storeDict) Discard() {
|
|
for k := range sd {
|
|
delete(sd, k)
|
|
}
|
|
statePool.Put(sd)
|
|
}
|
|
|
|
// clone and return parser current state.
|
|
func (p *parser) cloneState() storeDict {
|
|
if p.debug {
|
|
defer p.out(p.in("cloneState"))
|
|
}
|
|
|
|
state := statePool.Get().(storeDict)
|
|
for k, v := range p.cur.state {
|
|
if c, ok := v.(Cloner); ok {
|
|
state[k] = c.Clone()
|
|
} else {
|
|
state[k] = v
|
|
}
|
|
}
|
|
return state
|
|
}
|
|
|
|
// restore parser current state to the state storeDict.
|
|
// every restoreState should applied only one time for every cloned state
|
|
func (p *parser) restoreState(state storeDict) {
|
|
if p.debug {
|
|
defer p.out(p.in("restoreState"))
|
|
}
|
|
p.cur.state.Discard()
|
|
p.cur.state = state
|
|
}
|
|
|
|
// get the slice of bytes from the savepoint start to the current position.
|
|
func (p *parser) sliceFrom(start savepoint) []byte {
|
|
return p.data[start.position.offset:p.pt.position.offset]
|
|
}
|
|
|
|
func (p *parser) getMemoized(node any) (resultTuple, bool) {
|
|
if len(p.memo) == 0 {
|
|
return resultTuple{}, false
|
|
}
|
|
m := p.memo[p.pt.offset]
|
|
if len(m) == 0 {
|
|
return resultTuple{}, false
|
|
}
|
|
res, ok := m[node]
|
|
return res, ok
|
|
}
|
|
|
|
func (p *parser) setMemoized(pt savepoint, node any, tuple resultTuple) {
|
|
if p.memo == nil {
|
|
p.memo = make(map[int]map[any]resultTuple)
|
|
}
|
|
m := p.memo[pt.offset]
|
|
if m == nil {
|
|
m = make(map[any]resultTuple)
|
|
p.memo[pt.offset] = m
|
|
}
|
|
m[node] = tuple
|
|
}
|
|
|
|
func (p *parser) buildRulesTable(g *grammar) {
|
|
p.rules = make(map[string]*rule, len(g.rules))
|
|
for _, r := range g.rules {
|
|
p.rules[r.name] = r
|
|
}
|
|
}
|
|
|
|
// nolint: gocyclo
|
|
func (p *parser) parse(g *grammar) (val any, err error) {
|
|
if len(g.rules) == 0 {
|
|
p.addErr(errNoRule)
|
|
return nil, p.errs.err()
|
|
}
|
|
|
|
// TODO : not super critical but this could be generated
|
|
p.buildRulesTable(g)
|
|
|
|
if p.recover {
|
|
// panic can be used in action code to stop parsing immediately
|
|
// and return the panic as an error.
|
|
defer func() {
|
|
if e := recover(); e != nil {
|
|
if p.debug {
|
|
defer p.out(p.in("panic handler"))
|
|
}
|
|
val = nil
|
|
switch e := e.(type) {
|
|
case error:
|
|
p.addErr(e)
|
|
default:
|
|
p.addErr(fmt.Errorf("%v", e))
|
|
}
|
|
err = p.errs.err()
|
|
}
|
|
}()
|
|
}
|
|
|
|
startRule, ok := p.rules[p.entrypoint]
|
|
if !ok {
|
|
p.addErr(errInvalidEntrypoint)
|
|
return nil, p.errs.err()
|
|
}
|
|
|
|
p.read() // advance to first rune
|
|
val, ok = p.parseRuleWrap(startRule)
|
|
if !ok {
|
|
if len(*p.errs) == 0 {
|
|
// If parsing fails, but no errors have been recorded, the expected values
|
|
// for the farthest parser position are returned as error.
|
|
maxFailExpectedMap := make(map[string]struct{}, len(p.maxFailExpected))
|
|
for _, v := range p.maxFailExpected {
|
|
maxFailExpectedMap[v] = struct{}{}
|
|
}
|
|
expected := make([]string, 0, len(maxFailExpectedMap))
|
|
eof := false
|
|
if _, ok := maxFailExpectedMap["!."]; ok {
|
|
delete(maxFailExpectedMap, "!.")
|
|
eof = true
|
|
}
|
|
for k := range maxFailExpectedMap {
|
|
expected = append(expected, k)
|
|
}
|
|
sort.Strings(expected)
|
|
if eof {
|
|
expected = append(expected, "EOF")
|
|
}
|
|
p.addErrAt(errors.New("no match found, expected: "+listJoin(expected, ", ", "or")), p.maxFailPos, expected)
|
|
}
|
|
|
|
return nil, p.errs.err()
|
|
}
|
|
return val, p.errs.err()
|
|
}
|
|
|
|
func listJoin(list []string, sep string, lastSep string) string {
|
|
switch len(list) {
|
|
case 0:
|
|
return ""
|
|
case 1:
|
|
return list[0]
|
|
default:
|
|
return strings.Join(list[:len(list)-1], sep) + " " + lastSep + " " + list[len(list)-1]
|
|
}
|
|
}
|
|
|
|
func (p *parser) parseRuleMemoize(rule *rule) (any, bool) {
|
|
res, ok := p.getMemoized(rule)
|
|
if ok {
|
|
p.restore(res.end)
|
|
return res.v, res.b
|
|
}
|
|
|
|
startMark := p.pt
|
|
val, ok := p.parseRule(rule)
|
|
p.setMemoized(startMark, rule, resultTuple{val, ok, p.pt})
|
|
|
|
return val, ok
|
|
}
|
|
|
|
func (p *parser) parseRuleWrap(rule *rule) (any, bool) {
|
|
if p.debug {
|
|
defer p.out(p.in("parseRule " + rule.name))
|
|
}
|
|
var (
|
|
val any
|
|
ok bool
|
|
startMark = p.pt
|
|
)
|
|
|
|
if p.memoize {
|
|
val, ok = p.parseRuleMemoize(rule)
|
|
} else {
|
|
val, ok = p.parseRule(rule)
|
|
}
|
|
|
|
if ok && p.debug {
|
|
p.printIndent("MATCH", string(p.sliceFrom(startMark)))
|
|
}
|
|
return val, ok
|
|
}
|
|
|
|
func (p *parser) parseRule(rule *rule) (any, bool) {
|
|
p.rstack = append(p.rstack, rule)
|
|
p.pushV()
|
|
val, ok := p.parseExprWrap(rule.expr)
|
|
p.popV()
|
|
p.rstack = p.rstack[:len(p.rstack)-1]
|
|
return val, ok
|
|
}
|
|
|
|
func (p *parser) parseExprWrap(expr any) (any, bool) {
|
|
var pt savepoint
|
|
|
|
if p.memoize {
|
|
res, ok := p.getMemoized(expr)
|
|
if ok {
|
|
p.restore(res.end)
|
|
return res.v, res.b
|
|
}
|
|
pt = p.pt
|
|
}
|
|
|
|
val, ok := p.parseExpr(expr)
|
|
|
|
if p.memoize {
|
|
p.setMemoized(pt, expr, resultTuple{val, ok, p.pt})
|
|
}
|
|
return val, ok
|
|
}
|
|
|
|
// nolint: gocyclo
|
|
func (p *parser) parseExpr(expr any) (any, bool) {
|
|
p.ExprCnt++
|
|
if p.ExprCnt > p.maxExprCnt {
|
|
panic(errMaxExprCnt)
|
|
}
|
|
|
|
var val any
|
|
var ok bool
|
|
switch expr := expr.(type) {
|
|
case *actionExpr:
|
|
val, ok = p.parseActionExpr(expr)
|
|
case *andCodeExpr:
|
|
val, ok = p.parseAndCodeExpr(expr)
|
|
case *andExpr:
|
|
val, ok = p.parseAndExpr(expr)
|
|
case *anyMatcher:
|
|
val, ok = p.parseAnyMatcher(expr)
|
|
case *charClassMatcher:
|
|
val, ok = p.parseCharClassMatcher(expr)
|
|
case *choiceExpr:
|
|
val, ok = p.parseChoiceExpr(expr)
|
|
case *labeledExpr:
|
|
val, ok = p.parseLabeledExpr(expr)
|
|
case *litMatcher:
|
|
val, ok = p.parseLitMatcher(expr)
|
|
case *notCodeExpr:
|
|
val, ok = p.parseNotCodeExpr(expr)
|
|
case *notExpr:
|
|
val, ok = p.parseNotExpr(expr)
|
|
case *oneOrMoreExpr:
|
|
val, ok = p.parseOneOrMoreExpr(expr)
|
|
case *recoveryExpr:
|
|
val, ok = p.parseRecoveryExpr(expr)
|
|
case *ruleRefExpr:
|
|
val, ok = p.parseRuleRefExpr(expr)
|
|
case *seqExpr:
|
|
val, ok = p.parseSeqExpr(expr)
|
|
case *stateCodeExpr:
|
|
val, ok = p.parseStateCodeExpr(expr)
|
|
case *throwExpr:
|
|
val, ok = p.parseThrowExpr(expr)
|
|
case *zeroOrMoreExpr:
|
|
val, ok = p.parseZeroOrMoreExpr(expr)
|
|
case *zeroOrOneExpr:
|
|
val, ok = p.parseZeroOrOneExpr(expr)
|
|
default:
|
|
panic(fmt.Sprintf("unknown expression type %T", expr))
|
|
}
|
|
return val, ok
|
|
}
|
|
|
|
func (p *parser) parseActionExpr(act *actionExpr) (any, bool) {
|
|
if p.debug {
|
|
defer p.out(p.in("parseActionExpr"))
|
|
}
|
|
|
|
start := p.pt
|
|
val, ok := p.parseExprWrap(act.expr)
|
|
if ok {
|
|
p.cur.pos = start.position
|
|
p.cur.text = p.sliceFrom(start)
|
|
state := p.cloneState()
|
|
actVal, err := act.run(p)
|
|
if err != nil {
|
|
p.addErrAt(err, start.position, []string{})
|
|
}
|
|
p.restoreState(state)
|
|
|
|
val = actVal
|
|
}
|
|
if ok && p.debug {
|
|
p.printIndent("MATCH", string(p.sliceFrom(start)))
|
|
}
|
|
return val, ok
|
|
}
|
|
|
|
func (p *parser) parseAndCodeExpr(and *andCodeExpr) (any, bool) {
|
|
if p.debug {
|
|
defer p.out(p.in("parseAndCodeExpr"))
|
|
}
|
|
|
|
state := p.cloneState()
|
|
|
|
ok, err := and.run(p)
|
|
if err != nil {
|
|
p.addErr(err)
|
|
}
|
|
p.restoreState(state)
|
|
|
|
return nil, ok
|
|
}
|
|
|
|
func (p *parser) parseAndExpr(and *andExpr) (any, bool) {
|
|
if p.debug {
|
|
defer p.out(p.in("parseAndExpr"))
|
|
}
|
|
|
|
pt := p.pt
|
|
state := p.cloneState()
|
|
p.pushV()
|
|
_, ok := p.parseExprWrap(and.expr)
|
|
p.popV()
|
|
p.restoreState(state)
|
|
p.restore(pt)
|
|
|
|
return nil, ok
|
|
}
|
|
|
|
func (p *parser) parseAnyMatcher(any *anyMatcher) (any, bool) {
|
|
if p.debug {
|
|
defer p.out(p.in("parseAnyMatcher"))
|
|
}
|
|
|
|
if p.pt.rn == utf8.RuneError && p.pt.w == 0 {
|
|
// EOF - see utf8.DecodeRune
|
|
p.failAt(false, p.pt.position, ".")
|
|
return nil, false
|
|
}
|
|
start := p.pt
|
|
p.read()
|
|
p.failAt(true, start.position, ".")
|
|
return p.sliceFrom(start), true
|
|
}
|
|
|
|
// nolint: gocyclo
|
|
func (p *parser) parseCharClassMatcher(chr *charClassMatcher) (any, bool) {
|
|
if p.debug {
|
|
defer p.out(p.in("parseCharClassMatcher"))
|
|
}
|
|
|
|
cur := p.pt.rn
|
|
start := p.pt
|
|
|
|
// can't match EOF
|
|
if cur == utf8.RuneError && p.pt.w == 0 { // see utf8.DecodeRune
|
|
p.failAt(false, start.position, chr.val)
|
|
return nil, false
|
|
}
|
|
|
|
if chr.ignoreCase {
|
|
cur = unicode.ToLower(cur)
|
|
}
|
|
|
|
// try to match in the list of available chars
|
|
for _, rn := range chr.chars {
|
|
if rn == cur {
|
|
if chr.inverted {
|
|
p.failAt(false, start.position, chr.val)
|
|
return nil, false
|
|
}
|
|
p.read()
|
|
p.failAt(true, start.position, chr.val)
|
|
return p.sliceFrom(start), true
|
|
}
|
|
}
|
|
|
|
// try to match in the list of ranges
|
|
for i := 0; i < len(chr.ranges); i += 2 {
|
|
if cur >= chr.ranges[i] && cur <= chr.ranges[i+1] {
|
|
if chr.inverted {
|
|
p.failAt(false, start.position, chr.val)
|
|
return nil, false
|
|
}
|
|
p.read()
|
|
p.failAt(true, start.position, chr.val)
|
|
return p.sliceFrom(start), true
|
|
}
|
|
}
|
|
|
|
// try to match in the list of Unicode classes
|
|
for _, cl := range chr.classes {
|
|
if unicode.Is(cl, cur) {
|
|
if chr.inverted {
|
|
p.failAt(false, start.position, chr.val)
|
|
return nil, false
|
|
}
|
|
p.read()
|
|
p.failAt(true, start.position, chr.val)
|
|
return p.sliceFrom(start), true
|
|
}
|
|
}
|
|
|
|
if chr.inverted {
|
|
p.read()
|
|
p.failAt(true, start.position, chr.val)
|
|
return p.sliceFrom(start), true
|
|
}
|
|
p.failAt(false, start.position, chr.val)
|
|
return nil, false
|
|
}
|
|
|
|
func (p *parser) incChoiceAltCnt(ch *choiceExpr, altI int) {
|
|
choiceIdent := fmt.Sprintf("%s %d:%d", p.rstack[len(p.rstack)-1].name, ch.pos.line, ch.pos.col)
|
|
m := p.ChoiceAltCnt[choiceIdent]
|
|
if m == nil {
|
|
m = make(map[string]int)
|
|
p.ChoiceAltCnt[choiceIdent] = m
|
|
}
|
|
// We increment altI by 1, so the keys do not start at 0
|
|
alt := strconv.Itoa(altI + 1)
|
|
if altI == choiceNoMatch {
|
|
alt = p.choiceNoMatch
|
|
}
|
|
m[alt]++
|
|
}
|
|
|
|
func (p *parser) parseChoiceExpr(ch *choiceExpr) (any, bool) {
|
|
if p.debug {
|
|
defer p.out(p.in("parseChoiceExpr"))
|
|
}
|
|
|
|
for altI, alt := range ch.alternatives {
|
|
// dummy assignment to prevent compile error if optimized
|
|
_ = altI
|
|
|
|
state := p.cloneState()
|
|
|
|
p.pushV()
|
|
val, ok := p.parseExprWrap(alt)
|
|
p.popV()
|
|
if ok {
|
|
p.incChoiceAltCnt(ch, altI)
|
|
return val, ok
|
|
}
|
|
p.restoreState(state)
|
|
}
|
|
p.incChoiceAltCnt(ch, choiceNoMatch)
|
|
return nil, false
|
|
}
|
|
|
|
func (p *parser) parseLabeledExpr(lab *labeledExpr) (any, bool) {
|
|
if p.debug {
|
|
defer p.out(p.in("parseLabeledExpr"))
|
|
}
|
|
|
|
p.pushV()
|
|
val, ok := p.parseExprWrap(lab.expr)
|
|
p.popV()
|
|
if ok && lab.label != "" {
|
|
m := p.vstack[len(p.vstack)-1]
|
|
m[lab.label] = val
|
|
}
|
|
return val, ok
|
|
}
|
|
|
|
func (p *parser) parseLitMatcher(lit *litMatcher) (any, bool) {
|
|
if p.debug {
|
|
defer p.out(p.in("parseLitMatcher"))
|
|
}
|
|
|
|
start := p.pt
|
|
for _, want := range lit.val {
|
|
cur := p.pt.rn
|
|
if lit.ignoreCase {
|
|
cur = unicode.ToLower(cur)
|
|
}
|
|
if cur != want {
|
|
p.failAt(false, start.position, lit.want)
|
|
p.restore(start)
|
|
return nil, false
|
|
}
|
|
p.read()
|
|
}
|
|
p.failAt(true, start.position, lit.want)
|
|
return p.sliceFrom(start), true
|
|
}
|
|
|
|
func (p *parser) parseNotCodeExpr(not *notCodeExpr) (any, bool) {
|
|
if p.debug {
|
|
defer p.out(p.in("parseNotCodeExpr"))
|
|
}
|
|
|
|
state := p.cloneState()
|
|
|
|
ok, err := not.run(p)
|
|
if err != nil {
|
|
p.addErr(err)
|
|
}
|
|
p.restoreState(state)
|
|
|
|
return nil, !ok
|
|
}
|
|
|
|
func (p *parser) parseNotExpr(not *notExpr) (any, bool) {
|
|
if p.debug {
|
|
defer p.out(p.in("parseNotExpr"))
|
|
}
|
|
|
|
pt := p.pt
|
|
state := p.cloneState()
|
|
p.pushV()
|
|
p.maxFailInvertExpected = !p.maxFailInvertExpected
|
|
_, ok := p.parseExprWrap(not.expr)
|
|
p.maxFailInvertExpected = !p.maxFailInvertExpected
|
|
p.popV()
|
|
p.restoreState(state)
|
|
p.restore(pt)
|
|
|
|
return nil, !ok
|
|
}
|
|
|
|
func (p *parser) parseOneOrMoreExpr(expr *oneOrMoreExpr) (any, bool) {
|
|
if p.debug {
|
|
defer p.out(p.in("parseOneOrMoreExpr"))
|
|
}
|
|
|
|
var vals []any
|
|
|
|
for {
|
|
p.pushV()
|
|
val, ok := p.parseExprWrap(expr.expr)
|
|
p.popV()
|
|
if !ok {
|
|
if len(vals) == 0 {
|
|
// did not match once, no match
|
|
return nil, false
|
|
}
|
|
return vals, true
|
|
}
|
|
vals = append(vals, val)
|
|
}
|
|
}
|
|
|
|
func (p *parser) parseRecoveryExpr(recover *recoveryExpr) (any, bool) {
|
|
if p.debug {
|
|
defer p.out(p.in("parseRecoveryExpr (" + strings.Join(recover.failureLabel, ",") + ")"))
|
|
}
|
|
|
|
p.pushRecovery(recover.failureLabel, recover.recoverExpr)
|
|
val, ok := p.parseExprWrap(recover.expr)
|
|
p.popRecovery()
|
|
|
|
return val, ok
|
|
}
|
|
|
|
func (p *parser) parseRuleRefExpr(ref *ruleRefExpr) (any, bool) {
|
|
if p.debug {
|
|
defer p.out(p.in("parseRuleRefExpr " + ref.name))
|
|
}
|
|
|
|
if ref.name == "" {
|
|
panic(fmt.Sprintf("%s: invalid rule: missing name", ref.pos))
|
|
}
|
|
|
|
rule := p.rules[ref.name]
|
|
if rule == nil {
|
|
p.addErr(fmt.Errorf("undefined rule: %s", ref.name))
|
|
return nil, false
|
|
}
|
|
return p.parseRuleWrap(rule)
|
|
}
|
|
|
|
func (p *parser) parseSeqExpr(seq *seqExpr) (any, bool) {
|
|
if p.debug {
|
|
defer p.out(p.in("parseSeqExpr"))
|
|
}
|
|
|
|
vals := make([]any, 0, len(seq.exprs))
|
|
|
|
pt := p.pt
|
|
state := p.cloneState()
|
|
for _, expr := range seq.exprs {
|
|
val, ok := p.parseExprWrap(expr)
|
|
if !ok {
|
|
p.restoreState(state)
|
|
p.restore(pt)
|
|
return nil, false
|
|
}
|
|
vals = append(vals, val)
|
|
}
|
|
return vals, true
|
|
}
|
|
|
|
func (p *parser) parseStateCodeExpr(state *stateCodeExpr) (any, bool) {
|
|
if p.debug {
|
|
defer p.out(p.in("parseStateCodeExpr"))
|
|
}
|
|
|
|
err := state.run(p)
|
|
if err != nil {
|
|
p.addErr(err)
|
|
}
|
|
return nil, true
|
|
}
|
|
|
|
func (p *parser) parseThrowExpr(expr *throwExpr) (any, bool) {
|
|
if p.debug {
|
|
defer p.out(p.in("parseThrowExpr"))
|
|
}
|
|
|
|
for i := len(p.recoveryStack) - 1; i >= 0; i-- {
|
|
if recoverExpr, ok := p.recoveryStack[i][expr.label]; ok {
|
|
if val, ok := p.parseExprWrap(recoverExpr); ok {
|
|
return val, ok
|
|
}
|
|
}
|
|
}
|
|
|
|
return nil, false
|
|
}
|
|
|
|
func (p *parser) parseZeroOrMoreExpr(expr *zeroOrMoreExpr) (any, bool) {
|
|
if p.debug {
|
|
defer p.out(p.in("parseZeroOrMoreExpr"))
|
|
}
|
|
|
|
var vals []any
|
|
|
|
for {
|
|
p.pushV()
|
|
val, ok := p.parseExprWrap(expr.expr)
|
|
p.popV()
|
|
if !ok {
|
|
return vals, true
|
|
}
|
|
vals = append(vals, val)
|
|
}
|
|
}
|
|
|
|
func (p *parser) parseZeroOrOneExpr(expr *zeroOrOneExpr) (any, bool) {
|
|
if p.debug {
|
|
defer p.out(p.in("parseZeroOrOneExpr"))
|
|
}
|
|
|
|
p.pushV()
|
|
val, _ := p.parseExprWrap(expr.expr)
|
|
p.popV()
|
|
// whether it matched or not, consider it a match
|
|
return val, true
|
|
}
|
|
|
|
func rangeTable(class string) *unicode.RangeTable {
|
|
if rt, ok := unicode.Categories[class]; ok {
|
|
return rt
|
|
}
|
|
if rt, ok := unicode.Properties[class]; ok {
|
|
return rt
|
|
}
|
|
if rt, ok := unicode.Scripts[class]; ok {
|
|
return rt
|
|
}
|
|
|
|
// cannot happen
|
|
panic(fmt.Sprintf("invalid Unicode class: %s", class))
|
|
}
|