diff --git a/README.md b/README.md index 37138bb5..e9e14d96 100644 --- a/README.md +++ b/README.md @@ -69,18 +69,18 @@ var ops = map[string]func(int, int) int { }, } -func toIfaceSlice(v interface{}) []interface{} { +func toAnySlice(v any) []any { if v == nil { return nil } - return v.([]interface{}) + return v.([]any) } -func eval(first, rest interface{}) int { +func eval(first, rest any) int { l := first.(int) - restSl := toIfaceSlice(rest) + restSl := toAnySlice(rest) for _, v := range restSl { - restExpr := toIfaceSlice(v) + restExpr := toAnySlice(v) r := restExpr[3].(int) op := restExpr[1].(string) l = ops[op](l, r) diff --git a/ast/ast_optimize.go b/ast/ast_optimize.go index 84428688..4687c8bd 100644 --- a/ast/ast_optimize.go +++ b/ast/ast_optimize.go @@ -441,14 +441,14 @@ func escapeRune(r rune) string { // Optimize walks a given grammar and optimizes the grammar in regards // of parsing performance. This is done with several optimizations: -// * removal of unreferenced rules -// * replace rule references with a copy of the referenced Rule, if the -// referenced rule it self has no references. -// * resolve nested choice expressions -// * resolve choice expressions with only one alternative -// * resolve nested sequences expression -// * resolve sequence expressions with only one element -// * combine character class matcher and literal matcher, where possible +// - removal of unreferenced rules +// - replace rule references with a copy of the referenced Rule, if the +// referenced rule it self has no references. +// - resolve nested choice expressions +// - resolve choice expressions with only one alternative +// - resolve nested sequences expression +// - resolve sequence expressions with only one element +// - combine character class matcher and literal matcher, where possible func Optimize(g *Grammar, alternateEntrypoints ...string) { entrypoints := alternateEntrypoints if len(g.Rules) > 0 { diff --git a/ast/ast_walk.go b/ast/ast_walk.go index 862d7d8d..3a50ca48 100644 --- a/ast/ast_walk.go +++ b/ast/ast_walk.go @@ -15,7 +15,6 @@ type Visitor interface { // v.Visit(expr) is not nil, Walk is invoked recursively with visitor // w for each of the non-nil children of Expression, followed by a call of // w.Visit(nil). -// func Walk(v Visitor, expr Expression) { if v = v.Visit(expr); v == nil { return diff --git a/bootstrap/cmd/bootstrap-pigeon/bootstrap_pigeon.go b/bootstrap/cmd/bootstrap-pigeon/bootstrap_pigeon.go index 36839e55..fdfa0d70 100644 --- a/bootstrap/cmd/bootstrap-pigeon/bootstrap_pigeon.go +++ b/bootstrap/cmd/bootstrap-pigeon/bootstrap_pigeon.go @@ -29,7 +29,7 @@ var g = &grammar{ run: (*parser).callonGrammar1, expr: &seqExpr{ pos: position{line: 5, col: 11, offset: 30}, - exprs: []interface{}{ + exprs: []any{ &ruleRefExpr{ pos: position{line: 5, col: 11, offset: 30}, name: "__", @@ -41,7 +41,7 @@ var g = &grammar{ pos: position{line: 5, col: 28, offset: 47}, expr: &seqExpr{ pos: position{line: 5, col: 28, offset: 47}, - exprs: []interface{}{ + exprs: []any{ &ruleRefExpr{ pos: position{line: 5, col: 28, offset: 47}, name: "Initializer", @@ -61,7 +61,7 @@ var g = &grammar{ pos: position{line: 5, col: 54, offset: 73}, expr: &seqExpr{ pos: position{line: 5, col: 54, offset: 73}, - exprs: []interface{}{ + exprs: []any{ &ruleRefExpr{ pos: position{line: 5, col: 54, offset: 73}, name: "Rule", @@ -80,23 +80,23 @@ var g = &grammar{ }, { name: "Initializer", - pos: position{line: 24, col: 1, offset: 521}, + pos: position{line: 24, col: 1, offset: 509}, expr: &actionExpr{ - pos: position{line: 24, col: 15, offset: 537}, + pos: position{line: 24, col: 15, offset: 525}, run: (*parser).callonInitializer1, expr: &seqExpr{ - pos: position{line: 24, col: 15, offset: 537}, - exprs: []interface{}{ + pos: position{line: 24, col: 15, offset: 525}, + exprs: []any{ &labeledExpr{ - pos: position{line: 24, col: 15, offset: 537}, + pos: position{line: 24, col: 15, offset: 525}, label: "code", expr: &ruleRefExpr{ - pos: position{line: 24, col: 20, offset: 542}, + pos: position{line: 24, col: 20, offset: 530}, name: "CodeBlock", }, }, &ruleRefExpr{ - pos: position{line: 24, col: 30, offset: 552}, + pos: position{line: 24, col: 30, offset: 540}, name: "EOS", }, }, @@ -105,39 +105,39 @@ var g = &grammar{ }, { name: "Rule", - pos: position{line: 28, col: 1, offset: 582}, + pos: position{line: 28, col: 1, offset: 570}, expr: &actionExpr{ - pos: position{line: 28, col: 8, offset: 591}, + pos: position{line: 28, col: 8, offset: 579}, run: (*parser).callonRule1, expr: &seqExpr{ - pos: position{line: 28, col: 8, offset: 591}, - exprs: []interface{}{ + pos: position{line: 28, col: 8, offset: 579}, + exprs: []any{ &labeledExpr{ - pos: position{line: 28, col: 8, offset: 591}, + pos: position{line: 28, col: 8, offset: 579}, label: "name", expr: &ruleRefExpr{ - pos: position{line: 28, col: 13, offset: 596}, + pos: position{line: 28, col: 13, offset: 584}, name: "IdentifierName", }, }, &ruleRefExpr{ - pos: position{line: 28, col: 28, offset: 611}, + pos: position{line: 28, col: 28, offset: 599}, name: "__", }, &labeledExpr{ - pos: position{line: 28, col: 31, offset: 614}, + pos: position{line: 28, col: 31, offset: 602}, label: "display", expr: &zeroOrOneExpr{ - pos: position{line: 28, col: 41, offset: 624}, + pos: position{line: 28, col: 41, offset: 612}, expr: &seqExpr{ - pos: position{line: 28, col: 41, offset: 624}, - exprs: []interface{}{ + pos: position{line: 28, col: 41, offset: 612}, + exprs: []any{ &ruleRefExpr{ - pos: position{line: 28, col: 41, offset: 624}, + pos: position{line: 28, col: 41, offset: 612}, name: "StringLiteral", }, &ruleRefExpr{ - pos: position{line: 28, col: 55, offset: 638}, + pos: position{line: 28, col: 55, offset: 626}, name: "__", }, }, @@ -145,23 +145,23 @@ var g = &grammar{ }, }, &ruleRefExpr{ - pos: position{line: 28, col: 61, offset: 644}, + pos: position{line: 28, col: 61, offset: 632}, name: "RuleDefOp", }, &ruleRefExpr{ - pos: position{line: 28, col: 71, offset: 654}, + pos: position{line: 28, col: 71, offset: 642}, name: "__", }, &labeledExpr{ - pos: position{line: 28, col: 74, offset: 657}, + pos: position{line: 28, col: 74, offset: 645}, label: "expr", expr: &ruleRefExpr{ - pos: position{line: 28, col: 79, offset: 662}, + pos: position{line: 28, col: 79, offset: 650}, name: "Expression", }, }, &ruleRefExpr{ - pos: position{line: 28, col: 90, offset: 673}, + pos: position{line: 28, col: 90, offset: 661}, name: "EOS", }, }, @@ -170,53 +170,53 @@ var g = &grammar{ }, { name: "Expression", - pos: position{line: 41, col: 1, offset: 957}, + pos: position{line: 41, col: 1, offset: 943}, expr: &ruleRefExpr{ - pos: position{line: 41, col: 14, offset: 972}, + pos: position{line: 41, col: 14, offset: 958}, name: "ChoiceExpr", }, }, { name: "ChoiceExpr", - pos: position{line: 43, col: 1, offset: 984}, + pos: position{line: 43, col: 1, offset: 970}, expr: &actionExpr{ - pos: position{line: 43, col: 14, offset: 999}, + pos: position{line: 43, col: 14, offset: 985}, run: (*parser).callonChoiceExpr1, expr: &seqExpr{ - pos: position{line: 43, col: 14, offset: 999}, - exprs: []interface{}{ + pos: position{line: 43, col: 14, offset: 985}, + exprs: []any{ &labeledExpr{ - pos: position{line: 43, col: 14, offset: 999}, + pos: position{line: 43, col: 14, offset: 985}, label: "first", expr: &ruleRefExpr{ - pos: position{line: 43, col: 20, offset: 1005}, + pos: position{line: 43, col: 20, offset: 991}, name: "ActionExpr", }, }, &labeledExpr{ - pos: position{line: 43, col: 31, offset: 1016}, + pos: position{line: 43, col: 31, offset: 1002}, label: "rest", expr: &zeroOrMoreExpr{ - pos: position{line: 43, col: 38, offset: 1023}, + pos: position{line: 43, col: 38, offset: 1009}, expr: &seqExpr{ - pos: position{line: 43, col: 38, offset: 1023}, - exprs: []interface{}{ + pos: position{line: 43, col: 38, offset: 1009}, + exprs: []any{ &ruleRefExpr{ - pos: position{line: 43, col: 38, offset: 1023}, + pos: position{line: 43, col: 38, offset: 1009}, name: "__", }, &litMatcher{ - pos: position{line: 43, col: 41, offset: 1026}, + pos: position{line: 43, col: 41, offset: 1012}, val: "/", ignoreCase: false, want: "\"/\"", }, &ruleRefExpr{ - pos: position{line: 43, col: 45, offset: 1030}, + pos: position{line: 43, col: 45, offset: 1016}, name: "__", }, &ruleRefExpr{ - pos: position{line: 43, col: 48, offset: 1033}, + pos: position{line: 43, col: 48, offset: 1019}, name: "ActionExpr", }, }, @@ -229,35 +229,35 @@ var g = &grammar{ }, { name: "ActionExpr", - pos: position{line: 58, col: 1, offset: 1438}, + pos: position{line: 58, col: 1, offset: 1414}, expr: &actionExpr{ - pos: position{line: 58, col: 14, offset: 1453}, + pos: position{line: 58, col: 14, offset: 1429}, run: (*parser).callonActionExpr1, expr: &seqExpr{ - pos: position{line: 58, col: 14, offset: 1453}, - exprs: []interface{}{ + pos: position{line: 58, col: 14, offset: 1429}, + exprs: []any{ &labeledExpr{ - pos: position{line: 58, col: 14, offset: 1453}, + pos: position{line: 58, col: 14, offset: 1429}, label: "expr", expr: &ruleRefExpr{ - pos: position{line: 58, col: 19, offset: 1458}, + pos: position{line: 58, col: 19, offset: 1434}, name: "SeqExpr", }, }, &labeledExpr{ - pos: position{line: 58, col: 27, offset: 1466}, + pos: position{line: 58, col: 27, offset: 1442}, label: "code", expr: &zeroOrOneExpr{ - pos: position{line: 58, col: 34, offset: 1473}, + pos: position{line: 58, col: 34, offset: 1449}, expr: &seqExpr{ - pos: position{line: 58, col: 34, offset: 1473}, - exprs: []interface{}{ + pos: position{line: 58, col: 34, offset: 1449}, + exprs: []any{ &ruleRefExpr{ - pos: position{line: 58, col: 34, offset: 1473}, + pos: position{line: 58, col: 34, offset: 1449}, name: "__", }, &ruleRefExpr{ - pos: position{line: 58, col: 37, offset: 1476}, + pos: position{line: 58, col: 37, offset: 1452}, name: "CodeBlock", }, }, @@ -270,35 +270,35 @@ var g = &grammar{ }, { name: "SeqExpr", - pos: position{line: 72, col: 1, offset: 1742}, + pos: position{line: 72, col: 1, offset: 1716}, expr: &actionExpr{ - pos: position{line: 72, col: 11, offset: 1754}, + pos: position{line: 72, col: 11, offset: 1728}, run: (*parser).callonSeqExpr1, expr: &seqExpr{ - pos: position{line: 72, col: 11, offset: 1754}, - exprs: []interface{}{ + pos: position{line: 72, col: 11, offset: 1728}, + exprs: []any{ &labeledExpr{ - pos: position{line: 72, col: 11, offset: 1754}, + pos: position{line: 72, col: 11, offset: 1728}, label: "first", expr: &ruleRefExpr{ - pos: position{line: 72, col: 17, offset: 1760}, + pos: position{line: 72, col: 17, offset: 1734}, name: "LabeledExpr", }, }, &labeledExpr{ - pos: position{line: 72, col: 29, offset: 1772}, + pos: position{line: 72, col: 29, offset: 1746}, label: "rest", expr: &zeroOrMoreExpr{ - pos: position{line: 72, col: 36, offset: 1779}, + pos: position{line: 72, col: 36, offset: 1753}, expr: &seqExpr{ - pos: position{line: 72, col: 36, offset: 1779}, - exprs: []interface{}{ + pos: position{line: 72, col: 36, offset: 1753}, + exprs: []any{ &ruleRefExpr{ - pos: position{line: 72, col: 36, offset: 1779}, + pos: position{line: 72, col: 36, offset: 1753}, name: "__", }, &ruleRefExpr{ - pos: position{line: 72, col: 39, offset: 1782}, + pos: position{line: 72, col: 39, offset: 1756}, name: "LabeledExpr", }, }, @@ -311,43 +311,43 @@ var g = &grammar{ }, { name: "LabeledExpr", - pos: position{line: 85, col: 1, offset: 2133}, + pos: position{line: 85, col: 1, offset: 2097}, expr: &choiceExpr{ - pos: position{line: 85, col: 15, offset: 2149}, - alternatives: []interface{}{ + pos: position{line: 85, col: 15, offset: 2113}, + alternatives: []any{ &actionExpr{ - pos: position{line: 85, col: 15, offset: 2149}, + pos: position{line: 85, col: 15, offset: 2113}, run: (*parser).callonLabeledExpr2, expr: &seqExpr{ - pos: position{line: 85, col: 15, offset: 2149}, - exprs: []interface{}{ + pos: position{line: 85, col: 15, offset: 2113}, + exprs: []any{ &labeledExpr{ - pos: position{line: 85, col: 15, offset: 2149}, + pos: position{line: 85, col: 15, offset: 2113}, label: "label", expr: &ruleRefExpr{ - pos: position{line: 85, col: 21, offset: 2155}, + pos: position{line: 85, col: 21, offset: 2119}, name: "Identifier", }, }, &ruleRefExpr{ - pos: position{line: 85, col: 32, offset: 2166}, + pos: position{line: 85, col: 32, offset: 2130}, name: "__", }, &litMatcher{ - pos: position{line: 85, col: 35, offset: 2169}, + pos: position{line: 85, col: 35, offset: 2133}, val: ":", ignoreCase: false, want: "\":\"", }, &ruleRefExpr{ - pos: position{line: 85, col: 39, offset: 2173}, + pos: position{line: 85, col: 39, offset: 2137}, name: "__", }, &labeledExpr{ - pos: position{line: 85, col: 42, offset: 2176}, + pos: position{line: 85, col: 42, offset: 2140}, label: "expr", expr: &ruleRefExpr{ - pos: position{line: 85, col: 47, offset: 2181}, + pos: position{line: 85, col: 47, offset: 2145}, name: "PrefixedExpr", }, }, @@ -355,7 +355,7 @@ var g = &grammar{ }, }, &ruleRefExpr{ - pos: position{line: 91, col: 5, offset: 2354}, + pos: position{line: 91, col: 5, offset: 2318}, name: "PrefixedExpr", }, }, @@ -363,33 +363,33 @@ var g = &grammar{ }, { name: "PrefixedExpr", - pos: position{line: 93, col: 1, offset: 2368}, + pos: position{line: 93, col: 1, offset: 2332}, expr: &choiceExpr{ - pos: position{line: 93, col: 16, offset: 2385}, - alternatives: []interface{}{ + pos: position{line: 93, col: 16, offset: 2349}, + alternatives: []any{ &actionExpr{ - pos: position{line: 93, col: 16, offset: 2385}, + pos: position{line: 93, col: 16, offset: 2349}, run: (*parser).callonPrefixedExpr2, expr: &seqExpr{ - pos: position{line: 93, col: 16, offset: 2385}, - exprs: []interface{}{ + pos: position{line: 93, col: 16, offset: 2349}, + exprs: []any{ &labeledExpr{ - pos: position{line: 93, col: 16, offset: 2385}, + pos: position{line: 93, col: 16, offset: 2349}, label: "op", expr: &ruleRefExpr{ - pos: position{line: 93, col: 19, offset: 2388}, + pos: position{line: 93, col: 19, offset: 2352}, name: "PrefixedOp", }, }, &ruleRefExpr{ - pos: position{line: 93, col: 30, offset: 2399}, + pos: position{line: 93, col: 30, offset: 2363}, name: "__", }, &labeledExpr{ - pos: position{line: 93, col: 33, offset: 2402}, + pos: position{line: 93, col: 33, offset: 2366}, label: "expr", expr: &ruleRefExpr{ - pos: position{line: 93, col: 38, offset: 2407}, + pos: position{line: 93, col: 38, offset: 2371}, name: "SuffixedExpr", }, }, @@ -397,7 +397,7 @@ var g = &grammar{ }, }, &ruleRefExpr{ - pos: position{line: 104, col: 5, offset: 2689}, + pos: position{line: 104, col: 5, offset: 2653}, name: "SuffixedExpr", }, }, @@ -405,21 +405,21 @@ var g = &grammar{ }, { name: "PrefixedOp", - pos: position{line: 106, col: 1, offset: 2703}, + pos: position{line: 106, col: 1, offset: 2667}, expr: &actionExpr{ - pos: position{line: 106, col: 14, offset: 2718}, + pos: position{line: 106, col: 14, offset: 2682}, run: (*parser).callonPrefixedOp1, expr: &choiceExpr{ - pos: position{line: 106, col: 16, offset: 2720}, - alternatives: []interface{}{ + pos: position{line: 106, col: 16, offset: 2684}, + alternatives: []any{ &litMatcher{ - pos: position{line: 106, col: 16, offset: 2720}, + pos: position{line: 106, col: 16, offset: 2684}, val: "&", ignoreCase: false, want: "\"&\"", }, &litMatcher{ - pos: position{line: 106, col: 22, offset: 2726}, + pos: position{line: 106, col: 22, offset: 2690}, val: "!", ignoreCase: false, want: "\"!\"", @@ -430,33 +430,33 @@ var g = &grammar{ }, { name: "SuffixedExpr", - pos: position{line: 110, col: 1, offset: 2768}, + pos: position{line: 110, col: 1, offset: 2732}, expr: &choiceExpr{ - pos: position{line: 110, col: 16, offset: 2785}, - alternatives: []interface{}{ + pos: position{line: 110, col: 16, offset: 2749}, + alternatives: []any{ &actionExpr{ - pos: position{line: 110, col: 16, offset: 2785}, + pos: position{line: 110, col: 16, offset: 2749}, run: (*parser).callonSuffixedExpr2, expr: &seqExpr{ - pos: position{line: 110, col: 16, offset: 2785}, - exprs: []interface{}{ + pos: position{line: 110, col: 16, offset: 2749}, + exprs: []any{ &labeledExpr{ - pos: position{line: 110, col: 16, offset: 2785}, + pos: position{line: 110, col: 16, offset: 2749}, label: "expr", expr: &ruleRefExpr{ - pos: position{line: 110, col: 21, offset: 2790}, + pos: position{line: 110, col: 21, offset: 2754}, name: "PrimaryExpr", }, }, &ruleRefExpr{ - pos: position{line: 110, col: 33, offset: 2802}, + pos: position{line: 110, col: 33, offset: 2766}, name: "__", }, &labeledExpr{ - pos: position{line: 110, col: 36, offset: 2805}, + pos: position{line: 110, col: 36, offset: 2769}, label: "op", expr: &ruleRefExpr{ - pos: position{line: 110, col: 39, offset: 2808}, + pos: position{line: 110, col: 39, offset: 2772}, name: "SuffixedOp", }, }, @@ -464,7 +464,7 @@ var g = &grammar{ }, }, &ruleRefExpr{ - pos: position{line: 129, col: 5, offset: 3338}, + pos: position{line: 129, col: 5, offset: 3302}, name: "PrimaryExpr", }, }, @@ -472,27 +472,27 @@ var g = &grammar{ }, { name: "SuffixedOp", - pos: position{line: 131, col: 1, offset: 3352}, + pos: position{line: 131, col: 1, offset: 3316}, expr: &actionExpr{ - pos: position{line: 131, col: 14, offset: 3367}, + pos: position{line: 131, col: 14, offset: 3331}, run: (*parser).callonSuffixedOp1, expr: &choiceExpr{ - pos: position{line: 131, col: 16, offset: 3369}, - alternatives: []interface{}{ + pos: position{line: 131, col: 16, offset: 3333}, + alternatives: []any{ &litMatcher{ - pos: position{line: 131, col: 16, offset: 3369}, + pos: position{line: 131, col: 16, offset: 3333}, val: "?", ignoreCase: false, want: "\"?\"", }, &litMatcher{ - pos: position{line: 131, col: 22, offset: 3375}, + pos: position{line: 131, col: 22, offset: 3339}, val: "*", ignoreCase: false, want: "\"*\"", }, &litMatcher{ - pos: position{line: 131, col: 28, offset: 3381}, + pos: position{line: 131, col: 28, offset: 3345}, val: "+", ignoreCase: false, want: "\"+\"", @@ -503,60 +503,60 @@ var g = &grammar{ }, { name: "PrimaryExpr", - pos: position{line: 135, col: 1, offset: 3423}, + pos: position{line: 135, col: 1, offset: 3387}, expr: &choiceExpr{ - pos: position{line: 135, col: 15, offset: 3439}, - alternatives: []interface{}{ + pos: position{line: 135, col: 15, offset: 3403}, + alternatives: []any{ &ruleRefExpr{ - pos: position{line: 135, col: 15, offset: 3439}, + pos: position{line: 135, col: 15, offset: 3403}, name: "LitMatcher", }, &ruleRefExpr{ - pos: position{line: 135, col: 28, offset: 3452}, + pos: position{line: 135, col: 28, offset: 3416}, name: "CharClassMatcher", }, &ruleRefExpr{ - pos: position{line: 135, col: 47, offset: 3471}, + pos: position{line: 135, col: 47, offset: 3435}, name: "AnyMatcher", }, &ruleRefExpr{ - pos: position{line: 135, col: 60, offset: 3484}, + pos: position{line: 135, col: 60, offset: 3448}, name: "RuleRefExpr", }, &ruleRefExpr{ - pos: position{line: 135, col: 74, offset: 3498}, + pos: position{line: 135, col: 74, offset: 3462}, name: "SemanticPredExpr", }, &actionExpr{ - pos: position{line: 135, col: 93, offset: 3517}, + pos: position{line: 135, col: 93, offset: 3481}, run: (*parser).callonPrimaryExpr7, expr: &seqExpr{ - pos: position{line: 135, col: 93, offset: 3517}, - exprs: []interface{}{ + pos: position{line: 135, col: 93, offset: 3481}, + exprs: []any{ &litMatcher{ - pos: position{line: 135, col: 93, offset: 3517}, + pos: position{line: 135, col: 93, offset: 3481}, val: "(", ignoreCase: false, want: "\"(\"", }, &ruleRefExpr{ - pos: position{line: 135, col: 97, offset: 3521}, + pos: position{line: 135, col: 97, offset: 3485}, name: "__", }, &labeledExpr{ - pos: position{line: 135, col: 100, offset: 3524}, + pos: position{line: 135, col: 100, offset: 3488}, label: "expr", expr: &ruleRefExpr{ - pos: position{line: 135, col: 105, offset: 3529}, + pos: position{line: 135, col: 105, offset: 3493}, name: "Expression", }, }, &ruleRefExpr{ - pos: position{line: 135, col: 116, offset: 3540}, + pos: position{line: 135, col: 116, offset: 3504}, name: "__", }, &litMatcher{ - pos: position{line: 135, col: 119, offset: 3543}, + pos: position{line: 135, col: 119, offset: 3507}, val: ")", ignoreCase: false, want: "\")\"", @@ -569,48 +569,48 @@ var g = &grammar{ }, { name: "RuleRefExpr", - pos: position{line: 138, col: 1, offset: 3572}, + pos: position{line: 138, col: 1, offset: 3536}, expr: &actionExpr{ - pos: position{line: 138, col: 15, offset: 3588}, + pos: position{line: 138, col: 15, offset: 3552}, run: (*parser).callonRuleRefExpr1, expr: &seqExpr{ - pos: position{line: 138, col: 15, offset: 3588}, - exprs: []interface{}{ + pos: position{line: 138, col: 15, offset: 3552}, + exprs: []any{ &labeledExpr{ - pos: position{line: 138, col: 15, offset: 3588}, + pos: position{line: 138, col: 15, offset: 3552}, label: "name", expr: &ruleRefExpr{ - pos: position{line: 138, col: 20, offset: 3593}, + pos: position{line: 138, col: 20, offset: 3557}, name: "IdentifierName", }, }, ¬Expr{ - pos: position{line: 138, col: 35, offset: 3608}, + pos: position{line: 138, col: 35, offset: 3572}, expr: &seqExpr{ - pos: position{line: 138, col: 38, offset: 3611}, - exprs: []interface{}{ + pos: position{line: 138, col: 38, offset: 3575}, + exprs: []any{ &ruleRefExpr{ - pos: position{line: 138, col: 38, offset: 3611}, + pos: position{line: 138, col: 38, offset: 3575}, name: "__", }, &zeroOrOneExpr{ - pos: position{line: 138, col: 43, offset: 3616}, + pos: position{line: 138, col: 43, offset: 3580}, expr: &seqExpr{ - pos: position{line: 138, col: 43, offset: 3616}, - exprs: []interface{}{ + pos: position{line: 138, col: 43, offset: 3580}, + exprs: []any{ &ruleRefExpr{ - pos: position{line: 138, col: 43, offset: 3616}, + pos: position{line: 138, col: 43, offset: 3580}, name: "StringLiteral", }, &ruleRefExpr{ - pos: position{line: 138, col: 57, offset: 3630}, + pos: position{line: 138, col: 57, offset: 3594}, name: "__", }, }, }, }, &ruleRefExpr{ - pos: position{line: 138, col: 63, offset: 3636}, + pos: position{line: 138, col: 63, offset: 3600}, name: "RuleDefOp", }, }, @@ -622,30 +622,30 @@ var g = &grammar{ }, { name: "SemanticPredExpr", - pos: position{line: 143, col: 1, offset: 3752}, + pos: position{line: 143, col: 1, offset: 3716}, expr: &actionExpr{ - pos: position{line: 143, col: 20, offset: 3773}, + pos: position{line: 143, col: 20, offset: 3737}, run: (*parser).callonSemanticPredExpr1, expr: &seqExpr{ - pos: position{line: 143, col: 20, offset: 3773}, - exprs: []interface{}{ + pos: position{line: 143, col: 20, offset: 3737}, + exprs: []any{ &labeledExpr{ - pos: position{line: 143, col: 20, offset: 3773}, + pos: position{line: 143, col: 20, offset: 3737}, label: "op", expr: &ruleRefExpr{ - pos: position{line: 143, col: 23, offset: 3776}, + pos: position{line: 143, col: 23, offset: 3740}, name: "SemanticPredOp", }, }, &ruleRefExpr{ - pos: position{line: 143, col: 38, offset: 3791}, + pos: position{line: 143, col: 38, offset: 3755}, name: "__", }, &labeledExpr{ - pos: position{line: 143, col: 41, offset: 3794}, + pos: position{line: 143, col: 41, offset: 3758}, label: "code", expr: &ruleRefExpr{ - pos: position{line: 143, col: 46, offset: 3799}, + pos: position{line: 143, col: 46, offset: 3763}, name: "CodeBlock", }, }, @@ -655,21 +655,21 @@ var g = &grammar{ }, { name: "SemanticPredOp", - pos: position{line: 154, col: 1, offset: 4076}, + pos: position{line: 154, col: 1, offset: 4040}, expr: &actionExpr{ - pos: position{line: 154, col: 18, offset: 4095}, + pos: position{line: 154, col: 18, offset: 4059}, run: (*parser).callonSemanticPredOp1, expr: &choiceExpr{ - pos: position{line: 154, col: 20, offset: 4097}, - alternatives: []interface{}{ + pos: position{line: 154, col: 20, offset: 4061}, + alternatives: []any{ &litMatcher{ - pos: position{line: 154, col: 20, offset: 4097}, + pos: position{line: 154, col: 20, offset: 4061}, val: "&", ignoreCase: false, want: "\"&\"", }, &litMatcher{ - pos: position{line: 154, col: 26, offset: 4103}, + pos: position{line: 154, col: 26, offset: 4067}, val: "!", ignoreCase: false, want: "\"!\"", @@ -680,30 +680,30 @@ var g = &grammar{ }, { name: "RuleDefOp", - pos: position{line: 158, col: 1, offset: 4145}, + pos: position{line: 158, col: 1, offset: 4109}, expr: &choiceExpr{ - pos: position{line: 158, col: 13, offset: 4159}, - alternatives: []interface{}{ + pos: position{line: 158, col: 13, offset: 4123}, + alternatives: []any{ &litMatcher{ - pos: position{line: 158, col: 13, offset: 4159}, + pos: position{line: 158, col: 13, offset: 4123}, val: "=", ignoreCase: false, want: "\"=\"", }, &litMatcher{ - pos: position{line: 158, col: 19, offset: 4165}, + pos: position{line: 158, col: 19, offset: 4129}, val: "<-", ignoreCase: false, want: "\"<-\"", }, &litMatcher{ - pos: position{line: 158, col: 26, offset: 4172}, + pos: position{line: 158, col: 26, offset: 4136}, val: "←", ignoreCase: false, want: "\"←\"", }, &litMatcher{ - pos: position{line: 158, col: 37, offset: 4183}, + pos: position{line: 158, col: 37, offset: 4147}, val: "⟵", ignoreCase: false, want: "\"⟵\"", @@ -713,23 +713,23 @@ var g = &grammar{ }, { name: "SourceChar", - pos: position{line: 160, col: 1, offset: 4193}, + pos: position{line: 160, col: 1, offset: 4157}, expr: &anyMatcher{ - line: 160, col: 14, offset: 4208, + line: 160, col: 14, offset: 4172, }, }, { name: "Comment", - pos: position{line: 161, col: 1, offset: 4210}, + pos: position{line: 161, col: 1, offset: 4174}, expr: &choiceExpr{ - pos: position{line: 161, col: 11, offset: 4222}, - alternatives: []interface{}{ + pos: position{line: 161, col: 11, offset: 4186}, + alternatives: []any{ &ruleRefExpr{ - pos: position{line: 161, col: 11, offset: 4222}, + pos: position{line: 161, col: 11, offset: 4186}, name: "MultiLineComment", }, &ruleRefExpr{ - pos: position{line: 161, col: 30, offset: 4241}, + pos: position{line: 161, col: 30, offset: 4205}, name: "SingleLineComment", }, }, @@ -737,39 +737,39 @@ var g = &grammar{ }, { name: "MultiLineComment", - pos: position{line: 162, col: 1, offset: 4259}, + pos: position{line: 162, col: 1, offset: 4223}, expr: &seqExpr{ - pos: position{line: 162, col: 20, offset: 4280}, - exprs: []interface{}{ + pos: position{line: 162, col: 20, offset: 4244}, + exprs: []any{ &litMatcher{ - pos: position{line: 162, col: 20, offset: 4280}, + pos: position{line: 162, col: 20, offset: 4244}, val: "/*", ignoreCase: false, want: "\"/*\"", }, &zeroOrMoreExpr{ - pos: position{line: 162, col: 27, offset: 4287}, + pos: position{line: 162, col: 27, offset: 4251}, expr: &seqExpr{ - pos: position{line: 162, col: 27, offset: 4287}, - exprs: []interface{}{ + pos: position{line: 162, col: 27, offset: 4251}, + exprs: []any{ ¬Expr{ - pos: position{line: 162, col: 27, offset: 4287}, + pos: position{line: 162, col: 27, offset: 4251}, expr: &litMatcher{ - pos: position{line: 162, col: 28, offset: 4288}, + pos: position{line: 162, col: 28, offset: 4252}, val: "*/", ignoreCase: false, want: "\"*/\"", }, }, &ruleRefExpr{ - pos: position{line: 162, col: 33, offset: 4293}, + pos: position{line: 162, col: 33, offset: 4257}, name: "SourceChar", }, }, }, }, &litMatcher{ - pos: position{line: 162, col: 47, offset: 4307}, + pos: position{line: 162, col: 47, offset: 4271}, val: "*/", ignoreCase: false, want: "\"*/\"", @@ -779,48 +779,48 @@ var g = &grammar{ }, { name: "MultiLineCommentNoLineTerminator", - pos: position{line: 163, col: 1, offset: 4312}, + pos: position{line: 163, col: 1, offset: 4276}, expr: &seqExpr{ - pos: position{line: 163, col: 36, offset: 4349}, - exprs: []interface{}{ + pos: position{line: 163, col: 36, offset: 4313}, + exprs: []any{ &litMatcher{ - pos: position{line: 163, col: 36, offset: 4349}, + pos: position{line: 163, col: 36, offset: 4313}, val: "/*", ignoreCase: false, want: "\"/*\"", }, &zeroOrMoreExpr{ - pos: position{line: 163, col: 43, offset: 4356}, + pos: position{line: 163, col: 43, offset: 4320}, expr: &seqExpr{ - pos: position{line: 163, col: 43, offset: 4356}, - exprs: []interface{}{ + pos: position{line: 163, col: 43, offset: 4320}, + exprs: []any{ ¬Expr{ - pos: position{line: 163, col: 43, offset: 4356}, + pos: position{line: 163, col: 43, offset: 4320}, expr: &choiceExpr{ - pos: position{line: 163, col: 46, offset: 4359}, - alternatives: []interface{}{ + pos: position{line: 163, col: 46, offset: 4323}, + alternatives: []any{ &litMatcher{ - pos: position{line: 163, col: 46, offset: 4359}, + pos: position{line: 163, col: 46, offset: 4323}, val: "*/", ignoreCase: false, want: "\"*/\"", }, &ruleRefExpr{ - pos: position{line: 163, col: 53, offset: 4366}, + pos: position{line: 163, col: 53, offset: 4330}, name: "EOL", }, }, }, }, &ruleRefExpr{ - pos: position{line: 163, col: 59, offset: 4372}, + pos: position{line: 163, col: 59, offset: 4336}, name: "SourceChar", }, }, }, }, &litMatcher{ - pos: position{line: 163, col: 73, offset: 4386}, + pos: position{line: 163, col: 73, offset: 4350}, val: "*/", ignoreCase: false, want: "\"*/\"", @@ -830,30 +830,30 @@ var g = &grammar{ }, { name: "SingleLineComment", - pos: position{line: 164, col: 1, offset: 4391}, + pos: position{line: 164, col: 1, offset: 4355}, expr: &seqExpr{ - pos: position{line: 164, col: 21, offset: 4413}, - exprs: []interface{}{ + pos: position{line: 164, col: 21, offset: 4377}, + exprs: []any{ &litMatcher{ - pos: position{line: 164, col: 21, offset: 4413}, + pos: position{line: 164, col: 21, offset: 4377}, val: "//", ignoreCase: false, want: "\"//\"", }, &zeroOrMoreExpr{ - pos: position{line: 164, col: 28, offset: 4420}, + pos: position{line: 164, col: 28, offset: 4384}, expr: &seqExpr{ - pos: position{line: 164, col: 28, offset: 4420}, - exprs: []interface{}{ + pos: position{line: 164, col: 28, offset: 4384}, + exprs: []any{ ¬Expr{ - pos: position{line: 164, col: 28, offset: 4420}, + pos: position{line: 164, col: 28, offset: 4384}, expr: &ruleRefExpr{ - pos: position{line: 164, col: 29, offset: 4421}, + pos: position{line: 164, col: 29, offset: 4385}, name: "EOL", }, }, &ruleRefExpr{ - pos: position{line: 164, col: 33, offset: 4425}, + pos: position{line: 164, col: 33, offset: 4389}, name: "SourceChar", }, }, @@ -864,29 +864,29 @@ var g = &grammar{ }, { name: "Identifier", - pos: position{line: 166, col: 1, offset: 4440}, + pos: position{line: 166, col: 1, offset: 4404}, expr: &ruleRefExpr{ - pos: position{line: 166, col: 14, offset: 4455}, + pos: position{line: 166, col: 14, offset: 4419}, name: "IdentifierName", }, }, { name: "IdentifierName", - pos: position{line: 167, col: 1, offset: 4470}, + pos: position{line: 167, col: 1, offset: 4434}, expr: &actionExpr{ - pos: position{line: 167, col: 18, offset: 4489}, + pos: position{line: 167, col: 18, offset: 4453}, run: (*parser).callonIdentifierName1, expr: &seqExpr{ - pos: position{line: 167, col: 18, offset: 4489}, - exprs: []interface{}{ + pos: position{line: 167, col: 18, offset: 4453}, + exprs: []any{ &ruleRefExpr{ - pos: position{line: 167, col: 18, offset: 4489}, + pos: position{line: 167, col: 18, offset: 4453}, name: "IdentifierStart", }, &zeroOrMoreExpr{ - pos: position{line: 167, col: 34, offset: 4505}, + pos: position{line: 167, col: 34, offset: 4469}, expr: &ruleRefExpr{ - pos: position{line: 167, col: 34, offset: 4505}, + pos: position{line: 167, col: 34, offset: 4469}, name: "IdentifierPart", }, }, @@ -896,9 +896,9 @@ var g = &grammar{ }, { name: "IdentifierStart", - pos: position{line: 170, col: 1, offset: 4587}, + pos: position{line: 170, col: 1, offset: 4551}, expr: &charClassMatcher{ - pos: position{line: 170, col: 19, offset: 4607}, + pos: position{line: 170, col: 19, offset: 4571}, val: "[a-z_]i", chars: []rune{'_'}, ranges: []rune{'a', 'z'}, @@ -908,16 +908,16 @@ var g = &grammar{ }, { name: "IdentifierPart", - pos: position{line: 171, col: 1, offset: 4615}, + pos: position{line: 171, col: 1, offset: 4579}, expr: &choiceExpr{ - pos: position{line: 171, col: 18, offset: 4634}, - alternatives: []interface{}{ + pos: position{line: 171, col: 18, offset: 4598}, + alternatives: []any{ &ruleRefExpr{ - pos: position{line: 171, col: 18, offset: 4634}, + pos: position{line: 171, col: 18, offset: 4598}, name: "IdentifierStart", }, &charClassMatcher{ - pos: position{line: 171, col: 36, offset: 4652}, + pos: position{line: 171, col: 36, offset: 4616}, val: "[0-9]", ranges: []rune{'0', '9'}, ignoreCase: false, @@ -928,28 +928,28 @@ var g = &grammar{ }, { name: "LitMatcher", - pos: position{line: 173, col: 1, offset: 4659}, + pos: position{line: 173, col: 1, offset: 4623}, expr: &actionExpr{ - pos: position{line: 173, col: 14, offset: 4674}, + pos: position{line: 173, col: 14, offset: 4638}, run: (*parser).callonLitMatcher1, expr: &seqExpr{ - pos: position{line: 173, col: 14, offset: 4674}, - exprs: []interface{}{ + pos: position{line: 173, col: 14, offset: 4638}, + exprs: []any{ &labeledExpr{ - pos: position{line: 173, col: 14, offset: 4674}, + pos: position{line: 173, col: 14, offset: 4638}, label: "lit", expr: &ruleRefExpr{ - pos: position{line: 173, col: 18, offset: 4678}, + pos: position{line: 173, col: 18, offset: 4642}, name: "StringLiteral", }, }, &labeledExpr{ - pos: position{line: 173, col: 32, offset: 4692}, + pos: position{line: 173, col: 32, offset: 4656}, label: "ignore", expr: &zeroOrOneExpr{ - pos: position{line: 173, col: 39, offset: 4699}, + pos: position{line: 173, col: 39, offset: 4663}, expr: &litMatcher{ - pos: position{line: 173, col: 39, offset: 4699}, + pos: position{line: 173, col: 39, offset: 4663}, val: "i", ignoreCase: false, want: "\"i\"", @@ -962,31 +962,31 @@ var g = &grammar{ }, { name: "StringLiteral", - pos: position{line: 183, col: 1, offset: 4925}, + pos: position{line: 183, col: 1, offset: 4889}, expr: &actionExpr{ - pos: position{line: 183, col: 17, offset: 4943}, + pos: position{line: 183, col: 17, offset: 4907}, run: (*parser).callonStringLiteral1, expr: &choiceExpr{ - pos: position{line: 183, col: 19, offset: 4945}, - alternatives: []interface{}{ + pos: position{line: 183, col: 19, offset: 4909}, + alternatives: []any{ &seqExpr{ - pos: position{line: 183, col: 19, offset: 4945}, - exprs: []interface{}{ + pos: position{line: 183, col: 19, offset: 4909}, + exprs: []any{ &litMatcher{ - pos: position{line: 183, col: 19, offset: 4945}, + pos: position{line: 183, col: 19, offset: 4909}, val: "\"", ignoreCase: false, want: "\"\\\"\"", }, &zeroOrMoreExpr{ - pos: position{line: 183, col: 23, offset: 4949}, + pos: position{line: 183, col: 23, offset: 4913}, expr: &ruleRefExpr{ - pos: position{line: 183, col: 23, offset: 4949}, + pos: position{line: 183, col: 23, offset: 4913}, name: "DoubleStringChar", }, }, &litMatcher{ - pos: position{line: 183, col: 41, offset: 4967}, + pos: position{line: 183, col: 41, offset: 4931}, val: "\"", ignoreCase: false, want: "\"\\\"\"", @@ -994,20 +994,20 @@ var g = &grammar{ }, }, &seqExpr{ - pos: position{line: 183, col: 47, offset: 4973}, - exprs: []interface{}{ + pos: position{line: 183, col: 47, offset: 4937}, + exprs: []any{ &litMatcher{ - pos: position{line: 183, col: 47, offset: 4973}, + pos: position{line: 183, col: 47, offset: 4937}, val: "'", ignoreCase: false, want: "\"'\"", }, &ruleRefExpr{ - pos: position{line: 183, col: 51, offset: 4977}, + pos: position{line: 183, col: 51, offset: 4941}, name: "SingleStringChar", }, &litMatcher{ - pos: position{line: 183, col: 68, offset: 4994}, + pos: position{line: 183, col: 68, offset: 4958}, val: "'", ignoreCase: false, want: "\"'\"", @@ -1015,20 +1015,20 @@ var g = &grammar{ }, }, &seqExpr{ - pos: position{line: 183, col: 74, offset: 5000}, - exprs: []interface{}{ + pos: position{line: 183, col: 74, offset: 4964}, + exprs: []any{ &litMatcher{ - pos: position{line: 183, col: 74, offset: 5000}, + pos: position{line: 183, col: 74, offset: 4964}, val: "`", ignoreCase: false, want: "\"`\"", }, &ruleRefExpr{ - pos: position{line: 183, col: 78, offset: 5004}, + pos: position{line: 183, col: 78, offset: 4968}, name: "RawStringChar", }, &litMatcher{ - pos: position{line: 183, col: 92, offset: 5018}, + pos: position{line: 183, col: 92, offset: 4982}, val: "`", ignoreCase: false, want: "\"`\"", @@ -1041,54 +1041,54 @@ var g = &grammar{ }, { name: "DoubleStringChar", - pos: position{line: 186, col: 1, offset: 5089}, + pos: position{line: 186, col: 1, offset: 5053}, expr: &choiceExpr{ - pos: position{line: 186, col: 20, offset: 5110}, - alternatives: []interface{}{ + pos: position{line: 186, col: 20, offset: 5074}, + alternatives: []any{ &seqExpr{ - pos: position{line: 186, col: 20, offset: 5110}, - exprs: []interface{}{ + pos: position{line: 186, col: 20, offset: 5074}, + exprs: []any{ ¬Expr{ - pos: position{line: 186, col: 20, offset: 5110}, + pos: position{line: 186, col: 20, offset: 5074}, expr: &choiceExpr{ - pos: position{line: 186, col: 23, offset: 5113}, - alternatives: []interface{}{ + pos: position{line: 186, col: 23, offset: 5077}, + alternatives: []any{ &litMatcher{ - pos: position{line: 186, col: 23, offset: 5113}, + pos: position{line: 186, col: 23, offset: 5077}, val: "\"", ignoreCase: false, want: "\"\\\"\"", }, &litMatcher{ - pos: position{line: 186, col: 29, offset: 5119}, + pos: position{line: 186, col: 29, offset: 5083}, val: "\\", ignoreCase: false, want: "\"\\\\\"", }, &ruleRefExpr{ - pos: position{line: 186, col: 36, offset: 5126}, + pos: position{line: 186, col: 36, offset: 5090}, name: "EOL", }, }, }, }, &ruleRefExpr{ - pos: position{line: 186, col: 42, offset: 5132}, + pos: position{line: 186, col: 42, offset: 5096}, name: "SourceChar", }, }, }, &seqExpr{ - pos: position{line: 186, col: 55, offset: 5145}, - exprs: []interface{}{ + pos: position{line: 186, col: 55, offset: 5109}, + exprs: []any{ &litMatcher{ - pos: position{line: 186, col: 55, offset: 5145}, + pos: position{line: 186, col: 55, offset: 5109}, val: "\\", ignoreCase: false, want: "\"\\\\\"", }, &ruleRefExpr{ - pos: position{line: 186, col: 60, offset: 5150}, + pos: position{line: 186, col: 60, offset: 5114}, name: "DoubleStringEscape", }, }, @@ -1098,54 +1098,54 @@ var g = &grammar{ }, { name: "SingleStringChar", - pos: position{line: 187, col: 1, offset: 5169}, + pos: position{line: 187, col: 1, offset: 5133}, expr: &choiceExpr{ - pos: position{line: 187, col: 20, offset: 5190}, - alternatives: []interface{}{ + pos: position{line: 187, col: 20, offset: 5154}, + alternatives: []any{ &seqExpr{ - pos: position{line: 187, col: 20, offset: 5190}, - exprs: []interface{}{ + pos: position{line: 187, col: 20, offset: 5154}, + exprs: []any{ ¬Expr{ - pos: position{line: 187, col: 20, offset: 5190}, + pos: position{line: 187, col: 20, offset: 5154}, expr: &choiceExpr{ - pos: position{line: 187, col: 23, offset: 5193}, - alternatives: []interface{}{ + pos: position{line: 187, col: 23, offset: 5157}, + alternatives: []any{ &litMatcher{ - pos: position{line: 187, col: 23, offset: 5193}, + pos: position{line: 187, col: 23, offset: 5157}, val: "'", ignoreCase: false, want: "\"'\"", }, &litMatcher{ - pos: position{line: 187, col: 29, offset: 5199}, + pos: position{line: 187, col: 29, offset: 5163}, val: "\\", ignoreCase: false, want: "\"\\\\\"", }, &ruleRefExpr{ - pos: position{line: 187, col: 36, offset: 5206}, + pos: position{line: 187, col: 36, offset: 5170}, name: "EOL", }, }, }, }, &ruleRefExpr{ - pos: position{line: 187, col: 42, offset: 5212}, + pos: position{line: 187, col: 42, offset: 5176}, name: "SourceChar", }, }, }, &seqExpr{ - pos: position{line: 187, col: 55, offset: 5225}, - exprs: []interface{}{ + pos: position{line: 187, col: 55, offset: 5189}, + exprs: []any{ &litMatcher{ - pos: position{line: 187, col: 55, offset: 5225}, + pos: position{line: 187, col: 55, offset: 5189}, val: "\\", ignoreCase: false, want: "\"\\\\\"", }, &ruleRefExpr{ - pos: position{line: 187, col: 60, offset: 5230}, + pos: position{line: 187, col: 60, offset: 5194}, name: "SingleStringEscape", }, }, @@ -1155,21 +1155,21 @@ var g = &grammar{ }, { name: "RawStringChar", - pos: position{line: 188, col: 1, offset: 5249}, + pos: position{line: 188, col: 1, offset: 5213}, expr: &seqExpr{ - pos: position{line: 188, col: 17, offset: 5267}, - exprs: []interface{}{ + pos: position{line: 188, col: 17, offset: 5231}, + exprs: []any{ ¬Expr{ - pos: position{line: 188, col: 17, offset: 5267}, + pos: position{line: 188, col: 17, offset: 5231}, expr: &litMatcher{ - pos: position{line: 188, col: 18, offset: 5268}, + pos: position{line: 188, col: 18, offset: 5232}, val: "`", ignoreCase: false, want: "\"`\"", }, }, &ruleRefExpr{ - pos: position{line: 188, col: 22, offset: 5272}, + pos: position{line: 188, col: 22, offset: 5236}, name: "SourceChar", }, }, @@ -1177,18 +1177,18 @@ var g = &grammar{ }, { name: "DoubleStringEscape", - pos: position{line: 190, col: 1, offset: 5284}, + pos: position{line: 190, col: 1, offset: 5248}, expr: &choiceExpr{ - pos: position{line: 190, col: 22, offset: 5307}, - alternatives: []interface{}{ + pos: position{line: 190, col: 22, offset: 5271}, + alternatives: []any{ &litMatcher{ - pos: position{line: 190, col: 22, offset: 5307}, + pos: position{line: 190, col: 22, offset: 5271}, val: "'", ignoreCase: false, want: "\"'\"", }, &ruleRefExpr{ - pos: position{line: 190, col: 28, offset: 5313}, + pos: position{line: 190, col: 28, offset: 5277}, name: "CommonEscapeSequence", }, }, @@ -1196,18 +1196,18 @@ var g = &grammar{ }, { name: "SingleStringEscape", - pos: position{line: 191, col: 1, offset: 5334}, + pos: position{line: 191, col: 1, offset: 5298}, expr: &choiceExpr{ - pos: position{line: 191, col: 22, offset: 5357}, - alternatives: []interface{}{ + pos: position{line: 191, col: 22, offset: 5321}, + alternatives: []any{ &litMatcher{ - pos: position{line: 191, col: 22, offset: 5357}, + pos: position{line: 191, col: 22, offset: 5321}, val: "\"", ignoreCase: false, want: "\"\\\"\"", }, &ruleRefExpr{ - pos: position{line: 191, col: 28, offset: 5363}, + pos: position{line: 191, col: 28, offset: 5327}, name: "CommonEscapeSequence", }, }, @@ -1215,28 +1215,28 @@ var g = &grammar{ }, { name: "CommonEscapeSequence", - pos: position{line: 193, col: 1, offset: 5385}, + pos: position{line: 193, col: 1, offset: 5349}, expr: &choiceExpr{ - pos: position{line: 193, col: 24, offset: 5410}, - alternatives: []interface{}{ + pos: position{line: 193, col: 24, offset: 5374}, + alternatives: []any{ &ruleRefExpr{ - pos: position{line: 193, col: 24, offset: 5410}, + pos: position{line: 193, col: 24, offset: 5374}, name: "SingleCharEscape", }, &ruleRefExpr{ - pos: position{line: 193, col: 43, offset: 5429}, + pos: position{line: 193, col: 43, offset: 5393}, name: "OctalEscape", }, &ruleRefExpr{ - pos: position{line: 193, col: 57, offset: 5443}, + pos: position{line: 193, col: 57, offset: 5407}, name: "HexEscape", }, &ruleRefExpr{ - pos: position{line: 193, col: 69, offset: 5455}, + pos: position{line: 193, col: 69, offset: 5419}, name: "LongUnicodeEscape", }, &ruleRefExpr{ - pos: position{line: 193, col: 89, offset: 5475}, + pos: position{line: 193, col: 89, offset: 5439}, name: "ShortUnicodeEscape", }, }, @@ -1244,54 +1244,54 @@ var g = &grammar{ }, { name: "SingleCharEscape", - pos: position{line: 194, col: 1, offset: 5494}, + pos: position{line: 194, col: 1, offset: 5458}, expr: &choiceExpr{ - pos: position{line: 194, col: 20, offset: 5515}, - alternatives: []interface{}{ + pos: position{line: 194, col: 20, offset: 5479}, + alternatives: []any{ &litMatcher{ - pos: position{line: 194, col: 20, offset: 5515}, + pos: position{line: 194, col: 20, offset: 5479}, val: "a", ignoreCase: false, want: "\"a\"", }, &litMatcher{ - pos: position{line: 194, col: 26, offset: 5521}, + pos: position{line: 194, col: 26, offset: 5485}, val: "b", ignoreCase: false, want: "\"b\"", }, &litMatcher{ - pos: position{line: 194, col: 32, offset: 5527}, + pos: position{line: 194, col: 32, offset: 5491}, val: "n", ignoreCase: false, want: "\"n\"", }, &litMatcher{ - pos: position{line: 194, col: 38, offset: 5533}, + pos: position{line: 194, col: 38, offset: 5497}, val: "f", ignoreCase: false, want: "\"f\"", }, &litMatcher{ - pos: position{line: 194, col: 44, offset: 5539}, + pos: position{line: 194, col: 44, offset: 5503}, val: "r", ignoreCase: false, want: "\"r\"", }, &litMatcher{ - pos: position{line: 194, col: 50, offset: 5545}, + pos: position{line: 194, col: 50, offset: 5509}, val: "t", ignoreCase: false, want: "\"t\"", }, &litMatcher{ - pos: position{line: 194, col: 56, offset: 5551}, + pos: position{line: 194, col: 56, offset: 5515}, val: "v", ignoreCase: false, want: "\"v\"", }, &litMatcher{ - pos: position{line: 194, col: 62, offset: 5557}, + pos: position{line: 194, col: 62, offset: 5521}, val: "\\", ignoreCase: false, want: "\"\\\\\"", @@ -1301,20 +1301,20 @@ var g = &grammar{ }, { name: "OctalEscape", - pos: position{line: 195, col: 1, offset: 5562}, + pos: position{line: 195, col: 1, offset: 5526}, expr: &seqExpr{ - pos: position{line: 195, col: 15, offset: 5578}, - exprs: []interface{}{ + pos: position{line: 195, col: 15, offset: 5542}, + exprs: []any{ &ruleRefExpr{ - pos: position{line: 195, col: 15, offset: 5578}, + pos: position{line: 195, col: 15, offset: 5542}, name: "OctalDigit", }, &ruleRefExpr{ - pos: position{line: 195, col: 26, offset: 5589}, + pos: position{line: 195, col: 26, offset: 5553}, name: "OctalDigit", }, &ruleRefExpr{ - pos: position{line: 195, col: 37, offset: 5600}, + pos: position{line: 195, col: 37, offset: 5564}, name: "OctalDigit", }, }, @@ -1322,22 +1322,22 @@ var g = &grammar{ }, { name: "HexEscape", - pos: position{line: 196, col: 1, offset: 5611}, + pos: position{line: 196, col: 1, offset: 5575}, expr: &seqExpr{ - pos: position{line: 196, col: 13, offset: 5625}, - exprs: []interface{}{ + pos: position{line: 196, col: 13, offset: 5589}, + exprs: []any{ &litMatcher{ - pos: position{line: 196, col: 13, offset: 5625}, + pos: position{line: 196, col: 13, offset: 5589}, val: "x", ignoreCase: false, want: "\"x\"", }, &ruleRefExpr{ - pos: position{line: 196, col: 17, offset: 5629}, + pos: position{line: 196, col: 17, offset: 5593}, name: "HexDigit", }, &ruleRefExpr{ - pos: position{line: 196, col: 26, offset: 5638}, + pos: position{line: 196, col: 26, offset: 5602}, name: "HexDigit", }, }, @@ -1345,46 +1345,46 @@ var g = &grammar{ }, { name: "LongUnicodeEscape", - pos: position{line: 197, col: 1, offset: 5647}, + pos: position{line: 197, col: 1, offset: 5611}, expr: &seqExpr{ - pos: position{line: 197, col: 21, offset: 5669}, - exprs: []interface{}{ + pos: position{line: 197, col: 21, offset: 5633}, + exprs: []any{ &litMatcher{ - pos: position{line: 197, col: 21, offset: 5669}, + pos: position{line: 197, col: 21, offset: 5633}, val: "U", ignoreCase: false, want: "\"U\"", }, &ruleRefExpr{ - pos: position{line: 197, col: 25, offset: 5673}, + pos: position{line: 197, col: 25, offset: 5637}, name: "HexDigit", }, &ruleRefExpr{ - pos: position{line: 197, col: 34, offset: 5682}, + pos: position{line: 197, col: 34, offset: 5646}, name: "HexDigit", }, &ruleRefExpr{ - pos: position{line: 197, col: 43, offset: 5691}, + pos: position{line: 197, col: 43, offset: 5655}, name: "HexDigit", }, &ruleRefExpr{ - pos: position{line: 197, col: 52, offset: 5700}, + pos: position{line: 197, col: 52, offset: 5664}, name: "HexDigit", }, &ruleRefExpr{ - pos: position{line: 197, col: 61, offset: 5709}, + pos: position{line: 197, col: 61, offset: 5673}, name: "HexDigit", }, &ruleRefExpr{ - pos: position{line: 197, col: 70, offset: 5718}, + pos: position{line: 197, col: 70, offset: 5682}, name: "HexDigit", }, &ruleRefExpr{ - pos: position{line: 197, col: 79, offset: 5727}, + pos: position{line: 197, col: 79, offset: 5691}, name: "HexDigit", }, &ruleRefExpr{ - pos: position{line: 197, col: 88, offset: 5736}, + pos: position{line: 197, col: 88, offset: 5700}, name: "HexDigit", }, }, @@ -1392,30 +1392,30 @@ var g = &grammar{ }, { name: "ShortUnicodeEscape", - pos: position{line: 198, col: 1, offset: 5745}, + pos: position{line: 198, col: 1, offset: 5709}, expr: &seqExpr{ - pos: position{line: 198, col: 22, offset: 5768}, - exprs: []interface{}{ + pos: position{line: 198, col: 22, offset: 5732}, + exprs: []any{ &litMatcher{ - pos: position{line: 198, col: 22, offset: 5768}, + pos: position{line: 198, col: 22, offset: 5732}, val: "u", ignoreCase: false, want: "\"u\"", }, &ruleRefExpr{ - pos: position{line: 198, col: 26, offset: 5772}, + pos: position{line: 198, col: 26, offset: 5736}, name: "HexDigit", }, &ruleRefExpr{ - pos: position{line: 198, col: 35, offset: 5781}, + pos: position{line: 198, col: 35, offset: 5745}, name: "HexDigit", }, &ruleRefExpr{ - pos: position{line: 198, col: 44, offset: 5790}, + pos: position{line: 198, col: 44, offset: 5754}, name: "HexDigit", }, &ruleRefExpr{ - pos: position{line: 198, col: 53, offset: 5799}, + pos: position{line: 198, col: 53, offset: 5763}, name: "HexDigit", }, }, @@ -1423,9 +1423,9 @@ var g = &grammar{ }, { name: "OctalDigit", - pos: position{line: 200, col: 1, offset: 5809}, + pos: position{line: 200, col: 1, offset: 5773}, expr: &charClassMatcher{ - pos: position{line: 200, col: 14, offset: 5824}, + pos: position{line: 200, col: 14, offset: 5788}, val: "[0-7]", ranges: []rune{'0', '7'}, ignoreCase: false, @@ -1434,9 +1434,9 @@ var g = &grammar{ }, { name: "DecimalDigit", - pos: position{line: 201, col: 1, offset: 5830}, + pos: position{line: 201, col: 1, offset: 5794}, expr: &charClassMatcher{ - pos: position{line: 201, col: 16, offset: 5847}, + pos: position{line: 201, col: 16, offset: 5811}, val: "[0-9]", ranges: []rune{'0', '9'}, ignoreCase: false, @@ -1445,9 +1445,9 @@ var g = &grammar{ }, { name: "HexDigit", - pos: position{line: 202, col: 1, offset: 5853}, + pos: position{line: 202, col: 1, offset: 5817}, expr: &charClassMatcher{ - pos: position{line: 202, col: 12, offset: 5866}, + pos: position{line: 202, col: 12, offset: 5830}, val: "[0-9a-f]i", ranges: []rune{'0', '9', 'a', 'f'}, ignoreCase: true, @@ -1456,43 +1456,43 @@ var g = &grammar{ }, { name: "CharClassMatcher", - pos: position{line: 204, col: 1, offset: 5877}, + pos: position{line: 204, col: 1, offset: 5841}, expr: &actionExpr{ - pos: position{line: 204, col: 20, offset: 5898}, + pos: position{line: 204, col: 20, offset: 5862}, run: (*parser).callonCharClassMatcher1, expr: &seqExpr{ - pos: position{line: 204, col: 20, offset: 5898}, - exprs: []interface{}{ + pos: position{line: 204, col: 20, offset: 5862}, + exprs: []any{ &litMatcher{ - pos: position{line: 204, col: 20, offset: 5898}, + pos: position{line: 204, col: 20, offset: 5862}, val: "[", ignoreCase: false, want: "\"[\"", }, &zeroOrMoreExpr{ - pos: position{line: 204, col: 26, offset: 5904}, + pos: position{line: 204, col: 26, offset: 5868}, expr: &choiceExpr{ - pos: position{line: 204, col: 26, offset: 5904}, - alternatives: []interface{}{ + pos: position{line: 204, col: 26, offset: 5868}, + alternatives: []any{ &ruleRefExpr{ - pos: position{line: 204, col: 26, offset: 5904}, + pos: position{line: 204, col: 26, offset: 5868}, name: "ClassCharRange", }, &ruleRefExpr{ - pos: position{line: 204, col: 43, offset: 5921}, + pos: position{line: 204, col: 43, offset: 5885}, name: "ClassChar", }, &seqExpr{ - pos: position{line: 204, col: 55, offset: 5933}, - exprs: []interface{}{ + pos: position{line: 204, col: 55, offset: 5897}, + exprs: []any{ &litMatcher{ - pos: position{line: 204, col: 55, offset: 5933}, + pos: position{line: 204, col: 55, offset: 5897}, val: "\\", ignoreCase: false, want: "\"\\\\\"", }, &ruleRefExpr{ - pos: position{line: 204, col: 60, offset: 5938}, + pos: position{line: 204, col: 60, offset: 5902}, name: "UnicodeClassEscape", }, }, @@ -1501,15 +1501,15 @@ var g = &grammar{ }, }, &litMatcher{ - pos: position{line: 204, col: 82, offset: 5960}, + pos: position{line: 204, col: 82, offset: 5924}, val: "]", ignoreCase: false, want: "\"]\"", }, &zeroOrOneExpr{ - pos: position{line: 204, col: 86, offset: 5964}, + pos: position{line: 204, col: 86, offset: 5928}, expr: &litMatcher{ - pos: position{line: 204, col: 86, offset: 5964}, + pos: position{line: 204, col: 86, offset: 5928}, val: "i", ignoreCase: false, want: "\"i\"", @@ -1521,22 +1521,22 @@ var g = &grammar{ }, { name: "ClassCharRange", - pos: position{line: 209, col: 1, offset: 6069}, + pos: position{line: 209, col: 1, offset: 6033}, expr: &seqExpr{ - pos: position{line: 209, col: 18, offset: 6088}, - exprs: []interface{}{ + pos: position{line: 209, col: 18, offset: 6052}, + exprs: []any{ &ruleRefExpr{ - pos: position{line: 209, col: 18, offset: 6088}, + pos: position{line: 209, col: 18, offset: 6052}, name: "ClassChar", }, &litMatcher{ - pos: position{line: 209, col: 28, offset: 6098}, + pos: position{line: 209, col: 28, offset: 6062}, val: "-", ignoreCase: false, want: "\"-\"", }, &ruleRefExpr{ - pos: position{line: 209, col: 32, offset: 6102}, + pos: position{line: 209, col: 32, offset: 6066}, name: "ClassChar", }, }, @@ -1544,54 +1544,54 @@ var g = &grammar{ }, { name: "ClassChar", - pos: position{line: 210, col: 1, offset: 6112}, + pos: position{line: 210, col: 1, offset: 6076}, expr: &choiceExpr{ - pos: position{line: 210, col: 13, offset: 6126}, - alternatives: []interface{}{ + pos: position{line: 210, col: 13, offset: 6090}, + alternatives: []any{ &seqExpr{ - pos: position{line: 210, col: 13, offset: 6126}, - exprs: []interface{}{ + pos: position{line: 210, col: 13, offset: 6090}, + exprs: []any{ ¬Expr{ - pos: position{line: 210, col: 13, offset: 6126}, + pos: position{line: 210, col: 13, offset: 6090}, expr: &choiceExpr{ - pos: position{line: 210, col: 16, offset: 6129}, - alternatives: []interface{}{ + pos: position{line: 210, col: 16, offset: 6093}, + alternatives: []any{ &litMatcher{ - pos: position{line: 210, col: 16, offset: 6129}, + pos: position{line: 210, col: 16, offset: 6093}, val: "]", ignoreCase: false, want: "\"]\"", }, &litMatcher{ - pos: position{line: 210, col: 22, offset: 6135}, + pos: position{line: 210, col: 22, offset: 6099}, val: "\\", ignoreCase: false, want: "\"\\\\\"", }, &ruleRefExpr{ - pos: position{line: 210, col: 29, offset: 6142}, + pos: position{line: 210, col: 29, offset: 6106}, name: "EOL", }, }, }, }, &ruleRefExpr{ - pos: position{line: 210, col: 35, offset: 6148}, + pos: position{line: 210, col: 35, offset: 6112}, name: "SourceChar", }, }, }, &seqExpr{ - pos: position{line: 210, col: 48, offset: 6161}, - exprs: []interface{}{ + pos: position{line: 210, col: 48, offset: 6125}, + exprs: []any{ &litMatcher{ - pos: position{line: 210, col: 48, offset: 6161}, + pos: position{line: 210, col: 48, offset: 6125}, val: "\\", ignoreCase: false, want: "\"\\\\\"", }, &ruleRefExpr{ - pos: position{line: 210, col: 53, offset: 6166}, + pos: position{line: 210, col: 53, offset: 6130}, name: "CharClassEscape", }, }, @@ -1601,18 +1601,18 @@ var g = &grammar{ }, { name: "CharClassEscape", - pos: position{line: 211, col: 1, offset: 6182}, + pos: position{line: 211, col: 1, offset: 6146}, expr: &choiceExpr{ - pos: position{line: 211, col: 19, offset: 6202}, - alternatives: []interface{}{ + pos: position{line: 211, col: 19, offset: 6166}, + alternatives: []any{ &litMatcher{ - pos: position{line: 211, col: 19, offset: 6202}, + pos: position{line: 211, col: 19, offset: 6166}, val: "]", ignoreCase: false, want: "\"]\"", }, &ruleRefExpr{ - pos: position{line: 211, col: 25, offset: 6208}, + pos: position{line: 211, col: 25, offset: 6172}, name: "CommonEscapeSequence", }, }, @@ -1620,38 +1620,38 @@ var g = &grammar{ }, { name: "UnicodeClassEscape", - pos: position{line: 213, col: 1, offset: 6230}, + pos: position{line: 213, col: 1, offset: 6194}, expr: &seqExpr{ - pos: position{line: 213, col: 22, offset: 6253}, - exprs: []interface{}{ + pos: position{line: 213, col: 22, offset: 6217}, + exprs: []any{ &litMatcher{ - pos: position{line: 213, col: 22, offset: 6253}, + pos: position{line: 213, col: 22, offset: 6217}, val: "p", ignoreCase: false, want: "\"p\"", }, &choiceExpr{ - pos: position{line: 213, col: 28, offset: 6259}, - alternatives: []interface{}{ + pos: position{line: 213, col: 28, offset: 6223}, + alternatives: []any{ &ruleRefExpr{ - pos: position{line: 213, col: 28, offset: 6259}, + pos: position{line: 213, col: 28, offset: 6223}, name: "SingleCharUnicodeClass", }, &seqExpr{ - pos: position{line: 213, col: 53, offset: 6284}, - exprs: []interface{}{ + pos: position{line: 213, col: 53, offset: 6248}, + exprs: []any{ &litMatcher{ - pos: position{line: 213, col: 53, offset: 6284}, + pos: position{line: 213, col: 53, offset: 6248}, val: "{", ignoreCase: false, want: "\"{\"", }, &ruleRefExpr{ - pos: position{line: 213, col: 57, offset: 6288}, + pos: position{line: 213, col: 57, offset: 6252}, name: "UnicodeClass", }, &litMatcher{ - pos: position{line: 213, col: 70, offset: 6301}, + pos: position{line: 213, col: 70, offset: 6265}, val: "}", ignoreCase: false, want: "\"}\"", @@ -1665,9 +1665,9 @@ var g = &grammar{ }, { name: "SingleCharUnicodeClass", - pos: position{line: 214, col: 1, offset: 6307}, + pos: position{line: 214, col: 1, offset: 6271}, expr: &charClassMatcher{ - pos: position{line: 214, col: 26, offset: 6334}, + pos: position{line: 214, col: 26, offset: 6298}, val: "[LMNCPZS]", chars: []rune{'L', 'M', 'N', 'C', 'P', 'Z', 'S'}, ignoreCase: false, @@ -1676,11 +1676,11 @@ var g = &grammar{ }, { name: "UnicodeClass", - pos: position{line: 215, col: 1, offset: 6344}, + pos: position{line: 215, col: 1, offset: 6308}, expr: &oneOrMoreExpr{ - pos: position{line: 215, col: 16, offset: 6361}, + pos: position{line: 215, col: 16, offset: 6325}, expr: &charClassMatcher{ - pos: position{line: 215, col: 16, offset: 6361}, + pos: position{line: 215, col: 16, offset: 6325}, val: "[a-z_]i", chars: []rune{'_'}, ranges: []rune{'a', 'z'}, @@ -1691,12 +1691,12 @@ var g = &grammar{ }, { name: "AnyMatcher", - pos: position{line: 217, col: 1, offset: 6371}, + pos: position{line: 217, col: 1, offset: 6335}, expr: &actionExpr{ - pos: position{line: 217, col: 14, offset: 6386}, + pos: position{line: 217, col: 14, offset: 6350}, run: (*parser).callonAnyMatcher1, expr: &litMatcher{ - pos: position{line: 217, col: 14, offset: 6386}, + pos: position{line: 217, col: 14, offset: 6350}, val: ".", ignoreCase: false, want: "\".\"", @@ -1705,25 +1705,25 @@ var g = &grammar{ }, { name: "CodeBlock", - pos: position{line: 222, col: 1, offset: 6461}, + pos: position{line: 222, col: 1, offset: 6425}, expr: &actionExpr{ - pos: position{line: 222, col: 13, offset: 6475}, + pos: position{line: 222, col: 13, offset: 6439}, run: (*parser).callonCodeBlock1, expr: &seqExpr{ - pos: position{line: 222, col: 13, offset: 6475}, - exprs: []interface{}{ + pos: position{line: 222, col: 13, offset: 6439}, + exprs: []any{ &litMatcher{ - pos: position{line: 222, col: 13, offset: 6475}, + pos: position{line: 222, col: 13, offset: 6439}, val: "{", ignoreCase: false, want: "\"{\"", }, &ruleRefExpr{ - pos: position{line: 222, col: 17, offset: 6479}, + pos: position{line: 222, col: 17, offset: 6443}, name: "Code", }, &litMatcher{ - pos: position{line: 222, col: 22, offset: 6484}, + pos: position{line: 222, col: 22, offset: 6448}, val: "}", ignoreCase: false, want: "\"}\"", @@ -1734,21 +1734,21 @@ var g = &grammar{ }, { name: "Code", - pos: position{line: 228, col: 1, offset: 6582}, + pos: position{line: 228, col: 1, offset: 6546}, expr: &zeroOrMoreExpr{ - pos: position{line: 228, col: 10, offset: 6593}, + pos: position{line: 228, col: 10, offset: 6557}, expr: &choiceExpr{ - pos: position{line: 228, col: 10, offset: 6593}, - alternatives: []interface{}{ + pos: position{line: 228, col: 10, offset: 6557}, + alternatives: []any{ &oneOrMoreExpr{ - pos: position{line: 228, col: 12, offset: 6595}, + pos: position{line: 228, col: 12, offset: 6559}, expr: &seqExpr{ - pos: position{line: 228, col: 12, offset: 6595}, - exprs: []interface{}{ + pos: position{line: 228, col: 12, offset: 6559}, + exprs: []any{ ¬Expr{ - pos: position{line: 228, col: 12, offset: 6595}, + pos: position{line: 228, col: 12, offset: 6559}, expr: &charClassMatcher{ - pos: position{line: 228, col: 13, offset: 6596}, + pos: position{line: 228, col: 13, offset: 6560}, val: "[{}]", chars: []rune{'{', '}'}, ignoreCase: false, @@ -1756,27 +1756,27 @@ var g = &grammar{ }, }, &ruleRefExpr{ - pos: position{line: 228, col: 18, offset: 6601}, + pos: position{line: 228, col: 18, offset: 6565}, name: "SourceChar", }, }, }, }, &seqExpr{ - pos: position{line: 228, col: 34, offset: 6617}, - exprs: []interface{}{ + pos: position{line: 228, col: 34, offset: 6581}, + exprs: []any{ &litMatcher{ - pos: position{line: 228, col: 34, offset: 6617}, + pos: position{line: 228, col: 34, offset: 6581}, val: "{", ignoreCase: false, want: "\"{\"", }, &ruleRefExpr{ - pos: position{line: 228, col: 38, offset: 6621}, + pos: position{line: 228, col: 38, offset: 6585}, name: "Code", }, &litMatcher{ - pos: position{line: 228, col: 43, offset: 6626}, + pos: position{line: 228, col: 43, offset: 6590}, val: "}", ignoreCase: false, want: "\"}\"", @@ -1789,22 +1789,22 @@ var g = &grammar{ }, { name: "__", - pos: position{line: 230, col: 1, offset: 6634}, + pos: position{line: 230, col: 1, offset: 6598}, expr: &zeroOrMoreExpr{ - pos: position{line: 230, col: 8, offset: 6643}, + pos: position{line: 230, col: 8, offset: 6607}, expr: &choiceExpr{ - pos: position{line: 230, col: 8, offset: 6643}, - alternatives: []interface{}{ + pos: position{line: 230, col: 8, offset: 6607}, + alternatives: []any{ &ruleRefExpr{ - pos: position{line: 230, col: 8, offset: 6643}, + pos: position{line: 230, col: 8, offset: 6607}, name: "Whitespace", }, &ruleRefExpr{ - pos: position{line: 230, col: 21, offset: 6656}, + pos: position{line: 230, col: 21, offset: 6620}, name: "EOL", }, &ruleRefExpr{ - pos: position{line: 230, col: 27, offset: 6662}, + pos: position{line: 230, col: 27, offset: 6626}, name: "Comment", }, }, @@ -1813,18 +1813,18 @@ var g = &grammar{ }, { name: "_", - pos: position{line: 231, col: 1, offset: 6673}, + pos: position{line: 231, col: 1, offset: 6637}, expr: &zeroOrMoreExpr{ - pos: position{line: 231, col: 7, offset: 6681}, + pos: position{line: 231, col: 7, offset: 6645}, expr: &choiceExpr{ - pos: position{line: 231, col: 7, offset: 6681}, - alternatives: []interface{}{ + pos: position{line: 231, col: 7, offset: 6645}, + alternatives: []any{ &ruleRefExpr{ - pos: position{line: 231, col: 7, offset: 6681}, + pos: position{line: 231, col: 7, offset: 6645}, name: "Whitespace", }, &ruleRefExpr{ - pos: position{line: 231, col: 20, offset: 6694}, + pos: position{line: 231, col: 20, offset: 6658}, name: "MultiLineCommentNoLineTerminator", }, }, @@ -1833,9 +1833,9 @@ var g = &grammar{ }, { name: "Whitespace", - pos: position{line: 233, col: 1, offset: 6731}, + pos: position{line: 233, col: 1, offset: 6695}, expr: &charClassMatcher{ - pos: position{line: 233, col: 14, offset: 6746}, + pos: position{line: 233, col: 14, offset: 6710}, val: "[ \\t\\r]", chars: []rune{' ', '\t', '\r'}, ignoreCase: false, @@ -1844,9 +1844,9 @@ var g = &grammar{ }, { name: "EOL", - pos: position{line: 234, col: 1, offset: 6754}, + pos: position{line: 234, col: 1, offset: 6718}, expr: &litMatcher{ - pos: position{line: 234, col: 7, offset: 6762}, + pos: position{line: 234, col: 7, offset: 6726}, val: "\n", ignoreCase: false, want: "\"\\n\"", @@ -1854,19 +1854,19 @@ var g = &grammar{ }, { name: "EOS", - pos: position{line: 235, col: 1, offset: 6767}, + pos: position{line: 235, col: 1, offset: 6731}, expr: &choiceExpr{ - pos: position{line: 235, col: 7, offset: 6775}, - alternatives: []interface{}{ + pos: position{line: 235, col: 7, offset: 6739}, + alternatives: []any{ &seqExpr{ - pos: position{line: 235, col: 7, offset: 6775}, - exprs: []interface{}{ + pos: position{line: 235, col: 7, offset: 6739}, + exprs: []any{ &ruleRefExpr{ - pos: position{line: 235, col: 7, offset: 6775}, + pos: position{line: 235, col: 7, offset: 6739}, name: "__", }, &litMatcher{ - pos: position{line: 235, col: 10, offset: 6778}, + pos: position{line: 235, col: 10, offset: 6742}, val: ";", ignoreCase: false, want: "\";\"", @@ -1874,34 +1874,34 @@ var g = &grammar{ }, }, &seqExpr{ - pos: position{line: 235, col: 16, offset: 6784}, - exprs: []interface{}{ + pos: position{line: 235, col: 16, offset: 6748}, + exprs: []any{ &ruleRefExpr{ - pos: position{line: 235, col: 16, offset: 6784}, + pos: position{line: 235, col: 16, offset: 6748}, name: "_", }, &zeroOrOneExpr{ - pos: position{line: 235, col: 18, offset: 6786}, + pos: position{line: 235, col: 18, offset: 6750}, expr: &ruleRefExpr{ - pos: position{line: 235, col: 18, offset: 6786}, + pos: position{line: 235, col: 18, offset: 6750}, name: "SingleLineComment", }, }, &ruleRefExpr{ - pos: position{line: 235, col: 37, offset: 6805}, + pos: position{line: 235, col: 37, offset: 6769}, name: "EOL", }, }, }, &seqExpr{ - pos: position{line: 235, col: 43, offset: 6811}, - exprs: []interface{}{ + pos: position{line: 235, col: 43, offset: 6775}, + exprs: []any{ &ruleRefExpr{ - pos: position{line: 235, col: 43, offset: 6811}, + pos: position{line: 235, col: 43, offset: 6775}, name: "__", }, &ruleRefExpr{ - pos: position{line: 235, col: 46, offset: 6814}, + pos: position{line: 235, col: 46, offset: 6778}, name: "EOF", }, }, @@ -1911,57 +1911,57 @@ var g = &grammar{ }, { name: "EOF", - pos: position{line: 237, col: 1, offset: 6819}, + pos: position{line: 237, col: 1, offset: 6783}, expr: ¬Expr{ - pos: position{line: 237, col: 7, offset: 6827}, + pos: position{line: 237, col: 7, offset: 6791}, expr: &anyMatcher{ - line: 237, col: 8, offset: 6828, + line: 237, col: 8, offset: 6792, }, }, }, }, } -func (c *current) onGrammar1(initializer, rules interface{}) (interface{}, error) { +func (c *current) onGrammar1(initializer, rules any) (any, error) { pos := c.astPos() // create the grammar, assign its initializer g := ast.NewGrammar(pos) - initSlice := toIfaceSlice(initializer) + initSlice := toAnySlice(initializer) if len(initSlice) > 0 { g.Init = initSlice[0].(*ast.CodeBlock) } - rulesSlice := toIfaceSlice(rules) + rulesSlice := toAnySlice(rules) g.Rules = make([]*ast.Rule, len(rulesSlice)) for i, duo := range rulesSlice { - g.Rules[i] = duo.([]interface{})[0].(*ast.Rule) + g.Rules[i] = duo.([]any)[0].(*ast.Rule) } return g, nil } -func (p *parser) callonGrammar1() (interface{}, error) { +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 interface{}) (interface{}, error) { +func (c *current) onInitializer1(code any) (any, error) { return code, nil } -func (p *parser) callonInitializer1() (interface{}, error) { +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 interface{}) (interface{}, error) { +func (c *current) onRule1(name, display, expr any) (any, error) { pos := c.astPos() rule := ast.NewRule(pos, name.(*ast.Identifier)) - displaySlice := toIfaceSlice(display) + displaySlice := toAnySlice(display) if len(displaySlice) > 0 { rule.DisplayName = displaySlice[0].(*ast.StringLit) } @@ -1970,14 +1970,14 @@ func (c *current) onRule1(name, display, expr interface{}) (interface{}, error) return rule, nil } -func (p *parser) callonRule1() (interface{}, error) { +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) onChoiceExpr1(first, rest interface{}) (interface{}, error) { - restSlice := toIfaceSlice(rest) +func (c *current) onChoiceExpr1(first, rest any) (any, error) { + restSlice := toAnySlice(rest) if len(restSlice) == 0 { return first, nil } @@ -1986,18 +1986,18 @@ func (c *current) onChoiceExpr1(first, rest interface{}) (interface{}, error) { choice := ast.NewChoiceExpr(pos) choice.Alternatives = []ast.Expression{first.(ast.Expression)} for _, sl := range restSlice { - choice.Alternatives = append(choice.Alternatives, sl.([]interface{})[3].(ast.Expression)) + choice.Alternatives = append(choice.Alternatives, sl.([]any)[3].(ast.Expression)) } return choice, nil } -func (p *parser) callonChoiceExpr1() (interface{}, error) { +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 interface{}) (interface{}, error) { +func (c *current) onActionExpr1(expr, code any) (any, error) { if code == nil { return expr, nil } @@ -2005,38 +2005,38 @@ func (c *current) onActionExpr1(expr, code interface{}) (interface{}, error) { pos := c.astPos() act := ast.NewActionExpr(pos) act.Expr = expr.(ast.Expression) - codeSlice := toIfaceSlice(code) + codeSlice := toAnySlice(code) act.Code = codeSlice[1].(*ast.CodeBlock) return act, nil } -func (p *parser) callonActionExpr1() (interface{}, error) { +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 interface{}) (interface{}, error) { - restSlice := toIfaceSlice(rest) +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.([]interface{})[1].(ast.Expression)) + seq.Exprs = append(seq.Exprs, sl.([]any)[1].(ast.Expression)) } return seq, nil } -func (p *parser) callonSeqExpr1() (interface{}, error) { +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 interface{}) (interface{}, error) { +func (c *current) onLabeledExpr2(label, expr any) (any, error) { pos := c.astPos() lab := ast.NewLabeledExpr(pos) lab.Label = label.(*ast.Identifier) @@ -2044,13 +2044,13 @@ func (c *current) onLabeledExpr2(label, expr interface{}) (interface{}, error) { return lab, nil } -func (p *parser) callonLabeledExpr2() (interface{}, error) { +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 interface{}) (interface{}, error) { +func (c *current) onPrefixedExpr2(op, expr any) (any, error) { pos := c.astPos() opStr := op.(string) if opStr == "&" { @@ -2063,23 +2063,23 @@ func (c *current) onPrefixedExpr2(op, expr interface{}) (interface{}, error) { return not, nil } -func (p *parser) callonPrefixedExpr2() (interface{}, error) { +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() (interface{}, error) { +func (c *current) onPrefixedOp1() (any, error) { return string(c.text), nil } -func (p *parser) callonPrefixedOp1() (interface{}, error) { +func (p *parser) callonPrefixedOp1() (any, error) { stack := p.vstack[len(p.vstack)-1] _ = stack return p.cur.onPrefixedOp1() } -func (c *current) onSuffixedExpr2(expr, op interface{}) (interface{}, error) { +func (c *current) onSuffixedExpr2(expr, op any) (any, error) { pos := c.astPos() opStr := op.(string) switch opStr { @@ -2100,45 +2100,45 @@ func (c *current) onSuffixedExpr2(expr, op interface{}) (interface{}, error) { } } -func (p *parser) callonSuffixedExpr2() (interface{}, error) { +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() (interface{}, error) { +func (c *current) onSuffixedOp1() (any, error) { return string(c.text), nil } -func (p *parser) callonSuffixedOp1() (interface{}, error) { +func (p *parser) callonSuffixedOp1() (any, error) { stack := p.vstack[len(p.vstack)-1] _ = stack return p.cur.onSuffixedOp1() } -func (c *current) onPrimaryExpr7(expr interface{}) (interface{}, error) { +func (c *current) onPrimaryExpr7(expr any) (any, error) { return expr, nil } -func (p *parser) callonPrimaryExpr7() (interface{}, error) { +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 interface{}) (interface{}, error) { +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() (interface{}, error) { +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 interface{}) (interface{}, error) { +func (c *current) onSemanticPredExpr1(op, code any) (any, error) { opStr := op.(string) if opStr == "&" { and := ast.NewAndCodeExpr(c.astPos()) @@ -2150,33 +2150,33 @@ func (c *current) onSemanticPredExpr1(op, code interface{}) (interface{}, error) return not, nil } -func (p *parser) callonSemanticPredExpr1() (interface{}, error) { +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() (interface{}, error) { +func (c *current) onSemanticPredOp1() (any, error) { return string(c.text), nil } -func (p *parser) callonSemanticPredOp1() (interface{}, error) { +func (p *parser) callonSemanticPredOp1() (any, error) { stack := p.vstack[len(p.vstack)-1] _ = stack return p.cur.onSemanticPredOp1() } -func (c *current) onIdentifierName1() (interface{}, error) { +func (c *current) onIdentifierName1() (any, error) { return ast.NewIdentifier(c.astPos(), string(c.text)), nil } -func (p *parser) callonIdentifierName1() (interface{}, error) { +func (p *parser) callonIdentifierName1() (any, error) { stack := p.vstack[len(p.vstack)-1] _ = stack return p.cur.onIdentifierName1() } -func (c *current) onLitMatcher1(lit, ignore interface{}) (interface{}, error) { +func (c *current) onLitMatcher1(lit, ignore any) (any, error) { rawStr := lit.(*ast.StringLit).Val s, err := strconv.Unquote(rawStr) if err != nil { @@ -2187,52 +2187,52 @@ func (c *current) onLitMatcher1(lit, ignore interface{}) (interface{}, error) { return m, nil } -func (p *parser) callonLitMatcher1() (interface{}, error) { +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) onStringLiteral1() (interface{}, error) { +func (c *current) onStringLiteral1() (any, error) { return ast.NewStringLit(c.astPos(), string(c.text)), nil } -func (p *parser) callonStringLiteral1() (interface{}, error) { +func (p *parser) callonStringLiteral1() (any, error) { stack := p.vstack[len(p.vstack)-1] _ = stack return p.cur.onStringLiteral1() } -func (c *current) onCharClassMatcher1() (interface{}, error) { +func (c *current) onCharClassMatcher1() (any, error) { pos := c.astPos() cc := ast.NewCharClassMatcher(pos, string(c.text)) return cc, nil } -func (p *parser) callonCharClassMatcher1() (interface{}, error) { +func (p *parser) callonCharClassMatcher1() (any, error) { stack := p.vstack[len(p.vstack)-1] _ = stack return p.cur.onCharClassMatcher1() } -func (c *current) onAnyMatcher1() (interface{}, error) { +func (c *current) onAnyMatcher1() (any, error) { any := ast.NewAnyMatcher(c.astPos(), ".") return any, nil } -func (p *parser) callonAnyMatcher1() (interface{}, error) { +func (p *parser) callonAnyMatcher1() (any, error) { stack := p.vstack[len(p.vstack)-1] _ = stack return p.cur.onAnyMatcher1() } -func (c *current) onCodeBlock1() (interface{}, error) { +func (c *current) onCodeBlock1() (any, error) { pos := c.astPos() cb := ast.NewCodeBlock(pos, string(c.text)) return cb, nil } -func (p *parser) callonCodeBlock1() (interface{}, error) { +func (p *parser) callonCodeBlock1() (any, error) { stack := p.vstack[len(p.vstack)-1] _ = stack return p.cur.onCodeBlock1() @@ -2376,7 +2376,7 @@ func Recover(b bool) Option { // GlobalStore creates an Option to set a key to a certain value in // the globalStore. -func GlobalStore(key string, value interface{}) Option { +func GlobalStore(key string, value any) Option { return func(p *parser) Option { old := p.cur.globalStore[key] p.cur.globalStore[key] = value @@ -2386,7 +2386,7 @@ func GlobalStore(key string, value interface{}) Option { // InitState creates an Option to set a key to a certain value in // the global "state" store. -func InitState(key string, value interface{}) Option { +func InitState(key string, value any) Option { return func(p *parser) Option { old := p.cur.state[key] p.cur.state[key] = value @@ -2395,7 +2395,7 @@ func InitState(key string, value interface{}) Option { } // ParseFile parses the file identified by filename. -func ParseFile(filename string, opts ...Option) (i interface{}, err error) { +func ParseFile(filename string, opts ...Option) (i any, err error) { f, err := os.Open(filename) if err != nil { return nil, err @@ -2410,7 +2410,7 @@ func ParseFile(filename string, opts ...Option) (i interface{}, err error) { // ParseReader parses the data from r using filename as information in the // error messages. -func ParseReader(filename string, r io.Reader, opts ...Option) (interface{}, error) { +func ParseReader(filename string, r io.Reader, opts ...Option) (any, error) { b, err := io.ReadAll(r) if err != nil { return nil, err @@ -2421,7 +2421,7 @@ func ParseReader(filename string, r io.Reader, opts ...Option) (interface{}, err // Parse parses the data from b using filename as information in the // error messages. -func Parse(filename string, b []byte, opts ...Option) (interface{}, error) { +func Parse(filename string, b []byte, opts ...Option) (any, error) { return newParser(filename, b, opts...).parse(g) } @@ -2459,7 +2459,7 @@ type current struct { globalStore storeDict } -type storeDict map[string]interface{} +type storeDict map[string]any // the AST types... @@ -2472,30 +2472,30 @@ type rule struct { pos position name string displayName string - expr interface{} + expr any } type choiceExpr struct { pos position - alternatives []interface{} + alternatives []any } type actionExpr struct { pos position - expr interface{} - run func(*parser) (interface{}, error) + expr any + run func(*parser) (any, error) } type recoveryExpr struct { pos position - expr interface{} - recoverExpr interface{} + expr any + recoverExpr any failureLabel []string } type seqExpr struct { pos position - exprs []interface{} + exprs []any } type throwExpr struct { @@ -2506,19 +2506,21 @@ type throwExpr struct { type labeledExpr struct { pos position label string - expr interface{} + expr any } type expr struct { pos position - expr interface{} + expr any } -type andExpr expr -type notExpr expr -type zeroOrOneExpr expr -type zeroOrMoreExpr expr -type oneOrMoreExpr expr +type ( + andExpr expr + notExpr expr + zeroOrOneExpr expr + zeroOrMoreExpr expr + oneOrMoreExpr expr +) type ruleRefExpr struct { pos position @@ -2659,7 +2661,7 @@ func (p *parser) setOptions(opts []Option) { } type resultTuple struct { - v interface{} + v any b bool end savepoint } @@ -2703,12 +2705,12 @@ type parser struct { memoize bool // memoization table for the packrat algorithm: // map[offset in source] map[expression or rule] {value, match} - memo map[int]map[interface{}]resultTuple + 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]interface{} + vstack []map[string]any // rule stack, allows identification of the current rule in errors rstack []*rule @@ -2728,7 +2730,7 @@ type parser struct { choiceNoMatch string // recovery expression stack, keeps track of the currently available recovery expression, these are traversed in reverse - recoveryStack []map[string]interface{} + recoveryStack []map[string]any } // push a variable set on the vstack. @@ -2748,7 +2750,7 @@ func (p *parser) pushV() { return } - m = make(map[string]interface{}) + m = make(map[string]any) p.vstack[len(p.vstack)-1] = m } @@ -2764,7 +2766,7 @@ func (p *parser) popV() { } // push a recovery expression with its labels to the recoveryStack -func (p *parser) pushRecovery(labels []string, expr interface{}) { +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) @@ -2773,7 +2775,7 @@ func (p *parser) pushRecovery(labels []string, expr interface{}) { p.recoveryStack = p.recoveryStack[:len(p.recoveryStack)+1] } - m := make(map[string]interface{}, len(labels)) + m := make(map[string]any, len(labels)) for _, fl := range labels { m[fl] = expr } @@ -2893,11 +2895,11 @@ func (p *parser) restore(pt savepoint) { // copies of the state to allow the parser to properly restore the state in // the case of backtracking. type Cloner interface { - Clone() interface{} + Clone() any } var statePool = &sync.Pool{ - New: func() interface{} { return make(storeDict) }, + New: func() any { return make(storeDict) }, } func (sd storeDict) Discard() { @@ -2939,7 +2941,7 @@ func (p *parser) sliceFrom(start savepoint) []byte { return p.data[start.position.offset:p.pt.position.offset] } -func (p *parser) getMemoized(node interface{}) (resultTuple, bool) { +func (p *parser) getMemoized(node any) (resultTuple, bool) { if len(p.memo) == 0 { return resultTuple{}, false } @@ -2951,13 +2953,13 @@ func (p *parser) getMemoized(node interface{}) (resultTuple, bool) { return res, ok } -func (p *parser) setMemoized(pt savepoint, node interface{}, tuple resultTuple) { +func (p *parser) setMemoized(pt savepoint, node any, tuple resultTuple) { if p.memo == nil { - p.memo = make(map[int]map[interface{}]resultTuple) + p.memo = make(map[int]map[any]resultTuple) } m := p.memo[pt.offset] if m == nil { - m = make(map[interface{}]resultTuple) + m = make(map[any]resultTuple) p.memo[pt.offset] = m } m[node] = tuple @@ -2970,7 +2972,7 @@ func (p *parser) buildRulesTable(g *grammar) { } } -func (p *parser) parse(g *grammar) (val interface{}, err error) { +func (p *parser) parse(g *grammar) (val any, err error) { if len(g.rules) == 0 { p.addErr(errNoRule) return nil, p.errs.err() @@ -3047,7 +3049,7 @@ func listJoin(list []string, sep string, lastSep string) string { } } -func (p *parser) parseRule(rule *rule) (interface{}, bool) { +func (p *parser) parseRule(rule *rule) (any, bool) { if p.debug { defer p.out(p.in("parseRule " + rule.name)) } @@ -3076,7 +3078,7 @@ func (p *parser) parseRule(rule *rule) (interface{}, bool) { return val, ok } -func (p *parser) parseExpr(expr interface{}) (interface{}, bool) { +func (p *parser) parseExpr(expr any) (any, bool) { var pt savepoint if p.memoize { @@ -3093,7 +3095,7 @@ func (p *parser) parseExpr(expr interface{}) (interface{}, bool) { panic(errMaxExprCnt) } - var val interface{} + var val any var ok bool switch expr := expr.(type) { case *actionExpr: @@ -3141,7 +3143,7 @@ func (p *parser) parseExpr(expr interface{}) (interface{}, bool) { return val, ok } -func (p *parser) parseActionExpr(act *actionExpr) (interface{}, bool) { +func (p *parser) parseActionExpr(act *actionExpr) (any, bool) { if p.debug { defer p.out(p.in("parseActionExpr")) } @@ -3166,7 +3168,7 @@ func (p *parser) parseActionExpr(act *actionExpr) (interface{}, bool) { return val, ok } -func (p *parser) parseAndCodeExpr(and *andCodeExpr) (interface{}, bool) { +func (p *parser) parseAndCodeExpr(and *andCodeExpr) (any, bool) { if p.debug { defer p.out(p.in("parseAndCodeExpr")) } @@ -3182,7 +3184,7 @@ func (p *parser) parseAndCodeExpr(and *andCodeExpr) (interface{}, bool) { return nil, ok } -func (p *parser) parseAndExpr(and *andExpr) (interface{}, bool) { +func (p *parser) parseAndExpr(and *andExpr) (any, bool) { if p.debug { defer p.out(p.in("parseAndExpr")) } @@ -3198,7 +3200,7 @@ func (p *parser) parseAndExpr(and *andExpr) (interface{}, bool) { return nil, ok } -func (p *parser) parseAnyMatcher(any *anyMatcher) (interface{}, bool) { +func (p *parser) parseAnyMatcher(any *anyMatcher) (any, bool) { if p.debug { defer p.out(p.in("parseAnyMatcher")) } @@ -3214,7 +3216,7 @@ func (p *parser) parseAnyMatcher(any *anyMatcher) (interface{}, bool) { return p.sliceFrom(start), true } -func (p *parser) parseCharClassMatcher(chr *charClassMatcher) (interface{}, bool) { +func (p *parser) parseCharClassMatcher(chr *charClassMatcher) (any, bool) { if p.debug { defer p.out(p.in("parseCharClassMatcher")) } @@ -3295,7 +3297,7 @@ func (p *parser) incChoiceAltCnt(ch *choiceExpr, altI int) { m[alt]++ } -func (p *parser) parseChoiceExpr(ch *choiceExpr) (interface{}, bool) { +func (p *parser) parseChoiceExpr(ch *choiceExpr) (any, bool) { if p.debug { defer p.out(p.in("parseChoiceExpr")) } @@ -3319,7 +3321,7 @@ func (p *parser) parseChoiceExpr(ch *choiceExpr) (interface{}, bool) { return nil, false } -func (p *parser) parseLabeledExpr(lab *labeledExpr) (interface{}, bool) { +func (p *parser) parseLabeledExpr(lab *labeledExpr) (any, bool) { if p.debug { defer p.out(p.in("parseLabeledExpr")) } @@ -3334,7 +3336,7 @@ func (p *parser) parseLabeledExpr(lab *labeledExpr) (interface{}, bool) { return val, ok } -func (p *parser) parseLitMatcher(lit *litMatcher) (interface{}, bool) { +func (p *parser) parseLitMatcher(lit *litMatcher) (any, bool) { if p.debug { defer p.out(p.in("parseLitMatcher")) } @@ -3356,7 +3358,7 @@ func (p *parser) parseLitMatcher(lit *litMatcher) (interface{}, bool) { return p.sliceFrom(start), true } -func (p *parser) parseNotCodeExpr(not *notCodeExpr) (interface{}, bool) { +func (p *parser) parseNotCodeExpr(not *notCodeExpr) (any, bool) { if p.debug { defer p.out(p.in("parseNotCodeExpr")) } @@ -3372,7 +3374,7 @@ func (p *parser) parseNotCodeExpr(not *notCodeExpr) (interface{}, bool) { return nil, !ok } -func (p *parser) parseNotExpr(not *notExpr) (interface{}, bool) { +func (p *parser) parseNotExpr(not *notExpr) (any, bool) { if p.debug { defer p.out(p.in("parseNotExpr")) } @@ -3390,12 +3392,12 @@ func (p *parser) parseNotExpr(not *notExpr) (interface{}, bool) { return nil, !ok } -func (p *parser) parseOneOrMoreExpr(expr *oneOrMoreExpr) (interface{}, bool) { +func (p *parser) parseOneOrMoreExpr(expr *oneOrMoreExpr) (any, bool) { if p.debug { defer p.out(p.in("parseOneOrMoreExpr")) } - var vals []interface{} + var vals []any for { p.pushV() @@ -3412,7 +3414,7 @@ func (p *parser) parseOneOrMoreExpr(expr *oneOrMoreExpr) (interface{}, bool) { } } -func (p *parser) parseRecoveryExpr(recover *recoveryExpr) (interface{}, bool) { +func (p *parser) parseRecoveryExpr(recover *recoveryExpr) (any, bool) { if p.debug { defer p.out(p.in("parseRecoveryExpr (" + strings.Join(recover.failureLabel, ",") + ")")) } @@ -3424,7 +3426,7 @@ func (p *parser) parseRecoveryExpr(recover *recoveryExpr) (interface{}, bool) { return val, ok } -func (p *parser) parseRuleRefExpr(ref *ruleRefExpr) (interface{}, bool) { +func (p *parser) parseRuleRefExpr(ref *ruleRefExpr) (any, bool) { if p.debug { defer p.out(p.in("parseRuleRefExpr " + ref.name)) } @@ -3441,12 +3443,12 @@ func (p *parser) parseRuleRefExpr(ref *ruleRefExpr) (interface{}, bool) { return p.parseRule(rule) } -func (p *parser) parseSeqExpr(seq *seqExpr) (interface{}, bool) { +func (p *parser) parseSeqExpr(seq *seqExpr) (any, bool) { if p.debug { defer p.out(p.in("parseSeqExpr")) } - vals := make([]interface{}, 0, len(seq.exprs)) + vals := make([]any, 0, len(seq.exprs)) pt := p.pt state := p.cloneState() @@ -3462,7 +3464,7 @@ func (p *parser) parseSeqExpr(seq *seqExpr) (interface{}, bool) { return vals, true } -func (p *parser) parseStateCodeExpr(state *stateCodeExpr) (interface{}, bool) { +func (p *parser) parseStateCodeExpr(state *stateCodeExpr) (any, bool) { if p.debug { defer p.out(p.in("parseStateCodeExpr")) } @@ -3474,7 +3476,7 @@ func (p *parser) parseStateCodeExpr(state *stateCodeExpr) (interface{}, bool) { return nil, true } -func (p *parser) parseThrowExpr(expr *throwExpr) (interface{}, bool) { +func (p *parser) parseThrowExpr(expr *throwExpr) (any, bool) { if p.debug { defer p.out(p.in("parseThrowExpr")) } @@ -3490,12 +3492,12 @@ func (p *parser) parseThrowExpr(expr *throwExpr) (interface{}, bool) { return nil, false } -func (p *parser) parseZeroOrMoreExpr(expr *zeroOrMoreExpr) (interface{}, bool) { +func (p *parser) parseZeroOrMoreExpr(expr *zeroOrMoreExpr) (any, bool) { if p.debug { defer p.out(p.in("parseZeroOrMoreExpr")) } - var vals []interface{} + var vals []any for { p.pushV() @@ -3508,7 +3510,7 @@ func (p *parser) parseZeroOrMoreExpr(expr *zeroOrMoreExpr) (interface{}, bool) { } } -func (p *parser) parseZeroOrOneExpr(expr *zeroOrOneExpr) (interface{}, bool) { +func (p *parser) parseZeroOrOneExpr(expr *zeroOrOneExpr) (any, bool) { if p.debug { defer p.out(p.in("parseZeroOrOneExpr")) } diff --git a/bootstrap/cmd/bootstrap-pigeon/main.go b/bootstrap/cmd/bootstrap-pigeon/main.go index d1d3e3e3..b274e6f2 100644 --- a/bootstrap/cmd/bootstrap-pigeon/main.go +++ b/bootstrap/cmd/bootstrap-pigeon/main.go @@ -109,9 +109,9 @@ func (c *current) astPos() ast.Pos { return ast.Pos{Line: c.pos.line, Col: c.pos.col, Off: c.pos.offset} } -func toIfaceSlice(v interface{}) []interface{} { +func toAnySlice(v any) []any { if v == nil { return nil } - return v.([]interface{}) + return v.([]any) } diff --git a/bootstrap/scan.go b/bootstrap/scan.go index 891b1e75..41923f51 100644 --- a/bootstrap/scan.go +++ b/bootstrap/scan.go @@ -532,12 +532,12 @@ func (s *Scanner) error(p ast.Pos, err error) { } // helper to generate and notify of an error. -func (s *Scanner) errorf(f string, args ...interface{}) { +func (s *Scanner) errorf(f string, args ...any) { s.errorpf(s.cpos, f, args...) } // helper to generate and notify of an error at a specific position. -func (s *Scanner) errorpf(p ast.Pos, f string, args ...interface{}) { +func (s *Scanner) errorpf(p ast.Pos, f string, args ...any) { s.error(p, fmt.Errorf(f, args...)) } diff --git a/builder/builder.go b/builder/builder.go index a40f612d..ee76666a 100644 --- a/builder/builder.go +++ b/builder/builder.go @@ -6,13 +6,12 @@ import ( "bytes" "fmt" "io" + "regexp" "strconv" "strings" "text/template" "unicode" - "regexp" - "github.com/mna/pigeon/ast" ) @@ -20,7 +19,7 @@ const codeGeneratedComment = "// Code generated by pigeon; DO NOT EDIT.\n\n" // generated function templates var ( - onFuncTemplate = `func (%s *current) %s(%s) (interface{}, error) { + onFuncTemplate = `func (%s *current) %s(%s) (any, error) { %s } ` @@ -32,7 +31,7 @@ var ( %s } ` - callFuncTemplate = `func (p *parser) call%s() (interface{}, error) { + callFuncTemplate = `func (p *parser) call%s() (any, error) { stack := p.vstack[len(p.vstack)-1] _ = stack return p.cur.%[1]s(%s) @@ -383,7 +382,7 @@ func (b *builder) writeChoiceExpr(ch *ast.ChoiceExpr) { pos := ch.Pos() b.writelnf("\tpos: position{line: %d, col: %d, offset: %d},", pos.Line, pos.Col, pos.Off) if len(ch.Alternatives) > 0 { - b.writelnf("\talternatives: []interface{}{") + b.writelnf("\talternatives: []any{") for _, alt := range ch.Alternatives { b.writeExpr(alt) } @@ -515,7 +514,7 @@ func (b *builder) writeSeqExpr(seq *ast.SeqExpr) { pos := seq.Pos() b.writelnf("\tpos: position{line: %d, col: %d, offset: %d},", pos.Line, pos.Col, pos.Off) if len(seq.Exprs) > 0 { - b.writelnf("\texprs: []interface{}{") + b.writelnf("\texprs: []any{") for _, e := range seq.Exprs { b.writeExpr(e) } @@ -735,7 +734,7 @@ func (b *builder) writeFunc(funcIx int, code *ast.CodeBlock, callTpl, funcTpl st } } if args.Len() > 0 { - args.WriteString(" interface{}") + args.WriteString(" any") } fnNm := b.funcName(funcIx) @@ -800,13 +799,13 @@ func (b *builder) funcName(ix int) string { return "on" + b.ruleName + strconv.Itoa(ix) } -func (b *builder) writef(f string, args ...interface{}) { +func (b *builder) writef(f string, args ...any) { if b.err == nil { _, b.err = fmt.Fprintf(b.w, f, args...) } } -func (b *builder) writelnf(f string, args ...interface{}) { +func (b *builder) writelnf(f string, args ...any) { b.writef(f+"\n", args...) } diff --git a/builder/generated_static_code.go b/builder/generated_static_code.go index 78e45b6a..f408ef6f 100644 --- a/builder/generated_static_code.go +++ b/builder/generated_static_code.go @@ -62,18 +62,17 @@ func Entrypoint(ruleName string) Option { // // 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)) -// +// 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 @@ -145,7 +144,7 @@ func Recover(b bool) Option { // GlobalStore creates an Option to set a key to a certain value in // the globalStore. -func GlobalStore(key string, value interface{}) Option { +func GlobalStore(key string, value any) Option { return func(p *parser) Option { old := p.cur.globalStore[key] p.cur.globalStore[key] = value @@ -157,7 +156,7 @@ func GlobalStore(key string, value interface{}) Option { // InitState creates an Option to set a key to a certain value in // the global "state" store. -func InitState(key string, value interface{}) Option { +func InitState(key string, value any) Option { return func(p *parser) Option { old := p.cur.state[key] p.cur.state[key] = value @@ -168,7 +167,7 @@ func InitState(key string, value interface{}) Option { // {{ end }} ==template== // ParseFile parses the file identified by filename. -func ParseFile(filename string, opts ...Option) (i interface{}, err error) { //{{ if .Nolint }} nolint: deadcode {{else}} ==template== {{ end }} +func ParseFile(filename string, opts ...Option) (i any, err error) { //{{ if .Nolint }} nolint: deadcode {{else}} ==template== {{ end }} f, err := os.Open(filename) if err != nil { return nil, err @@ -183,7 +182,7 @@ func ParseFile(filename string, opts ...Option) (i interface{}, err error) { //{ // ParseReader parses the data from r using filename as information in the // error messages. -func ParseReader(filename string, r io.Reader, opts ...Option) (interface{}, error) { //{{ if .Nolint }} nolint: deadcode {{else}} ==template== {{ end }} +func ParseReader(filename string, r io.Reader, opts ...Option) (any, error) { //{{ if .Nolint }} nolint: deadcode {{else}} ==template== {{ end }} b, err := io.ReadAll(r) if err != nil { return nil, err @@ -194,7 +193,7 @@ func ParseReader(filename string, r io.Reader, opts ...Option) (interface{}, err // Parse parses the data from b using filename as information in the // error messages. -func Parse(filename string, b []byte, opts ...Option) (interface{}, error) { +func Parse(filename string, b []byte, opts ...Option) (any, error) { return newParser(filename, b, opts...).parse(g) } @@ -236,77 +235,79 @@ type current struct { globalStore storeDict } -type storeDict map[string]interface{} +type storeDict map[string]any // the AST types... -//{{ if .Nolint }} nolint: structcheck {{else}} ==template== {{ end }} +// {{ if .Nolint }} nolint: structcheck {{else}} ==template== {{ end }} type grammar struct { pos position rules []*rule } -//{{ if .Nolint }} nolint: structcheck {{else}} ==template== {{ end }} +// {{ if .Nolint }} nolint: structcheck {{else}} ==template== {{ end }} type rule struct { pos position name string displayName string - expr interface{} + expr any } -//{{ if .Nolint }} nolint: structcheck {{else}} ==template== {{ end }} +// {{ if .Nolint }} nolint: structcheck {{else}} ==template== {{ end }} type choiceExpr struct { pos position - alternatives []interface{} + alternatives []any } -//{{ if .Nolint }} nolint: structcheck {{else}} ==template== {{ end }} +// {{ if .Nolint }} nolint: structcheck {{else}} ==template== {{ end }} type actionExpr struct { pos position - expr interface{} - run func(*parser) (interface{}, error) + expr any + run func(*parser) (any, error) } -//{{ if .Nolint }} nolint: structcheck {{else}} ==template== {{ end }} +// {{ if .Nolint }} nolint: structcheck {{else}} ==template== {{ end }} type recoveryExpr struct { pos position - expr interface{} - recoverExpr interface{} + expr any + recoverExpr any failureLabel []string } -//{{ if .Nolint }} nolint: structcheck {{else}} ==template== {{ end }} +// {{ if .Nolint }} nolint: structcheck {{else}} ==template== {{ end }} type seqExpr struct { pos position - exprs []interface{} + exprs []any } -//{{ if .Nolint }} nolint: structcheck {{else}} ==template== {{ end }} +// {{ if .Nolint }} nolint: structcheck {{else}} ==template== {{ end }} type throwExpr struct { pos position label string } -//{{ if .Nolint }} nolint: structcheck {{else}} ==template== {{ end }} +// {{ if .Nolint }} nolint: structcheck {{else}} ==template== {{ end }} type labeledExpr struct { pos position label string - expr interface{} + expr any } -//{{ if .Nolint }} nolint: structcheck {{else}} ==template== {{ end }} +// {{ if .Nolint }} nolint: structcheck {{else}} ==template== {{ end }} type expr struct { pos position - expr interface{} + expr any } -type andExpr expr //{{ if .Nolint }} nolint: structcheck {{else}} ==template== {{ end }} -type notExpr expr //{{ if .Nolint }} nolint: structcheck {{else}} ==template== {{ end }} -type zeroOrOneExpr expr //{{ if .Nolint }} nolint: structcheck {{else}} ==template== {{ end }} -type zeroOrMoreExpr expr //{{ if .Nolint }} nolint: structcheck {{else}} ==template== {{ end }} -type oneOrMoreExpr expr //{{ if .Nolint }} nolint: structcheck {{else}} ==template== {{ end }} +type ( + andExpr expr //{{ if .Nolint }} nolint: structcheck {{else}} ==template== {{ end }} + notExpr expr //{{ if .Nolint }} nolint: structcheck {{else}} ==template== {{ end }} + zeroOrOneExpr expr //{{ if .Nolint }} nolint: structcheck {{else}} ==template== {{ end }} + zeroOrMoreExpr expr //{{ if .Nolint }} nolint: structcheck {{else}} ==template== {{ end }} + oneOrMoreExpr expr //{{ if .Nolint }} nolint: structcheck {{else}} ==template== {{ end }} +) -//{{ if .Nolint }} nolint: structcheck {{else}} ==template== {{ end }} +// {{ if .Nolint }} nolint: structcheck {{else}} ==template== {{ end }} type ruleRefExpr struct { pos position name string @@ -314,7 +315,7 @@ type ruleRefExpr struct { // ==template== {{ if or .GlobalState (not .Optimize) }} -//{{ if .Nolint }} nolint: structcheck {{else}} ==template== {{ end }} +// {{ if .Nolint }} nolint: structcheck {{else}} ==template== {{ end }} type stateCodeExpr struct { pos position run func(*parser) error @@ -322,19 +323,19 @@ type stateCodeExpr struct { // {{ end }} ==template== -//{{ if .Nolint }} nolint: structcheck {{else}} ==template== {{ end }} +// {{ if .Nolint }} nolint: structcheck {{else}} ==template== {{ end }} type andCodeExpr struct { pos position run func(*parser) (bool, error) } -//{{ if .Nolint }} nolint: structcheck {{else}} ==template== {{ end }} +// {{ if .Nolint }} nolint: structcheck {{else}} ==template== {{ end }} type notCodeExpr struct { pos position run func(*parser) (bool, error) } -//{{ if .Nolint }} nolint: structcheck {{else}} ==template== {{ end }} +// {{ if .Nolint }} nolint: structcheck {{else}} ==template== {{ end }} type litMatcher struct { pos position val string @@ -342,7 +343,7 @@ type litMatcher struct { want string } -//{{ if .Nolint }} nolint: structcheck {{else}} ==template== {{ end }} +// {{ if .Nolint }} nolint: structcheck {{else}} ==template== {{ end }} type charClassMatcher struct { pos position val string @@ -456,14 +457,14 @@ func (p *parser) setOptions(opts []Option) { } } -//{{ if .Nolint }} nolint: structcheck,deadcode {{else}} ==template== {{ end }} +// {{ if .Nolint }} nolint: structcheck,deadcode {{else}} ==template== {{ end }} type resultTuple struct { - v interface{} + v any b bool end savepoint } -//{{ if .Nolint }} nolint: varcheck {{else}} ==template== {{ end }} +// {{ if .Nolint }} nolint: varcheck {{else}} ==template== {{ end }} const choiceNoMatch = -1 // Stats stores some statistics, gathered during parsing @@ -488,7 +489,7 @@ type Stats struct { ChoiceAltCnt map[string]map[string]int } -//{{ if .Nolint }} nolint: structcheck,maligned {{else}} ==template== {{ end }} +// {{ if .Nolint }} nolint: structcheck,maligned {{else}} ==template== {{ end }} type parser struct { filename string pt savepoint @@ -505,13 +506,13 @@ type parser struct { memoize bool // memoization table for the packrat algorithm: // map[offset in source] map[expression or rule] {value, match} - memo map[int]map[interface{}]resultTuple + memo map[int]map[any]resultTuple // {{ end }} ==template== // rules table, maps the rule identifier to the rule node rules map[string]*rule // variables stack, map of label to value - vstack []map[string]interface{} + vstack []map[string]any // rule stack, allows identification of the current rule in errors rstack []*rule @@ -531,7 +532,7 @@ type parser struct { choiceNoMatch string // recovery expression stack, keeps track of the currently available recovery expression, these are traversed in reverse - recoveryStack []map[string]interface{} + recoveryStack []map[string]any } // push a variable set on the vstack. @@ -551,7 +552,7 @@ func (p *parser) pushV() { return } - m = make(map[string]interface{}) + m = make(map[string]any) p.vstack[len(p.vstack)-1] = m } @@ -567,7 +568,7 @@ func (p *parser) popV() { } // push a recovery expression with its labels to the recoveryStack -func (p *parser) pushRecovery(labels []string, expr interface{}) { +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) @@ -576,7 +577,7 @@ func (p *parser) pushRecovery(labels []string, expr interface{}) { p.recoveryStack = p.recoveryStack[:len(p.recoveryStack)+1] } - m := make(map[string]interface{}, len(labels)) + m := make(map[string]any, len(labels)) for _, fl := range labels { m[fl] = expr } @@ -703,11 +704,11 @@ func (p *parser) restore(pt savepoint) { // copies of the state to allow the parser to properly restore the state in // the case of backtracking. type Cloner interface { - Clone() interface{} + Clone() any } var statePool = &sync.Pool{ - New: func() interface{} { return make(storeDict) }, + New: func() any { return make(storeDict) }, } func (sd storeDict) Discard() { @@ -756,7 +757,7 @@ func (p *parser) sliceFrom(start savepoint) []byte { } // ==template== {{ if not .Optimize }} -func (p *parser) getMemoized(node interface{}) (resultTuple, bool) { +func (p *parser) getMemoized(node any) (resultTuple, bool) { if len(p.memo) == 0 { return resultTuple{}, false } @@ -768,13 +769,13 @@ func (p *parser) getMemoized(node interface{}) (resultTuple, bool) { return res, ok } -func (p *parser) setMemoized(pt savepoint, node interface{}, tuple resultTuple) { +func (p *parser) setMemoized(pt savepoint, node any, tuple resultTuple) { if p.memo == nil { - p.memo = make(map[int]map[interface{}]resultTuple) + p.memo = make(map[int]map[any]resultTuple) } m := p.memo[pt.offset] if m == nil { - m = make(map[interface{}]resultTuple) + m = make(map[any]resultTuple) p.memo[pt.offset] = m } m[node] = tuple @@ -789,8 +790,8 @@ func (p *parser) buildRulesTable(g *grammar) { } } -//{{ if .Nolint }} nolint: gocyclo {{else}} ==template== {{ end }} -func (p *parser) parse(g *grammar) (val interface{}, err error) { +// {{ if .Nolint }} nolint: gocyclo {{else}} ==template== {{ end }} +func (p *parser) parse(g *grammar) (val any, err error) { if len(g.rules) == 0 { p.addErr(errNoRule) return nil, p.errs.err() @@ -869,7 +870,7 @@ func listJoin(list []string, sep string, lastSep string) string { } } -func (p *parser) parseRule(rule *rule) (interface{}, bool) { +func (p *parser) parseRule(rule *rule) (any, bool) { // ==template== {{ if not .Optimize }} if p.debug { defer p.out(p.in("parseRule " + rule.name)) @@ -902,8 +903,8 @@ func (p *parser) parseRule(rule *rule) (interface{}, bool) { return val, ok } -//{{ if .Nolint }} nolint: gocyclo {{else}} ==template== {{ end }} -func (p *parser) parseExpr(expr interface{}) (interface{}, bool) { +// {{ if .Nolint }} nolint: gocyclo {{else}} ==template== {{ end }} +func (p *parser) parseExpr(expr any) (any, bool) { // ==template== {{ if not .Optimize }} var pt savepoint @@ -923,7 +924,7 @@ func (p *parser) parseExpr(expr interface{}) (interface{}, bool) { panic(errMaxExprCnt) } - var val interface{} + var val any var ok bool switch expr := expr.(type) { case *actionExpr: @@ -975,7 +976,7 @@ func (p *parser) parseExpr(expr interface{}) (interface{}, bool) { return val, ok } -func (p *parser) parseActionExpr(act *actionExpr) (interface{}, bool) { +func (p *parser) parseActionExpr(act *actionExpr) (any, bool) { // ==template== {{ if not .Optimize }} if p.debug { defer p.out(p.in("parseActionExpr")) @@ -1008,7 +1009,7 @@ func (p *parser) parseActionExpr(act *actionExpr) (interface{}, bool) { return val, ok } -func (p *parser) parseAndCodeExpr(and *andCodeExpr) (interface{}, bool) { +func (p *parser) parseAndCodeExpr(and *andCodeExpr) (any, bool) { // ==template== {{ if not .Optimize }} if p.debug { defer p.out(p.in("parseAndCodeExpr")) @@ -1030,7 +1031,7 @@ func (p *parser) parseAndCodeExpr(and *andCodeExpr) (interface{}, bool) { return nil, ok } -func (p *parser) parseAndExpr(and *andExpr) (interface{}, bool) { +func (p *parser) parseAndExpr(and *andExpr) (any, bool) { // ==template== {{ if not .Optimize }} if p.debug { defer p.out(p.in("parseAndExpr")) @@ -1052,7 +1053,7 @@ func (p *parser) parseAndExpr(and *andExpr) (interface{}, bool) { return nil, ok } -func (p *parser) parseAnyMatcher(any *anyMatcher) (interface{}, bool) { +func (p *parser) parseAnyMatcher(any *anyMatcher) (any, bool) { // ==template== {{ if not .Optimize }} if p.debug { defer p.out(p.in("parseAnyMatcher")) @@ -1070,8 +1071,8 @@ func (p *parser) parseAnyMatcher(any *anyMatcher) (interface{}, bool) { return p.sliceFrom(start), true } -//{{ if .Nolint }} nolint: gocyclo {{else}} ==template== {{ end }} -func (p *parser) parseCharClassMatcher(chr *charClassMatcher) (interface{}, bool) { +// {{ if .Nolint }} nolint: gocyclo {{else}} ==template== {{ end }} +func (p *parser) parseCharClassMatcher(chr *charClassMatcher) (any, bool) { // ==template== {{ if not .Optimize }} if p.debug { defer p.out(p.in("parseCharClassMatcher")) @@ -1170,7 +1171,7 @@ func (p *parser) incChoiceAltCnt(ch *choiceExpr, altI int) { // {{ end }} ==template== -func (p *parser) parseChoiceExpr(ch *choiceExpr) (interface{}, bool) { +func (p *parser) parseChoiceExpr(ch *choiceExpr) (any, bool) { // ==template== {{ if not .Optimize }} if p.debug { defer p.out(p.in("parseChoiceExpr")) @@ -1204,7 +1205,7 @@ func (p *parser) parseChoiceExpr(ch *choiceExpr) (interface{}, bool) { return nil, false } -func (p *parser) parseLabeledExpr(lab *labeledExpr) (interface{}, bool) { +func (p *parser) parseLabeledExpr(lab *labeledExpr) (any, bool) { // ==template== {{ if not .Optimize }} if p.debug { defer p.out(p.in("parseLabeledExpr")) @@ -1221,7 +1222,7 @@ func (p *parser) parseLabeledExpr(lab *labeledExpr) (interface{}, bool) { return val, ok } -func (p *parser) parseLitMatcher(lit *litMatcher) (interface{}, bool) { +func (p *parser) parseLitMatcher(lit *litMatcher) (any, bool) { // ==template== {{ if not .Optimize }} if p.debug { defer p.out(p.in("parseLitMatcher")) @@ -1245,7 +1246,7 @@ func (p *parser) parseLitMatcher(lit *litMatcher) (interface{}, bool) { return p.sliceFrom(start), true } -func (p *parser) parseNotCodeExpr(not *notCodeExpr) (interface{}, bool) { +func (p *parser) parseNotCodeExpr(not *notCodeExpr) (any, bool) { // ==template== {{ if not .Optimize }} if p.debug { defer p.out(p.in("parseNotCodeExpr")) @@ -1267,7 +1268,7 @@ func (p *parser) parseNotCodeExpr(not *notCodeExpr) (interface{}, bool) { return nil, !ok } -func (p *parser) parseNotExpr(not *notExpr) (interface{}, bool) { +func (p *parser) parseNotExpr(not *notExpr) (any, bool) { // ==template== {{ if not .Optimize }} if p.debug { defer p.out(p.in("parseNotExpr")) @@ -1291,14 +1292,14 @@ func (p *parser) parseNotExpr(not *notExpr) (interface{}, bool) { return nil, !ok } -func (p *parser) parseOneOrMoreExpr(expr *oneOrMoreExpr) (interface{}, bool) { +func (p *parser) parseOneOrMoreExpr(expr *oneOrMoreExpr) (any, bool) { // ==template== {{ if not .Optimize }} if p.debug { defer p.out(p.in("parseOneOrMoreExpr")) } // {{ end }} ==template== - var vals []interface{} + var vals []any for { p.pushV() @@ -1315,7 +1316,7 @@ func (p *parser) parseOneOrMoreExpr(expr *oneOrMoreExpr) (interface{}, bool) { } } -func (p *parser) parseRecoveryExpr(recover *recoveryExpr) (interface{}, bool) { +func (p *parser) parseRecoveryExpr(recover *recoveryExpr) (any, bool) { // ==template== {{ if not .Optimize }} if p.debug { defer p.out(p.in("parseRecoveryExpr (" + strings.Join(recover.failureLabel, ",") + ")")) @@ -1330,7 +1331,7 @@ func (p *parser) parseRecoveryExpr(recover *recoveryExpr) (interface{}, bool) { return val, ok } -func (p *parser) parseRuleRefExpr(ref *ruleRefExpr) (interface{}, bool) { +func (p *parser) parseRuleRefExpr(ref *ruleRefExpr) (any, bool) { // ==template== {{ if not .Optimize }} if p.debug { defer p.out(p.in("parseRuleRefExpr " + ref.name)) @@ -1349,14 +1350,14 @@ func (p *parser) parseRuleRefExpr(ref *ruleRefExpr) (interface{}, bool) { return p.parseRule(rule) } -func (p *parser) parseSeqExpr(seq *seqExpr) (interface{}, bool) { +func (p *parser) parseSeqExpr(seq *seqExpr) (any, bool) { // ==template== {{ if not .Optimize }} if p.debug { defer p.out(p.in("parseSeqExpr")) } // {{ end }} ==template== - vals := make([]interface{}, 0, len(seq.exprs)) + vals := make([]any, 0, len(seq.exprs)) pt := p.pt // ==template== {{ if or .GlobalState (not .Optimize) }} @@ -1378,7 +1379,7 @@ func (p *parser) parseSeqExpr(seq *seqExpr) (interface{}, bool) { // ==template== {{ if or .GlobalState (not .Optimize) }} -func (p *parser) parseStateCodeExpr(state *stateCodeExpr) (interface{}, bool) { +func (p *parser) parseStateCodeExpr(state *stateCodeExpr) (any, bool) { // ==template== {{ if not .Optimize }} if p.debug { defer p.out(p.in("parseStateCodeExpr")) @@ -1394,7 +1395,7 @@ func (p *parser) parseStateCodeExpr(state *stateCodeExpr) (interface{}, bool) { // {{ end }} ==template== -func (p *parser) parseThrowExpr(expr *throwExpr) (interface{}, bool) { +func (p *parser) parseThrowExpr(expr *throwExpr) (any, bool) { // ==template== {{ if not .Optimize }} if p.debug { defer p.out(p.in("parseThrowExpr")) @@ -1413,14 +1414,14 @@ func (p *parser) parseThrowExpr(expr *throwExpr) (interface{}, bool) { return nil, false } -func (p *parser) parseZeroOrMoreExpr(expr *zeroOrMoreExpr) (interface{}, bool) { +func (p *parser) parseZeroOrMoreExpr(expr *zeroOrMoreExpr) (any, bool) { // ==template== {{ if not .Optimize }} if p.debug { defer p.out(p.in("parseZeroOrMoreExpr")) } // {{ end }} ==template== - var vals []interface{} + var vals []any for { p.pushV() @@ -1433,7 +1434,7 @@ func (p *parser) parseZeroOrMoreExpr(expr *zeroOrMoreExpr) (interface{}, bool) { } } -func (p *parser) parseZeroOrOneExpr(expr *zeroOrOneExpr) (interface{}, bool) { +func (p *parser) parseZeroOrOneExpr(expr *zeroOrOneExpr) (any, bool) { // ==template== {{ if not .Optimize }} if p.debug { defer p.out(p.in("parseZeroOrOneExpr")) diff --git a/builder/static_code.go b/builder/static_code.go index 679df0e2..3628ae12 100644 --- a/builder/static_code.go +++ b/builder/static_code.go @@ -1,5 +1,6 @@ //go:generate go run ../bootstrap/cmd/static_code_generator/main.go -- $GOFILE generated_$GOFILE staticCode +//go:build static_code // +build static_code package builder @@ -79,18 +80,17 @@ func Entrypoint(ruleName string) Option { // // 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)) -// +// 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 @@ -162,7 +162,7 @@ func Recover(b bool) Option { // GlobalStore creates an Option to set a key to a certain value in // the globalStore. -func GlobalStore(key string, value interface{}) Option { +func GlobalStore(key string, value any) Option { return func(p *parser) Option { old := p.cur.globalStore[key] p.cur.globalStore[key] = value @@ -174,7 +174,7 @@ func GlobalStore(key string, value interface{}) Option { // InitState creates an Option to set a key to a certain value in // the global "state" store. -func InitState(key string, value interface{}) Option { +func InitState(key string, value any) Option { return func(p *parser) Option { old := p.cur.state[key] p.cur.state[key] = value @@ -185,7 +185,7 @@ func InitState(key string, value interface{}) Option { // {{ end }} ==template== // ParseFile parses the file identified by filename. -func ParseFile(filename string, opts ...Option) (i interface{}, err error) { //{{ if .Nolint }} nolint: deadcode {{else}} ==template== {{ end }} +func ParseFile(filename string, opts ...Option) (i any, err error) { //{{ if .Nolint }} nolint: deadcode {{else}} ==template== {{ end }} f, err := os.Open(filename) if err != nil { return nil, err @@ -200,7 +200,7 @@ func ParseFile(filename string, opts ...Option) (i interface{}, err error) { //{ // ParseReader parses the data from r using filename as information in the // error messages. -func ParseReader(filename string, r io.Reader, opts ...Option) (interface{}, error) { //{{ if .Nolint }} nolint: deadcode {{else}} ==template== {{ end }} +func ParseReader(filename string, r io.Reader, opts ...Option) (any, error) { //{{ if .Nolint }} nolint: deadcode {{else}} ==template== {{ end }} b, err := io.ReadAll(r) if err != nil { return nil, err @@ -211,7 +211,7 @@ func ParseReader(filename string, r io.Reader, opts ...Option) (interface{}, err // Parse parses the data from b using filename as information in the // error messages. -func Parse(filename string, b []byte, opts ...Option) (interface{}, error) { +func Parse(filename string, b []byte, opts ...Option) (any, error) { return newParser(filename, b, opts...).parse(g) } @@ -253,77 +253,79 @@ type current struct { globalStore storeDict } -type storeDict map[string]interface{} +type storeDict map[string]any // the AST types... -//{{ if .Nolint }} nolint: structcheck {{else}} ==template== {{ end }} +// {{ if .Nolint }} nolint: structcheck {{else}} ==template== {{ end }} type grammar struct { pos position rules []*rule } -//{{ if .Nolint }} nolint: structcheck {{else}} ==template== {{ end }} +// {{ if .Nolint }} nolint: structcheck {{else}} ==template== {{ end }} type rule struct { pos position name string displayName string - expr interface{} + expr any } -//{{ if .Nolint }} nolint: structcheck {{else}} ==template== {{ end }} +// {{ if .Nolint }} nolint: structcheck {{else}} ==template== {{ end }} type choiceExpr struct { pos position - alternatives []interface{} + alternatives []any } -//{{ if .Nolint }} nolint: structcheck {{else}} ==template== {{ end }} +// {{ if .Nolint }} nolint: structcheck {{else}} ==template== {{ end }} type actionExpr struct { pos position - expr interface{} - run func(*parser) (interface{}, error) + expr any + run func(*parser) (any, error) } -//{{ if .Nolint }} nolint: structcheck {{else}} ==template== {{ end }} +// {{ if .Nolint }} nolint: structcheck {{else}} ==template== {{ end }} type recoveryExpr struct { pos position - expr interface{} - recoverExpr interface{} + expr any + recoverExpr any failureLabel []string } -//{{ if .Nolint }} nolint: structcheck {{else}} ==template== {{ end }} +// {{ if .Nolint }} nolint: structcheck {{else}} ==template== {{ end }} type seqExpr struct { pos position - exprs []interface{} + exprs []any } -//{{ if .Nolint }} nolint: structcheck {{else}} ==template== {{ end }} +// {{ if .Nolint }} nolint: structcheck {{else}} ==template== {{ end }} type throwExpr struct { pos position label string } -//{{ if .Nolint }} nolint: structcheck {{else}} ==template== {{ end }} +// {{ if .Nolint }} nolint: structcheck {{else}} ==template== {{ end }} type labeledExpr struct { pos position label string - expr interface{} + expr any } -//{{ if .Nolint }} nolint: structcheck {{else}} ==template== {{ end }} +// {{ if .Nolint }} nolint: structcheck {{else}} ==template== {{ end }} type expr struct { pos position - expr interface{} + expr any } -type andExpr expr //{{ if .Nolint }} nolint: structcheck {{else}} ==template== {{ end }} -type notExpr expr //{{ if .Nolint }} nolint: structcheck {{else}} ==template== {{ end }} -type zeroOrOneExpr expr //{{ if .Nolint }} nolint: structcheck {{else}} ==template== {{ end }} -type zeroOrMoreExpr expr //{{ if .Nolint }} nolint: structcheck {{else}} ==template== {{ end }} -type oneOrMoreExpr expr //{{ if .Nolint }} nolint: structcheck {{else}} ==template== {{ end }} +type ( + andExpr expr //{{ if .Nolint }} nolint: structcheck {{else}} ==template== {{ end }} + notExpr expr //{{ if .Nolint }} nolint: structcheck {{else}} ==template== {{ end }} + zeroOrOneExpr expr //{{ if .Nolint }} nolint: structcheck {{else}} ==template== {{ end }} + zeroOrMoreExpr expr //{{ if .Nolint }} nolint: structcheck {{else}} ==template== {{ end }} + oneOrMoreExpr expr //{{ if .Nolint }} nolint: structcheck {{else}} ==template== {{ end }} +) -//{{ if .Nolint }} nolint: structcheck {{else}} ==template== {{ end }} +// {{ if .Nolint }} nolint: structcheck {{else}} ==template== {{ end }} type ruleRefExpr struct { pos position name string @@ -331,7 +333,7 @@ type ruleRefExpr struct { // ==template== {{ if or .GlobalState (not .Optimize) }} -//{{ if .Nolint }} nolint: structcheck {{else}} ==template== {{ end }} +// {{ if .Nolint }} nolint: structcheck {{else}} ==template== {{ end }} type stateCodeExpr struct { pos position run func(*parser) error @@ -339,19 +341,19 @@ type stateCodeExpr struct { // {{ end }} ==template== -//{{ if .Nolint }} nolint: structcheck {{else}} ==template== {{ end }} +// {{ if .Nolint }} nolint: structcheck {{else}} ==template== {{ end }} type andCodeExpr struct { pos position run func(*parser) (bool, error) } -//{{ if .Nolint }} nolint: structcheck {{else}} ==template== {{ end }} +// {{ if .Nolint }} nolint: structcheck {{else}} ==template== {{ end }} type notCodeExpr struct { pos position run func(*parser) (bool, error) } -//{{ if .Nolint }} nolint: structcheck {{else}} ==template== {{ end }} +// {{ if .Nolint }} nolint: structcheck {{else}} ==template== {{ end }} type litMatcher struct { pos position val string @@ -359,7 +361,7 @@ type litMatcher struct { want string } -//{{ if .Nolint }} nolint: structcheck {{else}} ==template== {{ end }} +// {{ if .Nolint }} nolint: structcheck {{else}} ==template== {{ end }} type charClassMatcher struct { pos position val string @@ -473,14 +475,14 @@ func (p *parser) setOptions(opts []Option) { } } -//{{ if .Nolint }} nolint: structcheck,deadcode {{else}} ==template== {{ end }} +// {{ if .Nolint }} nolint: structcheck,deadcode {{else}} ==template== {{ end }} type resultTuple struct { - v interface{} + v any b bool end savepoint } -//{{ if .Nolint }} nolint: varcheck {{else}} ==template== {{ end }} +// {{ if .Nolint }} nolint: varcheck {{else}} ==template== {{ end }} const choiceNoMatch = -1 // Stats stores some statistics, gathered during parsing @@ -505,7 +507,7 @@ type Stats struct { ChoiceAltCnt map[string]map[string]int } -//{{ if .Nolint }} nolint: structcheck,maligned {{else}} ==template== {{ end }} +// {{ if .Nolint }} nolint: structcheck,maligned {{else}} ==template== {{ end }} type parser struct { filename string pt savepoint @@ -522,13 +524,13 @@ type parser struct { memoize bool // memoization table for the packrat algorithm: // map[offset in source] map[expression or rule] {value, match} - memo map[int]map[interface{}]resultTuple + memo map[int]map[any]resultTuple // {{ end }} ==template== // rules table, maps the rule identifier to the rule node rules map[string]*rule // variables stack, map of label to value - vstack []map[string]interface{} + vstack []map[string]any // rule stack, allows identification of the current rule in errors rstack []*rule @@ -548,7 +550,7 @@ type parser struct { choiceNoMatch string // recovery expression stack, keeps track of the currently available recovery expression, these are traversed in reverse - recoveryStack []map[string]interface{} + recoveryStack []map[string]any } // push a variable set on the vstack. @@ -568,7 +570,7 @@ func (p *parser) pushV() { return } - m = make(map[string]interface{}) + m = make(map[string]any) p.vstack[len(p.vstack)-1] = m } @@ -584,7 +586,7 @@ func (p *parser) popV() { } // push a recovery expression with its labels to the recoveryStack -func (p *parser) pushRecovery(labels []string, expr interface{}) { +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) @@ -593,7 +595,7 @@ func (p *parser) pushRecovery(labels []string, expr interface{}) { p.recoveryStack = p.recoveryStack[:len(p.recoveryStack)+1] } - m := make(map[string]interface{}, len(labels)) + m := make(map[string]any, len(labels)) for _, fl := range labels { m[fl] = expr } @@ -720,11 +722,11 @@ func (p *parser) restore(pt savepoint) { // copies of the state to allow the parser to properly restore the state in // the case of backtracking. type Cloner interface { - Clone() interface{} + Clone() any } var statePool = &sync.Pool{ - New: func() interface{} { return make(storeDict) }, + New: func() any { return make(storeDict) }, } func (sd storeDict) Discard() { @@ -773,7 +775,7 @@ func (p *parser) sliceFrom(start savepoint) []byte { } // ==template== {{ if not .Optimize }} -func (p *parser) getMemoized(node interface{}) (resultTuple, bool) { +func (p *parser) getMemoized(node any) (resultTuple, bool) { if len(p.memo) == 0 { return resultTuple{}, false } @@ -785,13 +787,13 @@ func (p *parser) getMemoized(node interface{}) (resultTuple, bool) { return res, ok } -func (p *parser) setMemoized(pt savepoint, node interface{}, tuple resultTuple) { +func (p *parser) setMemoized(pt savepoint, node any, tuple resultTuple) { if p.memo == nil { - p.memo = make(map[int]map[interface{}]resultTuple) + p.memo = make(map[int]map[any]resultTuple) } m := p.memo[pt.offset] if m == nil { - m = make(map[interface{}]resultTuple) + m = make(map[any]resultTuple) p.memo[pt.offset] = m } m[node] = tuple @@ -806,8 +808,8 @@ func (p *parser) buildRulesTable(g *grammar) { } } -//{{ if .Nolint }} nolint: gocyclo {{else}} ==template== {{ end }} -func (p *parser) parse(g *grammar) (val interface{}, err error) { +// {{ if .Nolint }} nolint: gocyclo {{else}} ==template== {{ end }} +func (p *parser) parse(g *grammar) (val any, err error) { if len(g.rules) == 0 { p.addErr(errNoRule) return nil, p.errs.err() @@ -886,7 +888,7 @@ func listJoin(list []string, sep string, lastSep string) string { } } -func (p *parser) parseRule(rule *rule) (interface{}, bool) { +func (p *parser) parseRule(rule *rule) (any, bool) { // ==template== {{ if not .Optimize }} if p.debug { defer p.out(p.in("parseRule " + rule.name)) @@ -919,8 +921,8 @@ func (p *parser) parseRule(rule *rule) (interface{}, bool) { return val, ok } -//{{ if .Nolint }} nolint: gocyclo {{else}} ==template== {{ end }} -func (p *parser) parseExpr(expr interface{}) (interface{}, bool) { +// {{ if .Nolint }} nolint: gocyclo {{else}} ==template== {{ end }} +func (p *parser) parseExpr(expr any) (any, bool) { // ==template== {{ if not .Optimize }} var pt savepoint @@ -940,7 +942,7 @@ func (p *parser) parseExpr(expr interface{}) (interface{}, bool) { panic(errMaxExprCnt) } - var val interface{} + var val any var ok bool switch expr := expr.(type) { case *actionExpr: @@ -992,7 +994,7 @@ func (p *parser) parseExpr(expr interface{}) (interface{}, bool) { return val, ok } -func (p *parser) parseActionExpr(act *actionExpr) (interface{}, bool) { +func (p *parser) parseActionExpr(act *actionExpr) (any, bool) { // ==template== {{ if not .Optimize }} if p.debug { defer p.out(p.in("parseActionExpr")) @@ -1025,7 +1027,7 @@ func (p *parser) parseActionExpr(act *actionExpr) (interface{}, bool) { return val, ok } -func (p *parser) parseAndCodeExpr(and *andCodeExpr) (interface{}, bool) { +func (p *parser) parseAndCodeExpr(and *andCodeExpr) (any, bool) { // ==template== {{ if not .Optimize }} if p.debug { defer p.out(p.in("parseAndCodeExpr")) @@ -1047,7 +1049,7 @@ func (p *parser) parseAndCodeExpr(and *andCodeExpr) (interface{}, bool) { return nil, ok } -func (p *parser) parseAndExpr(and *andExpr) (interface{}, bool) { +func (p *parser) parseAndExpr(and *andExpr) (any, bool) { // ==template== {{ if not .Optimize }} if p.debug { defer p.out(p.in("parseAndExpr")) @@ -1069,7 +1071,7 @@ func (p *parser) parseAndExpr(and *andExpr) (interface{}, bool) { return nil, ok } -func (p *parser) parseAnyMatcher(any *anyMatcher) (interface{}, bool) { +func (p *parser) parseAnyMatcher(any *anyMatcher) (any, bool) { // ==template== {{ if not .Optimize }} if p.debug { defer p.out(p.in("parseAnyMatcher")) @@ -1087,8 +1089,8 @@ func (p *parser) parseAnyMatcher(any *anyMatcher) (interface{}, bool) { return p.sliceFrom(start), true } -//{{ if .Nolint }} nolint: gocyclo {{else}} ==template== {{ end }} -func (p *parser) parseCharClassMatcher(chr *charClassMatcher) (interface{}, bool) { +// {{ if .Nolint }} nolint: gocyclo {{else}} ==template== {{ end }} +func (p *parser) parseCharClassMatcher(chr *charClassMatcher) (any, bool) { // ==template== {{ if not .Optimize }} if p.debug { defer p.out(p.in("parseCharClassMatcher")) @@ -1187,7 +1189,7 @@ func (p *parser) incChoiceAltCnt(ch *choiceExpr, altI int) { // {{ end }} ==template== -func (p *parser) parseChoiceExpr(ch *choiceExpr) (interface{}, bool) { +func (p *parser) parseChoiceExpr(ch *choiceExpr) (any, bool) { // ==template== {{ if not .Optimize }} if p.debug { defer p.out(p.in("parseChoiceExpr")) @@ -1221,7 +1223,7 @@ func (p *parser) parseChoiceExpr(ch *choiceExpr) (interface{}, bool) { return nil, false } -func (p *parser) parseLabeledExpr(lab *labeledExpr) (interface{}, bool) { +func (p *parser) parseLabeledExpr(lab *labeledExpr) (any, bool) { // ==template== {{ if not .Optimize }} if p.debug { defer p.out(p.in("parseLabeledExpr")) @@ -1238,7 +1240,7 @@ func (p *parser) parseLabeledExpr(lab *labeledExpr) (interface{}, bool) { return val, ok } -func (p *parser) parseLitMatcher(lit *litMatcher) (interface{}, bool) { +func (p *parser) parseLitMatcher(lit *litMatcher) (any, bool) { // ==template== {{ if not .Optimize }} if p.debug { defer p.out(p.in("parseLitMatcher")) @@ -1262,7 +1264,7 @@ func (p *parser) parseLitMatcher(lit *litMatcher) (interface{}, bool) { return p.sliceFrom(start), true } -func (p *parser) parseNotCodeExpr(not *notCodeExpr) (interface{}, bool) { +func (p *parser) parseNotCodeExpr(not *notCodeExpr) (any, bool) { // ==template== {{ if not .Optimize }} if p.debug { defer p.out(p.in("parseNotCodeExpr")) @@ -1284,7 +1286,7 @@ func (p *parser) parseNotCodeExpr(not *notCodeExpr) (interface{}, bool) { return nil, !ok } -func (p *parser) parseNotExpr(not *notExpr) (interface{}, bool) { +func (p *parser) parseNotExpr(not *notExpr) (any, bool) { // ==template== {{ if not .Optimize }} if p.debug { defer p.out(p.in("parseNotExpr")) @@ -1308,14 +1310,14 @@ func (p *parser) parseNotExpr(not *notExpr) (interface{}, bool) { return nil, !ok } -func (p *parser) parseOneOrMoreExpr(expr *oneOrMoreExpr) (interface{}, bool) { +func (p *parser) parseOneOrMoreExpr(expr *oneOrMoreExpr) (any, bool) { // ==template== {{ if not .Optimize }} if p.debug { defer p.out(p.in("parseOneOrMoreExpr")) } // {{ end }} ==template== - var vals []interface{} + var vals []any for { p.pushV() @@ -1332,7 +1334,7 @@ func (p *parser) parseOneOrMoreExpr(expr *oneOrMoreExpr) (interface{}, bool) { } } -func (p *parser) parseRecoveryExpr(recover *recoveryExpr) (interface{}, bool) { +func (p *parser) parseRecoveryExpr(recover *recoveryExpr) (any, bool) { // ==template== {{ if not .Optimize }} if p.debug { defer p.out(p.in("parseRecoveryExpr (" + strings.Join(recover.failureLabel, ",") + ")")) @@ -1347,7 +1349,7 @@ func (p *parser) parseRecoveryExpr(recover *recoveryExpr) (interface{}, bool) { return val, ok } -func (p *parser) parseRuleRefExpr(ref *ruleRefExpr) (interface{}, bool) { +func (p *parser) parseRuleRefExpr(ref *ruleRefExpr) (any, bool) { // ==template== {{ if not .Optimize }} if p.debug { defer p.out(p.in("parseRuleRefExpr " + ref.name)) @@ -1366,14 +1368,14 @@ func (p *parser) parseRuleRefExpr(ref *ruleRefExpr) (interface{}, bool) { return p.parseRule(rule) } -func (p *parser) parseSeqExpr(seq *seqExpr) (interface{}, bool) { +func (p *parser) parseSeqExpr(seq *seqExpr) (any, bool) { // ==template== {{ if not .Optimize }} if p.debug { defer p.out(p.in("parseSeqExpr")) } // {{ end }} ==template== - vals := make([]interface{}, 0, len(seq.exprs)) + vals := make([]any, 0, len(seq.exprs)) pt := p.pt // ==template== {{ if or .GlobalState (not .Optimize) }} @@ -1395,7 +1397,7 @@ func (p *parser) parseSeqExpr(seq *seqExpr) (interface{}, bool) { // ==template== {{ if or .GlobalState (not .Optimize) }} -func (p *parser) parseStateCodeExpr(state *stateCodeExpr) (interface{}, bool) { +func (p *parser) parseStateCodeExpr(state *stateCodeExpr) (any, bool) { // ==template== {{ if not .Optimize }} if p.debug { defer p.out(p.in("parseStateCodeExpr")) @@ -1411,7 +1413,7 @@ func (p *parser) parseStateCodeExpr(state *stateCodeExpr) (interface{}, bool) { // {{ end }} ==template== -func (p *parser) parseThrowExpr(expr *throwExpr) (interface{}, bool) { +func (p *parser) parseThrowExpr(expr *throwExpr) (any, bool) { // ==template== {{ if not .Optimize }} if p.debug { defer p.out(p.in("parseThrowExpr")) @@ -1430,14 +1432,14 @@ func (p *parser) parseThrowExpr(expr *throwExpr) (interface{}, bool) { return nil, false } -func (p *parser) parseZeroOrMoreExpr(expr *zeroOrMoreExpr) (interface{}, bool) { +func (p *parser) parseZeroOrMoreExpr(expr *zeroOrMoreExpr) (any, bool) { // ==template== {{ if not .Optimize }} if p.debug { defer p.out(p.in("parseZeroOrMoreExpr")) } // {{ end }} ==template== - var vals []interface{} + var vals []any for { p.pushV() @@ -1450,7 +1452,7 @@ func (p *parser) parseZeroOrMoreExpr(expr *zeroOrMoreExpr) (interface{}, bool) { } } -func (p *parser) parseZeroOrOneExpr(expr *zeroOrOneExpr) (interface{}, bool) { +func (p *parser) parseZeroOrOneExpr(expr *zeroOrOneExpr) (any, bool) { // ==template== {{ if not .Optimize }} if p.debug { defer p.out(p.in("parseZeroOrOneExpr")) diff --git a/doc.go b/doc.go index 0b94889f..bfa9acb8 100644 --- a/doc.go +++ b/doc.go @@ -179,12 +179,12 @@ For predicates (& and !), the value is always nil. E.g.: For a sequence, the value is a slice of empty interfaces, one for each expression value in the sequence. The underlying types of each value in the slice follow the same rules described here, recursively. E.g.: - Rule = label:('a' 'b') { // label is []interface{} } + Rule = label:('a' 'b') { // label is []any } For a repetition (+ and *), the value is a slice of empty interfaces, one for each repetition. The underlying types of each value in the slice follow the same rules described here, recursively. E.g.: - Rule = label:[a-z]+ { // label is []interface{} } + Rule = label:[a-z]+ { // label is []any } For a choice expression, the value is that of the matching choice. E.g.: Rule = label:('a' / 'b') { // label is []byte } @@ -293,8 +293,8 @@ clause). E.g.: Action code blocks are code blocks declared after an expression in a rule. Those code blocks are turned into a method on the "*current" type in the generated source code. The method receives any labeled expression's value -as argument (as interface{}) and must return two values, the first being -the value of the expression (an interface{}), and the second an error. +as argument (as any) and must return two values, the first being +the value of the expression (an any), and the second an error. If a non-nil error is returned, it is added to the list of errors that the parser will return. E.g.: RuleA = "A"+ { @@ -306,7 +306,7 @@ parser will return. E.g.: Predicate code blocks are code blocks declared immediately after the and "&" or the not "!" operators. Like action code blocks, predicate code blocks are turned into a method on the "*current" type in the generated source code. -The method receives any labeled expression's value as argument (as interface{}) +The method receives any labeled expression's value as argument (as any) and must return two opt, the first being a bool and the second an error. If a non-nil error is returned, it is added to the list of errors that the parser will return. E.g.: @@ -320,7 +320,7 @@ modify values in the global "state" store (see below). State change code blocks are turned into a method on the "*current" type in the generated source code. The method is passed any labeled expression's value as an argument (of type -interface{}) and must return a value of type error. +any) and must return a value of type error. If a non-nil error is returned, it is added to the list of errors that the parser will return, note that the parser does NOT backtrack if a non-nil error is returned. @@ -345,7 +345,7 @@ The "text" field is the slice of bytes of the current match. It is empty in a predicate code block. The "state" field is a global store, with backtrack support, of type -"map[string]interface{}". The values in the store are tied to the parser's +"map[string]any". The values in the store are tied to the parser's backtracking, in particular if a rule fails to match then all updates to the state that occurred in the process of matching the rule are rolled back. For a key-value store that is not tied to the parser's backtracking, see the @@ -369,7 +369,7 @@ IMPORTANT: copy functionality may be used in the "Clone" method (e.g. https://github.com/mitchellh/copystructure). -The "globalStore" field is a global store of type "map[string]interface{}", +The "globalStore" field is a global store of type "map[string]any", which allows to store arbitrary values, which are available in action and predicate code blocks for read as well as write access. It is important to notice, that the global store is completely independent from @@ -430,13 +430,13 @@ Using the generated parser The parser generated by pigeon exports a few symbols so that it can be used as a package with public functions to parse input text. The exported API is: - - Parse(string, []byte, ...Option) (interface{}, error) - - ParseFile(string, ...Option) (interface{}, error) - - ParseReader(string, io.Reader, ...Option) (interface{}, error) + - Parse(string, []byte, ...Option) (any, error) + - ParseFile(string, ...Option) (any, error) + - ParseReader(string, io.Reader, ...Option) (any, error) - AllowInvalidUTF8(bool) Option - Debug(bool) Option - Entrypoint(string) Option - - GlobalStore(string, interface{}) Option + - GlobalStore(string, any) Option - MaxExpressions(uint64) Option - Memoize(bool) Option - Recover(bool) Option diff --git a/examples/calculator/calculator.go b/examples/calculator/calculator.go index be556a4b..4f4000a9 100644 --- a/examples/calculator/calculator.go +++ b/examples/calculator/calculator.go @@ -54,18 +54,18 @@ func main() { fmt.Println("=", got) } -func toIfaceSlice(v interface{}) []interface{} { +func toAnySlice(v any) []any { if v == nil { return nil } - return v.([]interface{}) + return v.([]any) } -func eval(first, rest interface{}) int { +func eval(first, rest any) int { l := first.(int) - restSl := toIfaceSlice(rest) + restSl := toAnySlice(rest) for _, v := range restSl { - restExpr := toIfaceSlice(v) + restExpr := toAnySlice(v) r := restExpr[3].(int) op := restExpr[1].(string) l = ops[op](l, r) @@ -77,23 +77,23 @@ var g = &grammar{ rules: []*rule{ { name: "Input", - pos: position{line: 61, col: 1, offset: 1247}, + pos: position{line: 61, col: 1, offset: 1209}, expr: &actionExpr{ - pos: position{line: 61, col: 10, offset: 1256}, + pos: position{line: 61, col: 10, offset: 1218}, run: (*parser).callonInput1, expr: &seqExpr{ - pos: position{line: 61, col: 10, offset: 1256}, - exprs: []interface{}{ + pos: position{line: 61, col: 10, offset: 1218}, + exprs: []any{ &labeledExpr{ - pos: position{line: 61, col: 10, offset: 1256}, + pos: position{line: 61, col: 10, offset: 1218}, label: "expr", expr: &ruleRefExpr{ - pos: position{line: 61, col: 15, offset: 1261}, + pos: position{line: 61, col: 15, offset: 1223}, name: "Expr", }, }, &ruleRefExpr{ - pos: position{line: 61, col: 20, offset: 1266}, + pos: position{line: 61, col: 20, offset: 1228}, name: "EOF", }, }, @@ -102,47 +102,47 @@ var g = &grammar{ }, { name: "Expr", - pos: position{line: 66, col: 1, offset: 1316}, + pos: position{line: 66, col: 1, offset: 1278}, expr: &actionExpr{ - pos: position{line: 66, col: 9, offset: 1324}, + pos: position{line: 66, col: 9, offset: 1286}, run: (*parser).callonExpr1, expr: &seqExpr{ - pos: position{line: 66, col: 9, offset: 1324}, - exprs: []interface{}{ + pos: position{line: 66, col: 9, offset: 1286}, + exprs: []any{ &ruleRefExpr{ - pos: position{line: 66, col: 9, offset: 1324}, + pos: position{line: 66, col: 9, offset: 1286}, name: "_", }, &labeledExpr{ - pos: position{line: 66, col: 11, offset: 1326}, + pos: position{line: 66, col: 11, offset: 1288}, label: "first", expr: &ruleRefExpr{ - pos: position{line: 66, col: 17, offset: 1332}, + pos: position{line: 66, col: 17, offset: 1294}, name: "Term", }, }, &labeledExpr{ - pos: position{line: 66, col: 22, offset: 1337}, + pos: position{line: 66, col: 22, offset: 1299}, label: "rest", expr: &zeroOrMoreExpr{ - pos: position{line: 66, col: 27, offset: 1342}, + pos: position{line: 66, col: 27, offset: 1304}, expr: &seqExpr{ - pos: position{line: 66, col: 29, offset: 1344}, - exprs: []interface{}{ + pos: position{line: 66, col: 29, offset: 1306}, + exprs: []any{ &ruleRefExpr{ - pos: position{line: 66, col: 29, offset: 1344}, + pos: position{line: 66, col: 29, offset: 1306}, name: "_", }, &ruleRefExpr{ - pos: position{line: 66, col: 31, offset: 1346}, + pos: position{line: 66, col: 31, offset: 1308}, name: "AddOp", }, &ruleRefExpr{ - pos: position{line: 66, col: 37, offset: 1352}, + pos: position{line: 66, col: 37, offset: 1314}, name: "_", }, &ruleRefExpr{ - pos: position{line: 66, col: 39, offset: 1354}, + pos: position{line: 66, col: 39, offset: 1316}, name: "Term", }, }, @@ -150,7 +150,7 @@ var g = &grammar{ }, }, &ruleRefExpr{ - pos: position{line: 66, col: 47, offset: 1362}, + pos: position{line: 66, col: 47, offset: 1324}, name: "_", }, }, @@ -159,43 +159,43 @@ var g = &grammar{ }, { name: "Term", - pos: position{line: 71, col: 1, offset: 1423}, + pos: position{line: 71, col: 1, offset: 1385}, expr: &actionExpr{ - pos: position{line: 71, col: 9, offset: 1431}, + pos: position{line: 71, col: 9, offset: 1393}, run: (*parser).callonTerm1, expr: &seqExpr{ - pos: position{line: 71, col: 9, offset: 1431}, - exprs: []interface{}{ + pos: position{line: 71, col: 9, offset: 1393}, + exprs: []any{ &labeledExpr{ - pos: position{line: 71, col: 9, offset: 1431}, + pos: position{line: 71, col: 9, offset: 1393}, label: "first", expr: &ruleRefExpr{ - pos: position{line: 71, col: 15, offset: 1437}, + pos: position{line: 71, col: 15, offset: 1399}, name: "Factor", }, }, &labeledExpr{ - pos: position{line: 71, col: 22, offset: 1444}, + pos: position{line: 71, col: 22, offset: 1406}, label: "rest", expr: &zeroOrMoreExpr{ - pos: position{line: 71, col: 27, offset: 1449}, + pos: position{line: 71, col: 27, offset: 1411}, expr: &seqExpr{ - pos: position{line: 71, col: 29, offset: 1451}, - exprs: []interface{}{ + pos: position{line: 71, col: 29, offset: 1413}, + exprs: []any{ &ruleRefExpr{ - pos: position{line: 71, col: 29, offset: 1451}, + pos: position{line: 71, col: 29, offset: 1413}, name: "_", }, &ruleRefExpr{ - pos: position{line: 71, col: 31, offset: 1453}, + pos: position{line: 71, col: 31, offset: 1415}, name: "MulOp", }, &ruleRefExpr{ - pos: position{line: 71, col: 37, offset: 1459}, + pos: position{line: 71, col: 37, offset: 1421}, name: "_", }, &ruleRefExpr{ - pos: position{line: 71, col: 39, offset: 1461}, + pos: position{line: 71, col: 39, offset: 1423}, name: "Factor", }, }, @@ -208,32 +208,32 @@ var g = &grammar{ }, { name: "Factor", - pos: position{line: 76, col: 1, offset: 1530}, + pos: position{line: 76, col: 1, offset: 1492}, expr: &choiceExpr{ - pos: position{line: 76, col: 11, offset: 1540}, - alternatives: []interface{}{ + pos: position{line: 76, col: 11, offset: 1502}, + alternatives: []any{ &actionExpr{ - pos: position{line: 76, col: 11, offset: 1540}, + pos: position{line: 76, col: 11, offset: 1502}, run: (*parser).callonFactor2, expr: &seqExpr{ - pos: position{line: 76, col: 11, offset: 1540}, - exprs: []interface{}{ + pos: position{line: 76, col: 11, offset: 1502}, + exprs: []any{ &litMatcher{ - pos: position{line: 76, col: 11, offset: 1540}, + pos: position{line: 76, col: 11, offset: 1502}, val: "(", ignoreCase: false, want: "\"(\"", }, &labeledExpr{ - pos: position{line: 76, col: 15, offset: 1544}, + pos: position{line: 76, col: 15, offset: 1506}, label: "expr", expr: &ruleRefExpr{ - pos: position{line: 76, col: 20, offset: 1549}, + pos: position{line: 76, col: 20, offset: 1511}, name: "Expr", }, }, &litMatcher{ - pos: position{line: 76, col: 25, offset: 1554}, + pos: position{line: 76, col: 25, offset: 1516}, val: ")", ignoreCase: false, want: "\")\"", @@ -242,13 +242,13 @@ var g = &grammar{ }, }, &actionExpr{ - pos: position{line: 79, col: 5, offset: 1605}, + pos: position{line: 79, col: 5, offset: 1567}, run: (*parser).callonFactor8, expr: &labeledExpr{ - pos: position{line: 79, col: 5, offset: 1605}, + pos: position{line: 79, col: 5, offset: 1567}, label: "integer", expr: &ruleRefExpr{ - pos: position{line: 79, col: 13, offset: 1613}, + pos: position{line: 79, col: 13, offset: 1575}, name: "Integer", }, }, @@ -258,21 +258,21 @@ var g = &grammar{ }, { name: "AddOp", - pos: position{line: 84, col: 1, offset: 1670}, + pos: position{line: 84, col: 1, offset: 1632}, expr: &actionExpr{ - pos: position{line: 84, col: 10, offset: 1679}, + pos: position{line: 84, col: 10, offset: 1641}, run: (*parser).callonAddOp1, expr: &choiceExpr{ - pos: position{line: 84, col: 12, offset: 1681}, - alternatives: []interface{}{ + pos: position{line: 84, col: 12, offset: 1643}, + alternatives: []any{ &litMatcher{ - pos: position{line: 84, col: 12, offset: 1681}, + pos: position{line: 84, col: 12, offset: 1643}, val: "+", ignoreCase: false, want: "\"+\"", }, &litMatcher{ - pos: position{line: 84, col: 18, offset: 1687}, + pos: position{line: 84, col: 18, offset: 1649}, val: "-", ignoreCase: false, want: "\"-\"", @@ -283,21 +283,21 @@ var g = &grammar{ }, { name: "MulOp", - pos: position{line: 89, col: 1, offset: 1749}, + pos: position{line: 89, col: 1, offset: 1711}, expr: &actionExpr{ - pos: position{line: 89, col: 10, offset: 1758}, + pos: position{line: 89, col: 10, offset: 1720}, run: (*parser).callonMulOp1, expr: &choiceExpr{ - pos: position{line: 89, col: 12, offset: 1760}, - alternatives: []interface{}{ + pos: position{line: 89, col: 12, offset: 1722}, + alternatives: []any{ &litMatcher{ - pos: position{line: 89, col: 12, offset: 1760}, + pos: position{line: 89, col: 12, offset: 1722}, val: "*", ignoreCase: false, want: "\"*\"", }, &litMatcher{ - pos: position{line: 89, col: 18, offset: 1766}, + pos: position{line: 89, col: 18, offset: 1728}, val: "/", ignoreCase: false, want: "\"/\"", @@ -308,26 +308,26 @@ var g = &grammar{ }, { name: "Integer", - pos: position{line: 94, col: 1, offset: 1828}, + pos: position{line: 94, col: 1, offset: 1790}, expr: &actionExpr{ - pos: position{line: 94, col: 12, offset: 1839}, + pos: position{line: 94, col: 12, offset: 1801}, run: (*parser).callonInteger1, expr: &seqExpr{ - pos: position{line: 94, col: 12, offset: 1839}, - exprs: []interface{}{ + pos: position{line: 94, col: 12, offset: 1801}, + exprs: []any{ &zeroOrOneExpr{ - pos: position{line: 94, col: 12, offset: 1839}, + pos: position{line: 94, col: 12, offset: 1801}, expr: &litMatcher{ - pos: position{line: 94, col: 12, offset: 1839}, + pos: position{line: 94, col: 12, offset: 1801}, val: "-", ignoreCase: false, want: "\"-\"", }, }, &oneOrMoreExpr{ - pos: position{line: 94, col: 17, offset: 1844}, + pos: position{line: 94, col: 17, offset: 1806}, expr: &charClassMatcher{ - pos: position{line: 94, col: 17, offset: 1844}, + pos: position{line: 94, col: 17, offset: 1806}, val: "[0-9]", ranges: []rune{'0', '9'}, ignoreCase: false, @@ -341,11 +341,11 @@ var g = &grammar{ { name: "_", displayName: "\"whitespace\"", - pos: position{line: 99, col: 1, offset: 1916}, + pos: position{line: 99, col: 1, offset: 1878}, expr: &zeroOrMoreExpr{ - pos: position{line: 99, col: 19, offset: 1934}, + pos: position{line: 99, col: 19, offset: 1896}, expr: &charClassMatcher{ - pos: position{line: 99, col: 19, offset: 1934}, + pos: position{line: 99, col: 19, offset: 1896}, val: "[ \\n\\t\\r]", chars: []rune{' ', '\n', '\t', '\r'}, ignoreCase: false, @@ -355,100 +355,100 @@ var g = &grammar{ }, { name: "EOF", - pos: position{line: 101, col: 1, offset: 1946}, + pos: position{line: 101, col: 1, offset: 1908}, expr: ¬Expr{ - pos: position{line: 101, col: 8, offset: 1953}, + pos: position{line: 101, col: 8, offset: 1915}, expr: &anyMatcher{ - line: 101, col: 9, offset: 1954, + line: 101, col: 9, offset: 1916, }, }, }, }, } -func (c *current) onInput1(expr interface{}) (interface{}, error) { +func (c *current) onInput1(expr any) (any, error) { cntCodeBlocks++ return expr, nil } -func (p *parser) callonInput1() (interface{}, error) { +func (p *parser) callonInput1() (any, error) { stack := p.vstack[len(p.vstack)-1] _ = stack return p.cur.onInput1(stack["expr"]) } -func (c *current) onExpr1(first, rest interface{}) (interface{}, error) { +func (c *current) onExpr1(first, rest any) (any, error) { cntCodeBlocks++ return eval(first, rest), nil } -func (p *parser) callonExpr1() (interface{}, error) { +func (p *parser) callonExpr1() (any, error) { stack := p.vstack[len(p.vstack)-1] _ = stack return p.cur.onExpr1(stack["first"], stack["rest"]) } -func (c *current) onTerm1(first, rest interface{}) (interface{}, error) { +func (c *current) onTerm1(first, rest any) (any, error) { cntCodeBlocks++ return eval(first, rest), nil } -func (p *parser) callonTerm1() (interface{}, error) { +func (p *parser) callonTerm1() (any, error) { stack := p.vstack[len(p.vstack)-1] _ = stack return p.cur.onTerm1(stack["first"], stack["rest"]) } -func (c *current) onFactor2(expr interface{}) (interface{}, error) { +func (c *current) onFactor2(expr any) (any, error) { cntCodeBlocks++ return expr, nil } -func (p *parser) callonFactor2() (interface{}, error) { +func (p *parser) callonFactor2() (any, error) { stack := p.vstack[len(p.vstack)-1] _ = stack return p.cur.onFactor2(stack["expr"]) } -func (c *current) onFactor8(integer interface{}) (interface{}, error) { +func (c *current) onFactor8(integer any) (any, error) { cntCodeBlocks++ return integer, nil } -func (p *parser) callonFactor8() (interface{}, error) { +func (p *parser) callonFactor8() (any, error) { stack := p.vstack[len(p.vstack)-1] _ = stack return p.cur.onFactor8(stack["integer"]) } -func (c *current) onAddOp1() (interface{}, error) { +func (c *current) onAddOp1() (any, error) { cntCodeBlocks++ return string(c.text), nil } -func (p *parser) callonAddOp1() (interface{}, error) { +func (p *parser) callonAddOp1() (any, error) { stack := p.vstack[len(p.vstack)-1] _ = stack return p.cur.onAddOp1() } -func (c *current) onMulOp1() (interface{}, error) { +func (c *current) onMulOp1() (any, error) { cntCodeBlocks++ return string(c.text), nil } -func (p *parser) callonMulOp1() (interface{}, error) { +func (p *parser) callonMulOp1() (any, error) { stack := p.vstack[len(p.vstack)-1] _ = stack return p.cur.onMulOp1() } -func (c *current) onInteger1() (interface{}, error) { +func (c *current) onInteger1() (any, error) { cntCodeBlocks++ return strconv.Atoi(string(c.text)) } -func (p *parser) callonInteger1() (interface{}, error) { +func (p *parser) callonInteger1() (any, error) { stack := p.vstack[len(p.vstack)-1] _ = stack return p.cur.onInteger1() @@ -592,7 +592,7 @@ func Recover(b bool) Option { // GlobalStore creates an Option to set a key to a certain value in // the globalStore. -func GlobalStore(key string, value interface{}) Option { +func GlobalStore(key string, value any) Option { return func(p *parser) Option { old := p.cur.globalStore[key] p.cur.globalStore[key] = value @@ -602,7 +602,7 @@ func GlobalStore(key string, value interface{}) Option { // InitState creates an Option to set a key to a certain value in // the global "state" store. -func InitState(key string, value interface{}) Option { +func InitState(key string, value any) Option { return func(p *parser) Option { old := p.cur.state[key] p.cur.state[key] = value @@ -611,7 +611,7 @@ func InitState(key string, value interface{}) Option { } // ParseFile parses the file identified by filename. -func ParseFile(filename string, opts ...Option) (i interface{}, err error) { // nolint: deadcode +func ParseFile(filename string, opts ...Option) (i any, err error) { // nolint: deadcode f, err := os.Open(filename) if err != nil { return nil, err @@ -626,7 +626,7 @@ func ParseFile(filename string, opts ...Option) (i interface{}, err error) { // // ParseReader parses the data from r using filename as information in the // error messages. -func ParseReader(filename string, r io.Reader, opts ...Option) (interface{}, error) { // nolint: deadcode +func ParseReader(filename string, r io.Reader, opts ...Option) (any, error) { // nolint: deadcode b, err := io.ReadAll(r) if err != nil { return nil, err @@ -637,7 +637,7 @@ func ParseReader(filename string, r io.Reader, opts ...Option) (interface{}, err // Parse parses the data from b using filename as information in the // error messages. -func Parse(filename string, b []byte, opts ...Option) (interface{}, error) { +func Parse(filename string, b []byte, opts ...Option) (any, error) { return newParser(filename, b, opts...).parse(g) } @@ -675,7 +675,7 @@ type current struct { globalStore storeDict } -type storeDict map[string]interface{} +type storeDict map[string]any // the AST types... @@ -690,34 +690,34 @@ type rule struct { pos position name string displayName string - expr interface{} + expr any } // nolint: structcheck type choiceExpr struct { pos position - alternatives []interface{} + alternatives []any } // nolint: structcheck type actionExpr struct { pos position - expr interface{} - run func(*parser) (interface{}, error) + expr any + run func(*parser) (any, error) } // nolint: structcheck type recoveryExpr struct { pos position - expr interface{} - recoverExpr interface{} + expr any + recoverExpr any failureLabel []string } // nolint: structcheck type seqExpr struct { pos position - exprs []interface{} + exprs []any } // nolint: structcheck @@ -730,20 +730,22 @@ type throwExpr struct { type labeledExpr struct { pos position label string - expr interface{} + expr any } // nolint: structcheck type expr struct { pos position - expr interface{} + expr any } -type andExpr expr // nolint: structcheck -type notExpr expr // nolint: structcheck -type zeroOrOneExpr expr // nolint: structcheck -type zeroOrMoreExpr expr // nolint: structcheck -type oneOrMoreExpr expr // nolint: structcheck +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 { @@ -891,7 +893,7 @@ func (p *parser) setOptions(opts []Option) { // nolint: structcheck,deadcode type resultTuple struct { - v interface{} + v any b bool end savepoint } @@ -937,12 +939,12 @@ type parser struct { memoize bool // memoization table for the packrat algorithm: // map[offset in source] map[expression or rule] {value, match} - memo map[int]map[interface{}]resultTuple + 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]interface{} + vstack []map[string]any // rule stack, allows identification of the current rule in errors rstack []*rule @@ -962,7 +964,7 @@ type parser struct { choiceNoMatch string // recovery expression stack, keeps track of the currently available recovery expression, these are traversed in reverse - recoveryStack []map[string]interface{} + recoveryStack []map[string]any } // push a variable set on the vstack. @@ -982,7 +984,7 @@ func (p *parser) pushV() { return } - m = make(map[string]interface{}) + m = make(map[string]any) p.vstack[len(p.vstack)-1] = m } @@ -998,7 +1000,7 @@ func (p *parser) popV() { } // push a recovery expression with its labels to the recoveryStack -func (p *parser) pushRecovery(labels []string, expr interface{}) { +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) @@ -1007,7 +1009,7 @@ func (p *parser) pushRecovery(labels []string, expr interface{}) { p.recoveryStack = p.recoveryStack[:len(p.recoveryStack)+1] } - m := make(map[string]interface{}, len(labels)) + m := make(map[string]any, len(labels)) for _, fl := range labels { m[fl] = expr } @@ -1127,11 +1129,11 @@ func (p *parser) restore(pt savepoint) { // copies of the state to allow the parser to properly restore the state in // the case of backtracking. type Cloner interface { - Clone() interface{} + Clone() any } var statePool = &sync.Pool{ - New: func() interface{} { return make(storeDict) }, + New: func() any { return make(storeDict) }, } func (sd storeDict) Discard() { @@ -1173,7 +1175,7 @@ func (p *parser) sliceFrom(start savepoint) []byte { return p.data[start.position.offset:p.pt.position.offset] } -func (p *parser) getMemoized(node interface{}) (resultTuple, bool) { +func (p *parser) getMemoized(node any) (resultTuple, bool) { if len(p.memo) == 0 { return resultTuple{}, false } @@ -1185,13 +1187,13 @@ func (p *parser) getMemoized(node interface{}) (resultTuple, bool) { return res, ok } -func (p *parser) setMemoized(pt savepoint, node interface{}, tuple resultTuple) { +func (p *parser) setMemoized(pt savepoint, node any, tuple resultTuple) { if p.memo == nil { - p.memo = make(map[int]map[interface{}]resultTuple) + p.memo = make(map[int]map[any]resultTuple) } m := p.memo[pt.offset] if m == nil { - m = make(map[interface{}]resultTuple) + m = make(map[any]resultTuple) p.memo[pt.offset] = m } m[node] = tuple @@ -1205,7 +1207,7 @@ func (p *parser) buildRulesTable(g *grammar) { } // nolint: gocyclo -func (p *parser) parse(g *grammar) (val interface{}, err error) { +func (p *parser) parse(g *grammar) (val any, err error) { if len(g.rules) == 0 { p.addErr(errNoRule) return nil, p.errs.err() @@ -1282,7 +1284,7 @@ func listJoin(list []string, sep string, lastSep string) string { } } -func (p *parser) parseRule(rule *rule) (interface{}, bool) { +func (p *parser) parseRule(rule *rule) (any, bool) { if p.debug { defer p.out(p.in("parseRule " + rule.name)) } @@ -1312,7 +1314,7 @@ func (p *parser) parseRule(rule *rule) (interface{}, bool) { } // nolint: gocyclo -func (p *parser) parseExpr(expr interface{}) (interface{}, bool) { +func (p *parser) parseExpr(expr any) (any, bool) { var pt savepoint if p.memoize { @@ -1329,7 +1331,7 @@ func (p *parser) parseExpr(expr interface{}) (interface{}, bool) { panic(errMaxExprCnt) } - var val interface{} + var val any var ok bool switch expr := expr.(type) { case *actionExpr: @@ -1377,7 +1379,7 @@ func (p *parser) parseExpr(expr interface{}) (interface{}, bool) { return val, ok } -func (p *parser) parseActionExpr(act *actionExpr) (interface{}, bool) { +func (p *parser) parseActionExpr(act *actionExpr) (any, bool) { if p.debug { defer p.out(p.in("parseActionExpr")) } @@ -1402,7 +1404,7 @@ func (p *parser) parseActionExpr(act *actionExpr) (interface{}, bool) { return val, ok } -func (p *parser) parseAndCodeExpr(and *andCodeExpr) (interface{}, bool) { +func (p *parser) parseAndCodeExpr(and *andCodeExpr) (any, bool) { if p.debug { defer p.out(p.in("parseAndCodeExpr")) } @@ -1418,7 +1420,7 @@ func (p *parser) parseAndCodeExpr(and *andCodeExpr) (interface{}, bool) { return nil, ok } -func (p *parser) parseAndExpr(and *andExpr) (interface{}, bool) { +func (p *parser) parseAndExpr(and *andExpr) (any, bool) { if p.debug { defer p.out(p.in("parseAndExpr")) } @@ -1434,7 +1436,7 @@ func (p *parser) parseAndExpr(and *andExpr) (interface{}, bool) { return nil, ok } -func (p *parser) parseAnyMatcher(any *anyMatcher) (interface{}, bool) { +func (p *parser) parseAnyMatcher(any *anyMatcher) (any, bool) { if p.debug { defer p.out(p.in("parseAnyMatcher")) } @@ -1451,7 +1453,7 @@ func (p *parser) parseAnyMatcher(any *anyMatcher) (interface{}, bool) { } // nolint: gocyclo -func (p *parser) parseCharClassMatcher(chr *charClassMatcher) (interface{}, bool) { +func (p *parser) parseCharClassMatcher(chr *charClassMatcher) (any, bool) { if p.debug { defer p.out(p.in("parseCharClassMatcher")) } @@ -1532,7 +1534,7 @@ func (p *parser) incChoiceAltCnt(ch *choiceExpr, altI int) { m[alt]++ } -func (p *parser) parseChoiceExpr(ch *choiceExpr) (interface{}, bool) { +func (p *parser) parseChoiceExpr(ch *choiceExpr) (any, bool) { if p.debug { defer p.out(p.in("parseChoiceExpr")) } @@ -1556,7 +1558,7 @@ func (p *parser) parseChoiceExpr(ch *choiceExpr) (interface{}, bool) { return nil, false } -func (p *parser) parseLabeledExpr(lab *labeledExpr) (interface{}, bool) { +func (p *parser) parseLabeledExpr(lab *labeledExpr) (any, bool) { if p.debug { defer p.out(p.in("parseLabeledExpr")) } @@ -1571,7 +1573,7 @@ func (p *parser) parseLabeledExpr(lab *labeledExpr) (interface{}, bool) { return val, ok } -func (p *parser) parseLitMatcher(lit *litMatcher) (interface{}, bool) { +func (p *parser) parseLitMatcher(lit *litMatcher) (any, bool) { if p.debug { defer p.out(p.in("parseLitMatcher")) } @@ -1593,7 +1595,7 @@ func (p *parser) parseLitMatcher(lit *litMatcher) (interface{}, bool) { return p.sliceFrom(start), true } -func (p *parser) parseNotCodeExpr(not *notCodeExpr) (interface{}, bool) { +func (p *parser) parseNotCodeExpr(not *notCodeExpr) (any, bool) { if p.debug { defer p.out(p.in("parseNotCodeExpr")) } @@ -1609,7 +1611,7 @@ func (p *parser) parseNotCodeExpr(not *notCodeExpr) (interface{}, bool) { return nil, !ok } -func (p *parser) parseNotExpr(not *notExpr) (interface{}, bool) { +func (p *parser) parseNotExpr(not *notExpr) (any, bool) { if p.debug { defer p.out(p.in("parseNotExpr")) } @@ -1627,12 +1629,12 @@ func (p *parser) parseNotExpr(not *notExpr) (interface{}, bool) { return nil, !ok } -func (p *parser) parseOneOrMoreExpr(expr *oneOrMoreExpr) (interface{}, bool) { +func (p *parser) parseOneOrMoreExpr(expr *oneOrMoreExpr) (any, bool) { if p.debug { defer p.out(p.in("parseOneOrMoreExpr")) } - var vals []interface{} + var vals []any for { p.pushV() @@ -1649,7 +1651,7 @@ func (p *parser) parseOneOrMoreExpr(expr *oneOrMoreExpr) (interface{}, bool) { } } -func (p *parser) parseRecoveryExpr(recover *recoveryExpr) (interface{}, bool) { +func (p *parser) parseRecoveryExpr(recover *recoveryExpr) (any, bool) { if p.debug { defer p.out(p.in("parseRecoveryExpr (" + strings.Join(recover.failureLabel, ",") + ")")) } @@ -1661,7 +1663,7 @@ func (p *parser) parseRecoveryExpr(recover *recoveryExpr) (interface{}, bool) { return val, ok } -func (p *parser) parseRuleRefExpr(ref *ruleRefExpr) (interface{}, bool) { +func (p *parser) parseRuleRefExpr(ref *ruleRefExpr) (any, bool) { if p.debug { defer p.out(p.in("parseRuleRefExpr " + ref.name)) } @@ -1678,12 +1680,12 @@ func (p *parser) parseRuleRefExpr(ref *ruleRefExpr) (interface{}, bool) { return p.parseRule(rule) } -func (p *parser) parseSeqExpr(seq *seqExpr) (interface{}, bool) { +func (p *parser) parseSeqExpr(seq *seqExpr) (any, bool) { if p.debug { defer p.out(p.in("parseSeqExpr")) } - vals := make([]interface{}, 0, len(seq.exprs)) + vals := make([]any, 0, len(seq.exprs)) pt := p.pt state := p.cloneState() @@ -1699,7 +1701,7 @@ func (p *parser) parseSeqExpr(seq *seqExpr) (interface{}, bool) { return vals, true } -func (p *parser) parseStateCodeExpr(state *stateCodeExpr) (interface{}, bool) { +func (p *parser) parseStateCodeExpr(state *stateCodeExpr) (any, bool) { if p.debug { defer p.out(p.in("parseStateCodeExpr")) } @@ -1711,7 +1713,7 @@ func (p *parser) parseStateCodeExpr(state *stateCodeExpr) (interface{}, bool) { return nil, true } -func (p *parser) parseThrowExpr(expr *throwExpr) (interface{}, bool) { +func (p *parser) parseThrowExpr(expr *throwExpr) (any, bool) { if p.debug { defer p.out(p.in("parseThrowExpr")) } @@ -1727,12 +1729,12 @@ func (p *parser) parseThrowExpr(expr *throwExpr) (interface{}, bool) { return nil, false } -func (p *parser) parseZeroOrMoreExpr(expr *zeroOrMoreExpr) (interface{}, bool) { +func (p *parser) parseZeroOrMoreExpr(expr *zeroOrMoreExpr) (any, bool) { if p.debug { defer p.out(p.in("parseZeroOrMoreExpr")) } - var vals []interface{} + var vals []any for { p.pushV() @@ -1745,7 +1747,7 @@ func (p *parser) parseZeroOrMoreExpr(expr *zeroOrMoreExpr) (interface{}, bool) { } } -func (p *parser) parseZeroOrOneExpr(expr *zeroOrOneExpr) (interface{}, bool) { +func (p *parser) parseZeroOrOneExpr(expr *zeroOrOneExpr) (any, bool) { if p.debug { defer p.out(p.in("parseZeroOrOneExpr")) } diff --git a/examples/calculator/calculator.peg b/examples/calculator/calculator.peg index 63ddf85a..1c259486 100644 --- a/examples/calculator/calculator.peg +++ b/examples/calculator/calculator.peg @@ -38,18 +38,18 @@ func main() { fmt.Println("=", got) } -func toIfaceSlice(v interface{}) []interface{} { +func toAnySlice(v any) []any { if v == nil { return nil } - return v.([]interface{}) + return v.([]any) } -func eval(first, rest interface{}) int { +func eval(first, rest any) int { l := first.(int) - restSl := toIfaceSlice(rest) + restSl := toAnySlice(rest) for _, v := range restSl { - restExpr := toIfaceSlice(v) + restExpr := toAnySlice(v) r := restExpr[3].(int) op := restExpr[1].(string) l = ops[op](l, r) diff --git a/examples/indentation/indentation.go b/examples/indentation/indentation.go index 474310bb..57a4d48f 100644 --- a/examples/indentation/indentation.go +++ b/examples/indentation/indentation.go @@ -17,46 +17,46 @@ import ( "unicode/utf8" ) -func toIfaceSlice(v interface{}) []interface{} { +func toAnySlice(v any) []any { if v == nil { return nil } - return v.([]interface{}) + return v.([]any) } var g = &grammar{ rules: []*rule{ { name: "Input", - pos: position{line: 13, col: 1, offset: 143}, + pos: position{line: 13, col: 1, offset: 117}, expr: &actionExpr{ - pos: position{line: 13, col: 15, offset: 159}, + pos: position{line: 13, col: 15, offset: 133}, run: (*parser).callonInput1, expr: &seqExpr{ - pos: position{line: 13, col: 15, offset: 159}, - exprs: []interface{}{ + pos: position{line: 13, col: 15, offset: 133}, + exprs: []any{ &stateCodeExpr{ - pos: position{line: 13, col: 15, offset: 159}, + pos: position{line: 13, col: 15, offset: 133}, run: (*parser).callonInput3, }, &labeledExpr{ - pos: position{line: 13, col: 59, offset: 203}, + pos: position{line: 13, col: 59, offset: 177}, label: "s", expr: &ruleRefExpr{ - pos: position{line: 13, col: 61, offset: 205}, + pos: position{line: 13, col: 61, offset: 179}, name: "Statements", }, }, &labeledExpr{ - pos: position{line: 13, col: 73, offset: 217}, + pos: position{line: 13, col: 73, offset: 191}, label: "r", expr: &ruleRefExpr{ - pos: position{line: 13, col: 75, offset: 219}, + pos: position{line: 13, col: 75, offset: 193}, name: "ReturnOp", }, }, &ruleRefExpr{ - pos: position{line: 13, col: 84, offset: 228}, + pos: position{line: 13, col: 84, offset: 202}, name: "EOF", }, }, @@ -65,17 +65,17 @@ var g = &grammar{ }, { name: "Statements", - pos: position{line: 15, col: 1, offset: 338}, + pos: position{line: 15, col: 1, offset: 312}, expr: &actionExpr{ - pos: position{line: 15, col: 15, offset: 354}, + pos: position{line: 15, col: 15, offset: 328}, run: (*parser).callonStatements1, expr: &labeledExpr{ - pos: position{line: 15, col: 15, offset: 354}, + pos: position{line: 15, col: 15, offset: 328}, label: "s", expr: &oneOrMoreExpr{ - pos: position{line: 15, col: 17, offset: 356}, + pos: position{line: 15, col: 17, offset: 330}, expr: &ruleRefExpr{ - pos: position{line: 15, col: 17, offset: 356}, + pos: position{line: 15, col: 17, offset: 330}, name: "Line", }, }, @@ -84,22 +84,22 @@ var g = &grammar{ }, { name: "Line", - pos: position{line: 16, col: 1, offset: 415}, + pos: position{line: 16, col: 1, offset: 389}, expr: &actionExpr{ - pos: position{line: 16, col: 15, offset: 431}, + pos: position{line: 16, col: 15, offset: 405}, run: (*parser).callonLine1, expr: &seqExpr{ - pos: position{line: 16, col: 15, offset: 431}, - exprs: []interface{}{ + pos: position{line: 16, col: 15, offset: 405}, + exprs: []any{ &ruleRefExpr{ - pos: position{line: 16, col: 15, offset: 431}, + pos: position{line: 16, col: 15, offset: 405}, name: "INDENTATION", }, &labeledExpr{ - pos: position{line: 16, col: 27, offset: 443}, + pos: position{line: 16, col: 27, offset: 417}, label: "s", expr: &ruleRefExpr{ - pos: position{line: 16, col: 29, offset: 445}, + pos: position{line: 16, col: 29, offset: 419}, name: "Statement", }, }, @@ -109,33 +109,33 @@ var g = &grammar{ }, { name: "ReturnOp", - pos: position{line: 17, col: 1, offset: 478}, + pos: position{line: 17, col: 1, offset: 452}, expr: &actionExpr{ - pos: position{line: 17, col: 15, offset: 494}, + pos: position{line: 17, col: 15, offset: 468}, run: (*parser).callonReturnOp1, expr: &seqExpr{ - pos: position{line: 17, col: 15, offset: 494}, - exprs: []interface{}{ + pos: position{line: 17, col: 15, offset: 468}, + exprs: []any{ &litMatcher{ - pos: position{line: 17, col: 15, offset: 494}, + pos: position{line: 17, col: 15, offset: 468}, val: "return", ignoreCase: false, want: "\"return\"", }, &ruleRefExpr{ - pos: position{line: 17, col: 24, offset: 503}, + pos: position{line: 17, col: 24, offset: 477}, name: "_", }, &labeledExpr{ - pos: position{line: 17, col: 26, offset: 505}, + pos: position{line: 17, col: 26, offset: 479}, label: "arg", expr: &ruleRefExpr{ - pos: position{line: 17, col: 30, offset: 509}, + pos: position{line: 17, col: 30, offset: 483}, name: "Identifier", }, }, &ruleRefExpr{ - pos: position{line: 17, col: 41, offset: 520}, + pos: position{line: 17, col: 41, offset: 494}, name: "EOL", }, }, @@ -144,86 +144,86 @@ var g = &grammar{ }, { name: "Statement", - pos: position{line: 19, col: 1, offset: 571}, + pos: position{line: 19, col: 1, offset: 545}, expr: &choiceExpr{ - pos: position{line: 19, col: 15, offset: 587}, - alternatives: []interface{}{ + pos: position{line: 19, col: 15, offset: 561}, + alternatives: []any{ &actionExpr{ - pos: position{line: 19, col: 15, offset: 587}, + pos: position{line: 19, col: 15, offset: 561}, run: (*parser).callonStatement2, expr: &seqExpr{ - pos: position{line: 19, col: 15, offset: 587}, - exprs: []interface{}{ + pos: position{line: 19, col: 15, offset: 561}, + exprs: []any{ &labeledExpr{ - pos: position{line: 19, col: 15, offset: 587}, + pos: position{line: 19, col: 15, offset: 561}, label: "s", expr: &ruleRefExpr{ - pos: position{line: 19, col: 17, offset: 589}, + pos: position{line: 19, col: 17, offset: 563}, name: "Assignment", }, }, &ruleRefExpr{ - pos: position{line: 19, col: 28, offset: 600}, + pos: position{line: 19, col: 28, offset: 574}, name: "EOL", }, }, }, }, &actionExpr{ - pos: position{line: 20, col: 7, offset: 657}, + pos: position{line: 20, col: 7, offset: 631}, run: (*parser).callonStatement7, expr: &seqExpr{ - pos: position{line: 20, col: 7, offset: 657}, - exprs: []interface{}{ + pos: position{line: 20, col: 7, offset: 631}, + exprs: []any{ &litMatcher{ - pos: position{line: 20, col: 7, offset: 657}, + pos: position{line: 20, col: 7, offset: 631}, val: "if", ignoreCase: false, want: "\"if\"", }, &ruleRefExpr{ - pos: position{line: 20, col: 12, offset: 662}, + pos: position{line: 20, col: 12, offset: 636}, name: "_", }, &labeledExpr{ - pos: position{line: 20, col: 14, offset: 664}, + pos: position{line: 20, col: 14, offset: 638}, label: "arg", expr: &ruleRefExpr{ - pos: position{line: 20, col: 18, offset: 668}, + pos: position{line: 20, col: 18, offset: 642}, name: "LogicalExpression", }, }, &zeroOrOneExpr{ - pos: position{line: 20, col: 36, offset: 686}, + pos: position{line: 20, col: 36, offset: 660}, expr: &ruleRefExpr{ - pos: position{line: 20, col: 36, offset: 686}, + pos: position{line: 20, col: 36, offset: 660}, name: "_", }, }, &litMatcher{ - pos: position{line: 20, col: 39, offset: 689}, + pos: position{line: 20, col: 39, offset: 663}, val: ":", ignoreCase: false, want: "\":\"", }, &ruleRefExpr{ - pos: position{line: 20, col: 43, offset: 693}, + pos: position{line: 20, col: 43, offset: 667}, name: "EOL", }, &ruleRefExpr{ - pos: position{line: 20, col: 47, offset: 697}, + pos: position{line: 20, col: 47, offset: 671}, name: "INDENT", }, &labeledExpr{ - pos: position{line: 20, col: 54, offset: 704}, + pos: position{line: 20, col: 54, offset: 678}, label: "s", expr: &ruleRefExpr{ - pos: position{line: 20, col: 56, offset: 706}, + pos: position{line: 20, col: 56, offset: 680}, name: "Statements", }, }, &ruleRefExpr{ - pos: position{line: 20, col: 67, offset: 717}, + pos: position{line: 20, col: 67, offset: 691}, name: "DEDENT", }, }, @@ -234,46 +234,46 @@ var g = &grammar{ }, { name: "Assignment", - pos: position{line: 24, col: 1, offset: 844}, + pos: position{line: 24, col: 1, offset: 818}, expr: &actionExpr{ - pos: position{line: 24, col: 14, offset: 859}, + pos: position{line: 24, col: 14, offset: 833}, run: (*parser).callonAssignment1, expr: &seqExpr{ - pos: position{line: 24, col: 14, offset: 859}, - exprs: []interface{}{ + pos: position{line: 24, col: 14, offset: 833}, + exprs: []any{ &labeledExpr{ - pos: position{line: 24, col: 14, offset: 859}, + pos: position{line: 24, col: 14, offset: 833}, label: "lvalue", expr: &ruleRefExpr{ - pos: position{line: 24, col: 21, offset: 866}, + pos: position{line: 24, col: 21, offset: 840}, name: "Identifier", }, }, &zeroOrOneExpr{ - pos: position{line: 24, col: 32, offset: 877}, + pos: position{line: 24, col: 32, offset: 851}, expr: &ruleRefExpr{ - pos: position{line: 24, col: 32, offset: 877}, + pos: position{line: 24, col: 32, offset: 851}, name: "_", }, }, &litMatcher{ - pos: position{line: 24, col: 35, offset: 880}, + pos: position{line: 24, col: 35, offset: 854}, val: "=", ignoreCase: false, want: "\"=\"", }, &zeroOrOneExpr{ - pos: position{line: 24, col: 39, offset: 884}, + pos: position{line: 24, col: 39, offset: 858}, expr: &ruleRefExpr{ - pos: position{line: 24, col: 39, offset: 884}, + pos: position{line: 24, col: 39, offset: 858}, name: "_", }, }, &labeledExpr{ - pos: position{line: 24, col: 42, offset: 887}, + pos: position{line: 24, col: 42, offset: 861}, label: "rvalue", expr: &ruleRefExpr{ - pos: position{line: 24, col: 49, offset: 894}, + pos: position{line: 24, col: 49, offset: 868}, name: "AdditiveExpression", }, }, @@ -283,15 +283,15 @@ var g = &grammar{ }, { name: "LogicalExpression", - pos: position{line: 27, col: 1, offset: 1044}, + pos: position{line: 27, col: 1, offset: 1018}, expr: &actionExpr{ - pos: position{line: 27, col: 23, offset: 1068}, + pos: position{line: 27, col: 23, offset: 1042}, run: (*parser).callonLogicalExpression1, expr: &labeledExpr{ - pos: position{line: 27, col: 23, offset: 1068}, + pos: position{line: 27, col: 23, offset: 1042}, label: "arg", expr: &ruleRefExpr{ - pos: position{line: 27, col: 27, offset: 1072}, + pos: position{line: 27, col: 27, offset: 1046}, name: "PrimaryExpression", }, }, @@ -299,43 +299,43 @@ var g = &grammar{ }, { name: "AdditiveExpression", - pos: position{line: 28, col: 1, offset: 1155}, + pos: position{line: 28, col: 1, offset: 1129}, expr: &actionExpr{ - pos: position{line: 28, col: 23, offset: 1179}, + pos: position{line: 28, col: 23, offset: 1153}, run: (*parser).callonAdditiveExpression1, expr: &seqExpr{ - pos: position{line: 28, col: 23, offset: 1179}, - exprs: []interface{}{ + pos: position{line: 28, col: 23, offset: 1153}, + exprs: []any{ &labeledExpr{ - pos: position{line: 28, col: 23, offset: 1179}, + pos: position{line: 28, col: 23, offset: 1153}, label: "arg", expr: &ruleRefExpr{ - pos: position{line: 28, col: 27, offset: 1183}, + pos: position{line: 28, col: 27, offset: 1157}, name: "PrimaryExpression", }, }, &labeledExpr{ - pos: position{line: 28, col: 45, offset: 1201}, + pos: position{line: 28, col: 45, offset: 1175}, label: "rest", expr: &zeroOrMoreExpr{ - pos: position{line: 28, col: 50, offset: 1206}, + pos: position{line: 28, col: 50, offset: 1180}, expr: &seqExpr{ - pos: position{line: 28, col: 52, offset: 1208}, - exprs: []interface{}{ + pos: position{line: 28, col: 52, offset: 1182}, + exprs: []any{ &ruleRefExpr{ - pos: position{line: 28, col: 52, offset: 1208}, + pos: position{line: 28, col: 52, offset: 1182}, name: "_", }, &ruleRefExpr{ - pos: position{line: 28, col: 54, offset: 1210}, + pos: position{line: 28, col: 54, offset: 1184}, name: "AddOp", }, &ruleRefExpr{ - pos: position{line: 28, col: 60, offset: 1216}, + pos: position{line: 28, col: 60, offset: 1190}, name: "_", }, &ruleRefExpr{ - pos: position{line: 28, col: 62, offset: 1218}, + pos: position{line: 28, col: 62, offset: 1192}, name: "PrimaryExpression", }, }, @@ -348,22 +348,22 @@ var g = &grammar{ }, { name: "PrimaryExpression", - pos: position{line: 30, col: 1, offset: 1354}, + pos: position{line: 30, col: 1, offset: 1328}, expr: &actionExpr{ - pos: position{line: 30, col: 23, offset: 1378}, + pos: position{line: 30, col: 23, offset: 1352}, run: (*parser).callonPrimaryExpression1, expr: &labeledExpr{ - pos: position{line: 30, col: 23, offset: 1378}, + pos: position{line: 30, col: 23, offset: 1352}, label: "arg", expr: &choiceExpr{ - pos: position{line: 30, col: 28, offset: 1383}, - alternatives: []interface{}{ + pos: position{line: 30, col: 28, offset: 1357}, + alternatives: []any{ &ruleRefExpr{ - pos: position{line: 30, col: 28, offset: 1383}, + pos: position{line: 30, col: 28, offset: 1357}, name: "Integer", }, &ruleRefExpr{ - pos: position{line: 30, col: 38, offset: 1393}, + pos: position{line: 30, col: 38, offset: 1367}, name: "Identifier", }, }, @@ -373,14 +373,14 @@ var g = &grammar{ }, { name: "Integer", - pos: position{line: 33, col: 1, offset: 1492}, + pos: position{line: 33, col: 1, offset: 1466}, expr: &actionExpr{ - pos: position{line: 33, col: 11, offset: 1504}, + pos: position{line: 33, col: 11, offset: 1478}, run: (*parser).callonInteger1, expr: &oneOrMoreExpr{ - pos: position{line: 33, col: 11, offset: 1504}, + pos: position{line: 33, col: 11, offset: 1478}, expr: &charClassMatcher{ - pos: position{line: 33, col: 11, offset: 1504}, + pos: position{line: 33, col: 11, offset: 1478}, val: "[0-9]", ranges: []rune{'0', '9'}, ignoreCase: false, @@ -391,24 +391,24 @@ var g = &grammar{ }, { name: "Identifier", - pos: position{line: 34, col: 1, offset: 1580}, + pos: position{line: 34, col: 1, offset: 1554}, expr: &actionExpr{ - pos: position{line: 34, col: 14, offset: 1595}, + pos: position{line: 34, col: 14, offset: 1569}, run: (*parser).callonIdentifier1, expr: &seqExpr{ - pos: position{line: 34, col: 14, offset: 1595}, - exprs: []interface{}{ + pos: position{line: 34, col: 14, offset: 1569}, + exprs: []any{ &charClassMatcher{ - pos: position{line: 34, col: 14, offset: 1595}, + pos: position{line: 34, col: 14, offset: 1569}, val: "[a-zA-Z]", ranges: []rune{'a', 'z', 'A', 'Z'}, ignoreCase: false, inverted: false, }, &zeroOrMoreExpr{ - pos: position{line: 34, col: 23, offset: 1604}, + pos: position{line: 34, col: 23, offset: 1578}, expr: &charClassMatcher{ - pos: position{line: 34, col: 23, offset: 1604}, + pos: position{line: 34, col: 23, offset: 1578}, val: "[a-zA-Z0-9]", ranges: []rune{'a', 'z', 'A', 'Z', '0', '9'}, ignoreCase: false, @@ -421,21 +421,21 @@ var g = &grammar{ }, { name: "AddOp", - pos: position{line: 36, col: 1, offset: 1672}, + pos: position{line: 36, col: 1, offset: 1646}, expr: &actionExpr{ - pos: position{line: 36, col: 9, offset: 1682}, + pos: position{line: 36, col: 9, offset: 1656}, run: (*parser).callonAddOp1, expr: &choiceExpr{ - pos: position{line: 36, col: 11, offset: 1684}, - alternatives: []interface{}{ + pos: position{line: 36, col: 11, offset: 1658}, + alternatives: []any{ &litMatcher{ - pos: position{line: 36, col: 11, offset: 1684}, + pos: position{line: 36, col: 11, offset: 1658}, val: "+", ignoreCase: false, want: "\"+\"", }, &litMatcher{ - pos: position{line: 36, col: 17, offset: 1690}, + pos: position{line: 36, col: 17, offset: 1664}, val: "-", ignoreCase: false, want: "\"-\"", @@ -446,11 +446,11 @@ var g = &grammar{ }, { name: "_", - pos: position{line: 38, col: 1, offset: 1749}, + pos: position{line: 38, col: 1, offset: 1723}, expr: &oneOrMoreExpr{ - pos: position{line: 38, col: 5, offset: 1755}, + pos: position{line: 38, col: 5, offset: 1729}, expr: &charClassMatcher{ - pos: position{line: 38, col: 5, offset: 1755}, + pos: position{line: 38, col: 5, offset: 1729}, val: "[ \\t]", chars: []rune{' ', '\t'}, ignoreCase: false, @@ -460,53 +460,53 @@ var g = &grammar{ }, { name: "EOL", - pos: position{line: 40, col: 1, offset: 1763}, + pos: position{line: 40, col: 1, offset: 1737}, expr: &seqExpr{ - pos: position{line: 40, col: 7, offset: 1771}, - exprs: []interface{}{ + pos: position{line: 40, col: 7, offset: 1745}, + exprs: []any{ &zeroOrOneExpr{ - pos: position{line: 40, col: 7, offset: 1771}, + pos: position{line: 40, col: 7, offset: 1745}, expr: &ruleRefExpr{ - pos: position{line: 40, col: 7, offset: 1771}, + pos: position{line: 40, col: 7, offset: 1745}, name: "_", }, }, &zeroOrOneExpr{ - pos: position{line: 40, col: 10, offset: 1774}, + pos: position{line: 40, col: 10, offset: 1748}, expr: &ruleRefExpr{ - pos: position{line: 40, col: 10, offset: 1774}, + pos: position{line: 40, col: 10, offset: 1748}, name: "Comment", }, }, &choiceExpr{ - pos: position{line: 40, col: 20, offset: 1784}, - alternatives: []interface{}{ + pos: position{line: 40, col: 20, offset: 1758}, + alternatives: []any{ &litMatcher{ - pos: position{line: 40, col: 20, offset: 1784}, + pos: position{line: 40, col: 20, offset: 1758}, val: "\r\n", ignoreCase: false, want: "\"\\r\\n\"", }, &litMatcher{ - pos: position{line: 40, col: 29, offset: 1793}, + pos: position{line: 40, col: 29, offset: 1767}, val: "\n\r", ignoreCase: false, want: "\"\\n\\r\"", }, &litMatcher{ - pos: position{line: 40, col: 38, offset: 1802}, + pos: position{line: 40, col: 38, offset: 1776}, val: "\r", ignoreCase: false, want: "\"\\r\"", }, &litMatcher{ - pos: position{line: 40, col: 45, offset: 1809}, + pos: position{line: 40, col: 45, offset: 1783}, val: "\n", ignoreCase: false, want: "\"\\n\"", }, &ruleRefExpr{ - pos: position{line: 40, col: 52, offset: 1816}, + pos: position{line: 40, col: 52, offset: 1790}, name: "EOF", }, }, @@ -516,20 +516,20 @@ var g = &grammar{ }, { name: "Comment", - pos: position{line: 42, col: 1, offset: 1822}, + pos: position{line: 42, col: 1, offset: 1796}, expr: &seqExpr{ - pos: position{line: 42, col: 11, offset: 1834}, - exprs: []interface{}{ + pos: position{line: 42, col: 11, offset: 1808}, + exprs: []any{ &litMatcher{ - pos: position{line: 42, col: 11, offset: 1834}, + pos: position{line: 42, col: 11, offset: 1808}, val: "//", ignoreCase: false, want: "\"//\"", }, &zeroOrMoreExpr{ - pos: position{line: 42, col: 16, offset: 1839}, + pos: position{line: 42, col: 16, offset: 1813}, expr: &charClassMatcher{ - pos: position{line: 42, col: 16, offset: 1839}, + pos: position{line: 42, col: 16, offset: 1813}, val: "[^\\r\\n]", chars: []rune{'\r', '\n'}, ignoreCase: false, @@ -541,27 +541,27 @@ var g = &grammar{ }, { name: "EOF", - pos: position{line: 44, col: 1, offset: 1849}, + pos: position{line: 44, col: 1, offset: 1823}, expr: ¬Expr{ - pos: position{line: 44, col: 7, offset: 1857}, + pos: position{line: 44, col: 7, offset: 1831}, expr: &anyMatcher{ - line: 44, col: 8, offset: 1858, + line: 44, col: 8, offset: 1832, }, }, }, { name: "INDENTATION", - pos: position{line: 46, col: 1, offset: 1861}, + pos: position{line: 46, col: 1, offset: 1835}, expr: &seqExpr{ - pos: position{line: 46, col: 15, offset: 1877}, - exprs: []interface{}{ + pos: position{line: 46, col: 15, offset: 1851}, + exprs: []any{ &labeledExpr{ - pos: position{line: 46, col: 15, offset: 1877}, + pos: position{line: 46, col: 15, offset: 1851}, label: "spaces", expr: &zeroOrMoreExpr{ - pos: position{line: 46, col: 22, offset: 1884}, + pos: position{line: 46, col: 22, offset: 1858}, expr: &litMatcher{ - pos: position{line: 46, col: 22, offset: 1884}, + pos: position{line: 46, col: 22, offset: 1858}, val: " ", ignoreCase: false, want: "\" \"", @@ -569,7 +569,7 @@ var g = &grammar{ }, }, &andCodeExpr{ - pos: position{line: 46, col: 27, offset: 1889}, + pos: position{line: 46, col: 27, offset: 1863}, run: (*parser).callonINDENTATION5, }, }, @@ -577,17 +577,17 @@ var g = &grammar{ }, { name: "INDENT", - pos: position{line: 48, col: 1, offset: 1965}, + pos: position{line: 48, col: 1, offset: 1937}, expr: &stateCodeExpr{ - pos: position{line: 48, col: 10, offset: 1976}, + pos: position{line: 48, col: 10, offset: 1948}, run: (*parser).callonINDENT1, }, }, { name: "DEDENT", - pos: position{line: 50, col: 1, offset: 2052}, + pos: position{line: 50, col: 1, offset: 2024}, expr: &stateCodeExpr{ - pos: position{line: 50, col: 10, offset: 2063}, + pos: position{line: 50, col: 10, offset: 2035}, run: (*parser).callonDEDENT1, }, }, @@ -605,138 +605,138 @@ func (p *parser) callonInput3() error { return p.cur.onInput3() } -func (c *current) onInput1(s, r interface{}) (interface{}, error) { +func (c *current) onInput1(s, r any) (any, error) { return newProgramNode(s.(StatementsNode), r.(ReturnNode)) } -func (p *parser) callonInput1() (interface{}, error) { +func (p *parser) callonInput1() (any, error) { stack := p.vstack[len(p.vstack)-1] _ = stack return p.cur.onInput1(stack["s"], stack["r"]) } -func (c *current) onStatements1(s interface{}) (interface{}, error) { +func (c *current) onStatements1(s any) (any, error) { return newStatementsNode(s) } -func (p *parser) callonStatements1() (interface{}, error) { +func (p *parser) callonStatements1() (any, error) { stack := p.vstack[len(p.vstack)-1] _ = stack return p.cur.onStatements1(stack["s"]) } -func (c *current) onLine1(s interface{}) (interface{}, error) { +func (c *current) onLine1(s any) (any, error) { return s, nil } -func (p *parser) callonLine1() (interface{}, error) { +func (p *parser) callonLine1() (any, error) { stack := p.vstack[len(p.vstack)-1] _ = stack return p.cur.onLine1(stack["s"]) } -func (c *current) onReturnOp1(arg interface{}) (interface{}, error) { +func (c *current) onReturnOp1(arg any) (any, error) { return newReturnNode(arg.(IdentifierNode)) } -func (p *parser) callonReturnOp1() (interface{}, error) { +func (p *parser) callonReturnOp1() (any, error) { stack := p.vstack[len(p.vstack)-1] _ = stack return p.cur.onReturnOp1(stack["arg"]) } -func (c *current) onStatement2(s interface{}) (interface{}, error) { +func (c *current) onStatement2(s any) (any, error) { return s.(AssignmentNode), nil } -func (p *parser) callonStatement2() (interface{}, error) { +func (p *parser) callonStatement2() (any, error) { stack := p.vstack[len(p.vstack)-1] _ = stack return p.cur.onStatement2(stack["s"]) } -func (c *current) onStatement7(arg, s interface{}) (interface{}, error) { +func (c *current) onStatement7(arg, s any) (any, error) { return newIfNode(arg.(LogicalExpressionNode), s.(StatementsNode)) } -func (p *parser) callonStatement7() (interface{}, error) { +func (p *parser) callonStatement7() (any, error) { stack := p.vstack[len(p.vstack)-1] _ = stack return p.cur.onStatement7(stack["arg"], stack["s"]) } -func (c *current) onAssignment1(lvalue, rvalue interface{}) (interface{}, error) { +func (c *current) onAssignment1(lvalue, rvalue any) (any, error) { return newAssignmentNode(lvalue.(IdentifierNode), rvalue.(AdditiveExpressionNode)) } -func (p *parser) callonAssignment1() (interface{}, error) { +func (p *parser) callonAssignment1() (any, error) { stack := p.vstack[len(p.vstack)-1] _ = stack return p.cur.onAssignment1(stack["lvalue"], stack["rvalue"]) } -func (c *current) onLogicalExpression1(arg interface{}) (interface{}, error) { +func (c *current) onLogicalExpression1(arg any) (any, error) { return newLogicalExpressionNode(arg.(PrimaryExpressionNode)) } -func (p *parser) callonLogicalExpression1() (interface{}, error) { +func (p *parser) callonLogicalExpression1() (any, error) { stack := p.vstack[len(p.vstack)-1] _ = stack return p.cur.onLogicalExpression1(stack["arg"]) } -func (c *current) onAdditiveExpression1(arg, rest interface{}) (interface{}, error) { +func (c *current) onAdditiveExpression1(arg, rest any) (any, error) { return newAdditiveExpressionNode(arg.(PrimaryExpressionNode), rest) } -func (p *parser) callonAdditiveExpression1() (interface{}, error) { +func (p *parser) callonAdditiveExpression1() (any, error) { stack := p.vstack[len(p.vstack)-1] _ = stack return p.cur.onAdditiveExpression1(stack["arg"], stack["rest"]) } -func (c *current) onPrimaryExpression1(arg interface{}) (interface{}, error) { +func (c *current) onPrimaryExpression1(arg any) (any, error) { return newPrimaryExpressionNode(arg) } -func (p *parser) callonPrimaryExpression1() (interface{}, error) { +func (p *parser) callonPrimaryExpression1() (any, error) { stack := p.vstack[len(p.vstack)-1] _ = stack return p.cur.onPrimaryExpression1(stack["arg"]) } -func (c *current) onInteger1() (interface{}, error) { +func (c *current) onInteger1() (any, error) { return newIntegerNode(string(c.text)) } -func (p *parser) callonInteger1() (interface{}, error) { +func (p *parser) callonInteger1() (any, error) { stack := p.vstack[len(p.vstack)-1] _ = stack return p.cur.onInteger1() } -func (c *current) onIdentifier1() (interface{}, error) { +func (c *current) onIdentifier1() (any, error) { return newIdentifierNode(string(c.text)) } -func (p *parser) callonIdentifier1() (interface{}, error) { +func (p *parser) callonIdentifier1() (any, error) { stack := p.vstack[len(p.vstack)-1] _ = stack return p.cur.onIdentifier1() } -func (c *current) onAddOp1() (interface{}, error) { +func (c *current) onAddOp1() (any, error) { return string(c.text), nil } -func (p *parser) callonAddOp1() (interface{}, error) { +func (p *parser) callonAddOp1() (any, error) { stack := p.vstack[len(p.vstack)-1] _ = stack return p.cur.onAddOp1() } -func (c *current) onINDENTATION5(spaces interface{}) (bool, error) { - return len(toIfaceSlice(spaces)) == c.state["Indentation"].(int), nil +func (c *current) onINDENTATION5(spaces any) (bool, error) { + return len(toAnySlice(spaces)) == c.state["Indentation"].(int), nil } func (p *parser) callonINDENTATION5() (bool, error) { @@ -905,7 +905,7 @@ func Recover(b bool) Option { // GlobalStore creates an Option to set a key to a certain value in // the globalStore. -func GlobalStore(key string, value interface{}) Option { +func GlobalStore(key string, value any) Option { return func(p *parser) Option { old := p.cur.globalStore[key] p.cur.globalStore[key] = value @@ -915,7 +915,7 @@ func GlobalStore(key string, value interface{}) Option { // InitState creates an Option to set a key to a certain value in // the global "state" store. -func InitState(key string, value interface{}) Option { +func InitState(key string, value any) Option { return func(p *parser) Option { old := p.cur.state[key] p.cur.state[key] = value @@ -924,7 +924,7 @@ func InitState(key string, value interface{}) Option { } // ParseFile parses the file identified by filename. -func ParseFile(filename string, opts ...Option) (i interface{}, err error) { // nolint: deadcode +func ParseFile(filename string, opts ...Option) (i any, err error) { // nolint: deadcode f, err := os.Open(filename) if err != nil { return nil, err @@ -939,7 +939,7 @@ func ParseFile(filename string, opts ...Option) (i interface{}, err error) { // // ParseReader parses the data from r using filename as information in the // error messages. -func ParseReader(filename string, r io.Reader, opts ...Option) (interface{}, error) { // nolint: deadcode +func ParseReader(filename string, r io.Reader, opts ...Option) (any, error) { // nolint: deadcode b, err := io.ReadAll(r) if err != nil { return nil, err @@ -950,7 +950,7 @@ func ParseReader(filename string, r io.Reader, opts ...Option) (interface{}, err // Parse parses the data from b using filename as information in the // error messages. -func Parse(filename string, b []byte, opts ...Option) (interface{}, error) { +func Parse(filename string, b []byte, opts ...Option) (any, error) { return newParser(filename, b, opts...).parse(g) } @@ -988,7 +988,7 @@ type current struct { globalStore storeDict } -type storeDict map[string]interface{} +type storeDict map[string]any // the AST types... @@ -1003,34 +1003,34 @@ type rule struct { pos position name string displayName string - expr interface{} + expr any } // nolint: structcheck type choiceExpr struct { pos position - alternatives []interface{} + alternatives []any } // nolint: structcheck type actionExpr struct { pos position - expr interface{} - run func(*parser) (interface{}, error) + expr any + run func(*parser) (any, error) } // nolint: structcheck type recoveryExpr struct { pos position - expr interface{} - recoverExpr interface{} + expr any + recoverExpr any failureLabel []string } // nolint: structcheck type seqExpr struct { pos position - exprs []interface{} + exprs []any } // nolint: structcheck @@ -1043,20 +1043,22 @@ type throwExpr struct { type labeledExpr struct { pos position label string - expr interface{} + expr any } // nolint: structcheck type expr struct { pos position - expr interface{} + expr any } -type andExpr expr // nolint: structcheck -type notExpr expr // nolint: structcheck -type zeroOrOneExpr expr // nolint: structcheck -type zeroOrMoreExpr expr // nolint: structcheck -type oneOrMoreExpr expr // nolint: structcheck +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 { @@ -1204,7 +1206,7 @@ func (p *parser) setOptions(opts []Option) { // nolint: structcheck,deadcode type resultTuple struct { - v interface{} + v any b bool end savepoint } @@ -1250,12 +1252,12 @@ type parser struct { memoize bool // memoization table for the packrat algorithm: // map[offset in source] map[expression or rule] {value, match} - memo map[int]map[interface{}]resultTuple + 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]interface{} + vstack []map[string]any // rule stack, allows identification of the current rule in errors rstack []*rule @@ -1275,7 +1277,7 @@ type parser struct { choiceNoMatch string // recovery expression stack, keeps track of the currently available recovery expression, these are traversed in reverse - recoveryStack []map[string]interface{} + recoveryStack []map[string]any } // push a variable set on the vstack. @@ -1295,7 +1297,7 @@ func (p *parser) pushV() { return } - m = make(map[string]interface{}) + m = make(map[string]any) p.vstack[len(p.vstack)-1] = m } @@ -1311,7 +1313,7 @@ func (p *parser) popV() { } // push a recovery expression with its labels to the recoveryStack -func (p *parser) pushRecovery(labels []string, expr interface{}) { +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) @@ -1320,7 +1322,7 @@ func (p *parser) pushRecovery(labels []string, expr interface{}) { p.recoveryStack = p.recoveryStack[:len(p.recoveryStack)+1] } - m := make(map[string]interface{}, len(labels)) + m := make(map[string]any, len(labels)) for _, fl := range labels { m[fl] = expr } @@ -1440,11 +1442,11 @@ func (p *parser) restore(pt savepoint) { // copies of the state to allow the parser to properly restore the state in // the case of backtracking. type Cloner interface { - Clone() interface{} + Clone() any } var statePool = &sync.Pool{ - New: func() interface{} { return make(storeDict) }, + New: func() any { return make(storeDict) }, } func (sd storeDict) Discard() { @@ -1486,7 +1488,7 @@ func (p *parser) sliceFrom(start savepoint) []byte { return p.data[start.position.offset:p.pt.position.offset] } -func (p *parser) getMemoized(node interface{}) (resultTuple, bool) { +func (p *parser) getMemoized(node any) (resultTuple, bool) { if len(p.memo) == 0 { return resultTuple{}, false } @@ -1498,13 +1500,13 @@ func (p *parser) getMemoized(node interface{}) (resultTuple, bool) { return res, ok } -func (p *parser) setMemoized(pt savepoint, node interface{}, tuple resultTuple) { +func (p *parser) setMemoized(pt savepoint, node any, tuple resultTuple) { if p.memo == nil { - p.memo = make(map[int]map[interface{}]resultTuple) + p.memo = make(map[int]map[any]resultTuple) } m := p.memo[pt.offset] if m == nil { - m = make(map[interface{}]resultTuple) + m = make(map[any]resultTuple) p.memo[pt.offset] = m } m[node] = tuple @@ -1518,7 +1520,7 @@ func (p *parser) buildRulesTable(g *grammar) { } // nolint: gocyclo -func (p *parser) parse(g *grammar) (val interface{}, err error) { +func (p *parser) parse(g *grammar) (val any, err error) { if len(g.rules) == 0 { p.addErr(errNoRule) return nil, p.errs.err() @@ -1595,7 +1597,7 @@ func listJoin(list []string, sep string, lastSep string) string { } } -func (p *parser) parseRule(rule *rule) (interface{}, bool) { +func (p *parser) parseRule(rule *rule) (any, bool) { if p.debug { defer p.out(p.in("parseRule " + rule.name)) } @@ -1625,7 +1627,7 @@ func (p *parser) parseRule(rule *rule) (interface{}, bool) { } // nolint: gocyclo -func (p *parser) parseExpr(expr interface{}) (interface{}, bool) { +func (p *parser) parseExpr(expr any) (any, bool) { var pt savepoint if p.memoize { @@ -1642,7 +1644,7 @@ func (p *parser) parseExpr(expr interface{}) (interface{}, bool) { panic(errMaxExprCnt) } - var val interface{} + var val any var ok bool switch expr := expr.(type) { case *actionExpr: @@ -1690,7 +1692,7 @@ func (p *parser) parseExpr(expr interface{}) (interface{}, bool) { return val, ok } -func (p *parser) parseActionExpr(act *actionExpr) (interface{}, bool) { +func (p *parser) parseActionExpr(act *actionExpr) (any, bool) { if p.debug { defer p.out(p.in("parseActionExpr")) } @@ -1715,7 +1717,7 @@ func (p *parser) parseActionExpr(act *actionExpr) (interface{}, bool) { return val, ok } -func (p *parser) parseAndCodeExpr(and *andCodeExpr) (interface{}, bool) { +func (p *parser) parseAndCodeExpr(and *andCodeExpr) (any, bool) { if p.debug { defer p.out(p.in("parseAndCodeExpr")) } @@ -1731,7 +1733,7 @@ func (p *parser) parseAndCodeExpr(and *andCodeExpr) (interface{}, bool) { return nil, ok } -func (p *parser) parseAndExpr(and *andExpr) (interface{}, bool) { +func (p *parser) parseAndExpr(and *andExpr) (any, bool) { if p.debug { defer p.out(p.in("parseAndExpr")) } @@ -1747,7 +1749,7 @@ func (p *parser) parseAndExpr(and *andExpr) (interface{}, bool) { return nil, ok } -func (p *parser) parseAnyMatcher(any *anyMatcher) (interface{}, bool) { +func (p *parser) parseAnyMatcher(any *anyMatcher) (any, bool) { if p.debug { defer p.out(p.in("parseAnyMatcher")) } @@ -1764,7 +1766,7 @@ func (p *parser) parseAnyMatcher(any *anyMatcher) (interface{}, bool) { } // nolint: gocyclo -func (p *parser) parseCharClassMatcher(chr *charClassMatcher) (interface{}, bool) { +func (p *parser) parseCharClassMatcher(chr *charClassMatcher) (any, bool) { if p.debug { defer p.out(p.in("parseCharClassMatcher")) } @@ -1845,7 +1847,7 @@ func (p *parser) incChoiceAltCnt(ch *choiceExpr, altI int) { m[alt]++ } -func (p *parser) parseChoiceExpr(ch *choiceExpr) (interface{}, bool) { +func (p *parser) parseChoiceExpr(ch *choiceExpr) (any, bool) { if p.debug { defer p.out(p.in("parseChoiceExpr")) } @@ -1869,7 +1871,7 @@ func (p *parser) parseChoiceExpr(ch *choiceExpr) (interface{}, bool) { return nil, false } -func (p *parser) parseLabeledExpr(lab *labeledExpr) (interface{}, bool) { +func (p *parser) parseLabeledExpr(lab *labeledExpr) (any, bool) { if p.debug { defer p.out(p.in("parseLabeledExpr")) } @@ -1884,7 +1886,7 @@ func (p *parser) parseLabeledExpr(lab *labeledExpr) (interface{}, bool) { return val, ok } -func (p *parser) parseLitMatcher(lit *litMatcher) (interface{}, bool) { +func (p *parser) parseLitMatcher(lit *litMatcher) (any, bool) { if p.debug { defer p.out(p.in("parseLitMatcher")) } @@ -1906,7 +1908,7 @@ func (p *parser) parseLitMatcher(lit *litMatcher) (interface{}, bool) { return p.sliceFrom(start), true } -func (p *parser) parseNotCodeExpr(not *notCodeExpr) (interface{}, bool) { +func (p *parser) parseNotCodeExpr(not *notCodeExpr) (any, bool) { if p.debug { defer p.out(p.in("parseNotCodeExpr")) } @@ -1922,7 +1924,7 @@ func (p *parser) parseNotCodeExpr(not *notCodeExpr) (interface{}, bool) { return nil, !ok } -func (p *parser) parseNotExpr(not *notExpr) (interface{}, bool) { +func (p *parser) parseNotExpr(not *notExpr) (any, bool) { if p.debug { defer p.out(p.in("parseNotExpr")) } @@ -1940,12 +1942,12 @@ func (p *parser) parseNotExpr(not *notExpr) (interface{}, bool) { return nil, !ok } -func (p *parser) parseOneOrMoreExpr(expr *oneOrMoreExpr) (interface{}, bool) { +func (p *parser) parseOneOrMoreExpr(expr *oneOrMoreExpr) (any, bool) { if p.debug { defer p.out(p.in("parseOneOrMoreExpr")) } - var vals []interface{} + var vals []any for { p.pushV() @@ -1962,7 +1964,7 @@ func (p *parser) parseOneOrMoreExpr(expr *oneOrMoreExpr) (interface{}, bool) { } } -func (p *parser) parseRecoveryExpr(recover *recoveryExpr) (interface{}, bool) { +func (p *parser) parseRecoveryExpr(recover *recoveryExpr) (any, bool) { if p.debug { defer p.out(p.in("parseRecoveryExpr (" + strings.Join(recover.failureLabel, ",") + ")")) } @@ -1974,7 +1976,7 @@ func (p *parser) parseRecoveryExpr(recover *recoveryExpr) (interface{}, bool) { return val, ok } -func (p *parser) parseRuleRefExpr(ref *ruleRefExpr) (interface{}, bool) { +func (p *parser) parseRuleRefExpr(ref *ruleRefExpr) (any, bool) { if p.debug { defer p.out(p.in("parseRuleRefExpr " + ref.name)) } @@ -1991,12 +1993,12 @@ func (p *parser) parseRuleRefExpr(ref *ruleRefExpr) (interface{}, bool) { return p.parseRule(rule) } -func (p *parser) parseSeqExpr(seq *seqExpr) (interface{}, bool) { +func (p *parser) parseSeqExpr(seq *seqExpr) (any, bool) { if p.debug { defer p.out(p.in("parseSeqExpr")) } - vals := make([]interface{}, 0, len(seq.exprs)) + vals := make([]any, 0, len(seq.exprs)) pt := p.pt state := p.cloneState() @@ -2012,7 +2014,7 @@ func (p *parser) parseSeqExpr(seq *seqExpr) (interface{}, bool) { return vals, true } -func (p *parser) parseStateCodeExpr(state *stateCodeExpr) (interface{}, bool) { +func (p *parser) parseStateCodeExpr(state *stateCodeExpr) (any, bool) { if p.debug { defer p.out(p.in("parseStateCodeExpr")) } @@ -2024,7 +2026,7 @@ func (p *parser) parseStateCodeExpr(state *stateCodeExpr) (interface{}, bool) { return nil, true } -func (p *parser) parseThrowExpr(expr *throwExpr) (interface{}, bool) { +func (p *parser) parseThrowExpr(expr *throwExpr) (any, bool) { if p.debug { defer p.out(p.in("parseThrowExpr")) } @@ -2040,12 +2042,12 @@ func (p *parser) parseThrowExpr(expr *throwExpr) (interface{}, bool) { return nil, false } -func (p *parser) parseZeroOrMoreExpr(expr *zeroOrMoreExpr) (interface{}, bool) { +func (p *parser) parseZeroOrMoreExpr(expr *zeroOrMoreExpr) (any, bool) { if p.debug { defer p.out(p.in("parseZeroOrMoreExpr")) } - var vals []interface{} + var vals []any for { p.pushV() @@ -2058,7 +2060,7 @@ func (p *parser) parseZeroOrMoreExpr(expr *zeroOrMoreExpr) (interface{}, bool) { } } -func (p *parser) parseZeroOrOneExpr(expr *zeroOrOneExpr) (interface{}, bool) { +func (p *parser) parseZeroOrOneExpr(expr *zeroOrOneExpr) (any, bool) { if p.debug { defer p.out(p.in("parseZeroOrOneExpr")) } diff --git a/examples/indentation/indentation.peg b/examples/indentation/indentation.peg index e203c236..c824bbb8 100644 --- a/examples/indentation/indentation.peg +++ b/examples/indentation/indentation.peg @@ -1,11 +1,11 @@ { package main -func toIfaceSlice(v interface{}) []interface{} { +func toAnySlice(v any) []any { if v == nil { return nil } - return v.([]interface{}) + return v.([]any) } } @@ -43,7 +43,7 @@ Comment ← "//" [^\r\n]* EOF ← !. -INDENTATION ← spaces:" "* &{ return len(toIfaceSlice(spaces)) == c.state["Indentation"].(int), nil } +INDENTATION ← spaces:" "* &{ return len(toAnySlice(spaces)) == c.state["Indentation"].(int), nil } INDENT ← #{ c.state["Indentation"] = c.state["Indentation"].(int) + 4; return nil } diff --git a/examples/indentation/indentation_ast.go b/examples/indentation/indentation_ast.go index 2b69b054..fa768ec9 100644 --- a/examples/indentation/indentation_ast.go +++ b/examples/indentation/indentation_ast.go @@ -45,6 +45,7 @@ type ProgramNode struct { func newProgramNode(stmts StatementsNode, ret ReturnNode) (ProgramNode, error) { return ProgramNode{stmts, ret}, nil } + func (n ProgramNode) exec() (int, error) { err := n.statements.exec() if err != nil { @@ -58,15 +59,15 @@ type StatementsNode struct { statements []Statement } -func newStatementsNode(stmts interface{}) (StatementsNode, error) { - - st := toIfaceSlice(stmts) +func newStatementsNode(stmts any) (StatementsNode, error) { + st := toAnySlice(stmts) ex := make([]Statement, len(st)) for i, v := range st { ex[i] = v.(Statement) } return StatementsNode{ex}, nil } + func (n StatementsNode) exec() error { for _, v := range n.statements { err := v.exec() @@ -85,6 +86,7 @@ type ReturnNode struct { func newReturnNode(arg IdentifierNode) (ReturnNode, error) { return ReturnNode{arg}, nil } + func (n ReturnNode) exec() (int, error) { v, err := n.arg.exec() return v, err @@ -99,6 +101,7 @@ type IfNode struct { func newIfNode(arg LogicalExpressionNode, stmts StatementsNode) (IfNode, error) { return IfNode{arg, stmts}, nil } + func (n IfNode) exec() error { cond, err := n.arg.exec() if err != nil { @@ -120,6 +123,7 @@ type AssignmentNode struct { func newAssignmentNode(lvalue IdentifierNode, rvalue AdditiveExpressionNode) (AssignmentNode, error) { return AssignmentNode{lvalue.val, rvalue}, nil } + func (n AssignmentNode) exec() error { v, err := n.rvalue.exec() if err != nil { @@ -137,6 +141,7 @@ type LogicalExpressionNode struct { func newLogicalExpressionNode(expr PrimaryExpressionNode) (LogicalExpressionNode, error) { return LogicalExpressionNode{expr}, nil } + func (n LogicalExpressionNode) exec() (bool, error) { ret, err := n.expr.exec() b := ret != 0 @@ -145,23 +150,23 @@ func (n LogicalExpressionNode) exec() (bool, error) { // AdditiveExpressionNode is a additive expression type AdditiveExpressionNode struct { - arg1 interface{} + arg1 any arg2 PrimaryExpressionNode op string } -func newAdditiveExpressionNode(arg PrimaryExpressionNode, rest interface{}) (AdditiveExpressionNode, error) { +func newAdditiveExpressionNode(arg PrimaryExpressionNode, rest any) (AdditiveExpressionNode, error) { var a AdditiveExpressionNode - var arg1 interface{} = arg + var arg1 any = arg - restSl := toIfaceSlice(rest) + restSl := toAnySlice(rest) if len(restSl) == 0 { zero, _ := newIntegerNode("0") arg2, _ := newPrimaryExpressionNode(zero) a = AdditiveExpressionNode{arg1, arg2, "+"} } for _, v := range restSl { - restExpr := toIfaceSlice(v) + restExpr := toAnySlice(v) arg2 := restExpr[3].(PrimaryExpressionNode) op := restExpr[1].(string) a = AdditiveExpressionNode{arg1, arg2, op} @@ -169,6 +174,7 @@ func newAdditiveExpressionNode(arg PrimaryExpressionNode, rest interface{}) (Add } return a, nil } + func (n AdditiveExpressionNode) exec() (int, error) { var v, varg1, varg2 int var err error @@ -197,12 +203,13 @@ func (n AdditiveExpressionNode) exec() (int, error) { // PrimaryExpressionNode is a basic element type PrimaryExpressionNode struct { - arg interface{} + arg any } -func newPrimaryExpressionNode(arg interface{}) (PrimaryExpressionNode, error) { +func newPrimaryExpressionNode(arg any) (PrimaryExpressionNode, error) { return PrimaryExpressionNode{arg}, nil } + func (n PrimaryExpressionNode) exec() (int, error) { var v int var err error @@ -226,6 +233,7 @@ func newIntegerNode(val string) (IntegerNode, error) { v, err := strconv.ParseInt(val, 0, 64) return IntegerNode{int(v)}, err } + func (n IntegerNode) exec() (int, error) { return n.val, nil } @@ -238,6 +246,7 @@ type IdentifierNode struct { func newIdentifierNode(val string) (IdentifierNode, error) { return IdentifierNode{val}, nil } + func (n IdentifierNode) exec() (int, error) { v, ok := lvalues[n.val] if !ok { diff --git a/examples/json/json.go b/examples/json/json.go index e330b700..6e6b17b0 100644 --- a/examples/json/json.go +++ b/examples/json/json.go @@ -22,38 +22,38 @@ import ( "unicode/utf8" ) -func toIfaceSlice(v interface{}) []interface{} { +func toAnySlice(v any) []any { if v == nil { return nil } - return v.([]interface{}) + return v.([]any) } var g = &grammar{ rules: []*rule{ { name: "JSON", - pos: position{line: 17, col: 1, offset: 347}, + pos: position{line: 17, col: 1, offset: 321}, expr: &actionExpr{ - pos: position{line: 17, col: 8, offset: 356}, + pos: position{line: 17, col: 8, offset: 330}, run: (*parser).callonJSON1, expr: &seqExpr{ - pos: position{line: 17, col: 8, offset: 356}, - exprs: []interface{}{ + pos: position{line: 17, col: 8, offset: 330}, + exprs: []any{ &ruleRefExpr{ - pos: position{line: 17, col: 8, offset: 356}, + pos: position{line: 17, col: 8, offset: 330}, name: "_", }, &labeledExpr{ - pos: position{line: 17, col: 10, offset: 358}, + pos: position{line: 17, col: 10, offset: 332}, label: "val", expr: &ruleRefExpr{ - pos: position{line: 17, col: 14, offset: 362}, + pos: position{line: 17, col: 14, offset: 336}, name: "Value", }, }, &ruleRefExpr{ - pos: position{line: 17, col: 20, offset: 368}, + pos: position{line: 17, col: 20, offset: 342}, name: "EOF", }, }, @@ -62,48 +62,48 @@ var g = &grammar{ }, { name: "Value", - pos: position{line: 21, col: 1, offset: 397}, + pos: position{line: 21, col: 1, offset: 371}, expr: &actionExpr{ - pos: position{line: 21, col: 9, offset: 407}, + pos: position{line: 21, col: 9, offset: 381}, run: (*parser).callonValue1, expr: &seqExpr{ - pos: position{line: 21, col: 9, offset: 407}, - exprs: []interface{}{ + pos: position{line: 21, col: 9, offset: 381}, + exprs: []any{ &labeledExpr{ - pos: position{line: 21, col: 9, offset: 407}, + pos: position{line: 21, col: 9, offset: 381}, label: "val", expr: &choiceExpr{ - pos: position{line: 21, col: 15, offset: 413}, - alternatives: []interface{}{ + pos: position{line: 21, col: 15, offset: 387}, + alternatives: []any{ &ruleRefExpr{ - pos: position{line: 21, col: 15, offset: 413}, + pos: position{line: 21, col: 15, offset: 387}, name: "Object", }, &ruleRefExpr{ - pos: position{line: 21, col: 24, offset: 422}, + pos: position{line: 21, col: 24, offset: 396}, name: "Array", }, &ruleRefExpr{ - pos: position{line: 21, col: 32, offset: 430}, + pos: position{line: 21, col: 32, offset: 404}, name: "Number", }, &ruleRefExpr{ - pos: position{line: 21, col: 41, offset: 439}, + pos: position{line: 21, col: 41, offset: 413}, name: "String", }, &ruleRefExpr{ - pos: position{line: 21, col: 50, offset: 448}, + pos: position{line: 21, col: 50, offset: 422}, name: "Bool", }, &ruleRefExpr{ - pos: position{line: 21, col: 57, offset: 455}, + pos: position{line: 21, col: 57, offset: 429}, name: "Null", }, }, }, }, &ruleRefExpr{ - pos: position{line: 21, col: 64, offset: 462}, + pos: position{line: 21, col: 64, offset: 436}, name: "_", }, }, @@ -112,88 +112,88 @@ var g = &grammar{ }, { name: "Object", - pos: position{line: 25, col: 1, offset: 489}, + pos: position{line: 25, col: 1, offset: 463}, expr: &actionExpr{ - pos: position{line: 25, col: 10, offset: 500}, + pos: position{line: 25, col: 10, offset: 474}, run: (*parser).callonObject1, expr: &seqExpr{ - pos: position{line: 25, col: 10, offset: 500}, - exprs: []interface{}{ + pos: position{line: 25, col: 10, offset: 474}, + exprs: []any{ &litMatcher{ - pos: position{line: 25, col: 10, offset: 500}, + pos: position{line: 25, col: 10, offset: 474}, val: "{", ignoreCase: false, want: "\"{\"", }, &ruleRefExpr{ - pos: position{line: 25, col: 14, offset: 504}, + pos: position{line: 25, col: 14, offset: 478}, name: "_", }, &labeledExpr{ - pos: position{line: 25, col: 16, offset: 506}, + pos: position{line: 25, col: 16, offset: 480}, label: "vals", expr: &zeroOrOneExpr{ - pos: position{line: 25, col: 21, offset: 511}, + pos: position{line: 25, col: 21, offset: 485}, expr: &seqExpr{ - pos: position{line: 25, col: 23, offset: 513}, - exprs: []interface{}{ + pos: position{line: 25, col: 23, offset: 487}, + exprs: []any{ &ruleRefExpr{ - pos: position{line: 25, col: 23, offset: 513}, + pos: position{line: 25, col: 23, offset: 487}, name: "String", }, &ruleRefExpr{ - pos: position{line: 25, col: 30, offset: 520}, + pos: position{line: 25, col: 30, offset: 494}, name: "_", }, &litMatcher{ - pos: position{line: 25, col: 32, offset: 522}, + pos: position{line: 25, col: 32, offset: 496}, val: ":", ignoreCase: false, want: "\":\"", }, &ruleRefExpr{ - pos: position{line: 25, col: 36, offset: 526}, + pos: position{line: 25, col: 36, offset: 500}, name: "_", }, &ruleRefExpr{ - pos: position{line: 25, col: 38, offset: 528}, + pos: position{line: 25, col: 38, offset: 502}, name: "Value", }, &zeroOrMoreExpr{ - pos: position{line: 25, col: 44, offset: 534}, + pos: position{line: 25, col: 44, offset: 508}, expr: &seqExpr{ - pos: position{line: 25, col: 46, offset: 536}, - exprs: []interface{}{ + pos: position{line: 25, col: 46, offset: 510}, + exprs: []any{ &litMatcher{ - pos: position{line: 25, col: 46, offset: 536}, + pos: position{line: 25, col: 46, offset: 510}, val: ",", ignoreCase: false, want: "\",\"", }, &ruleRefExpr{ - pos: position{line: 25, col: 50, offset: 540}, + pos: position{line: 25, col: 50, offset: 514}, name: "_", }, &ruleRefExpr{ - pos: position{line: 25, col: 52, offset: 542}, + pos: position{line: 25, col: 52, offset: 516}, name: "String", }, &ruleRefExpr{ - pos: position{line: 25, col: 59, offset: 549}, + pos: position{line: 25, col: 59, offset: 523}, name: "_", }, &litMatcher{ - pos: position{line: 25, col: 61, offset: 551}, + pos: position{line: 25, col: 61, offset: 525}, val: ":", ignoreCase: false, want: "\":\"", }, &ruleRefExpr{ - pos: position{line: 25, col: 65, offset: 555}, + pos: position{line: 25, col: 65, offset: 529}, name: "_", }, &ruleRefExpr{ - pos: position{line: 25, col: 67, offset: 557}, + pos: position{line: 25, col: 67, offset: 531}, name: "Value", }, }, @@ -204,7 +204,7 @@ var g = &grammar{ }, }, &litMatcher{ - pos: position{line: 25, col: 79, offset: 569}, + pos: position{line: 25, col: 79, offset: 543}, val: "}", ignoreCase: false, want: "\"}\"", @@ -215,52 +215,52 @@ var g = &grammar{ }, { name: "Array", - pos: position{line: 40, col: 1, offset: 911}, + pos: position{line: 40, col: 1, offset: 871}, expr: &actionExpr{ - pos: position{line: 40, col: 9, offset: 921}, + pos: position{line: 40, col: 9, offset: 881}, run: (*parser).callonArray1, expr: &seqExpr{ - pos: position{line: 40, col: 9, offset: 921}, - exprs: []interface{}{ + pos: position{line: 40, col: 9, offset: 881}, + exprs: []any{ &litMatcher{ - pos: position{line: 40, col: 9, offset: 921}, + pos: position{line: 40, col: 9, offset: 881}, val: "[", ignoreCase: false, want: "\"[\"", }, &ruleRefExpr{ - pos: position{line: 40, col: 13, offset: 925}, + pos: position{line: 40, col: 13, offset: 885}, name: "_", }, &labeledExpr{ - pos: position{line: 40, col: 15, offset: 927}, + pos: position{line: 40, col: 15, offset: 887}, label: "vals", expr: &zeroOrOneExpr{ - pos: position{line: 40, col: 20, offset: 932}, + pos: position{line: 40, col: 20, offset: 892}, expr: &seqExpr{ - pos: position{line: 40, col: 22, offset: 934}, - exprs: []interface{}{ + pos: position{line: 40, col: 22, offset: 894}, + exprs: []any{ &ruleRefExpr{ - pos: position{line: 40, col: 22, offset: 934}, + pos: position{line: 40, col: 22, offset: 894}, name: "Value", }, &zeroOrMoreExpr{ - pos: position{line: 40, col: 28, offset: 940}, + pos: position{line: 40, col: 28, offset: 900}, expr: &seqExpr{ - pos: position{line: 40, col: 30, offset: 942}, - exprs: []interface{}{ + pos: position{line: 40, col: 30, offset: 902}, + exprs: []any{ &litMatcher{ - pos: position{line: 40, col: 30, offset: 942}, + pos: position{line: 40, col: 30, offset: 902}, val: ",", ignoreCase: false, want: "\",\"", }, &ruleRefExpr{ - pos: position{line: 40, col: 34, offset: 946}, + pos: position{line: 40, col: 34, offset: 906}, name: "_", }, &ruleRefExpr{ - pos: position{line: 40, col: 36, offset: 948}, + pos: position{line: 40, col: 36, offset: 908}, name: "Value", }, }, @@ -271,7 +271,7 @@ var g = &grammar{ }, }, &litMatcher{ - pos: position{line: 40, col: 48, offset: 960}, + pos: position{line: 40, col: 48, offset: 920}, val: "]", ignoreCase: false, want: "\"]\"", @@ -282,41 +282,41 @@ var g = &grammar{ }, { name: "Number", - pos: position{line: 54, col: 1, offset: 1266}, + pos: position{line: 54, col: 1, offset: 1204}, expr: &actionExpr{ - pos: position{line: 54, col: 10, offset: 1277}, + pos: position{line: 54, col: 10, offset: 1215}, run: (*parser).callonNumber1, expr: &seqExpr{ - pos: position{line: 54, col: 10, offset: 1277}, - exprs: []interface{}{ + pos: position{line: 54, col: 10, offset: 1215}, + exprs: []any{ &zeroOrOneExpr{ - pos: position{line: 54, col: 10, offset: 1277}, + pos: position{line: 54, col: 10, offset: 1215}, expr: &litMatcher{ - pos: position{line: 54, col: 10, offset: 1277}, + pos: position{line: 54, col: 10, offset: 1215}, val: "-", ignoreCase: false, want: "\"-\"", }, }, &ruleRefExpr{ - pos: position{line: 54, col: 15, offset: 1282}, + pos: position{line: 54, col: 15, offset: 1220}, name: "Integer", }, &zeroOrOneExpr{ - pos: position{line: 54, col: 23, offset: 1290}, + pos: position{line: 54, col: 23, offset: 1228}, expr: &seqExpr{ - pos: position{line: 54, col: 25, offset: 1292}, - exprs: []interface{}{ + pos: position{line: 54, col: 25, offset: 1230}, + exprs: []any{ &litMatcher{ - pos: position{line: 54, col: 25, offset: 1292}, + pos: position{line: 54, col: 25, offset: 1230}, val: ".", ignoreCase: false, want: "\".\"", }, &oneOrMoreExpr{ - pos: position{line: 54, col: 29, offset: 1296}, + pos: position{line: 54, col: 29, offset: 1234}, expr: &ruleRefExpr{ - pos: position{line: 54, col: 29, offset: 1296}, + pos: position{line: 54, col: 29, offset: 1234}, name: "DecimalDigit", }, }, @@ -324,9 +324,9 @@ var g = &grammar{ }, }, &zeroOrOneExpr{ - pos: position{line: 54, col: 46, offset: 1313}, + pos: position{line: 54, col: 46, offset: 1251}, expr: &ruleRefExpr{ - pos: position{line: 54, col: 46, offset: 1313}, + pos: position{line: 54, col: 46, offset: 1251}, name: "Exponent", }, }, @@ -336,27 +336,27 @@ var g = &grammar{ }, { name: "Integer", - pos: position{line: 60, col: 1, offset: 1468}, + pos: position{line: 60, col: 1, offset: 1406}, expr: &choiceExpr{ - pos: position{line: 60, col: 11, offset: 1480}, - alternatives: []interface{}{ + pos: position{line: 60, col: 11, offset: 1418}, + alternatives: []any{ &litMatcher{ - pos: position{line: 60, col: 11, offset: 1480}, + pos: position{line: 60, col: 11, offset: 1418}, val: "0", ignoreCase: false, want: "\"0\"", }, &seqExpr{ - pos: position{line: 60, col: 17, offset: 1486}, - exprs: []interface{}{ + pos: position{line: 60, col: 17, offset: 1424}, + exprs: []any{ &ruleRefExpr{ - pos: position{line: 60, col: 17, offset: 1486}, + pos: position{line: 60, col: 17, offset: 1424}, name: "NonZeroDecimalDigit", }, &zeroOrMoreExpr{ - pos: position{line: 60, col: 37, offset: 1506}, + pos: position{line: 60, col: 37, offset: 1444}, expr: &ruleRefExpr{ - pos: position{line: 60, col: 37, offset: 1506}, + pos: position{line: 60, col: 37, offset: 1444}, name: "DecimalDigit", }, }, @@ -367,20 +367,20 @@ var g = &grammar{ }, { name: "Exponent", - pos: position{line: 62, col: 1, offset: 1521}, + pos: position{line: 62, col: 1, offset: 1459}, expr: &seqExpr{ - pos: position{line: 62, col: 12, offset: 1534}, - exprs: []interface{}{ + pos: position{line: 62, col: 12, offset: 1472}, + exprs: []any{ &litMatcher{ - pos: position{line: 62, col: 12, offset: 1534}, + pos: position{line: 62, col: 12, offset: 1472}, val: "e", ignoreCase: true, want: "\"e\"i", }, &zeroOrOneExpr{ - pos: position{line: 62, col: 17, offset: 1539}, + pos: position{line: 62, col: 17, offset: 1477}, expr: &charClassMatcher{ - pos: position{line: 62, col: 17, offset: 1539}, + pos: position{line: 62, col: 17, offset: 1477}, val: "[+-]", chars: []rune{'+', '-'}, ignoreCase: false, @@ -388,9 +388,9 @@ var g = &grammar{ }, }, &oneOrMoreExpr{ - pos: position{line: 62, col: 23, offset: 1545}, + pos: position{line: 62, col: 23, offset: 1483}, expr: &ruleRefExpr{ - pos: position{line: 62, col: 23, offset: 1545}, + pos: position{line: 62, col: 23, offset: 1483}, name: "DecimalDigit", }, }, @@ -399,50 +399,50 @@ var g = &grammar{ }, { name: "String", - pos: position{line: 64, col: 1, offset: 1560}, + pos: position{line: 64, col: 1, offset: 1498}, expr: &actionExpr{ - pos: position{line: 64, col: 10, offset: 1571}, + pos: position{line: 64, col: 10, offset: 1509}, run: (*parser).callonString1, expr: &seqExpr{ - pos: position{line: 64, col: 10, offset: 1571}, - exprs: []interface{}{ + pos: position{line: 64, col: 10, offset: 1509}, + exprs: []any{ &litMatcher{ - pos: position{line: 64, col: 10, offset: 1571}, + pos: position{line: 64, col: 10, offset: 1509}, val: "\"", ignoreCase: false, want: "\"\\\"\"", }, &zeroOrMoreExpr{ - pos: position{line: 64, col: 14, offset: 1575}, + pos: position{line: 64, col: 14, offset: 1513}, expr: &choiceExpr{ - pos: position{line: 64, col: 16, offset: 1577}, - alternatives: []interface{}{ + pos: position{line: 64, col: 16, offset: 1515}, + alternatives: []any{ &seqExpr{ - pos: position{line: 64, col: 16, offset: 1577}, - exprs: []interface{}{ + pos: position{line: 64, col: 16, offset: 1515}, + exprs: []any{ ¬Expr{ - pos: position{line: 64, col: 16, offset: 1577}, + pos: position{line: 64, col: 16, offset: 1515}, expr: &ruleRefExpr{ - pos: position{line: 64, col: 17, offset: 1578}, + pos: position{line: 64, col: 17, offset: 1516}, name: "EscapedChar", }, }, &anyMatcher{ - line: 64, col: 29, offset: 1590, + line: 64, col: 29, offset: 1528, }, }, }, &seqExpr{ - pos: position{line: 64, col: 33, offset: 1594}, - exprs: []interface{}{ + pos: position{line: 64, col: 33, offset: 1532}, + exprs: []any{ &litMatcher{ - pos: position{line: 64, col: 33, offset: 1594}, + pos: position{line: 64, col: 33, offset: 1532}, val: "\\", ignoreCase: false, want: "\"\\\\\"", }, &ruleRefExpr{ - pos: position{line: 64, col: 38, offset: 1599}, + pos: position{line: 64, col: 38, offset: 1537}, name: "EscapeSequence", }, }, @@ -451,7 +451,7 @@ var g = &grammar{ }, }, &litMatcher{ - pos: position{line: 64, col: 56, offset: 1617}, + pos: position{line: 64, col: 56, offset: 1555}, val: "\"", ignoreCase: false, want: "\"\\\"\"", @@ -462,9 +462,9 @@ var g = &grammar{ }, { name: "EscapedChar", - pos: position{line: 69, col: 1, offset: 1735}, + pos: position{line: 69, col: 1, offset: 1673}, expr: &charClassMatcher{ - pos: position{line: 69, col: 15, offset: 1751}, + pos: position{line: 69, col: 15, offset: 1689}, val: "[\\x00-\\x1f\"\\\\]", chars: []rune{'"', '\\'}, ranges: []rune{'\x00', '\x1f'}, @@ -474,16 +474,16 @@ var g = &grammar{ }, { name: "EscapeSequence", - pos: position{line: 71, col: 1, offset: 1767}, + pos: position{line: 71, col: 1, offset: 1705}, expr: &choiceExpr{ - pos: position{line: 71, col: 18, offset: 1786}, - alternatives: []interface{}{ + pos: position{line: 71, col: 18, offset: 1724}, + alternatives: []any{ &ruleRefExpr{ - pos: position{line: 71, col: 18, offset: 1786}, + pos: position{line: 71, col: 18, offset: 1724}, name: "SingleCharEscape", }, &ruleRefExpr{ - pos: position{line: 71, col: 37, offset: 1805}, + pos: position{line: 71, col: 37, offset: 1743}, name: "UnicodeEscape", }, }, @@ -491,9 +491,9 @@ var g = &grammar{ }, { name: "SingleCharEscape", - pos: position{line: 73, col: 1, offset: 1820}, + pos: position{line: 73, col: 1, offset: 1758}, expr: &charClassMatcher{ - pos: position{line: 73, col: 20, offset: 1841}, + pos: position{line: 73, col: 20, offset: 1779}, val: "[\"\\\\/bfnrt]", chars: []rune{'"', '\\', '/', 'b', 'f', 'n', 'r', 't'}, ignoreCase: false, @@ -502,30 +502,30 @@ var g = &grammar{ }, { name: "UnicodeEscape", - pos: position{line: 75, col: 1, offset: 1854}, + pos: position{line: 75, col: 1, offset: 1792}, expr: &seqExpr{ - pos: position{line: 75, col: 17, offset: 1872}, - exprs: []interface{}{ + pos: position{line: 75, col: 17, offset: 1810}, + exprs: []any{ &litMatcher{ - pos: position{line: 75, col: 17, offset: 1872}, + pos: position{line: 75, col: 17, offset: 1810}, val: "u", ignoreCase: false, want: "\"u\"", }, &ruleRefExpr{ - pos: position{line: 75, col: 21, offset: 1876}, + pos: position{line: 75, col: 21, offset: 1814}, name: "HexDigit", }, &ruleRefExpr{ - pos: position{line: 75, col: 30, offset: 1885}, + pos: position{line: 75, col: 30, offset: 1823}, name: "HexDigit", }, &ruleRefExpr{ - pos: position{line: 75, col: 39, offset: 1894}, + pos: position{line: 75, col: 39, offset: 1832}, name: "HexDigit", }, &ruleRefExpr{ - pos: position{line: 75, col: 48, offset: 1903}, + pos: position{line: 75, col: 48, offset: 1841}, name: "HexDigit", }, }, @@ -533,9 +533,9 @@ var g = &grammar{ }, { name: "DecimalDigit", - pos: position{line: 77, col: 1, offset: 1913}, + pos: position{line: 77, col: 1, offset: 1851}, expr: &charClassMatcher{ - pos: position{line: 77, col: 16, offset: 1930}, + pos: position{line: 77, col: 16, offset: 1868}, val: "[0-9]", ranges: []rune{'0', '9'}, ignoreCase: false, @@ -544,9 +544,9 @@ var g = &grammar{ }, { name: "NonZeroDecimalDigit", - pos: position{line: 79, col: 1, offset: 1937}, + pos: position{line: 79, col: 1, offset: 1875}, expr: &charClassMatcher{ - pos: position{line: 79, col: 23, offset: 1961}, + pos: position{line: 79, col: 23, offset: 1899}, val: "[1-9]", ranges: []rune{'1', '9'}, ignoreCase: false, @@ -555,9 +555,9 @@ var g = &grammar{ }, { name: "HexDigit", - pos: position{line: 81, col: 1, offset: 1968}, + pos: position{line: 81, col: 1, offset: 1906}, expr: &charClassMatcher{ - pos: position{line: 81, col: 12, offset: 1981}, + pos: position{line: 81, col: 12, offset: 1919}, val: "[0-9a-f]i", ranges: []rune{'0', '9', 'a', 'f'}, ignoreCase: true, @@ -566,25 +566,25 @@ var g = &grammar{ }, { name: "Bool", - pos: position{line: 83, col: 1, offset: 1992}, + pos: position{line: 83, col: 1, offset: 1930}, expr: &choiceExpr{ - pos: position{line: 83, col: 8, offset: 2001}, - alternatives: []interface{}{ + pos: position{line: 83, col: 8, offset: 1939}, + alternatives: []any{ &actionExpr{ - pos: position{line: 83, col: 8, offset: 2001}, + pos: position{line: 83, col: 8, offset: 1939}, run: (*parser).callonBool2, expr: &litMatcher{ - pos: position{line: 83, col: 8, offset: 2001}, + pos: position{line: 83, col: 8, offset: 1939}, val: "true", ignoreCase: false, want: "\"true\"", }, }, &actionExpr{ - pos: position{line: 83, col: 38, offset: 2031}, + pos: position{line: 83, col: 38, offset: 1969}, run: (*parser).callonBool4, expr: &litMatcher{ - pos: position{line: 83, col: 38, offset: 2031}, + pos: position{line: 83, col: 38, offset: 1969}, val: "false", ignoreCase: false, want: "\"false\"", @@ -595,12 +595,12 @@ var g = &grammar{ }, { name: "Null", - pos: position{line: 85, col: 1, offset: 2062}, + pos: position{line: 85, col: 1, offset: 2000}, expr: &actionExpr{ - pos: position{line: 85, col: 8, offset: 2071}, + pos: position{line: 85, col: 8, offset: 2009}, run: (*parser).callonNull1, expr: &litMatcher{ - pos: position{line: 85, col: 8, offset: 2071}, + pos: position{line: 85, col: 8, offset: 2009}, val: "null", ignoreCase: false, want: "\"null\"", @@ -610,11 +610,11 @@ var g = &grammar{ { name: "_", displayName: "\"whitespace\"", - pos: position{line: 87, col: 1, offset: 2099}, + pos: position{line: 87, col: 1, offset: 2037}, expr: &zeroOrMoreExpr{ - pos: position{line: 87, col: 18, offset: 2118}, + pos: position{line: 87, col: 18, offset: 2056}, expr: &charClassMatcher{ - pos: position{line: 87, col: 18, offset: 2118}, + pos: position{line: 87, col: 18, offset: 2056}, val: "[ \\t\\r\\n]", chars: []rune{' ', '\t', '\r', '\n'}, ignoreCase: false, @@ -624,126 +624,126 @@ var g = &grammar{ }, { name: "EOF", - pos: position{line: 89, col: 1, offset: 2130}, + pos: position{line: 89, col: 1, offset: 2068}, expr: ¬Expr{ - pos: position{line: 89, col: 7, offset: 2138}, + pos: position{line: 89, col: 7, offset: 2076}, expr: &anyMatcher{ - line: 89, col: 8, offset: 2139, + line: 89, col: 8, offset: 2077, }, }, }, }, } -func (c *current) onJSON1(val interface{}) (interface{}, error) { +func (c *current) onJSON1(val any) (any, error) { return val, nil } -func (p *parser) callonJSON1() (interface{}, error) { +func (p *parser) callonJSON1() (any, error) { stack := p.vstack[len(p.vstack)-1] _ = stack return p.cur.onJSON1(stack["val"]) } -func (c *current) onValue1(val interface{}) (interface{}, error) { +func (c *current) onValue1(val any) (any, error) { return val, nil } -func (p *parser) callonValue1() (interface{}, error) { +func (p *parser) callonValue1() (any, error) { stack := p.vstack[len(p.vstack)-1] _ = stack return p.cur.onValue1(stack["val"]) } -func (c *current) onObject1(vals interface{}) (interface{}, error) { - res := make(map[string]interface{}) - valsSl := toIfaceSlice(vals) +func (c *current) onObject1(vals any) (any, error) { + res := make(map[string]any) + valsSl := toAnySlice(vals) if len(valsSl) == 0 { return res, nil } res[valsSl[0].(string)] = valsSl[4] - restSl := toIfaceSlice(valsSl[5]) + restSl := toAnySlice(valsSl[5]) for _, v := range restSl { - vSl := toIfaceSlice(v) + vSl := toAnySlice(v) res[vSl[2].(string)] = vSl[6] } return res, nil } -func (p *parser) callonObject1() (interface{}, error) { +func (p *parser) callonObject1() (any, error) { stack := p.vstack[len(p.vstack)-1] _ = stack return p.cur.onObject1(stack["vals"]) } -func (c *current) onArray1(vals interface{}) (interface{}, error) { - valsSl := toIfaceSlice(vals) +func (c *current) onArray1(vals any) (any, error) { + valsSl := toAnySlice(vals) if len(valsSl) == 0 { - return []interface{}{}, nil + return []any{}, nil } - res := []interface{}{valsSl[0]} - restSl := toIfaceSlice(valsSl[1]) + res := []any{valsSl[0]} + restSl := toAnySlice(valsSl[1]) for _, v := range restSl { - vSl := toIfaceSlice(v) + vSl := toAnySlice(v) res = append(res, vSl[2]) } return res, nil } -func (p *parser) callonArray1() (interface{}, error) { +func (p *parser) callonArray1() (any, error) { stack := p.vstack[len(p.vstack)-1] _ = stack return p.cur.onArray1(stack["vals"]) } -func (c *current) onNumber1() (interface{}, error) { +func (c *current) onNumber1() (any, error) { // JSON numbers have the same syntax as Go's, and are parseable using // strconv. return strconv.ParseFloat(string(c.text), 64) } -func (p *parser) callonNumber1() (interface{}, error) { +func (p *parser) callonNumber1() (any, error) { stack := p.vstack[len(p.vstack)-1] _ = stack return p.cur.onNumber1() } -func (c *current) onString1() (interface{}, error) { +func (c *current) onString1() (any, error) { c.text = bytes.Replace(c.text, []byte(`\/`), []byte(`/`), -1) return strconv.Unquote(string(c.text)) } -func (p *parser) callonString1() (interface{}, error) { +func (p *parser) callonString1() (any, error) { stack := p.vstack[len(p.vstack)-1] _ = stack return p.cur.onString1() } -func (c *current) onBool2() (interface{}, error) { +func (c *current) onBool2() (any, error) { return true, nil } -func (p *parser) callonBool2() (interface{}, error) { +func (p *parser) callonBool2() (any, error) { stack := p.vstack[len(p.vstack)-1] _ = stack return p.cur.onBool2() } -func (c *current) onBool4() (interface{}, error) { +func (c *current) onBool4() (any, error) { return false, nil } -func (p *parser) callonBool4() (interface{}, error) { +func (p *parser) callonBool4() (any, error) { stack := p.vstack[len(p.vstack)-1] _ = stack return p.cur.onBool4() } -func (c *current) onNull1() (interface{}, error) { +func (c *current) onNull1() (any, error) { return nil, nil } -func (p *parser) callonNull1() (interface{}, error) { +func (p *parser) callonNull1() (any, error) { stack := p.vstack[len(p.vstack)-1] _ = stack return p.cur.onNull1() @@ -887,7 +887,7 @@ func Recover(b bool) Option { // GlobalStore creates an Option to set a key to a certain value in // the globalStore. -func GlobalStore(key string, value interface{}) Option { +func GlobalStore(key string, value any) Option { return func(p *parser) Option { old := p.cur.globalStore[key] p.cur.globalStore[key] = value @@ -897,7 +897,7 @@ func GlobalStore(key string, value interface{}) Option { // InitState creates an Option to set a key to a certain value in // the global "state" store. -func InitState(key string, value interface{}) Option { +func InitState(key string, value any) Option { return func(p *parser) Option { old := p.cur.state[key] p.cur.state[key] = value @@ -906,7 +906,7 @@ func InitState(key string, value interface{}) Option { } // ParseFile parses the file identified by filename. -func ParseFile(filename string, opts ...Option) (i interface{}, err error) { // nolint: deadcode +func ParseFile(filename string, opts ...Option) (i any, err error) { // nolint: deadcode f, err := os.Open(filename) if err != nil { return nil, err @@ -921,7 +921,7 @@ func ParseFile(filename string, opts ...Option) (i interface{}, err error) { // // ParseReader parses the data from r using filename as information in the // error messages. -func ParseReader(filename string, r io.Reader, opts ...Option) (interface{}, error) { // nolint: deadcode +func ParseReader(filename string, r io.Reader, opts ...Option) (any, error) { // nolint: deadcode b, err := io.ReadAll(r) if err != nil { return nil, err @@ -932,7 +932,7 @@ func ParseReader(filename string, r io.Reader, opts ...Option) (interface{}, err // Parse parses the data from b using filename as information in the // error messages. -func Parse(filename string, b []byte, opts ...Option) (interface{}, error) { +func Parse(filename string, b []byte, opts ...Option) (any, error) { return newParser(filename, b, opts...).parse(g) } @@ -970,7 +970,7 @@ type current struct { globalStore storeDict } -type storeDict map[string]interface{} +type storeDict map[string]any // the AST types... @@ -985,34 +985,34 @@ type rule struct { pos position name string displayName string - expr interface{} + expr any } // nolint: structcheck type choiceExpr struct { pos position - alternatives []interface{} + alternatives []any } // nolint: structcheck type actionExpr struct { pos position - expr interface{} - run func(*parser) (interface{}, error) + expr any + run func(*parser) (any, error) } // nolint: structcheck type recoveryExpr struct { pos position - expr interface{} - recoverExpr interface{} + expr any + recoverExpr any failureLabel []string } // nolint: structcheck type seqExpr struct { pos position - exprs []interface{} + exprs []any } // nolint: structcheck @@ -1025,20 +1025,22 @@ type throwExpr struct { type labeledExpr struct { pos position label string - expr interface{} + expr any } // nolint: structcheck type expr struct { pos position - expr interface{} + expr any } -type andExpr expr // nolint: structcheck -type notExpr expr // nolint: structcheck -type zeroOrOneExpr expr // nolint: structcheck -type zeroOrMoreExpr expr // nolint: structcheck -type oneOrMoreExpr expr // nolint: structcheck +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 { @@ -1186,7 +1188,7 @@ func (p *parser) setOptions(opts []Option) { // nolint: structcheck,deadcode type resultTuple struct { - v interface{} + v any b bool end savepoint } @@ -1232,12 +1234,12 @@ type parser struct { memoize bool // memoization table for the packrat algorithm: // map[offset in source] map[expression or rule] {value, match} - memo map[int]map[interface{}]resultTuple + 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]interface{} + vstack []map[string]any // rule stack, allows identification of the current rule in errors rstack []*rule @@ -1257,7 +1259,7 @@ type parser struct { choiceNoMatch string // recovery expression stack, keeps track of the currently available recovery expression, these are traversed in reverse - recoveryStack []map[string]interface{} + recoveryStack []map[string]any } // push a variable set on the vstack. @@ -1277,7 +1279,7 @@ func (p *parser) pushV() { return } - m = make(map[string]interface{}) + m = make(map[string]any) p.vstack[len(p.vstack)-1] = m } @@ -1293,7 +1295,7 @@ func (p *parser) popV() { } // push a recovery expression with its labels to the recoveryStack -func (p *parser) pushRecovery(labels []string, expr interface{}) { +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) @@ -1302,7 +1304,7 @@ func (p *parser) pushRecovery(labels []string, expr interface{}) { p.recoveryStack = p.recoveryStack[:len(p.recoveryStack)+1] } - m := make(map[string]interface{}, len(labels)) + m := make(map[string]any, len(labels)) for _, fl := range labels { m[fl] = expr } @@ -1422,11 +1424,11 @@ func (p *parser) restore(pt savepoint) { // copies of the state to allow the parser to properly restore the state in // the case of backtracking. type Cloner interface { - Clone() interface{} + Clone() any } var statePool = &sync.Pool{ - New: func() interface{} { return make(storeDict) }, + New: func() any { return make(storeDict) }, } func (sd storeDict) Discard() { @@ -1468,7 +1470,7 @@ func (p *parser) sliceFrom(start savepoint) []byte { return p.data[start.position.offset:p.pt.position.offset] } -func (p *parser) getMemoized(node interface{}) (resultTuple, bool) { +func (p *parser) getMemoized(node any) (resultTuple, bool) { if len(p.memo) == 0 { return resultTuple{}, false } @@ -1480,13 +1482,13 @@ func (p *parser) getMemoized(node interface{}) (resultTuple, bool) { return res, ok } -func (p *parser) setMemoized(pt savepoint, node interface{}, tuple resultTuple) { +func (p *parser) setMemoized(pt savepoint, node any, tuple resultTuple) { if p.memo == nil { - p.memo = make(map[int]map[interface{}]resultTuple) + p.memo = make(map[int]map[any]resultTuple) } m := p.memo[pt.offset] if m == nil { - m = make(map[interface{}]resultTuple) + m = make(map[any]resultTuple) p.memo[pt.offset] = m } m[node] = tuple @@ -1500,7 +1502,7 @@ func (p *parser) buildRulesTable(g *grammar) { } // nolint: gocyclo -func (p *parser) parse(g *grammar) (val interface{}, err error) { +func (p *parser) parse(g *grammar) (val any, err error) { if len(g.rules) == 0 { p.addErr(errNoRule) return nil, p.errs.err() @@ -1577,7 +1579,7 @@ func listJoin(list []string, sep string, lastSep string) string { } } -func (p *parser) parseRule(rule *rule) (interface{}, bool) { +func (p *parser) parseRule(rule *rule) (any, bool) { if p.debug { defer p.out(p.in("parseRule " + rule.name)) } @@ -1607,7 +1609,7 @@ func (p *parser) parseRule(rule *rule) (interface{}, bool) { } // nolint: gocyclo -func (p *parser) parseExpr(expr interface{}) (interface{}, bool) { +func (p *parser) parseExpr(expr any) (any, bool) { var pt savepoint if p.memoize { @@ -1624,7 +1626,7 @@ func (p *parser) parseExpr(expr interface{}) (interface{}, bool) { panic(errMaxExprCnt) } - var val interface{} + var val any var ok bool switch expr := expr.(type) { case *actionExpr: @@ -1672,7 +1674,7 @@ func (p *parser) parseExpr(expr interface{}) (interface{}, bool) { return val, ok } -func (p *parser) parseActionExpr(act *actionExpr) (interface{}, bool) { +func (p *parser) parseActionExpr(act *actionExpr) (any, bool) { if p.debug { defer p.out(p.in("parseActionExpr")) } @@ -1697,7 +1699,7 @@ func (p *parser) parseActionExpr(act *actionExpr) (interface{}, bool) { return val, ok } -func (p *parser) parseAndCodeExpr(and *andCodeExpr) (interface{}, bool) { +func (p *parser) parseAndCodeExpr(and *andCodeExpr) (any, bool) { if p.debug { defer p.out(p.in("parseAndCodeExpr")) } @@ -1713,7 +1715,7 @@ func (p *parser) parseAndCodeExpr(and *andCodeExpr) (interface{}, bool) { return nil, ok } -func (p *parser) parseAndExpr(and *andExpr) (interface{}, bool) { +func (p *parser) parseAndExpr(and *andExpr) (any, bool) { if p.debug { defer p.out(p.in("parseAndExpr")) } @@ -1729,7 +1731,7 @@ func (p *parser) parseAndExpr(and *andExpr) (interface{}, bool) { return nil, ok } -func (p *parser) parseAnyMatcher(any *anyMatcher) (interface{}, bool) { +func (p *parser) parseAnyMatcher(any *anyMatcher) (any, bool) { if p.debug { defer p.out(p.in("parseAnyMatcher")) } @@ -1746,7 +1748,7 @@ func (p *parser) parseAnyMatcher(any *anyMatcher) (interface{}, bool) { } // nolint: gocyclo -func (p *parser) parseCharClassMatcher(chr *charClassMatcher) (interface{}, bool) { +func (p *parser) parseCharClassMatcher(chr *charClassMatcher) (any, bool) { if p.debug { defer p.out(p.in("parseCharClassMatcher")) } @@ -1827,7 +1829,7 @@ func (p *parser) incChoiceAltCnt(ch *choiceExpr, altI int) { m[alt]++ } -func (p *parser) parseChoiceExpr(ch *choiceExpr) (interface{}, bool) { +func (p *parser) parseChoiceExpr(ch *choiceExpr) (any, bool) { if p.debug { defer p.out(p.in("parseChoiceExpr")) } @@ -1851,7 +1853,7 @@ func (p *parser) parseChoiceExpr(ch *choiceExpr) (interface{}, bool) { return nil, false } -func (p *parser) parseLabeledExpr(lab *labeledExpr) (interface{}, bool) { +func (p *parser) parseLabeledExpr(lab *labeledExpr) (any, bool) { if p.debug { defer p.out(p.in("parseLabeledExpr")) } @@ -1866,7 +1868,7 @@ func (p *parser) parseLabeledExpr(lab *labeledExpr) (interface{}, bool) { return val, ok } -func (p *parser) parseLitMatcher(lit *litMatcher) (interface{}, bool) { +func (p *parser) parseLitMatcher(lit *litMatcher) (any, bool) { if p.debug { defer p.out(p.in("parseLitMatcher")) } @@ -1888,7 +1890,7 @@ func (p *parser) parseLitMatcher(lit *litMatcher) (interface{}, bool) { return p.sliceFrom(start), true } -func (p *parser) parseNotCodeExpr(not *notCodeExpr) (interface{}, bool) { +func (p *parser) parseNotCodeExpr(not *notCodeExpr) (any, bool) { if p.debug { defer p.out(p.in("parseNotCodeExpr")) } @@ -1904,7 +1906,7 @@ func (p *parser) parseNotCodeExpr(not *notCodeExpr) (interface{}, bool) { return nil, !ok } -func (p *parser) parseNotExpr(not *notExpr) (interface{}, bool) { +func (p *parser) parseNotExpr(not *notExpr) (any, bool) { if p.debug { defer p.out(p.in("parseNotExpr")) } @@ -1922,12 +1924,12 @@ func (p *parser) parseNotExpr(not *notExpr) (interface{}, bool) { return nil, !ok } -func (p *parser) parseOneOrMoreExpr(expr *oneOrMoreExpr) (interface{}, bool) { +func (p *parser) parseOneOrMoreExpr(expr *oneOrMoreExpr) (any, bool) { if p.debug { defer p.out(p.in("parseOneOrMoreExpr")) } - var vals []interface{} + var vals []any for { p.pushV() @@ -1944,7 +1946,7 @@ func (p *parser) parseOneOrMoreExpr(expr *oneOrMoreExpr) (interface{}, bool) { } } -func (p *parser) parseRecoveryExpr(recover *recoveryExpr) (interface{}, bool) { +func (p *parser) parseRecoveryExpr(recover *recoveryExpr) (any, bool) { if p.debug { defer p.out(p.in("parseRecoveryExpr (" + strings.Join(recover.failureLabel, ",") + ")")) } @@ -1956,7 +1958,7 @@ func (p *parser) parseRecoveryExpr(recover *recoveryExpr) (interface{}, bool) { return val, ok } -func (p *parser) parseRuleRefExpr(ref *ruleRefExpr) (interface{}, bool) { +func (p *parser) parseRuleRefExpr(ref *ruleRefExpr) (any, bool) { if p.debug { defer p.out(p.in("parseRuleRefExpr " + ref.name)) } @@ -1973,12 +1975,12 @@ func (p *parser) parseRuleRefExpr(ref *ruleRefExpr) (interface{}, bool) { return p.parseRule(rule) } -func (p *parser) parseSeqExpr(seq *seqExpr) (interface{}, bool) { +func (p *parser) parseSeqExpr(seq *seqExpr) (any, bool) { if p.debug { defer p.out(p.in("parseSeqExpr")) } - vals := make([]interface{}, 0, len(seq.exprs)) + vals := make([]any, 0, len(seq.exprs)) pt := p.pt state := p.cloneState() @@ -1994,7 +1996,7 @@ func (p *parser) parseSeqExpr(seq *seqExpr) (interface{}, bool) { return vals, true } -func (p *parser) parseStateCodeExpr(state *stateCodeExpr) (interface{}, bool) { +func (p *parser) parseStateCodeExpr(state *stateCodeExpr) (any, bool) { if p.debug { defer p.out(p.in("parseStateCodeExpr")) } @@ -2006,7 +2008,7 @@ func (p *parser) parseStateCodeExpr(state *stateCodeExpr) (interface{}, bool) { return nil, true } -func (p *parser) parseThrowExpr(expr *throwExpr) (interface{}, bool) { +func (p *parser) parseThrowExpr(expr *throwExpr) (any, bool) { if p.debug { defer p.out(p.in("parseThrowExpr")) } @@ -2022,12 +2024,12 @@ func (p *parser) parseThrowExpr(expr *throwExpr) (interface{}, bool) { return nil, false } -func (p *parser) parseZeroOrMoreExpr(expr *zeroOrMoreExpr) (interface{}, bool) { +func (p *parser) parseZeroOrMoreExpr(expr *zeroOrMoreExpr) (any, bool) { if p.debug { defer p.out(p.in("parseZeroOrMoreExpr")) } - var vals []interface{} + var vals []any for { p.pushV() @@ -2040,7 +2042,7 @@ func (p *parser) parseZeroOrMoreExpr(expr *zeroOrMoreExpr) (interface{}, bool) { } } -func (p *parser) parseZeroOrOneExpr(expr *zeroOrOneExpr) (interface{}, bool) { +func (p *parser) parseZeroOrOneExpr(expr *zeroOrOneExpr) (any, bool) { if p.debug { defer p.out(p.in("parseZeroOrOneExpr")) } diff --git a/examples/json/json.peg b/examples/json/json.peg index b6130a26..0efadf79 100644 --- a/examples/json/json.peg +++ b/examples/json/json.peg @@ -6,11 +6,11 @@ // [1]: http://www.ecma-international.org/publications/files/ECMA-ST/ECMA-404.pdf package json -func toIfaceSlice(v interface{}) []interface{} { +func toAnySlice(v any) []any { if v == nil { return nil } - return v.([]interface{}) + return v.([]any) } } @@ -23,29 +23,29 @@ Value ← val:( Object / Array / Number / String / Bool / Null ) _ { } Object ← '{' _ vals:( String _ ':' _ Value ( ',' _ String _ ':' _ Value )* )? '}' { - res := make(map[string]interface{}) - valsSl := toIfaceSlice(vals) + res := make(map[string]any) + valsSl := toAnySlice(vals) if len(valsSl) == 0 { return res, nil } res[valsSl[0].(string)] = valsSl[4] - restSl := toIfaceSlice(valsSl[5]) + restSl := toAnySlice(valsSl[5]) for _, v := range restSl { - vSl := toIfaceSlice(v) + vSl := toAnySlice(v) res[vSl[2].(string)] = vSl[6] } return res, nil } Array ← '[' _ vals:( Value ( ',' _ Value )* )? ']' { - valsSl := toIfaceSlice(vals) + valsSl := toAnySlice(vals) if len(valsSl) == 0 { - return []interface{}{}, nil + return []any{}, nil } - res := []interface{}{valsSl[0]} - restSl := toIfaceSlice(valsSl[1]) + res := []any{valsSl[0]} + restSl := toAnySlice(valsSl[1]) for _, v := range restSl { - vSl := toIfaceSlice(v) + vSl := toAnySlice(v) res = append(res, vSl[2]) } return res, nil diff --git a/examples/json/json_test.go b/examples/json/json_test.go index 013d31b2..26557038 100644 --- a/examples/json/json_test.go +++ b/examples/json/json_test.go @@ -37,7 +37,7 @@ func TestCmpStdlib(t *testing.T) { t.Errorf("%s: os.ReadFile: %v", file, err) continue } - var jgot interface{} + var jgot any if err := json.Unmarshal(b, &jgot); err != nil { t.Errorf("%s: json.Unmarshal: %v", file, err) continue @@ -201,8 +201,8 @@ func BenchmarkStdlibJSON(b *testing.B) { b.ResetTimer() for i := 0; i < b.N; i++ { - var iface interface{} - if err := json.Unmarshal(d, &iface); err != nil { + var anyVal any + if err := json.Unmarshal(d, &anyVal); err != nil { b.Fatal(err) } } diff --git a/examples/json/optimized-grammar/json.go b/examples/json/optimized-grammar/json.go index f6b3d76e..2dff3d4f 100644 --- a/examples/json/optimized-grammar/json.go +++ b/examples/json/optimized-grammar/json.go @@ -22,28 +22,28 @@ import ( "unicode/utf8" ) -func toIfaceSlice(v interface{}) []interface{} { +func toAnySlice(v any) []any { if v == nil { return nil } - return v.([]interface{}) + return v.([]any) } var g = &grammar{ rules: []*rule{ { name: "JSON", - pos: position{line: 17, col: 1, offset: 347}, + pos: position{line: 17, col: 1, offset: 321}, expr: &actionExpr{ - pos: position{line: 17, col: 8, offset: 356}, + pos: position{line: 17, col: 8, offset: 330}, run: (*parser).callonJSON1, expr: &seqExpr{ - pos: position{line: 17, col: 8, offset: 356}, - exprs: []interface{}{ + pos: position{line: 17, col: 8, offset: 330}, + exprs: []any{ &zeroOrMoreExpr{ - pos: position{line: 87, col: 18, offset: 2118}, + pos: position{line: 87, col: 18, offset: 2056}, expr: &charClassMatcher{ - pos: position{line: 87, col: 18, offset: 2118}, + pos: position{line: 87, col: 18, offset: 2056}, val: "[ \\t\\r\\n]", chars: []rune{' ', '\t', '\r', '\n'}, ignoreCase: false, @@ -51,17 +51,17 @@ var g = &grammar{ }, }, &labeledExpr{ - pos: position{line: 17, col: 10, offset: 358}, + pos: position{line: 17, col: 10, offset: 332}, label: "val", expr: &ruleRefExpr{ - pos: position{line: 17, col: 14, offset: 362}, + pos: position{line: 17, col: 14, offset: 336}, name: "Value", }, }, ¬Expr{ - pos: position{line: 89, col: 7, offset: 2138}, + pos: position{line: 89, col: 7, offset: 2076}, expr: &anyMatcher{ - line: 89, col: 8, offset: 2139, + line: 89, col: 8, offset: 2077, }, }, }, @@ -70,65 +70,65 @@ var g = &grammar{ }, { name: "Value", - pos: position{line: 21, col: 1, offset: 397}, + pos: position{line: 21, col: 1, offset: 371}, expr: &actionExpr{ - pos: position{line: 21, col: 9, offset: 407}, + pos: position{line: 21, col: 9, offset: 381}, run: (*parser).callonValue1, expr: &seqExpr{ - pos: position{line: 21, col: 9, offset: 407}, - exprs: []interface{}{ + pos: position{line: 21, col: 9, offset: 381}, + exprs: []any{ &labeledExpr{ - pos: position{line: 21, col: 9, offset: 407}, + pos: position{line: 21, col: 9, offset: 381}, label: "val", expr: &choiceExpr{ - pos: position{line: 21, col: 15, offset: 413}, - alternatives: []interface{}{ + pos: position{line: 21, col: 15, offset: 387}, + alternatives: []any{ &ruleRefExpr{ - pos: position{line: 21, col: 15, offset: 413}, + pos: position{line: 21, col: 15, offset: 387}, name: "Object", }, &ruleRefExpr{ - pos: position{line: 21, col: 24, offset: 422}, + pos: position{line: 21, col: 24, offset: 396}, name: "Array", }, &actionExpr{ - pos: position{line: 54, col: 10, offset: 1277}, + pos: position{line: 54, col: 10, offset: 1215}, run: (*parser).callonValue7, expr: &seqExpr{ - pos: position{line: 54, col: 10, offset: 1277}, - exprs: []interface{}{ + pos: position{line: 54, col: 10, offset: 1215}, + exprs: []any{ &zeroOrOneExpr{ - pos: position{line: 54, col: 10, offset: 1277}, + pos: position{line: 54, col: 10, offset: 1215}, expr: &litMatcher{ - pos: position{line: 54, col: 10, offset: 1277}, + pos: position{line: 54, col: 10, offset: 1215}, val: "-", ignoreCase: false, want: "\"-\"", }, }, &choiceExpr{ - pos: position{line: 60, col: 11, offset: 1480}, - alternatives: []interface{}{ + pos: position{line: 60, col: 11, offset: 1418}, + alternatives: []any{ &litMatcher{ - pos: position{line: 60, col: 11, offset: 1480}, + pos: position{line: 60, col: 11, offset: 1418}, val: "0", ignoreCase: false, want: "\"0\"", }, &seqExpr{ - pos: position{line: 60, col: 17, offset: 1486}, - exprs: []interface{}{ + pos: position{line: 60, col: 17, offset: 1424}, + exprs: []any{ &charClassMatcher{ - pos: position{line: 79, col: 23, offset: 1961}, + pos: position{line: 79, col: 23, offset: 1899}, val: "[1-9]", ranges: []rune{'1', '9'}, ignoreCase: false, inverted: false, }, &zeroOrMoreExpr{ - pos: position{line: 60, col: 37, offset: 1506}, + pos: position{line: 60, col: 37, offset: 1444}, expr: &charClassMatcher{ - pos: position{line: 77, col: 16, offset: 1930}, + pos: position{line: 77, col: 16, offset: 1868}, val: "[0-9]", ranges: []rune{'0', '9'}, ignoreCase: false, @@ -140,20 +140,20 @@ var g = &grammar{ }, }, &zeroOrOneExpr{ - pos: position{line: 54, col: 23, offset: 1290}, + pos: position{line: 54, col: 23, offset: 1228}, expr: &seqExpr{ - pos: position{line: 54, col: 25, offset: 1292}, - exprs: []interface{}{ + pos: position{line: 54, col: 25, offset: 1230}, + exprs: []any{ &litMatcher{ - pos: position{line: 54, col: 25, offset: 1292}, + pos: position{line: 54, col: 25, offset: 1230}, val: ".", ignoreCase: false, want: "\".\"", }, &oneOrMoreExpr{ - pos: position{line: 54, col: 29, offset: 1296}, + pos: position{line: 54, col: 29, offset: 1234}, expr: &charClassMatcher{ - pos: position{line: 77, col: 16, offset: 1930}, + pos: position{line: 77, col: 16, offset: 1868}, val: "[0-9]", ranges: []rune{'0', '9'}, ignoreCase: false, @@ -164,20 +164,20 @@ var g = &grammar{ }, }, &zeroOrOneExpr{ - pos: position{line: 54, col: 46, offset: 1313}, + pos: position{line: 54, col: 46, offset: 1251}, expr: &seqExpr{ - pos: position{line: 62, col: 12, offset: 1534}, - exprs: []interface{}{ + pos: position{line: 62, col: 12, offset: 1472}, + exprs: []any{ &litMatcher{ - pos: position{line: 62, col: 12, offset: 1534}, + pos: position{line: 62, col: 12, offset: 1472}, val: "e", ignoreCase: true, want: "\"e\"i", }, &zeroOrOneExpr{ - pos: position{line: 62, col: 17, offset: 1539}, + pos: position{line: 62, col: 17, offset: 1477}, expr: &charClassMatcher{ - pos: position{line: 62, col: 17, offset: 1539}, + pos: position{line: 62, col: 17, offset: 1477}, val: "[+-]", chars: []rune{'+', '-'}, ignoreCase: false, @@ -185,9 +185,9 @@ var g = &grammar{ }, }, &oneOrMoreExpr{ - pos: position{line: 62, col: 23, offset: 1545}, + pos: position{line: 62, col: 23, offset: 1483}, expr: &charClassMatcher{ - pos: position{line: 77, col: 16, offset: 1930}, + pos: position{line: 77, col: 16, offset: 1868}, val: "[0-9]", ranges: []rune{'0', '9'}, ignoreCase: false, @@ -201,29 +201,29 @@ var g = &grammar{ }, }, &actionExpr{ - pos: position{line: 64, col: 10, offset: 1571}, + pos: position{line: 64, col: 10, offset: 1509}, run: (*parser).callonValue29, expr: &seqExpr{ - pos: position{line: 64, col: 10, offset: 1571}, - exprs: []interface{}{ + pos: position{line: 64, col: 10, offset: 1509}, + exprs: []any{ &litMatcher{ - pos: position{line: 64, col: 10, offset: 1571}, + pos: position{line: 64, col: 10, offset: 1509}, val: "\"", ignoreCase: false, want: "\"\\\"\"", }, &zeroOrMoreExpr{ - pos: position{line: 64, col: 14, offset: 1575}, + pos: position{line: 64, col: 14, offset: 1513}, expr: &choiceExpr{ - pos: position{line: 64, col: 16, offset: 1577}, - alternatives: []interface{}{ + pos: position{line: 64, col: 16, offset: 1515}, + alternatives: []any{ &seqExpr{ - pos: position{line: 64, col: 16, offset: 1577}, - exprs: []interface{}{ + pos: position{line: 64, col: 16, offset: 1515}, + exprs: []any{ ¬Expr{ - pos: position{line: 64, col: 16, offset: 1577}, + pos: position{line: 64, col: 16, offset: 1515}, expr: &charClassMatcher{ - pos: position{line: 69, col: 15, offset: 1751}, + pos: position{line: 69, col: 15, offset: 1689}, val: "[\"\\\\\\x00-\\x1f]", chars: []rune{'"', '\\'}, ranges: []rune{'\x00', '\x1f'}, @@ -232,61 +232,61 @@ var g = &grammar{ }, }, &anyMatcher{ - line: 64, col: 29, offset: 1590, + line: 64, col: 29, offset: 1528, }, }, }, &seqExpr{ - pos: position{line: 64, col: 33, offset: 1594}, - exprs: []interface{}{ + pos: position{line: 64, col: 33, offset: 1532}, + exprs: []any{ &litMatcher{ - pos: position{line: 64, col: 33, offset: 1594}, + pos: position{line: 64, col: 33, offset: 1532}, val: "\\", ignoreCase: false, want: "\"\\\\\"", }, &choiceExpr{ - pos: position{line: 71, col: 18, offset: 1786}, - alternatives: []interface{}{ + pos: position{line: 71, col: 18, offset: 1724}, + alternatives: []any{ &charClassMatcher{ - pos: position{line: 73, col: 20, offset: 1841}, + pos: position{line: 73, col: 20, offset: 1779}, val: "[\"\\\\/bfnrt]", chars: []rune{'"', '\\', '/', 'b', 'f', 'n', 'r', 't'}, ignoreCase: false, inverted: false, }, &seqExpr{ - pos: position{line: 75, col: 17, offset: 1872}, - exprs: []interface{}{ + pos: position{line: 75, col: 17, offset: 1810}, + exprs: []any{ &litMatcher{ - pos: position{line: 75, col: 17, offset: 1872}, + pos: position{line: 75, col: 17, offset: 1810}, val: "u", ignoreCase: false, want: "\"u\"", }, &charClassMatcher{ - pos: position{line: 81, col: 12, offset: 1981}, + pos: position{line: 81, col: 12, offset: 1919}, val: "[0-9a-f]i", ranges: []rune{'0', '9', 'a', 'f'}, ignoreCase: true, inverted: false, }, &charClassMatcher{ - pos: position{line: 81, col: 12, offset: 1981}, + pos: position{line: 81, col: 12, offset: 1919}, val: "[0-9a-f]i", ranges: []rune{'0', '9', 'a', 'f'}, ignoreCase: true, inverted: false, }, &charClassMatcher{ - pos: position{line: 81, col: 12, offset: 1981}, + pos: position{line: 81, col: 12, offset: 1919}, val: "[0-9a-f]i", ranges: []rune{'0', '9', 'a', 'f'}, ignoreCase: true, inverted: false, }, &charClassMatcher{ - pos: position{line: 81, col: 12, offset: 1981}, + pos: position{line: 81, col: 12, offset: 1919}, val: "[0-9a-f]i", ranges: []rune{'0', '9', 'a', 'f'}, ignoreCase: true, @@ -302,7 +302,7 @@ var g = &grammar{ }, }, &litMatcher{ - pos: position{line: 64, col: 56, offset: 1617}, + pos: position{line: 64, col: 56, offset: 1555}, val: "\"", ignoreCase: false, want: "\"\\\"\"", @@ -311,30 +311,30 @@ var g = &grammar{ }, }, &actionExpr{ - pos: position{line: 83, col: 8, offset: 2001}, + pos: position{line: 83, col: 8, offset: 1939}, run: (*parser).callonValue49, expr: &litMatcher{ - pos: position{line: 83, col: 8, offset: 2001}, + pos: position{line: 83, col: 8, offset: 1939}, val: "true", ignoreCase: false, want: "\"true\"", }, }, &actionExpr{ - pos: position{line: 83, col: 38, offset: 2031}, + pos: position{line: 83, col: 38, offset: 1969}, run: (*parser).callonValue51, expr: &litMatcher{ - pos: position{line: 83, col: 38, offset: 2031}, + pos: position{line: 83, col: 38, offset: 1969}, val: "false", ignoreCase: false, want: "\"false\"", }, }, &actionExpr{ - pos: position{line: 85, col: 8, offset: 2071}, + pos: position{line: 85, col: 8, offset: 2009}, run: (*parser).callonValue53, expr: &litMatcher{ - pos: position{line: 85, col: 8, offset: 2071}, + pos: position{line: 85, col: 8, offset: 2009}, val: "null", ignoreCase: false, want: "\"null\"", @@ -344,9 +344,9 @@ var g = &grammar{ }, }, &zeroOrMoreExpr{ - pos: position{line: 87, col: 18, offset: 2118}, + pos: position{line: 87, col: 18, offset: 2056}, expr: &charClassMatcher{ - pos: position{line: 87, col: 18, offset: 2118}, + pos: position{line: 87, col: 18, offset: 2056}, val: "[ \\t\\r\\n]", chars: []rune{' ', '\t', '\r', '\n'}, ignoreCase: false, @@ -359,23 +359,23 @@ var g = &grammar{ }, { name: "Object", - pos: position{line: 25, col: 1, offset: 489}, + pos: position{line: 25, col: 1, offset: 463}, expr: &actionExpr{ - pos: position{line: 25, col: 10, offset: 500}, + pos: position{line: 25, col: 10, offset: 474}, run: (*parser).callonObject1, expr: &seqExpr{ - pos: position{line: 25, col: 10, offset: 500}, - exprs: []interface{}{ + pos: position{line: 25, col: 10, offset: 474}, + exprs: []any{ &litMatcher{ - pos: position{line: 25, col: 10, offset: 500}, + pos: position{line: 25, col: 10, offset: 474}, val: "{", ignoreCase: false, want: "\"{\"", }, &zeroOrMoreExpr{ - pos: position{line: 87, col: 18, offset: 2118}, + pos: position{line: 87, col: 18, offset: 2056}, expr: &charClassMatcher{ - pos: position{line: 87, col: 18, offset: 2118}, + pos: position{line: 87, col: 18, offset: 2056}, val: "[ \\t\\r\\n]", chars: []rune{' ', '\t', '\r', '\n'}, ignoreCase: false, @@ -383,37 +383,37 @@ var g = &grammar{ }, }, &labeledExpr{ - pos: position{line: 25, col: 16, offset: 506}, + pos: position{line: 25, col: 16, offset: 480}, label: "vals", expr: &zeroOrOneExpr{ - pos: position{line: 25, col: 21, offset: 511}, + pos: position{line: 25, col: 21, offset: 485}, expr: &seqExpr{ - pos: position{line: 25, col: 23, offset: 513}, - exprs: []interface{}{ + pos: position{line: 25, col: 23, offset: 487}, + exprs: []any{ &actionExpr{ - pos: position{line: 64, col: 10, offset: 1571}, + pos: position{line: 64, col: 10, offset: 1509}, run: (*parser).callonObject9, expr: &seqExpr{ - pos: position{line: 64, col: 10, offset: 1571}, - exprs: []interface{}{ + pos: position{line: 64, col: 10, offset: 1509}, + exprs: []any{ &litMatcher{ - pos: position{line: 64, col: 10, offset: 1571}, + pos: position{line: 64, col: 10, offset: 1509}, val: "\"", ignoreCase: false, want: "\"\\\"\"", }, &zeroOrMoreExpr{ - pos: position{line: 64, col: 14, offset: 1575}, + pos: position{line: 64, col: 14, offset: 1513}, expr: &choiceExpr{ - pos: position{line: 64, col: 16, offset: 1577}, - alternatives: []interface{}{ + pos: position{line: 64, col: 16, offset: 1515}, + alternatives: []any{ &seqExpr{ - pos: position{line: 64, col: 16, offset: 1577}, - exprs: []interface{}{ + pos: position{line: 64, col: 16, offset: 1515}, + exprs: []any{ ¬Expr{ - pos: position{line: 64, col: 16, offset: 1577}, + pos: position{line: 64, col: 16, offset: 1515}, expr: &charClassMatcher{ - pos: position{line: 69, col: 15, offset: 1751}, + pos: position{line: 69, col: 15, offset: 1689}, val: "[\"\\\\\\x00-\\x1f]", chars: []rune{'"', '\\'}, ranges: []rune{'\x00', '\x1f'}, @@ -422,61 +422,61 @@ var g = &grammar{ }, }, &anyMatcher{ - line: 64, col: 29, offset: 1590, + line: 64, col: 29, offset: 1528, }, }, }, &seqExpr{ - pos: position{line: 64, col: 33, offset: 1594}, - exprs: []interface{}{ + pos: position{line: 64, col: 33, offset: 1532}, + exprs: []any{ &litMatcher{ - pos: position{line: 64, col: 33, offset: 1594}, + pos: position{line: 64, col: 33, offset: 1532}, val: "\\", ignoreCase: false, want: "\"\\\\\"", }, &choiceExpr{ - pos: position{line: 71, col: 18, offset: 1786}, - alternatives: []interface{}{ + pos: position{line: 71, col: 18, offset: 1724}, + alternatives: []any{ &charClassMatcher{ - pos: position{line: 73, col: 20, offset: 1841}, + pos: position{line: 73, col: 20, offset: 1779}, val: "[\"\\\\/bfnrt]", chars: []rune{'"', '\\', '/', 'b', 'f', 'n', 'r', 't'}, ignoreCase: false, inverted: false, }, &seqExpr{ - pos: position{line: 75, col: 17, offset: 1872}, - exprs: []interface{}{ + pos: position{line: 75, col: 17, offset: 1810}, + exprs: []any{ &litMatcher{ - pos: position{line: 75, col: 17, offset: 1872}, + pos: position{line: 75, col: 17, offset: 1810}, val: "u", ignoreCase: false, want: "\"u\"", }, &charClassMatcher{ - pos: position{line: 81, col: 12, offset: 1981}, + pos: position{line: 81, col: 12, offset: 1919}, val: "[0-9a-f]i", ranges: []rune{'0', '9', 'a', 'f'}, ignoreCase: true, inverted: false, }, &charClassMatcher{ - pos: position{line: 81, col: 12, offset: 1981}, + pos: position{line: 81, col: 12, offset: 1919}, val: "[0-9a-f]i", ranges: []rune{'0', '9', 'a', 'f'}, ignoreCase: true, inverted: false, }, &charClassMatcher{ - pos: position{line: 81, col: 12, offset: 1981}, + pos: position{line: 81, col: 12, offset: 1919}, val: "[0-9a-f]i", ranges: []rune{'0', '9', 'a', 'f'}, ignoreCase: true, inverted: false, }, &charClassMatcher{ - pos: position{line: 81, col: 12, offset: 1981}, + pos: position{line: 81, col: 12, offset: 1919}, val: "[0-9a-f]i", ranges: []rune{'0', '9', 'a', 'f'}, ignoreCase: true, @@ -492,7 +492,7 @@ var g = &grammar{ }, }, &litMatcher{ - pos: position{line: 64, col: 56, offset: 1617}, + pos: position{line: 64, col: 56, offset: 1555}, val: "\"", ignoreCase: false, want: "\"\\\"\"", @@ -501,9 +501,9 @@ var g = &grammar{ }, }, &zeroOrMoreExpr{ - pos: position{line: 87, col: 18, offset: 2118}, + pos: position{line: 87, col: 18, offset: 2056}, expr: &charClassMatcher{ - pos: position{line: 87, col: 18, offset: 2118}, + pos: position{line: 87, col: 18, offset: 2056}, val: "[ \\t\\r\\n]", chars: []rune{' ', '\t', '\r', '\n'}, ignoreCase: false, @@ -511,15 +511,15 @@ var g = &grammar{ }, }, &litMatcher{ - pos: position{line: 25, col: 32, offset: 522}, + pos: position{line: 25, col: 32, offset: 496}, val: ":", ignoreCase: false, want: "\":\"", }, &zeroOrMoreExpr{ - pos: position{line: 87, col: 18, offset: 2118}, + pos: position{line: 87, col: 18, offset: 2056}, expr: &charClassMatcher{ - pos: position{line: 87, col: 18, offset: 2118}, + pos: position{line: 87, col: 18, offset: 2056}, val: "[ \\t\\r\\n]", chars: []rune{' ', '\t', '\r', '\n'}, ignoreCase: false, @@ -527,24 +527,24 @@ var g = &grammar{ }, }, &ruleRefExpr{ - pos: position{line: 25, col: 38, offset: 528}, + pos: position{line: 25, col: 38, offset: 502}, name: "Value", }, &zeroOrMoreExpr{ - pos: position{line: 25, col: 44, offset: 534}, + pos: position{line: 25, col: 44, offset: 508}, expr: &seqExpr{ - pos: position{line: 25, col: 46, offset: 536}, - exprs: []interface{}{ + pos: position{line: 25, col: 46, offset: 510}, + exprs: []any{ &litMatcher{ - pos: position{line: 25, col: 46, offset: 536}, + pos: position{line: 25, col: 46, offset: 510}, val: ",", ignoreCase: false, want: "\",\"", }, &zeroOrMoreExpr{ - pos: position{line: 87, col: 18, offset: 2118}, + pos: position{line: 87, col: 18, offset: 2056}, expr: &charClassMatcher{ - pos: position{line: 87, col: 18, offset: 2118}, + pos: position{line: 87, col: 18, offset: 2056}, val: "[ \\t\\r\\n]", chars: []rune{' ', '\t', '\r', '\n'}, ignoreCase: false, @@ -552,29 +552,29 @@ var g = &grammar{ }, }, &actionExpr{ - pos: position{line: 64, col: 10, offset: 1571}, + pos: position{line: 64, col: 10, offset: 1509}, run: (*parser).callonObject40, expr: &seqExpr{ - pos: position{line: 64, col: 10, offset: 1571}, - exprs: []interface{}{ + pos: position{line: 64, col: 10, offset: 1509}, + exprs: []any{ &litMatcher{ - pos: position{line: 64, col: 10, offset: 1571}, + pos: position{line: 64, col: 10, offset: 1509}, val: "\"", ignoreCase: false, want: "\"\\\"\"", }, &zeroOrMoreExpr{ - pos: position{line: 64, col: 14, offset: 1575}, + pos: position{line: 64, col: 14, offset: 1513}, expr: &choiceExpr{ - pos: position{line: 64, col: 16, offset: 1577}, - alternatives: []interface{}{ + pos: position{line: 64, col: 16, offset: 1515}, + alternatives: []any{ &seqExpr{ - pos: position{line: 64, col: 16, offset: 1577}, - exprs: []interface{}{ + pos: position{line: 64, col: 16, offset: 1515}, + exprs: []any{ ¬Expr{ - pos: position{line: 64, col: 16, offset: 1577}, + pos: position{line: 64, col: 16, offset: 1515}, expr: &charClassMatcher{ - pos: position{line: 69, col: 15, offset: 1751}, + pos: position{line: 69, col: 15, offset: 1689}, val: "[\"\\\\\\x00-\\x1f]", chars: []rune{'"', '\\'}, ranges: []rune{'\x00', '\x1f'}, @@ -583,61 +583,61 @@ var g = &grammar{ }, }, &anyMatcher{ - line: 64, col: 29, offset: 1590, + line: 64, col: 29, offset: 1528, }, }, }, &seqExpr{ - pos: position{line: 64, col: 33, offset: 1594}, - exprs: []interface{}{ + pos: position{line: 64, col: 33, offset: 1532}, + exprs: []any{ &litMatcher{ - pos: position{line: 64, col: 33, offset: 1594}, + pos: position{line: 64, col: 33, offset: 1532}, val: "\\", ignoreCase: false, want: "\"\\\\\"", }, &choiceExpr{ - pos: position{line: 71, col: 18, offset: 1786}, - alternatives: []interface{}{ + pos: position{line: 71, col: 18, offset: 1724}, + alternatives: []any{ &charClassMatcher{ - pos: position{line: 73, col: 20, offset: 1841}, + pos: position{line: 73, col: 20, offset: 1779}, val: "[\"\\\\/bfnrt]", chars: []rune{'"', '\\', '/', 'b', 'f', 'n', 'r', 't'}, ignoreCase: false, inverted: false, }, &seqExpr{ - pos: position{line: 75, col: 17, offset: 1872}, - exprs: []interface{}{ + pos: position{line: 75, col: 17, offset: 1810}, + exprs: []any{ &litMatcher{ - pos: position{line: 75, col: 17, offset: 1872}, + pos: position{line: 75, col: 17, offset: 1810}, val: "u", ignoreCase: false, want: "\"u\"", }, &charClassMatcher{ - pos: position{line: 81, col: 12, offset: 1981}, + pos: position{line: 81, col: 12, offset: 1919}, val: "[0-9a-f]i", ranges: []rune{'0', '9', 'a', 'f'}, ignoreCase: true, inverted: false, }, &charClassMatcher{ - pos: position{line: 81, col: 12, offset: 1981}, + pos: position{line: 81, col: 12, offset: 1919}, val: "[0-9a-f]i", ranges: []rune{'0', '9', 'a', 'f'}, ignoreCase: true, inverted: false, }, &charClassMatcher{ - pos: position{line: 81, col: 12, offset: 1981}, + pos: position{line: 81, col: 12, offset: 1919}, val: "[0-9a-f]i", ranges: []rune{'0', '9', 'a', 'f'}, ignoreCase: true, inverted: false, }, &charClassMatcher{ - pos: position{line: 81, col: 12, offset: 1981}, + pos: position{line: 81, col: 12, offset: 1919}, val: "[0-9a-f]i", ranges: []rune{'0', '9', 'a', 'f'}, ignoreCase: true, @@ -653,7 +653,7 @@ var g = &grammar{ }, }, &litMatcher{ - pos: position{line: 64, col: 56, offset: 1617}, + pos: position{line: 64, col: 56, offset: 1555}, val: "\"", ignoreCase: false, want: "\"\\\"\"", @@ -662,9 +662,9 @@ var g = &grammar{ }, }, &zeroOrMoreExpr{ - pos: position{line: 87, col: 18, offset: 2118}, + pos: position{line: 87, col: 18, offset: 2056}, expr: &charClassMatcher{ - pos: position{line: 87, col: 18, offset: 2118}, + pos: position{line: 87, col: 18, offset: 2056}, val: "[ \\t\\r\\n]", chars: []rune{' ', '\t', '\r', '\n'}, ignoreCase: false, @@ -672,15 +672,15 @@ var g = &grammar{ }, }, &litMatcher{ - pos: position{line: 25, col: 61, offset: 551}, + pos: position{line: 25, col: 61, offset: 525}, val: ":", ignoreCase: false, want: "\":\"", }, &zeroOrMoreExpr{ - pos: position{line: 87, col: 18, offset: 2118}, + pos: position{line: 87, col: 18, offset: 2056}, expr: &charClassMatcher{ - pos: position{line: 87, col: 18, offset: 2118}, + pos: position{line: 87, col: 18, offset: 2056}, val: "[ \\t\\r\\n]", chars: []rune{' ', '\t', '\r', '\n'}, ignoreCase: false, @@ -688,7 +688,7 @@ var g = &grammar{ }, }, &ruleRefExpr{ - pos: position{line: 25, col: 67, offset: 557}, + pos: position{line: 25, col: 67, offset: 531}, name: "Value", }, }, @@ -699,7 +699,7 @@ var g = &grammar{ }, }, &litMatcher{ - pos: position{line: 25, col: 79, offset: 569}, + pos: position{line: 25, col: 79, offset: 543}, val: "}", ignoreCase: false, want: "\"}\"", @@ -710,23 +710,23 @@ var g = &grammar{ }, { name: "Array", - pos: position{line: 40, col: 1, offset: 911}, + pos: position{line: 40, col: 1, offset: 871}, expr: &actionExpr{ - pos: position{line: 40, col: 9, offset: 921}, + pos: position{line: 40, col: 9, offset: 881}, run: (*parser).callonArray1, expr: &seqExpr{ - pos: position{line: 40, col: 9, offset: 921}, - exprs: []interface{}{ + pos: position{line: 40, col: 9, offset: 881}, + exprs: []any{ &litMatcher{ - pos: position{line: 40, col: 9, offset: 921}, + pos: position{line: 40, col: 9, offset: 881}, val: "[", ignoreCase: false, want: "\"[\"", }, &zeroOrMoreExpr{ - pos: position{line: 87, col: 18, offset: 2118}, + pos: position{line: 87, col: 18, offset: 2056}, expr: &charClassMatcher{ - pos: position{line: 87, col: 18, offset: 2118}, + pos: position{line: 87, col: 18, offset: 2056}, val: "[ \\t\\r\\n]", chars: []rune{' ', '\t', '\r', '\n'}, ignoreCase: false, @@ -734,32 +734,32 @@ var g = &grammar{ }, }, &labeledExpr{ - pos: position{line: 40, col: 15, offset: 927}, + pos: position{line: 40, col: 15, offset: 887}, label: "vals", expr: &zeroOrOneExpr{ - pos: position{line: 40, col: 20, offset: 932}, + pos: position{line: 40, col: 20, offset: 892}, expr: &seqExpr{ - pos: position{line: 40, col: 22, offset: 934}, - exprs: []interface{}{ + pos: position{line: 40, col: 22, offset: 894}, + exprs: []any{ &ruleRefExpr{ - pos: position{line: 40, col: 22, offset: 934}, + pos: position{line: 40, col: 22, offset: 894}, name: "Value", }, &zeroOrMoreExpr{ - pos: position{line: 40, col: 28, offset: 940}, + pos: position{line: 40, col: 28, offset: 900}, expr: &seqExpr{ - pos: position{line: 40, col: 30, offset: 942}, - exprs: []interface{}{ + pos: position{line: 40, col: 30, offset: 902}, + exprs: []any{ &litMatcher{ - pos: position{line: 40, col: 30, offset: 942}, + pos: position{line: 40, col: 30, offset: 902}, val: ",", ignoreCase: false, want: "\",\"", }, &zeroOrMoreExpr{ - pos: position{line: 87, col: 18, offset: 2118}, + pos: position{line: 87, col: 18, offset: 2056}, expr: &charClassMatcher{ - pos: position{line: 87, col: 18, offset: 2118}, + pos: position{line: 87, col: 18, offset: 2056}, val: "[ \\t\\r\\n]", chars: []rune{' ', '\t', '\r', '\n'}, ignoreCase: false, @@ -767,7 +767,7 @@ var g = &grammar{ }, }, &ruleRefExpr{ - pos: position{line: 40, col: 36, offset: 948}, + pos: position{line: 40, col: 36, offset: 908}, name: "Value", }, }, @@ -778,7 +778,7 @@ var g = &grammar{ }, }, &litMatcher{ - pos: position{line: 40, col: 48, offset: 960}, + pos: position{line: 40, col: 48, offset: 920}, val: "]", ignoreCase: false, want: "\"]\"", @@ -790,137 +790,137 @@ var g = &grammar{ }, } -func (c *current) onJSON1(val interface{}) (interface{}, error) { +func (c *current) onJSON1(val any) (any, error) { return val, nil } -func (p *parser) callonJSON1() (interface{}, error) { +func (p *parser) callonJSON1() (any, error) { stack := p.vstack[len(p.vstack)-1] _ = stack return p.cur.onJSON1(stack["val"]) } -func (c *current) onValue7() (interface{}, error) { +func (c *current) onValue7() (any, error) { // JSON numbers have the same syntax as Go's, and are parseable using // strconv. return strconv.ParseFloat(string(c.text), 64) } -func (p *parser) callonValue7() (interface{}, error) { +func (p *parser) callonValue7() (any, error) { stack := p.vstack[len(p.vstack)-1] _ = stack return p.cur.onValue7() } -func (c *current) onValue29() (interface{}, error) { +func (c *current) onValue29() (any, error) { c.text = bytes.Replace(c.text, []byte(`\/`), []byte(`/`), -1) return strconv.Unquote(string(c.text)) } -func (p *parser) callonValue29() (interface{}, error) { +func (p *parser) callonValue29() (any, error) { stack := p.vstack[len(p.vstack)-1] _ = stack return p.cur.onValue29() } -func (c *current) onValue49() (interface{}, error) { +func (c *current) onValue49() (any, error) { return true, nil } -func (p *parser) callonValue49() (interface{}, error) { +func (p *parser) callonValue49() (any, error) { stack := p.vstack[len(p.vstack)-1] _ = stack return p.cur.onValue49() } -func (c *current) onValue51() (interface{}, error) { +func (c *current) onValue51() (any, error) { return false, nil } -func (p *parser) callonValue51() (interface{}, error) { +func (p *parser) callonValue51() (any, error) { stack := p.vstack[len(p.vstack)-1] _ = stack return p.cur.onValue51() } -func (c *current) onValue53() (interface{}, error) { +func (c *current) onValue53() (any, error) { return nil, nil } -func (p *parser) callonValue53() (interface{}, error) { +func (p *parser) callonValue53() (any, error) { stack := p.vstack[len(p.vstack)-1] _ = stack return p.cur.onValue53() } -func (c *current) onValue1(val interface{}) (interface{}, error) { +func (c *current) onValue1(val any) (any, error) { return val, nil } -func (p *parser) callonValue1() (interface{}, error) { +func (p *parser) callonValue1() (any, error) { stack := p.vstack[len(p.vstack)-1] _ = stack return p.cur.onValue1(stack["val"]) } -func (c *current) onObject9() (interface{}, error) { +func (c *current) onObject9() (any, error) { c.text = bytes.Replace(c.text, []byte(`\/`), []byte(`/`), -1) return strconv.Unquote(string(c.text)) } -func (p *parser) callonObject9() (interface{}, error) { +func (p *parser) callonObject9() (any, error) { stack := p.vstack[len(p.vstack)-1] _ = stack return p.cur.onObject9() } -func (c *current) onObject40() (interface{}, error) { +func (c *current) onObject40() (any, error) { c.text = bytes.Replace(c.text, []byte(`\/`), []byte(`/`), -1) return strconv.Unquote(string(c.text)) } -func (p *parser) callonObject40() (interface{}, error) { +func (p *parser) callonObject40() (any, error) { stack := p.vstack[len(p.vstack)-1] _ = stack return p.cur.onObject40() } -func (c *current) onObject1(vals interface{}) (interface{}, error) { - res := make(map[string]interface{}) - valsSl := toIfaceSlice(vals) +func (c *current) onObject1(vals any) (any, error) { + res := make(map[string]any) + valsSl := toAnySlice(vals) if len(valsSl) == 0 { return res, nil } res[valsSl[0].(string)] = valsSl[4] - restSl := toIfaceSlice(valsSl[5]) + restSl := toAnySlice(valsSl[5]) for _, v := range restSl { - vSl := toIfaceSlice(v) + vSl := toAnySlice(v) res[vSl[2].(string)] = vSl[6] } return res, nil } -func (p *parser) callonObject1() (interface{}, error) { +func (p *parser) callonObject1() (any, error) { stack := p.vstack[len(p.vstack)-1] _ = stack return p.cur.onObject1(stack["vals"]) } -func (c *current) onArray1(vals interface{}) (interface{}, error) { - valsSl := toIfaceSlice(vals) +func (c *current) onArray1(vals any) (any, error) { + valsSl := toAnySlice(vals) if len(valsSl) == 0 { - return []interface{}{}, nil + return []any{}, nil } - res := []interface{}{valsSl[0]} - restSl := toIfaceSlice(valsSl[1]) + res := []any{valsSl[0]} + restSl := toAnySlice(valsSl[1]) for _, v := range restSl { - vSl := toIfaceSlice(v) + vSl := toAnySlice(v) res = append(res, vSl[2]) } return res, nil } -func (p *parser) callonArray1() (interface{}, error) { +func (p *parser) callonArray1() (any, error) { stack := p.vstack[len(p.vstack)-1] _ = stack return p.cur.onArray1(stack["vals"]) @@ -1064,7 +1064,7 @@ func Recover(b bool) Option { // GlobalStore creates an Option to set a key to a certain value in // the globalStore. -func GlobalStore(key string, value interface{}) Option { +func GlobalStore(key string, value any) Option { return func(p *parser) Option { old := p.cur.globalStore[key] p.cur.globalStore[key] = value @@ -1074,7 +1074,7 @@ func GlobalStore(key string, value interface{}) Option { // InitState creates an Option to set a key to a certain value in // the global "state" store. -func InitState(key string, value interface{}) Option { +func InitState(key string, value any) Option { return func(p *parser) Option { old := p.cur.state[key] p.cur.state[key] = value @@ -1083,7 +1083,7 @@ func InitState(key string, value interface{}) Option { } // ParseFile parses the file identified by filename. -func ParseFile(filename string, opts ...Option) (i interface{}, err error) { // nolint: deadcode +func ParseFile(filename string, opts ...Option) (i any, err error) { // nolint: deadcode f, err := os.Open(filename) if err != nil { return nil, err @@ -1098,7 +1098,7 @@ func ParseFile(filename string, opts ...Option) (i interface{}, err error) { // // ParseReader parses the data from r using filename as information in the // error messages. -func ParseReader(filename string, r io.Reader, opts ...Option) (interface{}, error) { // nolint: deadcode +func ParseReader(filename string, r io.Reader, opts ...Option) (any, error) { // nolint: deadcode b, err := io.ReadAll(r) if err != nil { return nil, err @@ -1109,7 +1109,7 @@ func ParseReader(filename string, r io.Reader, opts ...Option) (interface{}, err // Parse parses the data from b using filename as information in the // error messages. -func Parse(filename string, b []byte, opts ...Option) (interface{}, error) { +func Parse(filename string, b []byte, opts ...Option) (any, error) { return newParser(filename, b, opts...).parse(g) } @@ -1147,7 +1147,7 @@ type current struct { globalStore storeDict } -type storeDict map[string]interface{} +type storeDict map[string]any // the AST types... @@ -1162,34 +1162,34 @@ type rule struct { pos position name string displayName string - expr interface{} + expr any } // nolint: structcheck type choiceExpr struct { pos position - alternatives []interface{} + alternatives []any } // nolint: structcheck type actionExpr struct { pos position - expr interface{} - run func(*parser) (interface{}, error) + expr any + run func(*parser) (any, error) } // nolint: structcheck type recoveryExpr struct { pos position - expr interface{} - recoverExpr interface{} + expr any + recoverExpr any failureLabel []string } // nolint: structcheck type seqExpr struct { pos position - exprs []interface{} + exprs []any } // nolint: structcheck @@ -1202,20 +1202,22 @@ type throwExpr struct { type labeledExpr struct { pos position label string - expr interface{} + expr any } // nolint: structcheck type expr struct { pos position - expr interface{} + expr any } -type andExpr expr // nolint: structcheck -type notExpr expr // nolint: structcheck -type zeroOrOneExpr expr // nolint: structcheck -type zeroOrMoreExpr expr // nolint: structcheck -type oneOrMoreExpr expr // nolint: structcheck +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 { @@ -1363,7 +1365,7 @@ func (p *parser) setOptions(opts []Option) { // nolint: structcheck,deadcode type resultTuple struct { - v interface{} + v any b bool end savepoint } @@ -1409,12 +1411,12 @@ type parser struct { memoize bool // memoization table for the packrat algorithm: // map[offset in source] map[expression or rule] {value, match} - memo map[int]map[interface{}]resultTuple + 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]interface{} + vstack []map[string]any // rule stack, allows identification of the current rule in errors rstack []*rule @@ -1434,7 +1436,7 @@ type parser struct { choiceNoMatch string // recovery expression stack, keeps track of the currently available recovery expression, these are traversed in reverse - recoveryStack []map[string]interface{} + recoveryStack []map[string]any } // push a variable set on the vstack. @@ -1454,7 +1456,7 @@ func (p *parser) pushV() { return } - m = make(map[string]interface{}) + m = make(map[string]any) p.vstack[len(p.vstack)-1] = m } @@ -1470,7 +1472,7 @@ func (p *parser) popV() { } // push a recovery expression with its labels to the recoveryStack -func (p *parser) pushRecovery(labels []string, expr interface{}) { +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) @@ -1479,7 +1481,7 @@ func (p *parser) pushRecovery(labels []string, expr interface{}) { p.recoveryStack = p.recoveryStack[:len(p.recoveryStack)+1] } - m := make(map[string]interface{}, len(labels)) + m := make(map[string]any, len(labels)) for _, fl := range labels { m[fl] = expr } @@ -1599,11 +1601,11 @@ func (p *parser) restore(pt savepoint) { // copies of the state to allow the parser to properly restore the state in // the case of backtracking. type Cloner interface { - Clone() interface{} + Clone() any } var statePool = &sync.Pool{ - New: func() interface{} { return make(storeDict) }, + New: func() any { return make(storeDict) }, } func (sd storeDict) Discard() { @@ -1645,7 +1647,7 @@ func (p *parser) sliceFrom(start savepoint) []byte { return p.data[start.position.offset:p.pt.position.offset] } -func (p *parser) getMemoized(node interface{}) (resultTuple, bool) { +func (p *parser) getMemoized(node any) (resultTuple, bool) { if len(p.memo) == 0 { return resultTuple{}, false } @@ -1657,13 +1659,13 @@ func (p *parser) getMemoized(node interface{}) (resultTuple, bool) { return res, ok } -func (p *parser) setMemoized(pt savepoint, node interface{}, tuple resultTuple) { +func (p *parser) setMemoized(pt savepoint, node any, tuple resultTuple) { if p.memo == nil { - p.memo = make(map[int]map[interface{}]resultTuple) + p.memo = make(map[int]map[any]resultTuple) } m := p.memo[pt.offset] if m == nil { - m = make(map[interface{}]resultTuple) + m = make(map[any]resultTuple) p.memo[pt.offset] = m } m[node] = tuple @@ -1677,7 +1679,7 @@ func (p *parser) buildRulesTable(g *grammar) { } // nolint: gocyclo -func (p *parser) parse(g *grammar) (val interface{}, err error) { +func (p *parser) parse(g *grammar) (val any, err error) { if len(g.rules) == 0 { p.addErr(errNoRule) return nil, p.errs.err() @@ -1754,7 +1756,7 @@ func listJoin(list []string, sep string, lastSep string) string { } } -func (p *parser) parseRule(rule *rule) (interface{}, bool) { +func (p *parser) parseRule(rule *rule) (any, bool) { if p.debug { defer p.out(p.in("parseRule " + rule.name)) } @@ -1784,7 +1786,7 @@ func (p *parser) parseRule(rule *rule) (interface{}, bool) { } // nolint: gocyclo -func (p *parser) parseExpr(expr interface{}) (interface{}, bool) { +func (p *parser) parseExpr(expr any) (any, bool) { var pt savepoint if p.memoize { @@ -1801,7 +1803,7 @@ func (p *parser) parseExpr(expr interface{}) (interface{}, bool) { panic(errMaxExprCnt) } - var val interface{} + var val any var ok bool switch expr := expr.(type) { case *actionExpr: @@ -1849,7 +1851,7 @@ func (p *parser) parseExpr(expr interface{}) (interface{}, bool) { return val, ok } -func (p *parser) parseActionExpr(act *actionExpr) (interface{}, bool) { +func (p *parser) parseActionExpr(act *actionExpr) (any, bool) { if p.debug { defer p.out(p.in("parseActionExpr")) } @@ -1874,7 +1876,7 @@ func (p *parser) parseActionExpr(act *actionExpr) (interface{}, bool) { return val, ok } -func (p *parser) parseAndCodeExpr(and *andCodeExpr) (interface{}, bool) { +func (p *parser) parseAndCodeExpr(and *andCodeExpr) (any, bool) { if p.debug { defer p.out(p.in("parseAndCodeExpr")) } @@ -1890,7 +1892,7 @@ func (p *parser) parseAndCodeExpr(and *andCodeExpr) (interface{}, bool) { return nil, ok } -func (p *parser) parseAndExpr(and *andExpr) (interface{}, bool) { +func (p *parser) parseAndExpr(and *andExpr) (any, bool) { if p.debug { defer p.out(p.in("parseAndExpr")) } @@ -1906,7 +1908,7 @@ func (p *parser) parseAndExpr(and *andExpr) (interface{}, bool) { return nil, ok } -func (p *parser) parseAnyMatcher(any *anyMatcher) (interface{}, bool) { +func (p *parser) parseAnyMatcher(any *anyMatcher) (any, bool) { if p.debug { defer p.out(p.in("parseAnyMatcher")) } @@ -1923,7 +1925,7 @@ func (p *parser) parseAnyMatcher(any *anyMatcher) (interface{}, bool) { } // nolint: gocyclo -func (p *parser) parseCharClassMatcher(chr *charClassMatcher) (interface{}, bool) { +func (p *parser) parseCharClassMatcher(chr *charClassMatcher) (any, bool) { if p.debug { defer p.out(p.in("parseCharClassMatcher")) } @@ -2004,7 +2006,7 @@ func (p *parser) incChoiceAltCnt(ch *choiceExpr, altI int) { m[alt]++ } -func (p *parser) parseChoiceExpr(ch *choiceExpr) (interface{}, bool) { +func (p *parser) parseChoiceExpr(ch *choiceExpr) (any, bool) { if p.debug { defer p.out(p.in("parseChoiceExpr")) } @@ -2028,7 +2030,7 @@ func (p *parser) parseChoiceExpr(ch *choiceExpr) (interface{}, bool) { return nil, false } -func (p *parser) parseLabeledExpr(lab *labeledExpr) (interface{}, bool) { +func (p *parser) parseLabeledExpr(lab *labeledExpr) (any, bool) { if p.debug { defer p.out(p.in("parseLabeledExpr")) } @@ -2043,7 +2045,7 @@ func (p *parser) parseLabeledExpr(lab *labeledExpr) (interface{}, bool) { return val, ok } -func (p *parser) parseLitMatcher(lit *litMatcher) (interface{}, bool) { +func (p *parser) parseLitMatcher(lit *litMatcher) (any, bool) { if p.debug { defer p.out(p.in("parseLitMatcher")) } @@ -2065,7 +2067,7 @@ func (p *parser) parseLitMatcher(lit *litMatcher) (interface{}, bool) { return p.sliceFrom(start), true } -func (p *parser) parseNotCodeExpr(not *notCodeExpr) (interface{}, bool) { +func (p *parser) parseNotCodeExpr(not *notCodeExpr) (any, bool) { if p.debug { defer p.out(p.in("parseNotCodeExpr")) } @@ -2081,7 +2083,7 @@ func (p *parser) parseNotCodeExpr(not *notCodeExpr) (interface{}, bool) { return nil, !ok } -func (p *parser) parseNotExpr(not *notExpr) (interface{}, bool) { +func (p *parser) parseNotExpr(not *notExpr) (any, bool) { if p.debug { defer p.out(p.in("parseNotExpr")) } @@ -2099,12 +2101,12 @@ func (p *parser) parseNotExpr(not *notExpr) (interface{}, bool) { return nil, !ok } -func (p *parser) parseOneOrMoreExpr(expr *oneOrMoreExpr) (interface{}, bool) { +func (p *parser) parseOneOrMoreExpr(expr *oneOrMoreExpr) (any, bool) { if p.debug { defer p.out(p.in("parseOneOrMoreExpr")) } - var vals []interface{} + var vals []any for { p.pushV() @@ -2121,7 +2123,7 @@ func (p *parser) parseOneOrMoreExpr(expr *oneOrMoreExpr) (interface{}, bool) { } } -func (p *parser) parseRecoveryExpr(recover *recoveryExpr) (interface{}, bool) { +func (p *parser) parseRecoveryExpr(recover *recoveryExpr) (any, bool) { if p.debug { defer p.out(p.in("parseRecoveryExpr (" + strings.Join(recover.failureLabel, ",") + ")")) } @@ -2133,7 +2135,7 @@ func (p *parser) parseRecoveryExpr(recover *recoveryExpr) (interface{}, bool) { return val, ok } -func (p *parser) parseRuleRefExpr(ref *ruleRefExpr) (interface{}, bool) { +func (p *parser) parseRuleRefExpr(ref *ruleRefExpr) (any, bool) { if p.debug { defer p.out(p.in("parseRuleRefExpr " + ref.name)) } @@ -2150,12 +2152,12 @@ func (p *parser) parseRuleRefExpr(ref *ruleRefExpr) (interface{}, bool) { return p.parseRule(rule) } -func (p *parser) parseSeqExpr(seq *seqExpr) (interface{}, bool) { +func (p *parser) parseSeqExpr(seq *seqExpr) (any, bool) { if p.debug { defer p.out(p.in("parseSeqExpr")) } - vals := make([]interface{}, 0, len(seq.exprs)) + vals := make([]any, 0, len(seq.exprs)) pt := p.pt state := p.cloneState() @@ -2171,7 +2173,7 @@ func (p *parser) parseSeqExpr(seq *seqExpr) (interface{}, bool) { return vals, true } -func (p *parser) parseStateCodeExpr(state *stateCodeExpr) (interface{}, bool) { +func (p *parser) parseStateCodeExpr(state *stateCodeExpr) (any, bool) { if p.debug { defer p.out(p.in("parseStateCodeExpr")) } @@ -2183,7 +2185,7 @@ func (p *parser) parseStateCodeExpr(state *stateCodeExpr) (interface{}, bool) { return nil, true } -func (p *parser) parseThrowExpr(expr *throwExpr) (interface{}, bool) { +func (p *parser) parseThrowExpr(expr *throwExpr) (any, bool) { if p.debug { defer p.out(p.in("parseThrowExpr")) } @@ -2199,12 +2201,12 @@ func (p *parser) parseThrowExpr(expr *throwExpr) (interface{}, bool) { return nil, false } -func (p *parser) parseZeroOrMoreExpr(expr *zeroOrMoreExpr) (interface{}, bool) { +func (p *parser) parseZeroOrMoreExpr(expr *zeroOrMoreExpr) (any, bool) { if p.debug { defer p.out(p.in("parseZeroOrMoreExpr")) } - var vals []interface{} + var vals []any for { p.pushV() @@ -2217,7 +2219,7 @@ func (p *parser) parseZeroOrMoreExpr(expr *zeroOrMoreExpr) (interface{}, bool) { } } -func (p *parser) parseZeroOrOneExpr(expr *zeroOrOneExpr) (interface{}, bool) { +func (p *parser) parseZeroOrOneExpr(expr *zeroOrOneExpr) (any, bool) { if p.debug { defer p.out(p.in("parseZeroOrOneExpr")) } diff --git a/examples/json/optimized/json.go b/examples/json/optimized/json.go index 18d8f697..013a8c0e 100644 --- a/examples/json/optimized/json.go +++ b/examples/json/optimized/json.go @@ -21,38 +21,38 @@ import ( "unicode/utf8" ) -func toIfaceSlice(v interface{}) []interface{} { +func toAnySlice(v any) []any { if v == nil { return nil } - return v.([]interface{}) + return v.([]any) } var g = &grammar{ rules: []*rule{ { name: "JSON", - pos: position{line: 17, col: 1, offset: 347}, + pos: position{line: 17, col: 1, offset: 321}, expr: &actionExpr{ - pos: position{line: 17, col: 8, offset: 356}, + pos: position{line: 17, col: 8, offset: 330}, run: (*parser).callonJSON1, expr: &seqExpr{ - pos: position{line: 17, col: 8, offset: 356}, - exprs: []interface{}{ + pos: position{line: 17, col: 8, offset: 330}, + exprs: []any{ &ruleRefExpr{ - pos: position{line: 17, col: 8, offset: 356}, + pos: position{line: 17, col: 8, offset: 330}, name: "_", }, &labeledExpr{ - pos: position{line: 17, col: 10, offset: 358}, + pos: position{line: 17, col: 10, offset: 332}, label: "val", expr: &ruleRefExpr{ - pos: position{line: 17, col: 14, offset: 362}, + pos: position{line: 17, col: 14, offset: 336}, name: "Value", }, }, &ruleRefExpr{ - pos: position{line: 17, col: 20, offset: 368}, + pos: position{line: 17, col: 20, offset: 342}, name: "EOF", }, }, @@ -61,48 +61,48 @@ var g = &grammar{ }, { name: "Value", - pos: position{line: 21, col: 1, offset: 397}, + pos: position{line: 21, col: 1, offset: 371}, expr: &actionExpr{ - pos: position{line: 21, col: 9, offset: 407}, + pos: position{line: 21, col: 9, offset: 381}, run: (*parser).callonValue1, expr: &seqExpr{ - pos: position{line: 21, col: 9, offset: 407}, - exprs: []interface{}{ + pos: position{line: 21, col: 9, offset: 381}, + exprs: []any{ &labeledExpr{ - pos: position{line: 21, col: 9, offset: 407}, + pos: position{line: 21, col: 9, offset: 381}, label: "val", expr: &choiceExpr{ - pos: position{line: 21, col: 15, offset: 413}, - alternatives: []interface{}{ + pos: position{line: 21, col: 15, offset: 387}, + alternatives: []any{ &ruleRefExpr{ - pos: position{line: 21, col: 15, offset: 413}, + pos: position{line: 21, col: 15, offset: 387}, name: "Object", }, &ruleRefExpr{ - pos: position{line: 21, col: 24, offset: 422}, + pos: position{line: 21, col: 24, offset: 396}, name: "Array", }, &ruleRefExpr{ - pos: position{line: 21, col: 32, offset: 430}, + pos: position{line: 21, col: 32, offset: 404}, name: "Number", }, &ruleRefExpr{ - pos: position{line: 21, col: 41, offset: 439}, + pos: position{line: 21, col: 41, offset: 413}, name: "String", }, &ruleRefExpr{ - pos: position{line: 21, col: 50, offset: 448}, + pos: position{line: 21, col: 50, offset: 422}, name: "Bool", }, &ruleRefExpr{ - pos: position{line: 21, col: 57, offset: 455}, + pos: position{line: 21, col: 57, offset: 429}, name: "Null", }, }, }, }, &ruleRefExpr{ - pos: position{line: 21, col: 64, offset: 462}, + pos: position{line: 21, col: 64, offset: 436}, name: "_", }, }, @@ -111,88 +111,88 @@ var g = &grammar{ }, { name: "Object", - pos: position{line: 25, col: 1, offset: 489}, + pos: position{line: 25, col: 1, offset: 463}, expr: &actionExpr{ - pos: position{line: 25, col: 10, offset: 500}, + pos: position{line: 25, col: 10, offset: 474}, run: (*parser).callonObject1, expr: &seqExpr{ - pos: position{line: 25, col: 10, offset: 500}, - exprs: []interface{}{ + pos: position{line: 25, col: 10, offset: 474}, + exprs: []any{ &litMatcher{ - pos: position{line: 25, col: 10, offset: 500}, + pos: position{line: 25, col: 10, offset: 474}, val: "{", ignoreCase: false, want: "\"{\"", }, &ruleRefExpr{ - pos: position{line: 25, col: 14, offset: 504}, + pos: position{line: 25, col: 14, offset: 478}, name: "_", }, &labeledExpr{ - pos: position{line: 25, col: 16, offset: 506}, + pos: position{line: 25, col: 16, offset: 480}, label: "vals", expr: &zeroOrOneExpr{ - pos: position{line: 25, col: 21, offset: 511}, + pos: position{line: 25, col: 21, offset: 485}, expr: &seqExpr{ - pos: position{line: 25, col: 23, offset: 513}, - exprs: []interface{}{ + pos: position{line: 25, col: 23, offset: 487}, + exprs: []any{ &ruleRefExpr{ - pos: position{line: 25, col: 23, offset: 513}, + pos: position{line: 25, col: 23, offset: 487}, name: "String", }, &ruleRefExpr{ - pos: position{line: 25, col: 30, offset: 520}, + pos: position{line: 25, col: 30, offset: 494}, name: "_", }, &litMatcher{ - pos: position{line: 25, col: 32, offset: 522}, + pos: position{line: 25, col: 32, offset: 496}, val: ":", ignoreCase: false, want: "\":\"", }, &ruleRefExpr{ - pos: position{line: 25, col: 36, offset: 526}, + pos: position{line: 25, col: 36, offset: 500}, name: "_", }, &ruleRefExpr{ - pos: position{line: 25, col: 38, offset: 528}, + pos: position{line: 25, col: 38, offset: 502}, name: "Value", }, &zeroOrMoreExpr{ - pos: position{line: 25, col: 44, offset: 534}, + pos: position{line: 25, col: 44, offset: 508}, expr: &seqExpr{ - pos: position{line: 25, col: 46, offset: 536}, - exprs: []interface{}{ + pos: position{line: 25, col: 46, offset: 510}, + exprs: []any{ &litMatcher{ - pos: position{line: 25, col: 46, offset: 536}, + pos: position{line: 25, col: 46, offset: 510}, val: ",", ignoreCase: false, want: "\",\"", }, &ruleRefExpr{ - pos: position{line: 25, col: 50, offset: 540}, + pos: position{line: 25, col: 50, offset: 514}, name: "_", }, &ruleRefExpr{ - pos: position{line: 25, col: 52, offset: 542}, + pos: position{line: 25, col: 52, offset: 516}, name: "String", }, &ruleRefExpr{ - pos: position{line: 25, col: 59, offset: 549}, + pos: position{line: 25, col: 59, offset: 523}, name: "_", }, &litMatcher{ - pos: position{line: 25, col: 61, offset: 551}, + pos: position{line: 25, col: 61, offset: 525}, val: ":", ignoreCase: false, want: "\":\"", }, &ruleRefExpr{ - pos: position{line: 25, col: 65, offset: 555}, + pos: position{line: 25, col: 65, offset: 529}, name: "_", }, &ruleRefExpr{ - pos: position{line: 25, col: 67, offset: 557}, + pos: position{line: 25, col: 67, offset: 531}, name: "Value", }, }, @@ -203,7 +203,7 @@ var g = &grammar{ }, }, &litMatcher{ - pos: position{line: 25, col: 79, offset: 569}, + pos: position{line: 25, col: 79, offset: 543}, val: "}", ignoreCase: false, want: "\"}\"", @@ -214,52 +214,52 @@ var g = &grammar{ }, { name: "Array", - pos: position{line: 40, col: 1, offset: 911}, + pos: position{line: 40, col: 1, offset: 871}, expr: &actionExpr{ - pos: position{line: 40, col: 9, offset: 921}, + pos: position{line: 40, col: 9, offset: 881}, run: (*parser).callonArray1, expr: &seqExpr{ - pos: position{line: 40, col: 9, offset: 921}, - exprs: []interface{}{ + pos: position{line: 40, col: 9, offset: 881}, + exprs: []any{ &litMatcher{ - pos: position{line: 40, col: 9, offset: 921}, + pos: position{line: 40, col: 9, offset: 881}, val: "[", ignoreCase: false, want: "\"[\"", }, &ruleRefExpr{ - pos: position{line: 40, col: 13, offset: 925}, + pos: position{line: 40, col: 13, offset: 885}, name: "_", }, &labeledExpr{ - pos: position{line: 40, col: 15, offset: 927}, + pos: position{line: 40, col: 15, offset: 887}, label: "vals", expr: &zeroOrOneExpr{ - pos: position{line: 40, col: 20, offset: 932}, + pos: position{line: 40, col: 20, offset: 892}, expr: &seqExpr{ - pos: position{line: 40, col: 22, offset: 934}, - exprs: []interface{}{ + pos: position{line: 40, col: 22, offset: 894}, + exprs: []any{ &ruleRefExpr{ - pos: position{line: 40, col: 22, offset: 934}, + pos: position{line: 40, col: 22, offset: 894}, name: "Value", }, &zeroOrMoreExpr{ - pos: position{line: 40, col: 28, offset: 940}, + pos: position{line: 40, col: 28, offset: 900}, expr: &seqExpr{ - pos: position{line: 40, col: 30, offset: 942}, - exprs: []interface{}{ + pos: position{line: 40, col: 30, offset: 902}, + exprs: []any{ &litMatcher{ - pos: position{line: 40, col: 30, offset: 942}, + pos: position{line: 40, col: 30, offset: 902}, val: ",", ignoreCase: false, want: "\",\"", }, &ruleRefExpr{ - pos: position{line: 40, col: 34, offset: 946}, + pos: position{line: 40, col: 34, offset: 906}, name: "_", }, &ruleRefExpr{ - pos: position{line: 40, col: 36, offset: 948}, + pos: position{line: 40, col: 36, offset: 908}, name: "Value", }, }, @@ -270,7 +270,7 @@ var g = &grammar{ }, }, &litMatcher{ - pos: position{line: 40, col: 48, offset: 960}, + pos: position{line: 40, col: 48, offset: 920}, val: "]", ignoreCase: false, want: "\"]\"", @@ -281,41 +281,41 @@ var g = &grammar{ }, { name: "Number", - pos: position{line: 54, col: 1, offset: 1266}, + pos: position{line: 54, col: 1, offset: 1204}, expr: &actionExpr{ - pos: position{line: 54, col: 10, offset: 1277}, + pos: position{line: 54, col: 10, offset: 1215}, run: (*parser).callonNumber1, expr: &seqExpr{ - pos: position{line: 54, col: 10, offset: 1277}, - exprs: []interface{}{ + pos: position{line: 54, col: 10, offset: 1215}, + exprs: []any{ &zeroOrOneExpr{ - pos: position{line: 54, col: 10, offset: 1277}, + pos: position{line: 54, col: 10, offset: 1215}, expr: &litMatcher{ - pos: position{line: 54, col: 10, offset: 1277}, + pos: position{line: 54, col: 10, offset: 1215}, val: "-", ignoreCase: false, want: "\"-\"", }, }, &ruleRefExpr{ - pos: position{line: 54, col: 15, offset: 1282}, + pos: position{line: 54, col: 15, offset: 1220}, name: "Integer", }, &zeroOrOneExpr{ - pos: position{line: 54, col: 23, offset: 1290}, + pos: position{line: 54, col: 23, offset: 1228}, expr: &seqExpr{ - pos: position{line: 54, col: 25, offset: 1292}, - exprs: []interface{}{ + pos: position{line: 54, col: 25, offset: 1230}, + exprs: []any{ &litMatcher{ - pos: position{line: 54, col: 25, offset: 1292}, + pos: position{line: 54, col: 25, offset: 1230}, val: ".", ignoreCase: false, want: "\".\"", }, &oneOrMoreExpr{ - pos: position{line: 54, col: 29, offset: 1296}, + pos: position{line: 54, col: 29, offset: 1234}, expr: &ruleRefExpr{ - pos: position{line: 54, col: 29, offset: 1296}, + pos: position{line: 54, col: 29, offset: 1234}, name: "DecimalDigit", }, }, @@ -323,9 +323,9 @@ var g = &grammar{ }, }, &zeroOrOneExpr{ - pos: position{line: 54, col: 46, offset: 1313}, + pos: position{line: 54, col: 46, offset: 1251}, expr: &ruleRefExpr{ - pos: position{line: 54, col: 46, offset: 1313}, + pos: position{line: 54, col: 46, offset: 1251}, name: "Exponent", }, }, @@ -335,27 +335,27 @@ var g = &grammar{ }, { name: "Integer", - pos: position{line: 60, col: 1, offset: 1468}, + pos: position{line: 60, col: 1, offset: 1406}, expr: &choiceExpr{ - pos: position{line: 60, col: 11, offset: 1480}, - alternatives: []interface{}{ + pos: position{line: 60, col: 11, offset: 1418}, + alternatives: []any{ &litMatcher{ - pos: position{line: 60, col: 11, offset: 1480}, + pos: position{line: 60, col: 11, offset: 1418}, val: "0", ignoreCase: false, want: "\"0\"", }, &seqExpr{ - pos: position{line: 60, col: 17, offset: 1486}, - exprs: []interface{}{ + pos: position{line: 60, col: 17, offset: 1424}, + exprs: []any{ &ruleRefExpr{ - pos: position{line: 60, col: 17, offset: 1486}, + pos: position{line: 60, col: 17, offset: 1424}, name: "NonZeroDecimalDigit", }, &zeroOrMoreExpr{ - pos: position{line: 60, col: 37, offset: 1506}, + pos: position{line: 60, col: 37, offset: 1444}, expr: &ruleRefExpr{ - pos: position{line: 60, col: 37, offset: 1506}, + pos: position{line: 60, col: 37, offset: 1444}, name: "DecimalDigit", }, }, @@ -366,20 +366,20 @@ var g = &grammar{ }, { name: "Exponent", - pos: position{line: 62, col: 1, offset: 1521}, + pos: position{line: 62, col: 1, offset: 1459}, expr: &seqExpr{ - pos: position{line: 62, col: 12, offset: 1534}, - exprs: []interface{}{ + pos: position{line: 62, col: 12, offset: 1472}, + exprs: []any{ &litMatcher{ - pos: position{line: 62, col: 12, offset: 1534}, + pos: position{line: 62, col: 12, offset: 1472}, val: "e", ignoreCase: true, want: "\"e\"i", }, &zeroOrOneExpr{ - pos: position{line: 62, col: 17, offset: 1539}, + pos: position{line: 62, col: 17, offset: 1477}, expr: &charClassMatcher{ - pos: position{line: 62, col: 17, offset: 1539}, + pos: position{line: 62, col: 17, offset: 1477}, val: "[+-]", chars: []rune{'+', '-'}, basicLatinChars: [128]bool{false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, true, false, true, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false}, @@ -388,9 +388,9 @@ var g = &grammar{ }, }, &oneOrMoreExpr{ - pos: position{line: 62, col: 23, offset: 1545}, + pos: position{line: 62, col: 23, offset: 1483}, expr: &ruleRefExpr{ - pos: position{line: 62, col: 23, offset: 1545}, + pos: position{line: 62, col: 23, offset: 1483}, name: "DecimalDigit", }, }, @@ -399,50 +399,50 @@ var g = &grammar{ }, { name: "String", - pos: position{line: 64, col: 1, offset: 1560}, + pos: position{line: 64, col: 1, offset: 1498}, expr: &actionExpr{ - pos: position{line: 64, col: 10, offset: 1571}, + pos: position{line: 64, col: 10, offset: 1509}, run: (*parser).callonString1, expr: &seqExpr{ - pos: position{line: 64, col: 10, offset: 1571}, - exprs: []interface{}{ + pos: position{line: 64, col: 10, offset: 1509}, + exprs: []any{ &litMatcher{ - pos: position{line: 64, col: 10, offset: 1571}, + pos: position{line: 64, col: 10, offset: 1509}, val: "\"", ignoreCase: false, want: "\"\\\"\"", }, &zeroOrMoreExpr{ - pos: position{line: 64, col: 14, offset: 1575}, + pos: position{line: 64, col: 14, offset: 1513}, expr: &choiceExpr{ - pos: position{line: 64, col: 16, offset: 1577}, - alternatives: []interface{}{ + pos: position{line: 64, col: 16, offset: 1515}, + alternatives: []any{ &seqExpr{ - pos: position{line: 64, col: 16, offset: 1577}, - exprs: []interface{}{ + pos: position{line: 64, col: 16, offset: 1515}, + exprs: []any{ ¬Expr{ - pos: position{line: 64, col: 16, offset: 1577}, + pos: position{line: 64, col: 16, offset: 1515}, expr: &ruleRefExpr{ - pos: position{line: 64, col: 17, offset: 1578}, + pos: position{line: 64, col: 17, offset: 1516}, name: "EscapedChar", }, }, &anyMatcher{ - line: 64, col: 29, offset: 1590, + line: 64, col: 29, offset: 1528, }, }, }, &seqExpr{ - pos: position{line: 64, col: 33, offset: 1594}, - exprs: []interface{}{ + pos: position{line: 64, col: 33, offset: 1532}, + exprs: []any{ &litMatcher{ - pos: position{line: 64, col: 33, offset: 1594}, + pos: position{line: 64, col: 33, offset: 1532}, val: "\\", ignoreCase: false, want: "\"\\\\\"", }, &ruleRefExpr{ - pos: position{line: 64, col: 38, offset: 1599}, + pos: position{line: 64, col: 38, offset: 1537}, name: "EscapeSequence", }, }, @@ -451,7 +451,7 @@ var g = &grammar{ }, }, &litMatcher{ - pos: position{line: 64, col: 56, offset: 1617}, + pos: position{line: 64, col: 56, offset: 1555}, val: "\"", ignoreCase: false, want: "\"\\\"\"", @@ -462,9 +462,9 @@ var g = &grammar{ }, { name: "EscapedChar", - pos: position{line: 69, col: 1, offset: 1735}, + pos: position{line: 69, col: 1, offset: 1673}, expr: &charClassMatcher{ - pos: position{line: 69, col: 15, offset: 1751}, + pos: position{line: 69, col: 15, offset: 1689}, val: "[\\x00-\\x1f\"\\\\]", chars: []rune{'"', '\\'}, ranges: []rune{'\x00', '\x1f'}, @@ -475,16 +475,16 @@ var g = &grammar{ }, { name: "EscapeSequence", - pos: position{line: 71, col: 1, offset: 1767}, + pos: position{line: 71, col: 1, offset: 1705}, expr: &choiceExpr{ - pos: position{line: 71, col: 18, offset: 1786}, - alternatives: []interface{}{ + pos: position{line: 71, col: 18, offset: 1724}, + alternatives: []any{ &ruleRefExpr{ - pos: position{line: 71, col: 18, offset: 1786}, + pos: position{line: 71, col: 18, offset: 1724}, name: "SingleCharEscape", }, &ruleRefExpr{ - pos: position{line: 71, col: 37, offset: 1805}, + pos: position{line: 71, col: 37, offset: 1743}, name: "UnicodeEscape", }, }, @@ -492,9 +492,9 @@ var g = &grammar{ }, { name: "SingleCharEscape", - pos: position{line: 73, col: 1, offset: 1820}, + pos: position{line: 73, col: 1, offset: 1758}, expr: &charClassMatcher{ - pos: position{line: 73, col: 20, offset: 1841}, + pos: position{line: 73, col: 20, offset: 1779}, val: "[\"\\\\/bfnrt]", chars: []rune{'"', '\\', '/', 'b', 'f', 'n', 'r', 't'}, basicLatinChars: [128]bool{false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, true, false, false, false, false, false, false, false, false, false, false, false, false, true, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, true, false, false, false, false, false, true, false, false, false, true, false, false, false, false, false, false, false, true, false, false, false, true, false, true, false, false, false, false, false, false, false, false, false, false, false}, @@ -504,30 +504,30 @@ var g = &grammar{ }, { name: "UnicodeEscape", - pos: position{line: 75, col: 1, offset: 1854}, + pos: position{line: 75, col: 1, offset: 1792}, expr: &seqExpr{ - pos: position{line: 75, col: 17, offset: 1872}, - exprs: []interface{}{ + pos: position{line: 75, col: 17, offset: 1810}, + exprs: []any{ &litMatcher{ - pos: position{line: 75, col: 17, offset: 1872}, + pos: position{line: 75, col: 17, offset: 1810}, val: "u", ignoreCase: false, want: "\"u\"", }, &ruleRefExpr{ - pos: position{line: 75, col: 21, offset: 1876}, + pos: position{line: 75, col: 21, offset: 1814}, name: "HexDigit", }, &ruleRefExpr{ - pos: position{line: 75, col: 30, offset: 1885}, + pos: position{line: 75, col: 30, offset: 1823}, name: "HexDigit", }, &ruleRefExpr{ - pos: position{line: 75, col: 39, offset: 1894}, + pos: position{line: 75, col: 39, offset: 1832}, name: "HexDigit", }, &ruleRefExpr{ - pos: position{line: 75, col: 48, offset: 1903}, + pos: position{line: 75, col: 48, offset: 1841}, name: "HexDigit", }, }, @@ -535,9 +535,9 @@ var g = &grammar{ }, { name: "DecimalDigit", - pos: position{line: 77, col: 1, offset: 1913}, + pos: position{line: 77, col: 1, offset: 1851}, expr: &charClassMatcher{ - pos: position{line: 77, col: 16, offset: 1930}, + pos: position{line: 77, col: 16, offset: 1868}, val: "[0-9]", ranges: []rune{'0', '9'}, basicLatinChars: [128]bool{false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, true, true, true, true, true, true, true, true, true, true, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false}, @@ -547,9 +547,9 @@ var g = &grammar{ }, { name: "NonZeroDecimalDigit", - pos: position{line: 79, col: 1, offset: 1937}, + pos: position{line: 79, col: 1, offset: 1875}, expr: &charClassMatcher{ - pos: position{line: 79, col: 23, offset: 1961}, + pos: position{line: 79, col: 23, offset: 1899}, val: "[1-9]", ranges: []rune{'1', '9'}, basicLatinChars: [128]bool{false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, true, true, true, true, true, true, true, true, true, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false}, @@ -559,9 +559,9 @@ var g = &grammar{ }, { name: "HexDigit", - pos: position{line: 81, col: 1, offset: 1968}, + pos: position{line: 81, col: 1, offset: 1906}, expr: &charClassMatcher{ - pos: position{line: 81, col: 12, offset: 1981}, + pos: position{line: 81, col: 12, offset: 1919}, val: "[0-9a-f]i", ranges: []rune{'0', '9', 'a', 'f'}, basicLatinChars: [128]bool{false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, true, true, true, true, true, true, true, true, true, true, false, false, false, false, false, false, false, true, true, true, true, true, true, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, true, true, true, true, true, true, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false}, @@ -571,25 +571,25 @@ var g = &grammar{ }, { name: "Bool", - pos: position{line: 83, col: 1, offset: 1992}, + pos: position{line: 83, col: 1, offset: 1930}, expr: &choiceExpr{ - pos: position{line: 83, col: 8, offset: 2001}, - alternatives: []interface{}{ + pos: position{line: 83, col: 8, offset: 1939}, + alternatives: []any{ &actionExpr{ - pos: position{line: 83, col: 8, offset: 2001}, + pos: position{line: 83, col: 8, offset: 1939}, run: (*parser).callonBool2, expr: &litMatcher{ - pos: position{line: 83, col: 8, offset: 2001}, + pos: position{line: 83, col: 8, offset: 1939}, val: "true", ignoreCase: false, want: "\"true\"", }, }, &actionExpr{ - pos: position{line: 83, col: 38, offset: 2031}, + pos: position{line: 83, col: 38, offset: 1969}, run: (*parser).callonBool4, expr: &litMatcher{ - pos: position{line: 83, col: 38, offset: 2031}, + pos: position{line: 83, col: 38, offset: 1969}, val: "false", ignoreCase: false, want: "\"false\"", @@ -600,12 +600,12 @@ var g = &grammar{ }, { name: "Null", - pos: position{line: 85, col: 1, offset: 2062}, + pos: position{line: 85, col: 1, offset: 2000}, expr: &actionExpr{ - pos: position{line: 85, col: 8, offset: 2071}, + pos: position{line: 85, col: 8, offset: 2009}, run: (*parser).callonNull1, expr: &litMatcher{ - pos: position{line: 85, col: 8, offset: 2071}, + pos: position{line: 85, col: 8, offset: 2009}, val: "null", ignoreCase: false, want: "\"null\"", @@ -615,11 +615,11 @@ var g = &grammar{ { name: "_", displayName: "\"whitespace\"", - pos: position{line: 87, col: 1, offset: 2099}, + pos: position{line: 87, col: 1, offset: 2037}, expr: &zeroOrMoreExpr{ - pos: position{line: 87, col: 18, offset: 2118}, + pos: position{line: 87, col: 18, offset: 2056}, expr: &charClassMatcher{ - pos: position{line: 87, col: 18, offset: 2118}, + pos: position{line: 87, col: 18, offset: 2056}, val: "[ \\t\\r\\n]", chars: []rune{' ', '\t', '\r', '\n'}, basicLatinChars: [128]bool{false, false, false, false, false, false, false, false, false, true, true, false, false, true, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, true, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false}, @@ -630,126 +630,126 @@ var g = &grammar{ }, { name: "EOF", - pos: position{line: 89, col: 1, offset: 2130}, + pos: position{line: 89, col: 1, offset: 2068}, expr: ¬Expr{ - pos: position{line: 89, col: 7, offset: 2138}, + pos: position{line: 89, col: 7, offset: 2076}, expr: &anyMatcher{ - line: 89, col: 8, offset: 2139, + line: 89, col: 8, offset: 2077, }, }, }, }, } -func (c *current) onJSON1(val interface{}) (interface{}, error) { +func (c *current) onJSON1(val any) (any, error) { return val, nil } -func (p *parser) callonJSON1() (interface{}, error) { +func (p *parser) callonJSON1() (any, error) { stack := p.vstack[len(p.vstack)-1] _ = stack return p.cur.onJSON1(stack["val"]) } -func (c *current) onValue1(val interface{}) (interface{}, error) { +func (c *current) onValue1(val any) (any, error) { return val, nil } -func (p *parser) callonValue1() (interface{}, error) { +func (p *parser) callonValue1() (any, error) { stack := p.vstack[len(p.vstack)-1] _ = stack return p.cur.onValue1(stack["val"]) } -func (c *current) onObject1(vals interface{}) (interface{}, error) { - res := make(map[string]interface{}) - valsSl := toIfaceSlice(vals) +func (c *current) onObject1(vals any) (any, error) { + res := make(map[string]any) + valsSl := toAnySlice(vals) if len(valsSl) == 0 { return res, nil } res[valsSl[0].(string)] = valsSl[4] - restSl := toIfaceSlice(valsSl[5]) + restSl := toAnySlice(valsSl[5]) for _, v := range restSl { - vSl := toIfaceSlice(v) + vSl := toAnySlice(v) res[vSl[2].(string)] = vSl[6] } return res, nil } -func (p *parser) callonObject1() (interface{}, error) { +func (p *parser) callonObject1() (any, error) { stack := p.vstack[len(p.vstack)-1] _ = stack return p.cur.onObject1(stack["vals"]) } -func (c *current) onArray1(vals interface{}) (interface{}, error) { - valsSl := toIfaceSlice(vals) +func (c *current) onArray1(vals any) (any, error) { + valsSl := toAnySlice(vals) if len(valsSl) == 0 { - return []interface{}{}, nil + return []any{}, nil } - res := []interface{}{valsSl[0]} - restSl := toIfaceSlice(valsSl[1]) + res := []any{valsSl[0]} + restSl := toAnySlice(valsSl[1]) for _, v := range restSl { - vSl := toIfaceSlice(v) + vSl := toAnySlice(v) res = append(res, vSl[2]) } return res, nil } -func (p *parser) callonArray1() (interface{}, error) { +func (p *parser) callonArray1() (any, error) { stack := p.vstack[len(p.vstack)-1] _ = stack return p.cur.onArray1(stack["vals"]) } -func (c *current) onNumber1() (interface{}, error) { +func (c *current) onNumber1() (any, error) { // JSON numbers have the same syntax as Go's, and are parseable using // strconv. return strconv.ParseFloat(string(c.text), 64) } -func (p *parser) callonNumber1() (interface{}, error) { +func (p *parser) callonNumber1() (any, error) { stack := p.vstack[len(p.vstack)-1] _ = stack return p.cur.onNumber1() } -func (c *current) onString1() (interface{}, error) { +func (c *current) onString1() (any, error) { c.text = bytes.Replace(c.text, []byte(`\/`), []byte(`/`), -1) return strconv.Unquote(string(c.text)) } -func (p *parser) callonString1() (interface{}, error) { +func (p *parser) callonString1() (any, error) { stack := p.vstack[len(p.vstack)-1] _ = stack return p.cur.onString1() } -func (c *current) onBool2() (interface{}, error) { +func (c *current) onBool2() (any, error) { return true, nil } -func (p *parser) callonBool2() (interface{}, error) { +func (p *parser) callonBool2() (any, error) { stack := p.vstack[len(p.vstack)-1] _ = stack return p.cur.onBool2() } -func (c *current) onBool4() (interface{}, error) { +func (c *current) onBool4() (any, error) { return false, nil } -func (p *parser) callonBool4() (interface{}, error) { +func (p *parser) callonBool4() (any, error) { stack := p.vstack[len(p.vstack)-1] _ = stack return p.cur.onBool4() } -func (c *current) onNull1() (interface{}, error) { +func (c *current) onNull1() (any, error) { return nil, nil } -func (p *parser) callonNull1() (interface{}, error) { +func (p *parser) callonNull1() (any, error) { stack := p.vstack[len(p.vstack)-1] _ = stack return p.cur.onNull1() @@ -837,7 +837,7 @@ func Recover(b bool) Option { // GlobalStore creates an Option to set a key to a certain value in // the globalStore. -func GlobalStore(key string, value interface{}) Option { +func GlobalStore(key string, value any) Option { return func(p *parser) Option { old := p.cur.globalStore[key] p.cur.globalStore[key] = value @@ -846,7 +846,7 @@ func GlobalStore(key string, value interface{}) Option { } // ParseFile parses the file identified by filename. -func ParseFile(filename string, opts ...Option) (i interface{}, err error) { // nolint: deadcode +func ParseFile(filename string, opts ...Option) (i any, err error) { // nolint: deadcode f, err := os.Open(filename) if err != nil { return nil, err @@ -861,7 +861,7 @@ func ParseFile(filename string, opts ...Option) (i interface{}, err error) { // // ParseReader parses the data from r using filename as information in the // error messages. -func ParseReader(filename string, r io.Reader, opts ...Option) (interface{}, error) { // nolint: deadcode +func ParseReader(filename string, r io.Reader, opts ...Option) (any, error) { // nolint: deadcode b, err := io.ReadAll(r) if err != nil { return nil, err @@ -872,7 +872,7 @@ func ParseReader(filename string, r io.Reader, opts ...Option) (interface{}, err // Parse parses the data from b using filename as information in the // error messages. -func Parse(filename string, b []byte, opts ...Option) (interface{}, error) { +func Parse(filename string, b []byte, opts ...Option) (any, error) { return newParser(filename, b, opts...).parse(g) } @@ -905,7 +905,7 @@ type current struct { globalStore storeDict } -type storeDict map[string]interface{} +type storeDict map[string]any // the AST types... @@ -920,34 +920,34 @@ type rule struct { pos position name string displayName string - expr interface{} + expr any } // nolint: structcheck type choiceExpr struct { pos position - alternatives []interface{} + alternatives []any } // nolint: structcheck type actionExpr struct { pos position - expr interface{} - run func(*parser) (interface{}, error) + expr any + run func(*parser) (any, error) } // nolint: structcheck type recoveryExpr struct { pos position - expr interface{} - recoverExpr interface{} + expr any + recoverExpr any failureLabel []string } // nolint: structcheck type seqExpr struct { pos position - exprs []interface{} + exprs []any } // nolint: structcheck @@ -960,20 +960,22 @@ type throwExpr struct { type labeledExpr struct { pos position label string - expr interface{} + expr any } // nolint: structcheck type expr struct { pos position - expr interface{} + expr any } -type andExpr expr // nolint: structcheck -type notExpr expr // nolint: structcheck -type zeroOrOneExpr expr // nolint: structcheck -type zeroOrMoreExpr expr // nolint: structcheck -type oneOrMoreExpr expr // nolint: structcheck +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 { @@ -1114,7 +1116,7 @@ func (p *parser) setOptions(opts []Option) { // nolint: structcheck,deadcode type resultTuple struct { - v interface{} + v any b bool end savepoint } @@ -1159,7 +1161,7 @@ type parser struct { // rules table, maps the rule identifier to the rule node rules map[string]*rule // variables stack, map of label to value - vstack []map[string]interface{} + vstack []map[string]any // rule stack, allows identification of the current rule in errors rstack []*rule @@ -1179,7 +1181,7 @@ type parser struct { choiceNoMatch string // recovery expression stack, keeps track of the currently available recovery expression, these are traversed in reverse - recoveryStack []map[string]interface{} + recoveryStack []map[string]any } // push a variable set on the vstack. @@ -1199,7 +1201,7 @@ func (p *parser) pushV() { return } - m = make(map[string]interface{}) + m = make(map[string]any) p.vstack[len(p.vstack)-1] = m } @@ -1215,7 +1217,7 @@ func (p *parser) popV() { } // push a recovery expression with its labels to the recoveryStack -func (p *parser) pushRecovery(labels []string, expr interface{}) { +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) @@ -1224,7 +1226,7 @@ func (p *parser) pushRecovery(labels []string, expr interface{}) { p.recoveryStack = p.recoveryStack[:len(p.recoveryStack)+1] } - m := make(map[string]interface{}, len(labels)) + m := make(map[string]any, len(labels)) for _, fl := range labels { m[fl] = expr } @@ -1326,7 +1328,7 @@ func (p *parser) buildRulesTable(g *grammar) { } // nolint: gocyclo -func (p *parser) parse(g *grammar) (val interface{}, err error) { +func (p *parser) parse(g *grammar) (val any, err error) { if len(g.rules) == 0 { p.addErr(errNoRule) return nil, p.errs.err() @@ -1400,7 +1402,7 @@ func listJoin(list []string, sep string, lastSep string) string { } } -func (p *parser) parseRule(rule *rule) (interface{}, bool) { +func (p *parser) parseRule(rule *rule) (any, bool) { p.rstack = append(p.rstack, rule) p.pushV() val, ok := p.parseExpr(rule.expr) @@ -1410,14 +1412,14 @@ func (p *parser) parseRule(rule *rule) (interface{}, bool) { } // nolint: gocyclo -func (p *parser) parseExpr(expr interface{}) (interface{}, bool) { +func (p *parser) parseExpr(expr any) (any, bool) { p.ExprCnt++ if p.ExprCnt > p.maxExprCnt { panic(errMaxExprCnt) } - var val interface{} + var val any var ok bool switch expr := expr.(type) { case *actionExpr: @@ -1460,7 +1462,7 @@ func (p *parser) parseExpr(expr interface{}) (interface{}, bool) { return val, ok } -func (p *parser) parseActionExpr(act *actionExpr) (interface{}, bool) { +func (p *parser) parseActionExpr(act *actionExpr) (any, bool) { start := p.pt val, ok := p.parseExpr(act.expr) if ok { @@ -1476,7 +1478,7 @@ func (p *parser) parseActionExpr(act *actionExpr) (interface{}, bool) { return val, ok } -func (p *parser) parseAndCodeExpr(and *andCodeExpr) (interface{}, bool) { +func (p *parser) parseAndCodeExpr(and *andCodeExpr) (any, bool) { ok, err := and.run(p) if err != nil { @@ -1486,7 +1488,7 @@ func (p *parser) parseAndCodeExpr(and *andCodeExpr) (interface{}, bool) { return nil, ok } -func (p *parser) parseAndExpr(and *andExpr) (interface{}, bool) { +func (p *parser) parseAndExpr(and *andExpr) (any, bool) { pt := p.pt p.pushV() _, ok := p.parseExpr(and.expr) @@ -1496,7 +1498,7 @@ func (p *parser) parseAndExpr(and *andExpr) (interface{}, bool) { return nil, ok } -func (p *parser) parseAnyMatcher(any *anyMatcher) (interface{}, bool) { +func (p *parser) parseAnyMatcher(any *anyMatcher) (any, bool) { if p.pt.rn == utf8.RuneError && p.pt.w == 0 { // EOF - see utf8.DecodeRune p.failAt(false, p.pt.position, ".") @@ -1509,7 +1511,7 @@ func (p *parser) parseAnyMatcher(any *anyMatcher) (interface{}, bool) { } // nolint: gocyclo -func (p *parser) parseCharClassMatcher(chr *charClassMatcher) (interface{}, bool) { +func (p *parser) parseCharClassMatcher(chr *charClassMatcher) (any, bool) { cur := p.pt.rn start := p.pt @@ -1581,7 +1583,7 @@ func (p *parser) parseCharClassMatcher(chr *charClassMatcher) (interface{}, bool return nil, false } -func (p *parser) parseChoiceExpr(ch *choiceExpr) (interface{}, bool) { +func (p *parser) parseChoiceExpr(ch *choiceExpr) (any, bool) { for altI, alt := range ch.alternatives { // dummy assignment to prevent compile error if optimized _ = altI @@ -1596,7 +1598,7 @@ func (p *parser) parseChoiceExpr(ch *choiceExpr) (interface{}, bool) { return nil, false } -func (p *parser) parseLabeledExpr(lab *labeledExpr) (interface{}, bool) { +func (p *parser) parseLabeledExpr(lab *labeledExpr) (any, bool) { p.pushV() val, ok := p.parseExpr(lab.expr) p.popV() @@ -1607,7 +1609,7 @@ func (p *parser) parseLabeledExpr(lab *labeledExpr) (interface{}, bool) { return val, ok } -func (p *parser) parseLitMatcher(lit *litMatcher) (interface{}, bool) { +func (p *parser) parseLitMatcher(lit *litMatcher) (any, bool) { start := p.pt for _, want := range lit.val { cur := p.pt.rn @@ -1625,7 +1627,7 @@ func (p *parser) parseLitMatcher(lit *litMatcher) (interface{}, bool) { return p.sliceFrom(start), true } -func (p *parser) parseNotCodeExpr(not *notCodeExpr) (interface{}, bool) { +func (p *parser) parseNotCodeExpr(not *notCodeExpr) (any, bool) { ok, err := not.run(p) if err != nil { p.addErr(err) @@ -1634,7 +1636,7 @@ func (p *parser) parseNotCodeExpr(not *notCodeExpr) (interface{}, bool) { return nil, !ok } -func (p *parser) parseNotExpr(not *notExpr) (interface{}, bool) { +func (p *parser) parseNotExpr(not *notExpr) (any, bool) { pt := p.pt p.pushV() p.maxFailInvertExpected = !p.maxFailInvertExpected @@ -1646,8 +1648,8 @@ func (p *parser) parseNotExpr(not *notExpr) (interface{}, bool) { return nil, !ok } -func (p *parser) parseOneOrMoreExpr(expr *oneOrMoreExpr) (interface{}, bool) { - var vals []interface{} +func (p *parser) parseOneOrMoreExpr(expr *oneOrMoreExpr) (any, bool) { + var vals []any for { p.pushV() @@ -1664,7 +1666,7 @@ func (p *parser) parseOneOrMoreExpr(expr *oneOrMoreExpr) (interface{}, bool) { } } -func (p *parser) parseRecoveryExpr(recover *recoveryExpr) (interface{}, bool) { +func (p *parser) parseRecoveryExpr(recover *recoveryExpr) (any, bool) { p.pushRecovery(recover.failureLabel, recover.recoverExpr) val, ok := p.parseExpr(recover.expr) @@ -1673,7 +1675,7 @@ func (p *parser) parseRecoveryExpr(recover *recoveryExpr) (interface{}, bool) { return val, ok } -func (p *parser) parseRuleRefExpr(ref *ruleRefExpr) (interface{}, bool) { +func (p *parser) parseRuleRefExpr(ref *ruleRefExpr) (any, bool) { if ref.name == "" { panic(fmt.Sprintf("%s: invalid rule: missing name", ref.pos)) } @@ -1686,8 +1688,8 @@ func (p *parser) parseRuleRefExpr(ref *ruleRefExpr) (interface{}, bool) { return p.parseRule(rule) } -func (p *parser) parseSeqExpr(seq *seqExpr) (interface{}, bool) { - vals := make([]interface{}, 0, len(seq.exprs)) +func (p *parser) parseSeqExpr(seq *seqExpr) (any, bool) { + vals := make([]any, 0, len(seq.exprs)) pt := p.pt for _, expr := range seq.exprs { @@ -1701,7 +1703,7 @@ func (p *parser) parseSeqExpr(seq *seqExpr) (interface{}, bool) { return vals, true } -func (p *parser) parseThrowExpr(expr *throwExpr) (interface{}, bool) { +func (p *parser) parseThrowExpr(expr *throwExpr) (any, bool) { for i := len(p.recoveryStack) - 1; i >= 0; i-- { if recoverExpr, ok := p.recoveryStack[i][expr.label]; ok { @@ -1714,8 +1716,8 @@ func (p *parser) parseThrowExpr(expr *throwExpr) (interface{}, bool) { return nil, false } -func (p *parser) parseZeroOrMoreExpr(expr *zeroOrMoreExpr) (interface{}, bool) { - var vals []interface{} +func (p *parser) parseZeroOrMoreExpr(expr *zeroOrMoreExpr) (any, bool) { + var vals []any for { p.pushV() @@ -1728,7 +1730,7 @@ func (p *parser) parseZeroOrMoreExpr(expr *zeroOrMoreExpr) (interface{}, bool) { } } -func (p *parser) parseZeroOrOneExpr(expr *zeroOrOneExpr) (interface{}, bool) { +func (p *parser) parseZeroOrOneExpr(expr *zeroOrOneExpr) (any, bool) { p.pushV() val, _ := p.parseExpr(expr.expr) p.popV() diff --git a/grammar/bootstrap.peg b/grammar/bootstrap.peg index f8020042..560cf9d0 100644 --- a/grammar/bootstrap.peg +++ b/grammar/bootstrap.peg @@ -7,15 +7,15 @@ Grammar ← __ initializer:( Initializer __ )? rules:( Rule __ )+ { // create the grammar, assign its initializer g := ast.NewGrammar(pos) - initSlice := toIfaceSlice(initializer) + initSlice := toAnySlice(initializer) if len(initSlice) > 0 { g.Init = initSlice[0].(*ast.CodeBlock) } - rulesSlice := toIfaceSlice(rules) + rulesSlice := toAnySlice(rules) g.Rules = make([]*ast.Rule, len(rulesSlice)) for i, duo := range rulesSlice { - g.Rules[i] = duo.([]interface{})[0].(*ast.Rule) + g.Rules[i] = duo.([]any)[0].(*ast.Rule) } return g, nil @@ -29,7 +29,7 @@ Rule ← name:IdentifierName __ display:( StringLiteral __ )? RuleDefOp __ expr: pos := c.astPos() rule := ast.NewRule(pos, name.(*ast.Identifier)) - displaySlice := toIfaceSlice(display) + displaySlice := toAnySlice(display) if len(displaySlice) > 0 { rule.DisplayName = displaySlice[0].(*ast.StringLit) } @@ -41,7 +41,7 @@ Rule ← name:IdentifierName __ display:( StringLiteral __ )? RuleDefOp __ expr: Expression ← ChoiceExpr ChoiceExpr ← first:ActionExpr rest:( __ "/" __ ActionExpr )* { - restSlice := toIfaceSlice(rest) + restSlice := toAnySlice(rest) if len(restSlice) == 0 { return first, nil } @@ -50,7 +50,7 @@ ChoiceExpr ← first:ActionExpr rest:( __ "/" __ ActionExpr )* { choice := ast.NewChoiceExpr(pos) choice.Alternatives = []ast.Expression{first.(ast.Expression)} for _, sl := range restSlice { - choice.Alternatives = append(choice.Alternatives, sl.([]interface{})[3].(ast.Expression)) + choice.Alternatives = append(choice.Alternatives, sl.([]any)[3].(ast.Expression)) } return choice, nil } @@ -63,21 +63,21 @@ ActionExpr ← expr:SeqExpr code:( __ CodeBlock )? { pos := c.astPos() act := ast.NewActionExpr(pos) act.Expr = expr.(ast.Expression) - codeSlice := toIfaceSlice(code) + codeSlice := toAnySlice(code) act.Code = codeSlice[1].(*ast.CodeBlock) return act, nil } SeqExpr ← first:LabeledExpr rest:( __ LabeledExpr )* { - restSlice := toIfaceSlice(rest) + 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.([]interface{})[1].(ast.Expression)) + seq.Exprs = append(seq.Exprs, sl.([]any)[1].(ast.Expression)) } return seq, nil } diff --git a/grammar/pigeon.peg b/grammar/pigeon.peg index 7b284255..e94965ba 100644 --- a/grammar/pigeon.peg +++ b/grammar/pigeon.peg @@ -7,15 +7,15 @@ Grammar ← __ initializer:( Initializer __ )? rules:( Rule __ )+ EOF { // create the grammar, assign its initializer g := ast.NewGrammar(pos) - initSlice := toIfaceSlice(initializer) + initSlice := toAnySlice(initializer) if len(initSlice) > 0 { g.Init = initSlice[0].(*ast.CodeBlock) } - rulesSlice := toIfaceSlice(rules) + rulesSlice := toAnySlice(rules) g.Rules = make([]*ast.Rule, len(rulesSlice)) for i, duo := range rulesSlice { - g.Rules[i] = duo.([]interface{})[0].(*ast.Rule) + g.Rules[i] = duo.([]any)[0].(*ast.Rule) } return g, nil @@ -29,7 +29,7 @@ Rule ← name:IdentifierName __ display:( StringLiteral __ )? RuleDefOp __ expr: pos := c.astPos() rule := ast.NewRule(pos, name.(*ast.Identifier)) - displaySlice := toIfaceSlice(display) + displaySlice := toAnySlice(display) if len(displaySlice) > 0 { rule.DisplayName = displaySlice[0].(*ast.StringLit) } @@ -41,14 +41,14 @@ Rule ← name:IdentifierName __ display:( StringLiteral __ )? RuleDefOp __ expr: Expression ← RecoveryExpr RecoveryExpr ← expr:ChoiceExpr recoverExprs:( __ "//{" __ Labels __ "}" __ ChoiceExpr )* { - recoverExprSlice := toIfaceSlice(recoverExprs) + recoverExprSlice := toAnySlice(recoverExprs) recover := expr.(ast.Expression) for _, sl := range recoverExprSlice { pos := c.astPos() r := ast.NewRecoveryExpr(pos) r.Expr = recover - r.RecoverExpr = sl.([]interface{})[7].(ast.Expression) - r.Labels = sl.([]interface{})[3].([]ast.FailureLabel) + r.RecoverExpr = sl.([]any)[7].(ast.Expression) + r.Labels = sl.([]any)[3].([]ast.FailureLabel) recover = r } @@ -57,15 +57,15 @@ RecoveryExpr ← expr:ChoiceExpr recoverExprs:( __ "//{" __ Labels __ "}" __ Cho Labels ← label:IdentifierName labels:( __ "," __ IdentifierName)* { failureLabels := []ast.FailureLabel{ast.FailureLabel(label.(*ast.Identifier).Val)} - labelSlice := toIfaceSlice(labels) + labelSlice := toAnySlice(labels) for _, fl := range labelSlice { - failureLabels = append(failureLabels, ast.FailureLabel(fl.([]interface{})[3].(*ast.Identifier).Val)) + failureLabels = append(failureLabels, ast.FailureLabel(fl.([]any)[3].(*ast.Identifier).Val)) } return failureLabels, nil } ChoiceExpr ← first:ActionExpr rest:( __ "/" __ ActionExpr )* { - restSlice := toIfaceSlice(rest) + restSlice := toAnySlice(rest) if len(restSlice) == 0 { return first, nil } @@ -74,7 +74,7 @@ ChoiceExpr ← first:ActionExpr rest:( __ "/" __ ActionExpr )* { choice := ast.NewChoiceExpr(pos) choice.Alternatives = []ast.Expression{first.(ast.Expression)} for _, sl := range restSlice { - choice.Alternatives = append(choice.Alternatives, sl.([]interface{})[3].(ast.Expression)) + choice.Alternatives = append(choice.Alternatives, sl.([]any)[3].(ast.Expression)) } return choice, nil } @@ -87,21 +87,21 @@ ActionExpr ← expr:SeqExpr code:( __ CodeBlock )? { pos := c.astPos() act := ast.NewActionExpr(pos) act.Expr = expr.(ast.Expression) - codeSlice := toIfaceSlice(code) + codeSlice := toAnySlice(code) act.Code = codeSlice[1].(*ast.CodeBlock) return act, nil } SeqExpr ← first:LabeledExpr rest:( __ LabeledExpr )* { - restSlice := toIfaceSlice(rest) + 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.([]interface{})[1].(ast.Expression)) + seq.Exprs = append(seq.Exprs, sl.([]any)[1].(ast.Expression)) } return seq, nil } diff --git a/main.go b/main.go index a00be22e..e1d3423c 100644 --- a/main.go +++ b/main.go @@ -218,7 +218,7 @@ func usage() { // argError prints an error message to stderr, prints the command usage // and exits with the specified exit code. -func argError(exitCode int, msg string, args ...interface{}) { +func argError(exitCode int, msg string, args ...any) { fmt.Fprintf(os.Stderr, msg, args...) fmt.Fprintln(os.Stderr) usage() @@ -271,18 +271,18 @@ func (c *current) astPos() ast.Pos { return ast.Pos{Line: c.pos.line, Col: c.pos.col, Off: c.pos.offset} } -// toIfaceSlice is a helper function for the PEG grammar parser. It converts +// toAnySlice is a helper function for the PEG grammar parser. It converts // v to a slice of empty interfaces. -func toIfaceSlice(v interface{}) []interface{} { +func toAnySlice(v any) []any { if v == nil { return nil } - return v.([]interface{}) + return v.([]any) } // validateUnicodeEscape checks that the provided escape sequence is a // valid Unicode escape sequence. -func validateUnicodeEscape(escape, errMsg string) (interface{}, error) { +func validateUnicodeEscape(escape, errMsg string) (any, error) { r, _, _, err := strconv.UnquoteChar("\\"+escape, '"') if err != nil { return nil, errors.New(errMsg) diff --git a/pigeon.go b/pigeon.go index f59d6efb..b38c26da 100644 --- a/pigeon.go +++ b/pigeon.go @@ -29,7 +29,7 @@ var g = &grammar{ run: (*parser).callonGrammar1, expr: &seqExpr{ pos: position{line: 5, col: 11, offset: 30}, - exprs: []interface{}{ + exprs: []any{ &ruleRefExpr{ pos: position{line: 5, col: 11, offset: 30}, name: "__", @@ -41,7 +41,7 @@ var g = &grammar{ pos: position{line: 5, col: 26, offset: 45}, expr: &seqExpr{ pos: position{line: 5, col: 28, offset: 47}, - exprs: []interface{}{ + exprs: []any{ &ruleRefExpr{ pos: position{line: 5, col: 28, offset: 47}, name: "Initializer", @@ -61,7 +61,7 @@ var g = &grammar{ pos: position{line: 5, col: 52, offset: 71}, expr: &seqExpr{ pos: position{line: 5, col: 54, offset: 73}, - exprs: []interface{}{ + exprs: []any{ &ruleRefExpr{ pos: position{line: 5, col: 54, offset: 73}, name: "Rule", @@ -84,23 +84,23 @@ var g = &grammar{ }, { name: "Initializer", - pos: position{line: 24, col: 1, offset: 525}, + pos: position{line: 24, col: 1, offset: 513}, expr: &actionExpr{ - pos: position{line: 24, col: 15, offset: 541}, + pos: position{line: 24, col: 15, offset: 529}, run: (*parser).callonInitializer1, expr: &seqExpr{ - pos: position{line: 24, col: 15, offset: 541}, - exprs: []interface{}{ + pos: position{line: 24, col: 15, offset: 529}, + exprs: []any{ &labeledExpr{ - pos: position{line: 24, col: 15, offset: 541}, + pos: position{line: 24, col: 15, offset: 529}, label: "code", expr: &ruleRefExpr{ - pos: position{line: 24, col: 20, offset: 546}, + pos: position{line: 24, col: 20, offset: 534}, name: "CodeBlock", }, }, &ruleRefExpr{ - pos: position{line: 24, col: 30, offset: 556}, + pos: position{line: 24, col: 30, offset: 544}, name: "EOS", }, }, @@ -109,39 +109,39 @@ var g = &grammar{ }, { name: "Rule", - pos: position{line: 28, col: 1, offset: 586}, + pos: position{line: 28, col: 1, offset: 574}, expr: &actionExpr{ - pos: position{line: 28, col: 8, offset: 595}, + pos: position{line: 28, col: 8, offset: 583}, run: (*parser).callonRule1, expr: &seqExpr{ - pos: position{line: 28, col: 8, offset: 595}, - exprs: []interface{}{ + pos: position{line: 28, col: 8, offset: 583}, + exprs: []any{ &labeledExpr{ - pos: position{line: 28, col: 8, offset: 595}, + pos: position{line: 28, col: 8, offset: 583}, label: "name", expr: &ruleRefExpr{ - pos: position{line: 28, col: 13, offset: 600}, + pos: position{line: 28, col: 13, offset: 588}, name: "IdentifierName", }, }, &ruleRefExpr{ - pos: position{line: 28, col: 28, offset: 615}, + pos: position{line: 28, col: 28, offset: 603}, name: "__", }, &labeledExpr{ - pos: position{line: 28, col: 31, offset: 618}, + pos: position{line: 28, col: 31, offset: 606}, label: "display", expr: &zeroOrOneExpr{ - pos: position{line: 28, col: 39, offset: 626}, + pos: position{line: 28, col: 39, offset: 614}, expr: &seqExpr{ - pos: position{line: 28, col: 41, offset: 628}, - exprs: []interface{}{ + pos: position{line: 28, col: 41, offset: 616}, + exprs: []any{ &ruleRefExpr{ - pos: position{line: 28, col: 41, offset: 628}, + pos: position{line: 28, col: 41, offset: 616}, name: "StringLiteral", }, &ruleRefExpr{ - pos: position{line: 28, col: 55, offset: 642}, + pos: position{line: 28, col: 55, offset: 630}, name: "__", }, }, @@ -149,23 +149,23 @@ var g = &grammar{ }, }, &ruleRefExpr{ - pos: position{line: 28, col: 61, offset: 648}, + pos: position{line: 28, col: 61, offset: 636}, name: "RuleDefOp", }, &ruleRefExpr{ - pos: position{line: 28, col: 71, offset: 658}, + pos: position{line: 28, col: 71, offset: 646}, name: "__", }, &labeledExpr{ - pos: position{line: 28, col: 74, offset: 661}, + pos: position{line: 28, col: 74, offset: 649}, label: "expr", expr: &ruleRefExpr{ - pos: position{line: 28, col: 79, offset: 666}, + pos: position{line: 28, col: 79, offset: 654}, name: "Expression", }, }, &ruleRefExpr{ - pos: position{line: 28, col: 90, offset: 677}, + pos: position{line: 28, col: 90, offset: 665}, name: "EOS", }, }, @@ -174,71 +174,71 @@ var g = &grammar{ }, { name: "Expression", - pos: position{line: 41, col: 1, offset: 961}, + pos: position{line: 41, col: 1, offset: 947}, expr: &ruleRefExpr{ - pos: position{line: 41, col: 14, offset: 976}, + pos: position{line: 41, col: 14, offset: 962}, name: "RecoveryExpr", }, }, { name: "RecoveryExpr", - pos: position{line: 43, col: 1, offset: 990}, + pos: position{line: 43, col: 1, offset: 976}, expr: &actionExpr{ - pos: position{line: 43, col: 16, offset: 1007}, + pos: position{line: 43, col: 16, offset: 993}, run: (*parser).callonRecoveryExpr1, expr: &seqExpr{ - pos: position{line: 43, col: 16, offset: 1007}, - exprs: []interface{}{ + pos: position{line: 43, col: 16, offset: 993}, + exprs: []any{ &labeledExpr{ - pos: position{line: 43, col: 16, offset: 1007}, + pos: position{line: 43, col: 16, offset: 993}, label: "expr", expr: &ruleRefExpr{ - pos: position{line: 43, col: 21, offset: 1012}, + pos: position{line: 43, col: 21, offset: 998}, name: "ChoiceExpr", }, }, &labeledExpr{ - pos: position{line: 43, col: 32, offset: 1023}, + pos: position{line: 43, col: 32, offset: 1009}, label: "recoverExprs", expr: &zeroOrMoreExpr{ - pos: position{line: 43, col: 45, offset: 1036}, + pos: position{line: 43, col: 45, offset: 1022}, expr: &seqExpr{ - pos: position{line: 43, col: 47, offset: 1038}, - exprs: []interface{}{ + pos: position{line: 43, col: 47, offset: 1024}, + exprs: []any{ &ruleRefExpr{ - pos: position{line: 43, col: 47, offset: 1038}, + pos: position{line: 43, col: 47, offset: 1024}, name: "__", }, &litMatcher{ - pos: position{line: 43, col: 50, offset: 1041}, + pos: position{line: 43, col: 50, offset: 1027}, val: "//{", ignoreCase: false, want: "\"//{\"", }, &ruleRefExpr{ - pos: position{line: 43, col: 56, offset: 1047}, + pos: position{line: 43, col: 56, offset: 1033}, name: "__", }, &ruleRefExpr{ - pos: position{line: 43, col: 59, offset: 1050}, + pos: position{line: 43, col: 59, offset: 1036}, name: "Labels", }, &ruleRefExpr{ - pos: position{line: 43, col: 66, offset: 1057}, + pos: position{line: 43, col: 66, offset: 1043}, name: "__", }, &litMatcher{ - pos: position{line: 43, col: 69, offset: 1060}, + pos: position{line: 43, col: 69, offset: 1046}, val: "}", ignoreCase: false, want: "\"}\"", }, &ruleRefExpr{ - pos: position{line: 43, col: 73, offset: 1064}, + pos: position{line: 43, col: 73, offset: 1050}, name: "__", }, &ruleRefExpr{ - pos: position{line: 43, col: 76, offset: 1067}, + pos: position{line: 43, col: 76, offset: 1053}, name: "ChoiceExpr", }, }, @@ -251,45 +251,45 @@ var g = &grammar{ }, { name: "Labels", - pos: position{line: 58, col: 1, offset: 1481}, + pos: position{line: 58, col: 1, offset: 1449}, expr: &actionExpr{ - pos: position{line: 58, col: 10, offset: 1492}, + pos: position{line: 58, col: 10, offset: 1460}, run: (*parser).callonLabels1, expr: &seqExpr{ - pos: position{line: 58, col: 10, offset: 1492}, - exprs: []interface{}{ + pos: position{line: 58, col: 10, offset: 1460}, + exprs: []any{ &labeledExpr{ - pos: position{line: 58, col: 10, offset: 1492}, + pos: position{line: 58, col: 10, offset: 1460}, label: "label", expr: &ruleRefExpr{ - pos: position{line: 58, col: 16, offset: 1498}, + pos: position{line: 58, col: 16, offset: 1466}, name: "IdentifierName", }, }, &labeledExpr{ - pos: position{line: 58, col: 31, offset: 1513}, + pos: position{line: 58, col: 31, offset: 1481}, label: "labels", expr: &zeroOrMoreExpr{ - pos: position{line: 58, col: 38, offset: 1520}, + pos: position{line: 58, col: 38, offset: 1488}, expr: &seqExpr{ - pos: position{line: 58, col: 40, offset: 1522}, - exprs: []interface{}{ + pos: position{line: 58, col: 40, offset: 1490}, + exprs: []any{ &ruleRefExpr{ - pos: position{line: 58, col: 40, offset: 1522}, + pos: position{line: 58, col: 40, offset: 1490}, name: "__", }, &litMatcher{ - pos: position{line: 58, col: 43, offset: 1525}, + pos: position{line: 58, col: 43, offset: 1493}, val: ",", ignoreCase: false, want: "\",\"", }, &ruleRefExpr{ - pos: position{line: 58, col: 47, offset: 1529}, + pos: position{line: 58, col: 47, offset: 1497}, name: "__", }, &ruleRefExpr{ - pos: position{line: 58, col: 50, offset: 1532}, + pos: position{line: 58, col: 50, offset: 1500}, name: "IdentifierName", }, }, @@ -302,45 +302,45 @@ var g = &grammar{ }, { name: "ChoiceExpr", - pos: position{line: 67, col: 1, offset: 1861}, + pos: position{line: 67, col: 1, offset: 1819}, expr: &actionExpr{ - pos: position{line: 67, col: 14, offset: 1876}, + pos: position{line: 67, col: 14, offset: 1834}, run: (*parser).callonChoiceExpr1, expr: &seqExpr{ - pos: position{line: 67, col: 14, offset: 1876}, - exprs: []interface{}{ + pos: position{line: 67, col: 14, offset: 1834}, + exprs: []any{ &labeledExpr{ - pos: position{line: 67, col: 14, offset: 1876}, + pos: position{line: 67, col: 14, offset: 1834}, label: "first", expr: &ruleRefExpr{ - pos: position{line: 67, col: 20, offset: 1882}, + pos: position{line: 67, col: 20, offset: 1840}, name: "ActionExpr", }, }, &labeledExpr{ - pos: position{line: 67, col: 31, offset: 1893}, + pos: position{line: 67, col: 31, offset: 1851}, label: "rest", expr: &zeroOrMoreExpr{ - pos: position{line: 67, col: 36, offset: 1898}, + pos: position{line: 67, col: 36, offset: 1856}, expr: &seqExpr{ - pos: position{line: 67, col: 38, offset: 1900}, - exprs: []interface{}{ + pos: position{line: 67, col: 38, offset: 1858}, + exprs: []any{ &ruleRefExpr{ - pos: position{line: 67, col: 38, offset: 1900}, + pos: position{line: 67, col: 38, offset: 1858}, name: "__", }, &litMatcher{ - pos: position{line: 67, col: 41, offset: 1903}, + pos: position{line: 67, col: 41, offset: 1861}, val: "/", ignoreCase: false, want: "\"/\"", }, &ruleRefExpr{ - pos: position{line: 67, col: 45, offset: 1907}, + pos: position{line: 67, col: 45, offset: 1865}, name: "__", }, &ruleRefExpr{ - pos: position{line: 67, col: 48, offset: 1910}, + pos: position{line: 67, col: 48, offset: 1868}, name: "ActionExpr", }, }, @@ -353,35 +353,35 @@ var g = &grammar{ }, { name: "ActionExpr", - pos: position{line: 82, col: 1, offset: 2315}, + pos: position{line: 82, col: 1, offset: 2263}, expr: &actionExpr{ - pos: position{line: 82, col: 14, offset: 2330}, + pos: position{line: 82, col: 14, offset: 2278}, run: (*parser).callonActionExpr1, expr: &seqExpr{ - pos: position{line: 82, col: 14, offset: 2330}, - exprs: []interface{}{ + pos: position{line: 82, col: 14, offset: 2278}, + exprs: []any{ &labeledExpr{ - pos: position{line: 82, col: 14, offset: 2330}, + pos: position{line: 82, col: 14, offset: 2278}, label: "expr", expr: &ruleRefExpr{ - pos: position{line: 82, col: 19, offset: 2335}, + pos: position{line: 82, col: 19, offset: 2283}, name: "SeqExpr", }, }, &labeledExpr{ - pos: position{line: 82, col: 27, offset: 2343}, + pos: position{line: 82, col: 27, offset: 2291}, label: "code", expr: &zeroOrOneExpr{ - pos: position{line: 82, col: 32, offset: 2348}, + pos: position{line: 82, col: 32, offset: 2296}, expr: &seqExpr{ - pos: position{line: 82, col: 34, offset: 2350}, - exprs: []interface{}{ + pos: position{line: 82, col: 34, offset: 2298}, + exprs: []any{ &ruleRefExpr{ - pos: position{line: 82, col: 34, offset: 2350}, + pos: position{line: 82, col: 34, offset: 2298}, name: "__", }, &ruleRefExpr{ - pos: position{line: 82, col: 37, offset: 2353}, + pos: position{line: 82, col: 37, offset: 2301}, name: "CodeBlock", }, }, @@ -394,35 +394,35 @@ var g = &grammar{ }, { name: "SeqExpr", - pos: position{line: 96, col: 1, offset: 2619}, + pos: position{line: 96, col: 1, offset: 2565}, expr: &actionExpr{ - pos: position{line: 96, col: 11, offset: 2631}, + pos: position{line: 96, col: 11, offset: 2577}, run: (*parser).callonSeqExpr1, expr: &seqExpr{ - pos: position{line: 96, col: 11, offset: 2631}, - exprs: []interface{}{ + pos: position{line: 96, col: 11, offset: 2577}, + exprs: []any{ &labeledExpr{ - pos: position{line: 96, col: 11, offset: 2631}, + pos: position{line: 96, col: 11, offset: 2577}, label: "first", expr: &ruleRefExpr{ - pos: position{line: 96, col: 17, offset: 2637}, + pos: position{line: 96, col: 17, offset: 2583}, name: "LabeledExpr", }, }, &labeledExpr{ - pos: position{line: 96, col: 29, offset: 2649}, + pos: position{line: 96, col: 29, offset: 2595}, label: "rest", expr: &zeroOrMoreExpr{ - pos: position{line: 96, col: 34, offset: 2654}, + pos: position{line: 96, col: 34, offset: 2600}, expr: &seqExpr{ - pos: position{line: 96, col: 36, offset: 2656}, - exprs: []interface{}{ + pos: position{line: 96, col: 36, offset: 2602}, + exprs: []any{ &ruleRefExpr{ - pos: position{line: 96, col: 36, offset: 2656}, + pos: position{line: 96, col: 36, offset: 2602}, name: "__", }, &ruleRefExpr{ - pos: position{line: 96, col: 39, offset: 2659}, + pos: position{line: 96, col: 39, offset: 2605}, name: "LabeledExpr", }, }, @@ -435,43 +435,43 @@ var g = &grammar{ }, { name: "LabeledExpr", - pos: position{line: 109, col: 1, offset: 3010}, + pos: position{line: 109, col: 1, offset: 2946}, expr: &choiceExpr{ - pos: position{line: 109, col: 15, offset: 3026}, - alternatives: []interface{}{ + pos: position{line: 109, col: 15, offset: 2962}, + alternatives: []any{ &actionExpr{ - pos: position{line: 109, col: 15, offset: 3026}, + pos: position{line: 109, col: 15, offset: 2962}, run: (*parser).callonLabeledExpr2, expr: &seqExpr{ - pos: position{line: 109, col: 15, offset: 3026}, - exprs: []interface{}{ + pos: position{line: 109, col: 15, offset: 2962}, + exprs: []any{ &labeledExpr{ - pos: position{line: 109, col: 15, offset: 3026}, + pos: position{line: 109, col: 15, offset: 2962}, label: "label", expr: &ruleRefExpr{ - pos: position{line: 109, col: 21, offset: 3032}, + pos: position{line: 109, col: 21, offset: 2968}, name: "Identifier", }, }, &ruleRefExpr{ - pos: position{line: 109, col: 32, offset: 3043}, + pos: position{line: 109, col: 32, offset: 2979}, name: "__", }, &litMatcher{ - pos: position{line: 109, col: 35, offset: 3046}, + pos: position{line: 109, col: 35, offset: 2982}, val: ":", ignoreCase: false, want: "\":\"", }, &ruleRefExpr{ - pos: position{line: 109, col: 39, offset: 3050}, + pos: position{line: 109, col: 39, offset: 2986}, name: "__", }, &labeledExpr{ - pos: position{line: 109, col: 42, offset: 3053}, + pos: position{line: 109, col: 42, offset: 2989}, label: "expr", expr: &ruleRefExpr{ - pos: position{line: 109, col: 47, offset: 3058}, + pos: position{line: 109, col: 47, offset: 2994}, name: "PrefixedExpr", }, }, @@ -479,11 +479,11 @@ var g = &grammar{ }, }, &ruleRefExpr{ - pos: position{line: 115, col: 5, offset: 3231}, + pos: position{line: 115, col: 5, offset: 3167}, name: "PrefixedExpr", }, &ruleRefExpr{ - pos: position{line: 115, col: 20, offset: 3246}, + pos: position{line: 115, col: 20, offset: 3182}, name: "ThrowExpr", }, }, @@ -491,33 +491,33 @@ var g = &grammar{ }, { name: "PrefixedExpr", - pos: position{line: 117, col: 1, offset: 3257}, + pos: position{line: 117, col: 1, offset: 3193}, expr: &choiceExpr{ - pos: position{line: 117, col: 16, offset: 3274}, - alternatives: []interface{}{ + pos: position{line: 117, col: 16, offset: 3210}, + alternatives: []any{ &actionExpr{ - pos: position{line: 117, col: 16, offset: 3274}, + pos: position{line: 117, col: 16, offset: 3210}, run: (*parser).callonPrefixedExpr2, expr: &seqExpr{ - pos: position{line: 117, col: 16, offset: 3274}, - exprs: []interface{}{ + pos: position{line: 117, col: 16, offset: 3210}, + exprs: []any{ &labeledExpr{ - pos: position{line: 117, col: 16, offset: 3274}, + pos: position{line: 117, col: 16, offset: 3210}, label: "op", expr: &ruleRefExpr{ - pos: position{line: 117, col: 19, offset: 3277}, + pos: position{line: 117, col: 19, offset: 3213}, name: "PrefixedOp", }, }, &ruleRefExpr{ - pos: position{line: 117, col: 30, offset: 3288}, + pos: position{line: 117, col: 30, offset: 3224}, name: "__", }, &labeledExpr{ - pos: position{line: 117, col: 33, offset: 3291}, + pos: position{line: 117, col: 33, offset: 3227}, label: "expr", expr: &ruleRefExpr{ - pos: position{line: 117, col: 38, offset: 3296}, + pos: position{line: 117, col: 38, offset: 3232}, name: "SuffixedExpr", }, }, @@ -525,7 +525,7 @@ var g = &grammar{ }, }, &ruleRefExpr{ - pos: position{line: 128, col: 5, offset: 3578}, + pos: position{line: 128, col: 5, offset: 3514}, name: "SuffixedExpr", }, }, @@ -533,21 +533,21 @@ var g = &grammar{ }, { name: "PrefixedOp", - pos: position{line: 130, col: 1, offset: 3592}, + pos: position{line: 130, col: 1, offset: 3528}, expr: &actionExpr{ - pos: position{line: 130, col: 14, offset: 3607}, + pos: position{line: 130, col: 14, offset: 3543}, run: (*parser).callonPrefixedOp1, expr: &choiceExpr{ - pos: position{line: 130, col: 16, offset: 3609}, - alternatives: []interface{}{ + pos: position{line: 130, col: 16, offset: 3545}, + alternatives: []any{ &litMatcher{ - pos: position{line: 130, col: 16, offset: 3609}, + pos: position{line: 130, col: 16, offset: 3545}, val: "&", ignoreCase: false, want: "\"&\"", }, &litMatcher{ - pos: position{line: 130, col: 22, offset: 3615}, + pos: position{line: 130, col: 22, offset: 3551}, val: "!", ignoreCase: false, want: "\"!\"", @@ -558,33 +558,33 @@ var g = &grammar{ }, { name: "SuffixedExpr", - pos: position{line: 134, col: 1, offset: 3657}, + pos: position{line: 134, col: 1, offset: 3593}, expr: &choiceExpr{ - pos: position{line: 134, col: 16, offset: 3674}, - alternatives: []interface{}{ + pos: position{line: 134, col: 16, offset: 3610}, + alternatives: []any{ &actionExpr{ - pos: position{line: 134, col: 16, offset: 3674}, + pos: position{line: 134, col: 16, offset: 3610}, run: (*parser).callonSuffixedExpr2, expr: &seqExpr{ - pos: position{line: 134, col: 16, offset: 3674}, - exprs: []interface{}{ + pos: position{line: 134, col: 16, offset: 3610}, + exprs: []any{ &labeledExpr{ - pos: position{line: 134, col: 16, offset: 3674}, + pos: position{line: 134, col: 16, offset: 3610}, label: "expr", expr: &ruleRefExpr{ - pos: position{line: 134, col: 21, offset: 3679}, + pos: position{line: 134, col: 21, offset: 3615}, name: "PrimaryExpr", }, }, &ruleRefExpr{ - pos: position{line: 134, col: 33, offset: 3691}, + pos: position{line: 134, col: 33, offset: 3627}, name: "__", }, &labeledExpr{ - pos: position{line: 134, col: 36, offset: 3694}, + pos: position{line: 134, col: 36, offset: 3630}, label: "op", expr: &ruleRefExpr{ - pos: position{line: 134, col: 39, offset: 3697}, + pos: position{line: 134, col: 39, offset: 3633}, name: "SuffixedOp", }, }, @@ -592,7 +592,7 @@ var g = &grammar{ }, }, &ruleRefExpr{ - pos: position{line: 153, col: 5, offset: 4227}, + pos: position{line: 153, col: 5, offset: 4163}, name: "PrimaryExpr", }, }, @@ -600,27 +600,27 @@ var g = &grammar{ }, { name: "SuffixedOp", - pos: position{line: 155, col: 1, offset: 4240}, + pos: position{line: 155, col: 1, offset: 4176}, expr: &actionExpr{ - pos: position{line: 155, col: 14, offset: 4255}, + pos: position{line: 155, col: 14, offset: 4191}, run: (*parser).callonSuffixedOp1, expr: &choiceExpr{ - pos: position{line: 155, col: 16, offset: 4257}, - alternatives: []interface{}{ + pos: position{line: 155, col: 16, offset: 4193}, + alternatives: []any{ &litMatcher{ - pos: position{line: 155, col: 16, offset: 4257}, + pos: position{line: 155, col: 16, offset: 4193}, val: "?", ignoreCase: false, want: "\"?\"", }, &litMatcher{ - pos: position{line: 155, col: 22, offset: 4263}, + pos: position{line: 155, col: 22, offset: 4199}, val: "*", ignoreCase: false, want: "\"*\"", }, &litMatcher{ - pos: position{line: 155, col: 28, offset: 4269}, + pos: position{line: 155, col: 28, offset: 4205}, val: "+", ignoreCase: false, want: "\"+\"", @@ -631,60 +631,60 @@ var g = &grammar{ }, { name: "PrimaryExpr", - pos: position{line: 159, col: 1, offset: 4311}, + pos: position{line: 159, col: 1, offset: 4247}, expr: &choiceExpr{ - pos: position{line: 159, col: 15, offset: 4327}, - alternatives: []interface{}{ + pos: position{line: 159, col: 15, offset: 4263}, + alternatives: []any{ &ruleRefExpr{ - pos: position{line: 159, col: 15, offset: 4327}, + pos: position{line: 159, col: 15, offset: 4263}, name: "LitMatcher", }, &ruleRefExpr{ - pos: position{line: 159, col: 28, offset: 4340}, + pos: position{line: 159, col: 28, offset: 4276}, name: "CharClassMatcher", }, &ruleRefExpr{ - pos: position{line: 159, col: 47, offset: 4359}, + pos: position{line: 159, col: 47, offset: 4295}, name: "AnyMatcher", }, &ruleRefExpr{ - pos: position{line: 159, col: 60, offset: 4372}, + pos: position{line: 159, col: 60, offset: 4308}, name: "RuleRefExpr", }, &ruleRefExpr{ - pos: position{line: 159, col: 74, offset: 4386}, + pos: position{line: 159, col: 74, offset: 4322}, name: "SemanticPredExpr", }, &actionExpr{ - pos: position{line: 159, col: 93, offset: 4405}, + pos: position{line: 159, col: 93, offset: 4341}, run: (*parser).callonPrimaryExpr7, expr: &seqExpr{ - pos: position{line: 159, col: 93, offset: 4405}, - exprs: []interface{}{ + pos: position{line: 159, col: 93, offset: 4341}, + exprs: []any{ &litMatcher{ - pos: position{line: 159, col: 93, offset: 4405}, + pos: position{line: 159, col: 93, offset: 4341}, val: "(", ignoreCase: false, want: "\"(\"", }, &ruleRefExpr{ - pos: position{line: 159, col: 97, offset: 4409}, + pos: position{line: 159, col: 97, offset: 4345}, name: "__", }, &labeledExpr{ - pos: position{line: 159, col: 100, offset: 4412}, + pos: position{line: 159, col: 100, offset: 4348}, label: "expr", expr: &ruleRefExpr{ - pos: position{line: 159, col: 105, offset: 4417}, + pos: position{line: 159, col: 105, offset: 4353}, name: "Expression", }, }, &ruleRefExpr{ - pos: position{line: 159, col: 116, offset: 4428}, + pos: position{line: 159, col: 116, offset: 4364}, name: "__", }, &litMatcher{ - pos: position{line: 159, col: 119, offset: 4431}, + pos: position{line: 159, col: 119, offset: 4367}, val: ")", ignoreCase: false, want: "\")\"", @@ -697,48 +697,48 @@ var g = &grammar{ }, { name: "RuleRefExpr", - pos: position{line: 162, col: 1, offset: 4460}, + pos: position{line: 162, col: 1, offset: 4396}, expr: &actionExpr{ - pos: position{line: 162, col: 15, offset: 4476}, + pos: position{line: 162, col: 15, offset: 4412}, run: (*parser).callonRuleRefExpr1, expr: &seqExpr{ - pos: position{line: 162, col: 15, offset: 4476}, - exprs: []interface{}{ + pos: position{line: 162, col: 15, offset: 4412}, + exprs: []any{ &labeledExpr{ - pos: position{line: 162, col: 15, offset: 4476}, + pos: position{line: 162, col: 15, offset: 4412}, label: "name", expr: &ruleRefExpr{ - pos: position{line: 162, col: 20, offset: 4481}, + pos: position{line: 162, col: 20, offset: 4417}, name: "IdentifierName", }, }, ¬Expr{ - pos: position{line: 162, col: 35, offset: 4496}, + pos: position{line: 162, col: 35, offset: 4432}, expr: &seqExpr{ - pos: position{line: 162, col: 38, offset: 4499}, - exprs: []interface{}{ + pos: position{line: 162, col: 38, offset: 4435}, + exprs: []any{ &ruleRefExpr{ - pos: position{line: 162, col: 38, offset: 4499}, + pos: position{line: 162, col: 38, offset: 4435}, name: "__", }, &zeroOrOneExpr{ - pos: position{line: 162, col: 41, offset: 4502}, + pos: position{line: 162, col: 41, offset: 4438}, expr: &seqExpr{ - pos: position{line: 162, col: 43, offset: 4504}, - exprs: []interface{}{ + pos: position{line: 162, col: 43, offset: 4440}, + exprs: []any{ &ruleRefExpr{ - pos: position{line: 162, col: 43, offset: 4504}, + pos: position{line: 162, col: 43, offset: 4440}, name: "StringLiteral", }, &ruleRefExpr{ - pos: position{line: 162, col: 57, offset: 4518}, + pos: position{line: 162, col: 57, offset: 4454}, name: "__", }, }, }, }, &ruleRefExpr{ - pos: position{line: 162, col: 63, offset: 4524}, + pos: position{line: 162, col: 63, offset: 4460}, name: "RuleDefOp", }, }, @@ -750,30 +750,30 @@ var g = &grammar{ }, { name: "SemanticPredExpr", - pos: position{line: 167, col: 1, offset: 4640}, + pos: position{line: 167, col: 1, offset: 4576}, expr: &actionExpr{ - pos: position{line: 167, col: 20, offset: 4661}, + pos: position{line: 167, col: 20, offset: 4597}, run: (*parser).callonSemanticPredExpr1, expr: &seqExpr{ - pos: position{line: 167, col: 20, offset: 4661}, - exprs: []interface{}{ + pos: position{line: 167, col: 20, offset: 4597}, + exprs: []any{ &labeledExpr{ - pos: position{line: 167, col: 20, offset: 4661}, + pos: position{line: 167, col: 20, offset: 4597}, label: "op", expr: &ruleRefExpr{ - pos: position{line: 167, col: 23, offset: 4664}, + pos: position{line: 167, col: 23, offset: 4600}, name: "SemanticPredOp", }, }, &ruleRefExpr{ - pos: position{line: 167, col: 38, offset: 4679}, + pos: position{line: 167, col: 38, offset: 4615}, name: "__", }, &labeledExpr{ - pos: position{line: 167, col: 41, offset: 4682}, + pos: position{line: 167, col: 41, offset: 4618}, label: "code", expr: &ruleRefExpr{ - pos: position{line: 167, col: 46, offset: 4687}, + pos: position{line: 167, col: 46, offset: 4623}, name: "CodeBlock", }, }, @@ -783,27 +783,27 @@ var g = &grammar{ }, { name: "SemanticPredOp", - pos: position{line: 187, col: 1, offset: 5134}, + pos: position{line: 187, col: 1, offset: 5070}, expr: &actionExpr{ - pos: position{line: 187, col: 18, offset: 5153}, + pos: position{line: 187, col: 18, offset: 5089}, run: (*parser).callonSemanticPredOp1, expr: &choiceExpr{ - pos: position{line: 187, col: 20, offset: 5155}, - alternatives: []interface{}{ + pos: position{line: 187, col: 20, offset: 5091}, + alternatives: []any{ &litMatcher{ - pos: position{line: 187, col: 20, offset: 5155}, + pos: position{line: 187, col: 20, offset: 5091}, val: "#", ignoreCase: false, want: "\"#\"", }, &litMatcher{ - pos: position{line: 187, col: 26, offset: 5161}, + pos: position{line: 187, col: 26, offset: 5097}, val: "&", ignoreCase: false, want: "\"&\"", }, &litMatcher{ - pos: position{line: 187, col: 32, offset: 5167}, + pos: position{line: 187, col: 32, offset: 5103}, val: "!", ignoreCase: false, want: "\"!\"", @@ -814,30 +814,30 @@ var g = &grammar{ }, { name: "RuleDefOp", - pos: position{line: 191, col: 1, offset: 5209}, + pos: position{line: 191, col: 1, offset: 5145}, expr: &choiceExpr{ - pos: position{line: 191, col: 13, offset: 5223}, - alternatives: []interface{}{ + pos: position{line: 191, col: 13, offset: 5159}, + alternatives: []any{ &litMatcher{ - pos: position{line: 191, col: 13, offset: 5223}, + pos: position{line: 191, col: 13, offset: 5159}, val: "=", ignoreCase: false, want: "\"=\"", }, &litMatcher{ - pos: position{line: 191, col: 19, offset: 5229}, + pos: position{line: 191, col: 19, offset: 5165}, val: "<-", ignoreCase: false, want: "\"<-\"", }, &litMatcher{ - pos: position{line: 191, col: 26, offset: 5236}, + pos: position{line: 191, col: 26, offset: 5172}, val: "←", ignoreCase: false, want: "\"←\"", }, &litMatcher{ - pos: position{line: 191, col: 37, offset: 5247}, + pos: position{line: 191, col: 37, offset: 5183}, val: "⟵", ignoreCase: false, want: "\"⟵\"", @@ -847,23 +847,23 @@ var g = &grammar{ }, { name: "SourceChar", - pos: position{line: 193, col: 1, offset: 5257}, + pos: position{line: 193, col: 1, offset: 5193}, expr: &anyMatcher{ - line: 193, col: 14, offset: 5272, + line: 193, col: 14, offset: 5208, }, }, { name: "Comment", - pos: position{line: 194, col: 1, offset: 5274}, + pos: position{line: 194, col: 1, offset: 5210}, expr: &choiceExpr{ - pos: position{line: 194, col: 11, offset: 5286}, - alternatives: []interface{}{ + pos: position{line: 194, col: 11, offset: 5222}, + alternatives: []any{ &ruleRefExpr{ - pos: position{line: 194, col: 11, offset: 5286}, + pos: position{line: 194, col: 11, offset: 5222}, name: "MultiLineComment", }, &ruleRefExpr{ - pos: position{line: 194, col: 30, offset: 5305}, + pos: position{line: 194, col: 30, offset: 5241}, name: "SingleLineComment", }, }, @@ -871,39 +871,39 @@ var g = &grammar{ }, { name: "MultiLineComment", - pos: position{line: 195, col: 1, offset: 5323}, + pos: position{line: 195, col: 1, offset: 5259}, expr: &seqExpr{ - pos: position{line: 195, col: 20, offset: 5344}, - exprs: []interface{}{ + pos: position{line: 195, col: 20, offset: 5280}, + exprs: []any{ &litMatcher{ - pos: position{line: 195, col: 20, offset: 5344}, + pos: position{line: 195, col: 20, offset: 5280}, val: "/*", ignoreCase: false, want: "\"/*\"", }, &zeroOrMoreExpr{ - pos: position{line: 195, col: 25, offset: 5349}, + pos: position{line: 195, col: 25, offset: 5285}, expr: &seqExpr{ - pos: position{line: 195, col: 27, offset: 5351}, - exprs: []interface{}{ + pos: position{line: 195, col: 27, offset: 5287}, + exprs: []any{ ¬Expr{ - pos: position{line: 195, col: 27, offset: 5351}, + pos: position{line: 195, col: 27, offset: 5287}, expr: &litMatcher{ - pos: position{line: 195, col: 28, offset: 5352}, + pos: position{line: 195, col: 28, offset: 5288}, val: "*/", ignoreCase: false, want: "\"*/\"", }, }, &ruleRefExpr{ - pos: position{line: 195, col: 33, offset: 5357}, + pos: position{line: 195, col: 33, offset: 5293}, name: "SourceChar", }, }, }, }, &litMatcher{ - pos: position{line: 195, col: 47, offset: 5371}, + pos: position{line: 195, col: 47, offset: 5307}, val: "*/", ignoreCase: false, want: "\"*/\"", @@ -913,48 +913,48 @@ var g = &grammar{ }, { name: "MultiLineCommentNoLineTerminator", - pos: position{line: 196, col: 1, offset: 5376}, + pos: position{line: 196, col: 1, offset: 5312}, expr: &seqExpr{ - pos: position{line: 196, col: 36, offset: 5413}, - exprs: []interface{}{ + pos: position{line: 196, col: 36, offset: 5349}, + exprs: []any{ &litMatcher{ - pos: position{line: 196, col: 36, offset: 5413}, + pos: position{line: 196, col: 36, offset: 5349}, val: "/*", ignoreCase: false, want: "\"/*\"", }, &zeroOrMoreExpr{ - pos: position{line: 196, col: 41, offset: 5418}, + pos: position{line: 196, col: 41, offset: 5354}, expr: &seqExpr{ - pos: position{line: 196, col: 43, offset: 5420}, - exprs: []interface{}{ + pos: position{line: 196, col: 43, offset: 5356}, + exprs: []any{ ¬Expr{ - pos: position{line: 196, col: 43, offset: 5420}, + pos: position{line: 196, col: 43, offset: 5356}, expr: &choiceExpr{ - pos: position{line: 196, col: 46, offset: 5423}, - alternatives: []interface{}{ + pos: position{line: 196, col: 46, offset: 5359}, + alternatives: []any{ &litMatcher{ - pos: position{line: 196, col: 46, offset: 5423}, + pos: position{line: 196, col: 46, offset: 5359}, val: "*/", ignoreCase: false, want: "\"*/\"", }, &ruleRefExpr{ - pos: position{line: 196, col: 53, offset: 5430}, + pos: position{line: 196, col: 53, offset: 5366}, name: "EOL", }, }, }, }, &ruleRefExpr{ - pos: position{line: 196, col: 59, offset: 5436}, + pos: position{line: 196, col: 59, offset: 5372}, name: "SourceChar", }, }, }, }, &litMatcher{ - pos: position{line: 196, col: 73, offset: 5450}, + pos: position{line: 196, col: 73, offset: 5386}, val: "*/", ignoreCase: false, want: "\"*/\"", @@ -964,39 +964,39 @@ var g = &grammar{ }, { name: "SingleLineComment", - pos: position{line: 197, col: 1, offset: 5455}, + pos: position{line: 197, col: 1, offset: 5391}, expr: &seqExpr{ - pos: position{line: 197, col: 21, offset: 5477}, - exprs: []interface{}{ + pos: position{line: 197, col: 21, offset: 5413}, + exprs: []any{ ¬Expr{ - pos: position{line: 197, col: 21, offset: 5477}, + pos: position{line: 197, col: 21, offset: 5413}, expr: &litMatcher{ - pos: position{line: 197, col: 23, offset: 5479}, + pos: position{line: 197, col: 23, offset: 5415}, val: "//{", ignoreCase: false, want: "\"//{\"", }, }, &litMatcher{ - pos: position{line: 197, col: 30, offset: 5486}, + pos: position{line: 197, col: 30, offset: 5422}, val: "//", ignoreCase: false, want: "\"//\"", }, &zeroOrMoreExpr{ - pos: position{line: 197, col: 35, offset: 5491}, + pos: position{line: 197, col: 35, offset: 5427}, expr: &seqExpr{ - pos: position{line: 197, col: 37, offset: 5493}, - exprs: []interface{}{ + pos: position{line: 197, col: 37, offset: 5429}, + exprs: []any{ ¬Expr{ - pos: position{line: 197, col: 37, offset: 5493}, + pos: position{line: 197, col: 37, offset: 5429}, expr: &ruleRefExpr{ - pos: position{line: 197, col: 38, offset: 5494}, + pos: position{line: 197, col: 38, offset: 5430}, name: "EOL", }, }, &ruleRefExpr{ - pos: position{line: 197, col: 42, offset: 5498}, + pos: position{line: 197, col: 42, offset: 5434}, name: "SourceChar", }, }, @@ -1007,15 +1007,15 @@ var g = &grammar{ }, { name: "Identifier", - pos: position{line: 199, col: 1, offset: 5513}, + pos: position{line: 199, col: 1, offset: 5449}, expr: &actionExpr{ - pos: position{line: 199, col: 14, offset: 5528}, + pos: position{line: 199, col: 14, offset: 5464}, run: (*parser).callonIdentifier1, expr: &labeledExpr{ - pos: position{line: 199, col: 14, offset: 5528}, + pos: position{line: 199, col: 14, offset: 5464}, label: "ident", expr: &ruleRefExpr{ - pos: position{line: 199, col: 20, offset: 5534}, + pos: position{line: 199, col: 20, offset: 5470}, name: "IdentifierName", }, }, @@ -1023,21 +1023,21 @@ var g = &grammar{ }, { name: "IdentifierName", - pos: position{line: 207, col: 1, offset: 5753}, + pos: position{line: 207, col: 1, offset: 5689}, expr: &actionExpr{ - pos: position{line: 207, col: 18, offset: 5772}, + pos: position{line: 207, col: 18, offset: 5708}, run: (*parser).callonIdentifierName1, expr: &seqExpr{ - pos: position{line: 207, col: 18, offset: 5772}, - exprs: []interface{}{ + pos: position{line: 207, col: 18, offset: 5708}, + exprs: []any{ &ruleRefExpr{ - pos: position{line: 207, col: 18, offset: 5772}, + pos: position{line: 207, col: 18, offset: 5708}, name: "IdentifierStart", }, &zeroOrMoreExpr{ - pos: position{line: 207, col: 34, offset: 5788}, + pos: position{line: 207, col: 34, offset: 5724}, expr: &ruleRefExpr{ - pos: position{line: 207, col: 34, offset: 5788}, + pos: position{line: 207, col: 34, offset: 5724}, name: "IdentifierPart", }, }, @@ -1047,9 +1047,9 @@ var g = &grammar{ }, { name: "IdentifierStart", - pos: position{line: 210, col: 1, offset: 5870}, + pos: position{line: 210, col: 1, offset: 5806}, expr: &charClassMatcher{ - pos: position{line: 210, col: 19, offset: 5890}, + pos: position{line: 210, col: 19, offset: 5826}, val: "[\\pL_]", chars: []rune{'_'}, classes: []*unicode.RangeTable{rangeTable("L")}, @@ -1059,16 +1059,16 @@ var g = &grammar{ }, { name: "IdentifierPart", - pos: position{line: 211, col: 1, offset: 5897}, + pos: position{line: 211, col: 1, offset: 5833}, expr: &choiceExpr{ - pos: position{line: 211, col: 18, offset: 5916}, - alternatives: []interface{}{ + pos: position{line: 211, col: 18, offset: 5852}, + alternatives: []any{ &ruleRefExpr{ - pos: position{line: 211, col: 18, offset: 5916}, + pos: position{line: 211, col: 18, offset: 5852}, name: "IdentifierStart", }, &charClassMatcher{ - pos: position{line: 211, col: 36, offset: 5934}, + pos: position{line: 211, col: 36, offset: 5870}, val: "[\\p{Nd}]", classes: []*unicode.RangeTable{rangeTable("Nd")}, ignoreCase: false, @@ -1079,28 +1079,28 @@ var g = &grammar{ }, { name: "LitMatcher", - pos: position{line: 213, col: 1, offset: 5944}, + pos: position{line: 213, col: 1, offset: 5880}, expr: &actionExpr{ - pos: position{line: 213, col: 14, offset: 5959}, + pos: position{line: 213, col: 14, offset: 5895}, run: (*parser).callonLitMatcher1, expr: &seqExpr{ - pos: position{line: 213, col: 14, offset: 5959}, - exprs: []interface{}{ + pos: position{line: 213, col: 14, offset: 5895}, + exprs: []any{ &labeledExpr{ - pos: position{line: 213, col: 14, offset: 5959}, + pos: position{line: 213, col: 14, offset: 5895}, label: "lit", expr: &ruleRefExpr{ - pos: position{line: 213, col: 18, offset: 5963}, + pos: position{line: 213, col: 18, offset: 5899}, name: "StringLiteral", }, }, &labeledExpr{ - pos: position{line: 213, col: 32, offset: 5977}, + pos: position{line: 213, col: 32, offset: 5913}, label: "ignore", expr: &zeroOrOneExpr{ - pos: position{line: 213, col: 39, offset: 5984}, + pos: position{line: 213, col: 39, offset: 5920}, expr: &litMatcher{ - pos: position{line: 213, col: 39, offset: 5984}, + pos: position{line: 213, col: 39, offset: 5920}, val: "i", ignoreCase: false, want: "\"i\"", @@ -1113,34 +1113,34 @@ var g = &grammar{ }, { name: "StringLiteral", - pos: position{line: 226, col: 1, offset: 6383}, + pos: position{line: 226, col: 1, offset: 6319}, expr: &choiceExpr{ - pos: position{line: 226, col: 17, offset: 6401}, - alternatives: []interface{}{ + pos: position{line: 226, col: 17, offset: 6337}, + alternatives: []any{ &actionExpr{ - pos: position{line: 226, col: 17, offset: 6401}, + pos: position{line: 226, col: 17, offset: 6337}, run: (*parser).callonStringLiteral2, expr: &choiceExpr{ - pos: position{line: 226, col: 19, offset: 6403}, - alternatives: []interface{}{ + pos: position{line: 226, col: 19, offset: 6339}, + alternatives: []any{ &seqExpr{ - pos: position{line: 226, col: 19, offset: 6403}, - exprs: []interface{}{ + pos: position{line: 226, col: 19, offset: 6339}, + exprs: []any{ &litMatcher{ - pos: position{line: 226, col: 19, offset: 6403}, + pos: position{line: 226, col: 19, offset: 6339}, val: "\"", ignoreCase: false, want: "\"\\\"\"", }, &zeroOrMoreExpr{ - pos: position{line: 226, col: 23, offset: 6407}, + pos: position{line: 226, col: 23, offset: 6343}, expr: &ruleRefExpr{ - pos: position{line: 226, col: 23, offset: 6407}, + pos: position{line: 226, col: 23, offset: 6343}, name: "DoubleStringChar", }, }, &litMatcher{ - pos: position{line: 226, col: 41, offset: 6425}, + pos: position{line: 226, col: 41, offset: 6361}, val: "\"", ignoreCase: false, want: "\"\\\"\"", @@ -1148,20 +1148,20 @@ var g = &grammar{ }, }, &seqExpr{ - pos: position{line: 226, col: 47, offset: 6431}, - exprs: []interface{}{ + pos: position{line: 226, col: 47, offset: 6367}, + exprs: []any{ &litMatcher{ - pos: position{line: 226, col: 47, offset: 6431}, + pos: position{line: 226, col: 47, offset: 6367}, val: "'", ignoreCase: false, want: "\"'\"", }, &ruleRefExpr{ - pos: position{line: 226, col: 51, offset: 6435}, + pos: position{line: 226, col: 51, offset: 6371}, name: "SingleStringChar", }, &litMatcher{ - pos: position{line: 226, col: 68, offset: 6452}, + pos: position{line: 226, col: 68, offset: 6388}, val: "'", ignoreCase: false, want: "\"'\"", @@ -1169,23 +1169,23 @@ var g = &grammar{ }, }, &seqExpr{ - pos: position{line: 226, col: 74, offset: 6458}, - exprs: []interface{}{ + pos: position{line: 226, col: 74, offset: 6394}, + exprs: []any{ &litMatcher{ - pos: position{line: 226, col: 74, offset: 6458}, + pos: position{line: 226, col: 74, offset: 6394}, val: "`", ignoreCase: false, want: "\"`\"", }, &zeroOrMoreExpr{ - pos: position{line: 226, col: 78, offset: 6462}, + pos: position{line: 226, col: 78, offset: 6398}, expr: &ruleRefExpr{ - pos: position{line: 226, col: 78, offset: 6462}, + pos: position{line: 226, col: 78, offset: 6398}, name: "RawStringChar", }, }, &litMatcher{ - pos: position{line: 226, col: 93, offset: 6477}, + pos: position{line: 226, col: 93, offset: 6413}, val: "`", ignoreCase: false, want: "\"`\"", @@ -1196,36 +1196,36 @@ var g = &grammar{ }, }, &actionExpr{ - pos: position{line: 228, col: 5, offset: 6550}, + pos: position{line: 228, col: 5, offset: 6486}, run: (*parser).callonStringLiteral18, expr: &choiceExpr{ - pos: position{line: 228, col: 7, offset: 6552}, - alternatives: []interface{}{ + pos: position{line: 228, col: 7, offset: 6488}, + alternatives: []any{ &seqExpr{ - pos: position{line: 228, col: 9, offset: 6554}, - exprs: []interface{}{ + pos: position{line: 228, col: 9, offset: 6490}, + exprs: []any{ &litMatcher{ - pos: position{line: 228, col: 9, offset: 6554}, + pos: position{line: 228, col: 9, offset: 6490}, val: "\"", ignoreCase: false, want: "\"\\\"\"", }, &zeroOrMoreExpr{ - pos: position{line: 228, col: 13, offset: 6558}, + pos: position{line: 228, col: 13, offset: 6494}, expr: &ruleRefExpr{ - pos: position{line: 228, col: 13, offset: 6558}, + pos: position{line: 228, col: 13, offset: 6494}, name: "DoubleStringChar", }, }, &choiceExpr{ - pos: position{line: 228, col: 33, offset: 6578}, - alternatives: []interface{}{ + pos: position{line: 228, col: 33, offset: 6514}, + alternatives: []any{ &ruleRefExpr{ - pos: position{line: 228, col: 33, offset: 6578}, + pos: position{line: 228, col: 33, offset: 6514}, name: "EOL", }, &ruleRefExpr{ - pos: position{line: 228, col: 39, offset: 6584}, + pos: position{line: 228, col: 39, offset: 6520}, name: "EOF", }, }, @@ -1233,30 +1233,30 @@ var g = &grammar{ }, }, &seqExpr{ - pos: position{line: 228, col: 51, offset: 6596}, - exprs: []interface{}{ + pos: position{line: 228, col: 51, offset: 6532}, + exprs: []any{ &litMatcher{ - pos: position{line: 228, col: 51, offset: 6596}, + pos: position{line: 228, col: 51, offset: 6532}, val: "'", ignoreCase: false, want: "\"'\"", }, &zeroOrOneExpr{ - pos: position{line: 228, col: 55, offset: 6600}, + pos: position{line: 228, col: 55, offset: 6536}, expr: &ruleRefExpr{ - pos: position{line: 228, col: 55, offset: 6600}, + pos: position{line: 228, col: 55, offset: 6536}, name: "SingleStringChar", }, }, &choiceExpr{ - pos: position{line: 228, col: 75, offset: 6620}, - alternatives: []interface{}{ + pos: position{line: 228, col: 75, offset: 6556}, + alternatives: []any{ &ruleRefExpr{ - pos: position{line: 228, col: 75, offset: 6620}, + pos: position{line: 228, col: 75, offset: 6556}, name: "EOL", }, &ruleRefExpr{ - pos: position{line: 228, col: 81, offset: 6626}, + pos: position{line: 228, col: 81, offset: 6562}, name: "EOF", }, }, @@ -1264,23 +1264,23 @@ var g = &grammar{ }, }, &seqExpr{ - pos: position{line: 228, col: 91, offset: 6636}, - exprs: []interface{}{ + pos: position{line: 228, col: 91, offset: 6572}, + exprs: []any{ &litMatcher{ - pos: position{line: 228, col: 91, offset: 6636}, + pos: position{line: 228, col: 91, offset: 6572}, val: "`", ignoreCase: false, want: "\"`\"", }, &zeroOrMoreExpr{ - pos: position{line: 228, col: 95, offset: 6640}, + pos: position{line: 228, col: 95, offset: 6576}, expr: &ruleRefExpr{ - pos: position{line: 228, col: 95, offset: 6640}, + pos: position{line: 228, col: 95, offset: 6576}, name: "RawStringChar", }, }, &ruleRefExpr{ - pos: position{line: 228, col: 110, offset: 6655}, + pos: position{line: 228, col: 110, offset: 6591}, name: "EOF", }, }, @@ -1293,54 +1293,54 @@ var g = &grammar{ }, { name: "DoubleStringChar", - pos: position{line: 232, col: 1, offset: 6757}, + pos: position{line: 232, col: 1, offset: 6693}, expr: &choiceExpr{ - pos: position{line: 232, col: 20, offset: 6778}, - alternatives: []interface{}{ + pos: position{line: 232, col: 20, offset: 6714}, + alternatives: []any{ &seqExpr{ - pos: position{line: 232, col: 20, offset: 6778}, - exprs: []interface{}{ + pos: position{line: 232, col: 20, offset: 6714}, + exprs: []any{ ¬Expr{ - pos: position{line: 232, col: 20, offset: 6778}, + pos: position{line: 232, col: 20, offset: 6714}, expr: &choiceExpr{ - pos: position{line: 232, col: 23, offset: 6781}, - alternatives: []interface{}{ + pos: position{line: 232, col: 23, offset: 6717}, + alternatives: []any{ &litMatcher{ - pos: position{line: 232, col: 23, offset: 6781}, + pos: position{line: 232, col: 23, offset: 6717}, val: "\"", ignoreCase: false, want: "\"\\\"\"", }, &litMatcher{ - pos: position{line: 232, col: 29, offset: 6787}, + pos: position{line: 232, col: 29, offset: 6723}, val: "\\", ignoreCase: false, want: "\"\\\\\"", }, &ruleRefExpr{ - pos: position{line: 232, col: 36, offset: 6794}, + pos: position{line: 232, col: 36, offset: 6730}, name: "EOL", }, }, }, }, &ruleRefExpr{ - pos: position{line: 232, col: 42, offset: 6800}, + pos: position{line: 232, col: 42, offset: 6736}, name: "SourceChar", }, }, }, &seqExpr{ - pos: position{line: 232, col: 55, offset: 6813}, - exprs: []interface{}{ + pos: position{line: 232, col: 55, offset: 6749}, + exprs: []any{ &litMatcher{ - pos: position{line: 232, col: 55, offset: 6813}, + pos: position{line: 232, col: 55, offset: 6749}, val: "\\", ignoreCase: false, want: "\"\\\\\"", }, &ruleRefExpr{ - pos: position{line: 232, col: 60, offset: 6818}, + pos: position{line: 232, col: 60, offset: 6754}, name: "DoubleStringEscape", }, }, @@ -1350,54 +1350,54 @@ var g = &grammar{ }, { name: "SingleStringChar", - pos: position{line: 233, col: 1, offset: 6837}, + pos: position{line: 233, col: 1, offset: 6773}, expr: &choiceExpr{ - pos: position{line: 233, col: 20, offset: 6858}, - alternatives: []interface{}{ + pos: position{line: 233, col: 20, offset: 6794}, + alternatives: []any{ &seqExpr{ - pos: position{line: 233, col: 20, offset: 6858}, - exprs: []interface{}{ + pos: position{line: 233, col: 20, offset: 6794}, + exprs: []any{ ¬Expr{ - pos: position{line: 233, col: 20, offset: 6858}, + pos: position{line: 233, col: 20, offset: 6794}, expr: &choiceExpr{ - pos: position{line: 233, col: 23, offset: 6861}, - alternatives: []interface{}{ + pos: position{line: 233, col: 23, offset: 6797}, + alternatives: []any{ &litMatcher{ - pos: position{line: 233, col: 23, offset: 6861}, + pos: position{line: 233, col: 23, offset: 6797}, val: "'", ignoreCase: false, want: "\"'\"", }, &litMatcher{ - pos: position{line: 233, col: 29, offset: 6867}, + pos: position{line: 233, col: 29, offset: 6803}, val: "\\", ignoreCase: false, want: "\"\\\\\"", }, &ruleRefExpr{ - pos: position{line: 233, col: 36, offset: 6874}, + pos: position{line: 233, col: 36, offset: 6810}, name: "EOL", }, }, }, }, &ruleRefExpr{ - pos: position{line: 233, col: 42, offset: 6880}, + pos: position{line: 233, col: 42, offset: 6816}, name: "SourceChar", }, }, }, &seqExpr{ - pos: position{line: 233, col: 55, offset: 6893}, - exprs: []interface{}{ + pos: position{line: 233, col: 55, offset: 6829}, + exprs: []any{ &litMatcher{ - pos: position{line: 233, col: 55, offset: 6893}, + pos: position{line: 233, col: 55, offset: 6829}, val: "\\", ignoreCase: false, want: "\"\\\\\"", }, &ruleRefExpr{ - pos: position{line: 233, col: 60, offset: 6898}, + pos: position{line: 233, col: 60, offset: 6834}, name: "SingleStringEscape", }, }, @@ -1407,21 +1407,21 @@ var g = &grammar{ }, { name: "RawStringChar", - pos: position{line: 234, col: 1, offset: 6917}, + pos: position{line: 234, col: 1, offset: 6853}, expr: &seqExpr{ - pos: position{line: 234, col: 17, offset: 6935}, - exprs: []interface{}{ + pos: position{line: 234, col: 17, offset: 6871}, + exprs: []any{ ¬Expr{ - pos: position{line: 234, col: 17, offset: 6935}, + pos: position{line: 234, col: 17, offset: 6871}, expr: &litMatcher{ - pos: position{line: 234, col: 18, offset: 6936}, + pos: position{line: 234, col: 18, offset: 6872}, val: "`", ignoreCase: false, want: "\"`\"", }, }, &ruleRefExpr{ - pos: position{line: 234, col: 22, offset: 6940}, + pos: position{line: 234, col: 22, offset: 6876}, name: "SourceChar", }, }, @@ -1429,41 +1429,41 @@ var g = &grammar{ }, { name: "DoubleStringEscape", - pos: position{line: 236, col: 1, offset: 6952}, + pos: position{line: 236, col: 1, offset: 6888}, expr: &choiceExpr{ - pos: position{line: 236, col: 22, offset: 6975}, - alternatives: []interface{}{ + pos: position{line: 236, col: 22, offset: 6911}, + alternatives: []any{ &choiceExpr{ - pos: position{line: 236, col: 24, offset: 6977}, - alternatives: []interface{}{ + pos: position{line: 236, col: 24, offset: 6913}, + alternatives: []any{ &litMatcher{ - pos: position{line: 236, col: 24, offset: 6977}, + pos: position{line: 236, col: 24, offset: 6913}, val: "\"", ignoreCase: false, want: "\"\\\"\"", }, &ruleRefExpr{ - pos: position{line: 236, col: 30, offset: 6983}, + pos: position{line: 236, col: 30, offset: 6919}, name: "CommonEscapeSequence", }, }, }, &actionExpr{ - pos: position{line: 237, col: 7, offset: 7012}, + pos: position{line: 237, col: 7, offset: 6948}, run: (*parser).callonDoubleStringEscape5, expr: &choiceExpr{ - pos: position{line: 237, col: 9, offset: 7014}, - alternatives: []interface{}{ + pos: position{line: 237, col: 9, offset: 6950}, + alternatives: []any{ &ruleRefExpr{ - pos: position{line: 237, col: 9, offset: 7014}, + pos: position{line: 237, col: 9, offset: 6950}, name: "SourceChar", }, &ruleRefExpr{ - pos: position{line: 237, col: 22, offset: 7027}, + pos: position{line: 237, col: 22, offset: 6963}, name: "EOL", }, &ruleRefExpr{ - pos: position{line: 237, col: 28, offset: 7033}, + pos: position{line: 237, col: 28, offset: 6969}, name: "EOF", }, }, @@ -1474,41 +1474,41 @@ var g = &grammar{ }, { name: "SingleStringEscape", - pos: position{line: 240, col: 1, offset: 7098}, + pos: position{line: 240, col: 1, offset: 7034}, expr: &choiceExpr{ - pos: position{line: 240, col: 22, offset: 7121}, - alternatives: []interface{}{ + pos: position{line: 240, col: 22, offset: 7057}, + alternatives: []any{ &choiceExpr{ - pos: position{line: 240, col: 24, offset: 7123}, - alternatives: []interface{}{ + pos: position{line: 240, col: 24, offset: 7059}, + alternatives: []any{ &litMatcher{ - pos: position{line: 240, col: 24, offset: 7123}, + pos: position{line: 240, col: 24, offset: 7059}, val: "'", ignoreCase: false, want: "\"'\"", }, &ruleRefExpr{ - pos: position{line: 240, col: 30, offset: 7129}, + pos: position{line: 240, col: 30, offset: 7065}, name: "CommonEscapeSequence", }, }, }, &actionExpr{ - pos: position{line: 241, col: 7, offset: 7158}, + pos: position{line: 241, col: 7, offset: 7094}, run: (*parser).callonSingleStringEscape5, expr: &choiceExpr{ - pos: position{line: 241, col: 9, offset: 7160}, - alternatives: []interface{}{ + pos: position{line: 241, col: 9, offset: 7096}, + alternatives: []any{ &ruleRefExpr{ - pos: position{line: 241, col: 9, offset: 7160}, + pos: position{line: 241, col: 9, offset: 7096}, name: "SourceChar", }, &ruleRefExpr{ - pos: position{line: 241, col: 22, offset: 7173}, + pos: position{line: 241, col: 22, offset: 7109}, name: "EOL", }, &ruleRefExpr{ - pos: position{line: 241, col: 28, offset: 7179}, + pos: position{line: 241, col: 28, offset: 7115}, name: "EOF", }, }, @@ -1519,28 +1519,28 @@ var g = &grammar{ }, { name: "CommonEscapeSequence", - pos: position{line: 245, col: 1, offset: 7245}, + pos: position{line: 245, col: 1, offset: 7181}, expr: &choiceExpr{ - pos: position{line: 245, col: 24, offset: 7270}, - alternatives: []interface{}{ + pos: position{line: 245, col: 24, offset: 7206}, + alternatives: []any{ &ruleRefExpr{ - pos: position{line: 245, col: 24, offset: 7270}, + pos: position{line: 245, col: 24, offset: 7206}, name: "SingleCharEscape", }, &ruleRefExpr{ - pos: position{line: 245, col: 43, offset: 7289}, + pos: position{line: 245, col: 43, offset: 7225}, name: "OctalEscape", }, &ruleRefExpr{ - pos: position{line: 245, col: 57, offset: 7303}, + pos: position{line: 245, col: 57, offset: 7239}, name: "HexEscape", }, &ruleRefExpr{ - pos: position{line: 245, col: 69, offset: 7315}, + pos: position{line: 245, col: 69, offset: 7251}, name: "LongUnicodeEscape", }, &ruleRefExpr{ - pos: position{line: 245, col: 89, offset: 7335}, + pos: position{line: 245, col: 89, offset: 7271}, name: "ShortUnicodeEscape", }, }, @@ -1548,54 +1548,54 @@ var g = &grammar{ }, { name: "SingleCharEscape", - pos: position{line: 246, col: 1, offset: 7354}, + pos: position{line: 246, col: 1, offset: 7290}, expr: &choiceExpr{ - pos: position{line: 246, col: 20, offset: 7375}, - alternatives: []interface{}{ + pos: position{line: 246, col: 20, offset: 7311}, + alternatives: []any{ &litMatcher{ - pos: position{line: 246, col: 20, offset: 7375}, + pos: position{line: 246, col: 20, offset: 7311}, val: "a", ignoreCase: false, want: "\"a\"", }, &litMatcher{ - pos: position{line: 246, col: 26, offset: 7381}, + pos: position{line: 246, col: 26, offset: 7317}, val: "b", ignoreCase: false, want: "\"b\"", }, &litMatcher{ - pos: position{line: 246, col: 32, offset: 7387}, + pos: position{line: 246, col: 32, offset: 7323}, val: "n", ignoreCase: false, want: "\"n\"", }, &litMatcher{ - pos: position{line: 246, col: 38, offset: 7393}, + pos: position{line: 246, col: 38, offset: 7329}, val: "f", ignoreCase: false, want: "\"f\"", }, &litMatcher{ - pos: position{line: 246, col: 44, offset: 7399}, + pos: position{line: 246, col: 44, offset: 7335}, val: "r", ignoreCase: false, want: "\"r\"", }, &litMatcher{ - pos: position{line: 246, col: 50, offset: 7405}, + pos: position{line: 246, col: 50, offset: 7341}, val: "t", ignoreCase: false, want: "\"t\"", }, &litMatcher{ - pos: position{line: 246, col: 56, offset: 7411}, + pos: position{line: 246, col: 56, offset: 7347}, val: "v", ignoreCase: false, want: "\"v\"", }, &litMatcher{ - pos: position{line: 246, col: 62, offset: 7417}, + pos: position{line: 246, col: 62, offset: 7353}, val: "\\", ignoreCase: false, want: "\"\\\\\"", @@ -1605,50 +1605,50 @@ var g = &grammar{ }, { name: "OctalEscape", - pos: position{line: 247, col: 1, offset: 7422}, + pos: position{line: 247, col: 1, offset: 7358}, expr: &choiceExpr{ - pos: position{line: 247, col: 15, offset: 7438}, - alternatives: []interface{}{ + pos: position{line: 247, col: 15, offset: 7374}, + alternatives: []any{ &seqExpr{ - pos: position{line: 247, col: 15, offset: 7438}, - exprs: []interface{}{ + pos: position{line: 247, col: 15, offset: 7374}, + exprs: []any{ &ruleRefExpr{ - pos: position{line: 247, col: 15, offset: 7438}, + pos: position{line: 247, col: 15, offset: 7374}, name: "OctalDigit", }, &ruleRefExpr{ - pos: position{line: 247, col: 26, offset: 7449}, + pos: position{line: 247, col: 26, offset: 7385}, name: "OctalDigit", }, &ruleRefExpr{ - pos: position{line: 247, col: 37, offset: 7460}, + pos: position{line: 247, col: 37, offset: 7396}, name: "OctalDigit", }, }, }, &actionExpr{ - pos: position{line: 248, col: 7, offset: 7477}, + pos: position{line: 248, col: 7, offset: 7413}, run: (*parser).callonOctalEscape6, expr: &seqExpr{ - pos: position{line: 248, col: 7, offset: 7477}, - exprs: []interface{}{ + pos: position{line: 248, col: 7, offset: 7413}, + exprs: []any{ &ruleRefExpr{ - pos: position{line: 248, col: 7, offset: 7477}, + pos: position{line: 248, col: 7, offset: 7413}, name: "OctalDigit", }, &choiceExpr{ - pos: position{line: 248, col: 20, offset: 7490}, - alternatives: []interface{}{ + pos: position{line: 248, col: 20, offset: 7426}, + alternatives: []any{ &ruleRefExpr{ - pos: position{line: 248, col: 20, offset: 7490}, + pos: position{line: 248, col: 20, offset: 7426}, name: "SourceChar", }, &ruleRefExpr{ - pos: position{line: 248, col: 33, offset: 7503}, + pos: position{line: 248, col: 33, offset: 7439}, name: "EOL", }, &ruleRefExpr{ - pos: position{line: 248, col: 39, offset: 7509}, + pos: position{line: 248, col: 39, offset: 7445}, name: "EOF", }, }, @@ -1661,54 +1661,54 @@ var g = &grammar{ }, { name: "HexEscape", - pos: position{line: 251, col: 1, offset: 7570}, + pos: position{line: 251, col: 1, offset: 7506}, expr: &choiceExpr{ - pos: position{line: 251, col: 13, offset: 7584}, - alternatives: []interface{}{ + pos: position{line: 251, col: 13, offset: 7520}, + alternatives: []any{ &seqExpr{ - pos: position{line: 251, col: 13, offset: 7584}, - exprs: []interface{}{ + pos: position{line: 251, col: 13, offset: 7520}, + exprs: []any{ &litMatcher{ - pos: position{line: 251, col: 13, offset: 7584}, + pos: position{line: 251, col: 13, offset: 7520}, val: "x", ignoreCase: false, want: "\"x\"", }, &ruleRefExpr{ - pos: position{line: 251, col: 17, offset: 7588}, + pos: position{line: 251, col: 17, offset: 7524}, name: "HexDigit", }, &ruleRefExpr{ - pos: position{line: 251, col: 26, offset: 7597}, + pos: position{line: 251, col: 26, offset: 7533}, name: "HexDigit", }, }, }, &actionExpr{ - pos: position{line: 252, col: 7, offset: 7612}, + pos: position{line: 252, col: 7, offset: 7548}, run: (*parser).callonHexEscape6, expr: &seqExpr{ - pos: position{line: 252, col: 7, offset: 7612}, - exprs: []interface{}{ + pos: position{line: 252, col: 7, offset: 7548}, + exprs: []any{ &litMatcher{ - pos: position{line: 252, col: 7, offset: 7612}, + pos: position{line: 252, col: 7, offset: 7548}, val: "x", ignoreCase: false, want: "\"x\"", }, &choiceExpr{ - pos: position{line: 252, col: 13, offset: 7618}, - alternatives: []interface{}{ + pos: position{line: 252, col: 13, offset: 7554}, + alternatives: []any{ &ruleRefExpr{ - pos: position{line: 252, col: 13, offset: 7618}, + pos: position{line: 252, col: 13, offset: 7554}, name: "SourceChar", }, &ruleRefExpr{ - pos: position{line: 252, col: 26, offset: 7631}, + pos: position{line: 252, col: 26, offset: 7567}, name: "EOL", }, &ruleRefExpr{ - pos: position{line: 252, col: 32, offset: 7637}, + pos: position{line: 252, col: 32, offset: 7573}, name: "EOF", }, }, @@ -1721,82 +1721,82 @@ var g = &grammar{ }, { name: "LongUnicodeEscape", - pos: position{line: 255, col: 1, offset: 7704}, + pos: position{line: 255, col: 1, offset: 7640}, expr: &choiceExpr{ - pos: position{line: 256, col: 5, offset: 7730}, - alternatives: []interface{}{ + pos: position{line: 256, col: 5, offset: 7666}, + alternatives: []any{ &actionExpr{ - pos: position{line: 256, col: 5, offset: 7730}, + pos: position{line: 256, col: 5, offset: 7666}, run: (*parser).callonLongUnicodeEscape2, expr: &seqExpr{ - pos: position{line: 256, col: 5, offset: 7730}, - exprs: []interface{}{ + pos: position{line: 256, col: 5, offset: 7666}, + exprs: []any{ &litMatcher{ - pos: position{line: 256, col: 5, offset: 7730}, + pos: position{line: 256, col: 5, offset: 7666}, val: "U", ignoreCase: false, want: "\"U\"", }, &ruleRefExpr{ - pos: position{line: 256, col: 9, offset: 7734}, + pos: position{line: 256, col: 9, offset: 7670}, name: "HexDigit", }, &ruleRefExpr{ - pos: position{line: 256, col: 18, offset: 7743}, + pos: position{line: 256, col: 18, offset: 7679}, name: "HexDigit", }, &ruleRefExpr{ - pos: position{line: 256, col: 27, offset: 7752}, + pos: position{line: 256, col: 27, offset: 7688}, name: "HexDigit", }, &ruleRefExpr{ - pos: position{line: 256, col: 36, offset: 7761}, + pos: position{line: 256, col: 36, offset: 7697}, name: "HexDigit", }, &ruleRefExpr{ - pos: position{line: 256, col: 45, offset: 7770}, + pos: position{line: 256, col: 45, offset: 7706}, name: "HexDigit", }, &ruleRefExpr{ - pos: position{line: 256, col: 54, offset: 7779}, + pos: position{line: 256, col: 54, offset: 7715}, name: "HexDigit", }, &ruleRefExpr{ - pos: position{line: 256, col: 63, offset: 7788}, + pos: position{line: 256, col: 63, offset: 7724}, name: "HexDigit", }, &ruleRefExpr{ - pos: position{line: 256, col: 72, offset: 7797}, + pos: position{line: 256, col: 72, offset: 7733}, name: "HexDigit", }, }, }, }, &actionExpr{ - pos: position{line: 259, col: 7, offset: 7899}, + pos: position{line: 259, col: 7, offset: 7835}, run: (*parser).callonLongUnicodeEscape13, expr: &seqExpr{ - pos: position{line: 259, col: 7, offset: 7899}, - exprs: []interface{}{ + pos: position{line: 259, col: 7, offset: 7835}, + exprs: []any{ &litMatcher{ - pos: position{line: 259, col: 7, offset: 7899}, + pos: position{line: 259, col: 7, offset: 7835}, val: "U", ignoreCase: false, want: "\"U\"", }, &choiceExpr{ - pos: position{line: 259, col: 13, offset: 7905}, - alternatives: []interface{}{ + pos: position{line: 259, col: 13, offset: 7841}, + alternatives: []any{ &ruleRefExpr{ - pos: position{line: 259, col: 13, offset: 7905}, + pos: position{line: 259, col: 13, offset: 7841}, name: "SourceChar", }, &ruleRefExpr{ - pos: position{line: 259, col: 26, offset: 7918}, + pos: position{line: 259, col: 26, offset: 7854}, name: "EOL", }, &ruleRefExpr{ - pos: position{line: 259, col: 32, offset: 7924}, + pos: position{line: 259, col: 32, offset: 7860}, name: "EOF", }, }, @@ -1809,66 +1809,66 @@ var g = &grammar{ }, { name: "ShortUnicodeEscape", - pos: position{line: 262, col: 1, offset: 7987}, + pos: position{line: 262, col: 1, offset: 7923}, expr: &choiceExpr{ - pos: position{line: 263, col: 5, offset: 8014}, - alternatives: []interface{}{ + pos: position{line: 263, col: 5, offset: 7950}, + alternatives: []any{ &actionExpr{ - pos: position{line: 263, col: 5, offset: 8014}, + pos: position{line: 263, col: 5, offset: 7950}, run: (*parser).callonShortUnicodeEscape2, expr: &seqExpr{ - pos: position{line: 263, col: 5, offset: 8014}, - exprs: []interface{}{ + pos: position{line: 263, col: 5, offset: 7950}, + exprs: []any{ &litMatcher{ - pos: position{line: 263, col: 5, offset: 8014}, + pos: position{line: 263, col: 5, offset: 7950}, val: "u", ignoreCase: false, want: "\"u\"", }, &ruleRefExpr{ - pos: position{line: 263, col: 9, offset: 8018}, + pos: position{line: 263, col: 9, offset: 7954}, name: "HexDigit", }, &ruleRefExpr{ - pos: position{line: 263, col: 18, offset: 8027}, + pos: position{line: 263, col: 18, offset: 7963}, name: "HexDigit", }, &ruleRefExpr{ - pos: position{line: 263, col: 27, offset: 8036}, + pos: position{line: 263, col: 27, offset: 7972}, name: "HexDigit", }, &ruleRefExpr{ - pos: position{line: 263, col: 36, offset: 8045}, + pos: position{line: 263, col: 36, offset: 7981}, name: "HexDigit", }, }, }, }, &actionExpr{ - pos: position{line: 266, col: 7, offset: 8147}, + pos: position{line: 266, col: 7, offset: 8083}, run: (*parser).callonShortUnicodeEscape9, expr: &seqExpr{ - pos: position{line: 266, col: 7, offset: 8147}, - exprs: []interface{}{ + pos: position{line: 266, col: 7, offset: 8083}, + exprs: []any{ &litMatcher{ - pos: position{line: 266, col: 7, offset: 8147}, + pos: position{line: 266, col: 7, offset: 8083}, val: "u", ignoreCase: false, want: "\"u\"", }, &choiceExpr{ - pos: position{line: 266, col: 13, offset: 8153}, - alternatives: []interface{}{ + pos: position{line: 266, col: 13, offset: 8089}, + alternatives: []any{ &ruleRefExpr{ - pos: position{line: 266, col: 13, offset: 8153}, + pos: position{line: 266, col: 13, offset: 8089}, name: "SourceChar", }, &ruleRefExpr{ - pos: position{line: 266, col: 26, offset: 8166}, + pos: position{line: 266, col: 26, offset: 8102}, name: "EOL", }, &ruleRefExpr{ - pos: position{line: 266, col: 32, offset: 8172}, + pos: position{line: 266, col: 32, offset: 8108}, name: "EOF", }, }, @@ -1881,9 +1881,9 @@ var g = &grammar{ }, { name: "OctalDigit", - pos: position{line: 270, col: 1, offset: 8236}, + pos: position{line: 270, col: 1, offset: 8172}, expr: &charClassMatcher{ - pos: position{line: 270, col: 14, offset: 8251}, + pos: position{line: 270, col: 14, offset: 8187}, val: "[0-7]", ranges: []rune{'0', '7'}, ignoreCase: false, @@ -1892,9 +1892,9 @@ var g = &grammar{ }, { name: "DecimalDigit", - pos: position{line: 271, col: 1, offset: 8257}, + pos: position{line: 271, col: 1, offset: 8193}, expr: &charClassMatcher{ - pos: position{line: 271, col: 16, offset: 8274}, + pos: position{line: 271, col: 16, offset: 8210}, val: "[0-9]", ranges: []rune{'0', '9'}, ignoreCase: false, @@ -1903,9 +1903,9 @@ var g = &grammar{ }, { name: "HexDigit", - pos: position{line: 272, col: 1, offset: 8280}, + pos: position{line: 272, col: 1, offset: 8216}, expr: &charClassMatcher{ - pos: position{line: 272, col: 12, offset: 8293}, + pos: position{line: 272, col: 12, offset: 8229}, val: "[0-9a-f]i", ranges: []rune{'0', '9', 'a', 'f'}, ignoreCase: true, @@ -1914,46 +1914,46 @@ var g = &grammar{ }, { name: "CharClassMatcher", - pos: position{line: 274, col: 1, offset: 8304}, + pos: position{line: 274, col: 1, offset: 8240}, expr: &choiceExpr{ - pos: position{line: 274, col: 20, offset: 8325}, - alternatives: []interface{}{ + pos: position{line: 274, col: 20, offset: 8261}, + alternatives: []any{ &actionExpr{ - pos: position{line: 274, col: 20, offset: 8325}, + pos: position{line: 274, col: 20, offset: 8261}, run: (*parser).callonCharClassMatcher2, expr: &seqExpr{ - pos: position{line: 274, col: 20, offset: 8325}, - exprs: []interface{}{ + pos: position{line: 274, col: 20, offset: 8261}, + exprs: []any{ &litMatcher{ - pos: position{line: 274, col: 20, offset: 8325}, + pos: position{line: 274, col: 20, offset: 8261}, val: "[", ignoreCase: false, want: "\"[\"", }, &zeroOrMoreExpr{ - pos: position{line: 274, col: 24, offset: 8329}, + pos: position{line: 274, col: 24, offset: 8265}, expr: &choiceExpr{ - pos: position{line: 274, col: 26, offset: 8331}, - alternatives: []interface{}{ + pos: position{line: 274, col: 26, offset: 8267}, + alternatives: []any{ &ruleRefExpr{ - pos: position{line: 274, col: 26, offset: 8331}, + pos: position{line: 274, col: 26, offset: 8267}, name: "ClassCharRange", }, &ruleRefExpr{ - pos: position{line: 274, col: 43, offset: 8348}, + pos: position{line: 274, col: 43, offset: 8284}, name: "ClassChar", }, &seqExpr{ - pos: position{line: 274, col: 55, offset: 8360}, - exprs: []interface{}{ + pos: position{line: 274, col: 55, offset: 8296}, + exprs: []any{ &litMatcher{ - pos: position{line: 274, col: 55, offset: 8360}, + pos: position{line: 274, col: 55, offset: 8296}, val: "\\", ignoreCase: false, want: "\"\\\\\"", }, &ruleRefExpr{ - pos: position{line: 274, col: 60, offset: 8365}, + pos: position{line: 274, col: 60, offset: 8301}, name: "UnicodeClassEscape", }, }, @@ -1962,15 +1962,15 @@ var g = &grammar{ }, }, &litMatcher{ - pos: position{line: 274, col: 82, offset: 8387}, + pos: position{line: 274, col: 82, offset: 8323}, val: "]", ignoreCase: false, want: "\"]\"", }, &zeroOrOneExpr{ - pos: position{line: 274, col: 86, offset: 8391}, + pos: position{line: 274, col: 86, offset: 8327}, expr: &litMatcher{ - pos: position{line: 274, col: 86, offset: 8391}, + pos: position{line: 274, col: 86, offset: 8327}, val: "i", ignoreCase: false, want: "\"i\"", @@ -1980,45 +1980,45 @@ var g = &grammar{ }, }, &actionExpr{ - pos: position{line: 278, col: 5, offset: 8498}, + pos: position{line: 278, col: 5, offset: 8434}, run: (*parser).callonCharClassMatcher15, expr: &seqExpr{ - pos: position{line: 278, col: 5, offset: 8498}, - exprs: []interface{}{ + pos: position{line: 278, col: 5, offset: 8434}, + exprs: []any{ &litMatcher{ - pos: position{line: 278, col: 5, offset: 8498}, + pos: position{line: 278, col: 5, offset: 8434}, val: "[", ignoreCase: false, want: "\"[\"", }, &zeroOrMoreExpr{ - pos: position{line: 278, col: 9, offset: 8502}, + pos: position{line: 278, col: 9, offset: 8438}, expr: &seqExpr{ - pos: position{line: 278, col: 11, offset: 8504}, - exprs: []interface{}{ + pos: position{line: 278, col: 11, offset: 8440}, + exprs: []any{ ¬Expr{ - pos: position{line: 278, col: 11, offset: 8504}, + pos: position{line: 278, col: 11, offset: 8440}, expr: &ruleRefExpr{ - pos: position{line: 278, col: 14, offset: 8507}, + pos: position{line: 278, col: 14, offset: 8443}, name: "EOL", }, }, &ruleRefExpr{ - pos: position{line: 278, col: 20, offset: 8513}, + pos: position{line: 278, col: 20, offset: 8449}, name: "SourceChar", }, }, }, }, &choiceExpr{ - pos: position{line: 278, col: 36, offset: 8529}, - alternatives: []interface{}{ + pos: position{line: 278, col: 36, offset: 8465}, + alternatives: []any{ &ruleRefExpr{ - pos: position{line: 278, col: 36, offset: 8529}, + pos: position{line: 278, col: 36, offset: 8465}, name: "EOL", }, &ruleRefExpr{ - pos: position{line: 278, col: 42, offset: 8535}, + pos: position{line: 278, col: 42, offset: 8471}, name: "EOF", }, }, @@ -2031,22 +2031,22 @@ var g = &grammar{ }, { name: "ClassCharRange", - pos: position{line: 282, col: 1, offset: 8645}, + pos: position{line: 282, col: 1, offset: 8581}, expr: &seqExpr{ - pos: position{line: 282, col: 18, offset: 8664}, - exprs: []interface{}{ + pos: position{line: 282, col: 18, offset: 8600}, + exprs: []any{ &ruleRefExpr{ - pos: position{line: 282, col: 18, offset: 8664}, + pos: position{line: 282, col: 18, offset: 8600}, name: "ClassChar", }, &litMatcher{ - pos: position{line: 282, col: 28, offset: 8674}, + pos: position{line: 282, col: 28, offset: 8610}, val: "-", ignoreCase: false, want: "\"-\"", }, &ruleRefExpr{ - pos: position{line: 282, col: 32, offset: 8678}, + pos: position{line: 282, col: 32, offset: 8614}, name: "ClassChar", }, }, @@ -2054,54 +2054,54 @@ var g = &grammar{ }, { name: "ClassChar", - pos: position{line: 283, col: 1, offset: 8688}, + pos: position{line: 283, col: 1, offset: 8624}, expr: &choiceExpr{ - pos: position{line: 283, col: 13, offset: 8702}, - alternatives: []interface{}{ + pos: position{line: 283, col: 13, offset: 8638}, + alternatives: []any{ &seqExpr{ - pos: position{line: 283, col: 13, offset: 8702}, - exprs: []interface{}{ + pos: position{line: 283, col: 13, offset: 8638}, + exprs: []any{ ¬Expr{ - pos: position{line: 283, col: 13, offset: 8702}, + pos: position{line: 283, col: 13, offset: 8638}, expr: &choiceExpr{ - pos: position{line: 283, col: 16, offset: 8705}, - alternatives: []interface{}{ + pos: position{line: 283, col: 16, offset: 8641}, + alternatives: []any{ &litMatcher{ - pos: position{line: 283, col: 16, offset: 8705}, + pos: position{line: 283, col: 16, offset: 8641}, val: "]", ignoreCase: false, want: "\"]\"", }, &litMatcher{ - pos: position{line: 283, col: 22, offset: 8711}, + pos: position{line: 283, col: 22, offset: 8647}, val: "\\", ignoreCase: false, want: "\"\\\\\"", }, &ruleRefExpr{ - pos: position{line: 283, col: 29, offset: 8718}, + pos: position{line: 283, col: 29, offset: 8654}, name: "EOL", }, }, }, }, &ruleRefExpr{ - pos: position{line: 283, col: 35, offset: 8724}, + pos: position{line: 283, col: 35, offset: 8660}, name: "SourceChar", }, }, }, &seqExpr{ - pos: position{line: 283, col: 48, offset: 8737}, - exprs: []interface{}{ + pos: position{line: 283, col: 48, offset: 8673}, + exprs: []any{ &litMatcher{ - pos: position{line: 283, col: 48, offset: 8737}, + pos: position{line: 283, col: 48, offset: 8673}, val: "\\", ignoreCase: false, want: "\"\\\\\"", }, &ruleRefExpr{ - pos: position{line: 283, col: 53, offset: 8742}, + pos: position{line: 283, col: 53, offset: 8678}, name: "CharClassEscape", }, }, @@ -2111,53 +2111,53 @@ var g = &grammar{ }, { name: "CharClassEscape", - pos: position{line: 284, col: 1, offset: 8758}, + pos: position{line: 284, col: 1, offset: 8694}, expr: &choiceExpr{ - pos: position{line: 284, col: 19, offset: 8778}, - alternatives: []interface{}{ + pos: position{line: 284, col: 19, offset: 8714}, + alternatives: []any{ &choiceExpr{ - pos: position{line: 284, col: 21, offset: 8780}, - alternatives: []interface{}{ + pos: position{line: 284, col: 21, offset: 8716}, + alternatives: []any{ &litMatcher{ - pos: position{line: 284, col: 21, offset: 8780}, + pos: position{line: 284, col: 21, offset: 8716}, val: "]", ignoreCase: false, want: "\"]\"", }, &ruleRefExpr{ - pos: position{line: 284, col: 27, offset: 8786}, + pos: position{line: 284, col: 27, offset: 8722}, name: "CommonEscapeSequence", }, }, }, &actionExpr{ - pos: position{line: 285, col: 7, offset: 8815}, + pos: position{line: 285, col: 7, offset: 8751}, run: (*parser).callonCharClassEscape5, expr: &seqExpr{ - pos: position{line: 285, col: 7, offset: 8815}, - exprs: []interface{}{ + pos: position{line: 285, col: 7, offset: 8751}, + exprs: []any{ ¬Expr{ - pos: position{line: 285, col: 7, offset: 8815}, + pos: position{line: 285, col: 7, offset: 8751}, expr: &litMatcher{ - pos: position{line: 285, col: 8, offset: 8816}, + pos: position{line: 285, col: 8, offset: 8752}, val: "p", ignoreCase: false, want: "\"p\"", }, }, &choiceExpr{ - pos: position{line: 285, col: 14, offset: 8822}, - alternatives: []interface{}{ + pos: position{line: 285, col: 14, offset: 8758}, + alternatives: []any{ &ruleRefExpr{ - pos: position{line: 285, col: 14, offset: 8822}, + pos: position{line: 285, col: 14, offset: 8758}, name: "SourceChar", }, &ruleRefExpr{ - pos: position{line: 285, col: 27, offset: 8835}, + pos: position{line: 285, col: 27, offset: 8771}, name: "EOL", }, &ruleRefExpr{ - pos: position{line: 285, col: 33, offset: 8841}, + pos: position{line: 285, col: 33, offset: 8777}, name: "EOF", }, }, @@ -2170,51 +2170,51 @@ var g = &grammar{ }, { name: "UnicodeClassEscape", - pos: position{line: 289, col: 1, offset: 8907}, + pos: position{line: 289, col: 1, offset: 8843}, expr: &seqExpr{ - pos: position{line: 289, col: 22, offset: 8930}, - exprs: []interface{}{ + pos: position{line: 289, col: 22, offset: 8866}, + exprs: []any{ &litMatcher{ - pos: position{line: 289, col: 22, offset: 8930}, + pos: position{line: 289, col: 22, offset: 8866}, val: "p", ignoreCase: false, want: "\"p\"", }, &choiceExpr{ - pos: position{line: 290, col: 7, offset: 8942}, - alternatives: []interface{}{ + pos: position{line: 290, col: 7, offset: 8878}, + alternatives: []any{ &ruleRefExpr{ - pos: position{line: 290, col: 7, offset: 8942}, + pos: position{line: 290, col: 7, offset: 8878}, name: "SingleCharUnicodeClass", }, &actionExpr{ - pos: position{line: 291, col: 7, offset: 8971}, + pos: position{line: 291, col: 7, offset: 8907}, run: (*parser).callonUnicodeClassEscape5, expr: &seqExpr{ - pos: position{line: 291, col: 7, offset: 8971}, - exprs: []interface{}{ + pos: position{line: 291, col: 7, offset: 8907}, + exprs: []any{ ¬Expr{ - pos: position{line: 291, col: 7, offset: 8971}, + pos: position{line: 291, col: 7, offset: 8907}, expr: &litMatcher{ - pos: position{line: 291, col: 8, offset: 8972}, + pos: position{line: 291, col: 8, offset: 8908}, val: "{", ignoreCase: false, want: "\"{\"", }, }, &choiceExpr{ - pos: position{line: 291, col: 14, offset: 8978}, - alternatives: []interface{}{ + pos: position{line: 291, col: 14, offset: 8914}, + alternatives: []any{ &ruleRefExpr{ - pos: position{line: 291, col: 14, offset: 8978}, + pos: position{line: 291, col: 14, offset: 8914}, name: "SourceChar", }, &ruleRefExpr{ - pos: position{line: 291, col: 27, offset: 8991}, + pos: position{line: 291, col: 27, offset: 8927}, name: "EOL", }, &ruleRefExpr{ - pos: position{line: 291, col: 33, offset: 8997}, + pos: position{line: 291, col: 33, offset: 8933}, name: "EOF", }, }, @@ -2223,27 +2223,27 @@ var g = &grammar{ }, }, &actionExpr{ - pos: position{line: 292, col: 7, offset: 9068}, + pos: position{line: 292, col: 7, offset: 9004}, run: (*parser).callonUnicodeClassEscape13, expr: &seqExpr{ - pos: position{line: 292, col: 7, offset: 9068}, - exprs: []interface{}{ + pos: position{line: 292, col: 7, offset: 9004}, + exprs: []any{ &litMatcher{ - pos: position{line: 292, col: 7, offset: 9068}, + pos: position{line: 292, col: 7, offset: 9004}, val: "{", ignoreCase: false, want: "\"{\"", }, &labeledExpr{ - pos: position{line: 292, col: 11, offset: 9072}, + pos: position{line: 292, col: 11, offset: 9008}, label: "ident", expr: &ruleRefExpr{ - pos: position{line: 292, col: 17, offset: 9078}, + pos: position{line: 292, col: 17, offset: 9014}, name: "IdentifierName", }, }, &litMatcher{ - pos: position{line: 292, col: 32, offset: 9093}, + pos: position{line: 292, col: 32, offset: 9029}, val: "}", ignoreCase: false, want: "\"}\"", @@ -2252,36 +2252,36 @@ var g = &grammar{ }, }, &actionExpr{ - pos: position{line: 298, col: 7, offset: 9270}, + pos: position{line: 298, col: 7, offset: 9206}, run: (*parser).callonUnicodeClassEscape19, expr: &seqExpr{ - pos: position{line: 298, col: 7, offset: 9270}, - exprs: []interface{}{ + pos: position{line: 298, col: 7, offset: 9206}, + exprs: []any{ &litMatcher{ - pos: position{line: 298, col: 7, offset: 9270}, + pos: position{line: 298, col: 7, offset: 9206}, val: "{", ignoreCase: false, want: "\"{\"", }, &ruleRefExpr{ - pos: position{line: 298, col: 11, offset: 9274}, + pos: position{line: 298, col: 11, offset: 9210}, name: "IdentifierName", }, &choiceExpr{ - pos: position{line: 298, col: 28, offset: 9291}, - alternatives: []interface{}{ + pos: position{line: 298, col: 28, offset: 9227}, + alternatives: []any{ &litMatcher{ - pos: position{line: 298, col: 28, offset: 9291}, + pos: position{line: 298, col: 28, offset: 9227}, val: "]", ignoreCase: false, want: "\"]\"", }, &ruleRefExpr{ - pos: position{line: 298, col: 34, offset: 9297}, + pos: position{line: 298, col: 34, offset: 9233}, name: "EOL", }, &ruleRefExpr{ - pos: position{line: 298, col: 40, offset: 9303}, + pos: position{line: 298, col: 40, offset: 9239}, name: "EOF", }, }, @@ -2296,9 +2296,9 @@ var g = &grammar{ }, { name: "SingleCharUnicodeClass", - pos: position{line: 302, col: 1, offset: 9386}, + pos: position{line: 302, col: 1, offset: 9322}, expr: &charClassMatcher{ - pos: position{line: 302, col: 26, offset: 9413}, + pos: position{line: 302, col: 26, offset: 9349}, val: "[LMNCPZS]", chars: []rune{'L', 'M', 'N', 'C', 'P', 'Z', 'S'}, ignoreCase: false, @@ -2307,12 +2307,12 @@ var g = &grammar{ }, { name: "AnyMatcher", - pos: position{line: 304, col: 1, offset: 9424}, + pos: position{line: 304, col: 1, offset: 9360}, expr: &actionExpr{ - pos: position{line: 304, col: 14, offset: 9439}, + pos: position{line: 304, col: 14, offset: 9375}, run: (*parser).callonAnyMatcher1, expr: &litMatcher{ - pos: position{line: 304, col: 14, offset: 9439}, + pos: position{line: 304, col: 14, offset: 9375}, val: ".", ignoreCase: false, want: "\".\"", @@ -2321,38 +2321,38 @@ var g = &grammar{ }, { name: "ThrowExpr", - pos: position{line: 309, col: 1, offset: 9514}, + pos: position{line: 309, col: 1, offset: 9450}, expr: &choiceExpr{ - pos: position{line: 309, col: 13, offset: 9528}, - alternatives: []interface{}{ + pos: position{line: 309, col: 13, offset: 9464}, + alternatives: []any{ &actionExpr{ - pos: position{line: 309, col: 13, offset: 9528}, + pos: position{line: 309, col: 13, offset: 9464}, run: (*parser).callonThrowExpr2, expr: &seqExpr{ - pos: position{line: 309, col: 13, offset: 9528}, - exprs: []interface{}{ + pos: position{line: 309, col: 13, offset: 9464}, + exprs: []any{ &litMatcher{ - pos: position{line: 309, col: 13, offset: 9528}, + pos: position{line: 309, col: 13, offset: 9464}, val: "%", ignoreCase: false, want: "\"%\"", }, &litMatcher{ - pos: position{line: 309, col: 17, offset: 9532}, + pos: position{line: 309, col: 17, offset: 9468}, val: "{", ignoreCase: false, want: "\"{\"", }, &labeledExpr{ - pos: position{line: 309, col: 21, offset: 9536}, + pos: position{line: 309, col: 21, offset: 9472}, label: "label", expr: &ruleRefExpr{ - pos: position{line: 309, col: 27, offset: 9542}, + pos: position{line: 309, col: 27, offset: 9478}, name: "IdentifierName", }, }, &litMatcher{ - pos: position{line: 309, col: 42, offset: 9557}, + pos: position{line: 309, col: 42, offset: 9493}, val: "}", ignoreCase: false, want: "\"}\"", @@ -2361,29 +2361,29 @@ var g = &grammar{ }, }, &actionExpr{ - pos: position{line: 313, col: 5, offset: 9665}, + pos: position{line: 313, col: 5, offset: 9601}, run: (*parser).callonThrowExpr9, expr: &seqExpr{ - pos: position{line: 313, col: 5, offset: 9665}, - exprs: []interface{}{ + pos: position{line: 313, col: 5, offset: 9601}, + exprs: []any{ &litMatcher{ - pos: position{line: 313, col: 5, offset: 9665}, + pos: position{line: 313, col: 5, offset: 9601}, val: "%", ignoreCase: false, want: "\"%\"", }, &litMatcher{ - pos: position{line: 313, col: 9, offset: 9669}, + pos: position{line: 313, col: 9, offset: 9605}, val: "{", ignoreCase: false, want: "\"{\"", }, &ruleRefExpr{ - pos: position{line: 313, col: 13, offset: 9673}, + pos: position{line: 313, col: 13, offset: 9609}, name: "IdentifierName", }, &ruleRefExpr{ - pos: position{line: 313, col: 28, offset: 9688}, + pos: position{line: 313, col: 28, offset: 9624}, name: "EOF", }, }, @@ -2394,28 +2394,28 @@ var g = &grammar{ }, { name: "CodeBlock", - pos: position{line: 317, col: 1, offset: 9759}, + pos: position{line: 317, col: 1, offset: 9695}, expr: &choiceExpr{ - pos: position{line: 317, col: 13, offset: 9773}, - alternatives: []interface{}{ + pos: position{line: 317, col: 13, offset: 9709}, + alternatives: []any{ &actionExpr{ - pos: position{line: 317, col: 13, offset: 9773}, + pos: position{line: 317, col: 13, offset: 9709}, run: (*parser).callonCodeBlock2, expr: &seqExpr{ - pos: position{line: 317, col: 13, offset: 9773}, - exprs: []interface{}{ + pos: position{line: 317, col: 13, offset: 9709}, + exprs: []any{ &litMatcher{ - pos: position{line: 317, col: 13, offset: 9773}, + pos: position{line: 317, col: 13, offset: 9709}, val: "{", ignoreCase: false, want: "\"{\"", }, &ruleRefExpr{ - pos: position{line: 317, col: 17, offset: 9777}, + pos: position{line: 317, col: 17, offset: 9713}, name: "Code", }, &litMatcher{ - pos: position{line: 317, col: 22, offset: 9782}, + pos: position{line: 317, col: 22, offset: 9718}, val: "}", ignoreCase: false, want: "\"}\"", @@ -2424,23 +2424,23 @@ var g = &grammar{ }, }, &actionExpr{ - pos: position{line: 321, col: 5, offset: 9881}, + pos: position{line: 321, col: 5, offset: 9817}, run: (*parser).callonCodeBlock7, expr: &seqExpr{ - pos: position{line: 321, col: 5, offset: 9881}, - exprs: []interface{}{ + pos: position{line: 321, col: 5, offset: 9817}, + exprs: []any{ &litMatcher{ - pos: position{line: 321, col: 5, offset: 9881}, + pos: position{line: 321, col: 5, offset: 9817}, val: "{", ignoreCase: false, want: "\"{\"", }, &ruleRefExpr{ - pos: position{line: 321, col: 9, offset: 9885}, + pos: position{line: 321, col: 9, offset: 9821}, name: "Code", }, &ruleRefExpr{ - pos: position{line: 321, col: 14, offset: 9890}, + pos: position{line: 321, col: 14, offset: 9826}, name: "EOF", }, }, @@ -2451,28 +2451,28 @@ var g = &grammar{ }, { name: "Code", - pos: position{line: 325, col: 1, offset: 9955}, + pos: position{line: 325, col: 1, offset: 9891}, expr: &zeroOrMoreExpr{ - pos: position{line: 325, col: 8, offset: 9964}, + pos: position{line: 325, col: 8, offset: 9900}, expr: &choiceExpr{ - pos: position{line: 325, col: 10, offset: 9966}, - alternatives: []interface{}{ + pos: position{line: 325, col: 10, offset: 9902}, + alternatives: []any{ &oneOrMoreExpr{ - pos: position{line: 325, col: 10, offset: 9966}, + pos: position{line: 325, col: 10, offset: 9902}, expr: &choiceExpr{ - pos: position{line: 325, col: 12, offset: 9968}, - alternatives: []interface{}{ + pos: position{line: 325, col: 12, offset: 9904}, + alternatives: []any{ &ruleRefExpr{ - pos: position{line: 325, col: 12, offset: 9968}, + pos: position{line: 325, col: 12, offset: 9904}, name: "Comment", }, &seqExpr{ - pos: position{line: 325, col: 22, offset: 9978}, - exprs: []interface{}{ + pos: position{line: 325, col: 22, offset: 9914}, + exprs: []any{ ¬Expr{ - pos: position{line: 325, col: 22, offset: 9978}, + pos: position{line: 325, col: 22, offset: 9914}, expr: &charClassMatcher{ - pos: position{line: 325, col: 23, offset: 9979}, + pos: position{line: 325, col: 23, offset: 9915}, val: "[{}]", chars: []rune{'{', '}'}, ignoreCase: false, @@ -2480,7 +2480,7 @@ var g = &grammar{ }, }, &ruleRefExpr{ - pos: position{line: 325, col: 28, offset: 9984}, + pos: position{line: 325, col: 28, offset: 9920}, name: "SourceChar", }, }, @@ -2489,20 +2489,20 @@ var g = &grammar{ }, }, &seqExpr{ - pos: position{line: 325, col: 44, offset: 10000}, - exprs: []interface{}{ + pos: position{line: 325, col: 44, offset: 9936}, + exprs: []any{ &litMatcher{ - pos: position{line: 325, col: 44, offset: 10000}, + pos: position{line: 325, col: 44, offset: 9936}, val: "{", ignoreCase: false, want: "\"{\"", }, &ruleRefExpr{ - pos: position{line: 325, col: 48, offset: 10004}, + pos: position{line: 325, col: 48, offset: 9940}, name: "Code", }, &litMatcher{ - pos: position{line: 325, col: 53, offset: 10009}, + pos: position{line: 325, col: 53, offset: 9945}, val: "}", ignoreCase: false, want: "\"}\"", @@ -2515,22 +2515,22 @@ var g = &grammar{ }, { name: "__", - pos: position{line: 327, col: 1, offset: 10017}, + pos: position{line: 327, col: 1, offset: 9953}, expr: &zeroOrMoreExpr{ - pos: position{line: 327, col: 6, offset: 10024}, + pos: position{line: 327, col: 6, offset: 9960}, expr: &choiceExpr{ - pos: position{line: 327, col: 8, offset: 10026}, - alternatives: []interface{}{ + pos: position{line: 327, col: 8, offset: 9962}, + alternatives: []any{ &ruleRefExpr{ - pos: position{line: 327, col: 8, offset: 10026}, + pos: position{line: 327, col: 8, offset: 9962}, name: "Whitespace", }, &ruleRefExpr{ - pos: position{line: 327, col: 21, offset: 10039}, + pos: position{line: 327, col: 21, offset: 9975}, name: "EOL", }, &ruleRefExpr{ - pos: position{line: 327, col: 27, offset: 10045}, + pos: position{line: 327, col: 27, offset: 9981}, name: "Comment", }, }, @@ -2539,18 +2539,18 @@ var g = &grammar{ }, { name: "_", - pos: position{line: 328, col: 1, offset: 10056}, + pos: position{line: 328, col: 1, offset: 9992}, expr: &zeroOrMoreExpr{ - pos: position{line: 328, col: 5, offset: 10062}, + pos: position{line: 328, col: 5, offset: 9998}, expr: &choiceExpr{ - pos: position{line: 328, col: 7, offset: 10064}, - alternatives: []interface{}{ + pos: position{line: 328, col: 7, offset: 10000}, + alternatives: []any{ &ruleRefExpr{ - pos: position{line: 328, col: 7, offset: 10064}, + pos: position{line: 328, col: 7, offset: 10000}, name: "Whitespace", }, &ruleRefExpr{ - pos: position{line: 328, col: 20, offset: 10077}, + pos: position{line: 328, col: 20, offset: 10013}, name: "MultiLineCommentNoLineTerminator", }, }, @@ -2559,9 +2559,9 @@ var g = &grammar{ }, { name: "Whitespace", - pos: position{line: 330, col: 1, offset: 10114}, + pos: position{line: 330, col: 1, offset: 10050}, expr: &charClassMatcher{ - pos: position{line: 330, col: 14, offset: 10129}, + pos: position{line: 330, col: 14, offset: 10065}, val: "[ \\t\\r]", chars: []rune{' ', '\t', '\r'}, ignoreCase: false, @@ -2570,9 +2570,9 @@ var g = &grammar{ }, { name: "EOL", - pos: position{line: 331, col: 1, offset: 10137}, + pos: position{line: 331, col: 1, offset: 10073}, expr: &litMatcher{ - pos: position{line: 331, col: 7, offset: 10145}, + pos: position{line: 331, col: 7, offset: 10081}, val: "\n", ignoreCase: false, want: "\"\\n\"", @@ -2580,19 +2580,19 @@ var g = &grammar{ }, { name: "EOS", - pos: position{line: 332, col: 1, offset: 10150}, + pos: position{line: 332, col: 1, offset: 10086}, expr: &choiceExpr{ - pos: position{line: 332, col: 7, offset: 10158}, - alternatives: []interface{}{ + pos: position{line: 332, col: 7, offset: 10094}, + alternatives: []any{ &seqExpr{ - pos: position{line: 332, col: 7, offset: 10158}, - exprs: []interface{}{ + pos: position{line: 332, col: 7, offset: 10094}, + exprs: []any{ &ruleRefExpr{ - pos: position{line: 332, col: 7, offset: 10158}, + pos: position{line: 332, col: 7, offset: 10094}, name: "__", }, &litMatcher{ - pos: position{line: 332, col: 10, offset: 10161}, + pos: position{line: 332, col: 10, offset: 10097}, val: ";", ignoreCase: false, want: "\";\"", @@ -2600,34 +2600,34 @@ var g = &grammar{ }, }, &seqExpr{ - pos: position{line: 332, col: 16, offset: 10167}, - exprs: []interface{}{ + pos: position{line: 332, col: 16, offset: 10103}, + exprs: []any{ &ruleRefExpr{ - pos: position{line: 332, col: 16, offset: 10167}, + pos: position{line: 332, col: 16, offset: 10103}, name: "_", }, &zeroOrOneExpr{ - pos: position{line: 332, col: 18, offset: 10169}, + pos: position{line: 332, col: 18, offset: 10105}, expr: &ruleRefExpr{ - pos: position{line: 332, col: 18, offset: 10169}, + pos: position{line: 332, col: 18, offset: 10105}, name: "SingleLineComment", }, }, &ruleRefExpr{ - pos: position{line: 332, col: 37, offset: 10188}, + pos: position{line: 332, col: 37, offset: 10124}, name: "EOL", }, }, }, &seqExpr{ - pos: position{line: 332, col: 43, offset: 10194}, - exprs: []interface{}{ + pos: position{line: 332, col: 43, offset: 10130}, + exprs: []any{ &ruleRefExpr{ - pos: position{line: 332, col: 43, offset: 10194}, + pos: position{line: 332, col: 43, offset: 10130}, name: "__", }, &ruleRefExpr{ - pos: position{line: 332, col: 46, offset: 10197}, + pos: position{line: 332, col: 46, offset: 10133}, name: "EOF", }, }, @@ -2637,57 +2637,57 @@ var g = &grammar{ }, { name: "EOF", - pos: position{line: 334, col: 1, offset: 10202}, + pos: position{line: 334, col: 1, offset: 10138}, expr: ¬Expr{ - pos: position{line: 334, col: 7, offset: 10210}, + pos: position{line: 334, col: 7, offset: 10146}, expr: &anyMatcher{ - line: 334, col: 8, offset: 10211, + line: 334, col: 8, offset: 10147, }, }, }, }, } -func (c *current) onGrammar1(initializer, rules interface{}) (interface{}, error) { +func (c *current) onGrammar1(initializer, rules any) (any, error) { pos := c.astPos() // create the grammar, assign its initializer g := ast.NewGrammar(pos) - initSlice := toIfaceSlice(initializer) + initSlice := toAnySlice(initializer) if len(initSlice) > 0 { g.Init = initSlice[0].(*ast.CodeBlock) } - rulesSlice := toIfaceSlice(rules) + rulesSlice := toAnySlice(rules) g.Rules = make([]*ast.Rule, len(rulesSlice)) for i, duo := range rulesSlice { - g.Rules[i] = duo.([]interface{})[0].(*ast.Rule) + g.Rules[i] = duo.([]any)[0].(*ast.Rule) } return g, nil } -func (p *parser) callonGrammar1() (interface{}, error) { +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 interface{}) (interface{}, error) { +func (c *current) onInitializer1(code any) (any, error) { return code, nil } -func (p *parser) callonInitializer1() (interface{}, error) { +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 interface{}) (interface{}, error) { +func (c *current) onRule1(name, display, expr any) (any, error) { pos := c.astPos() rule := ast.NewRule(pos, name.(*ast.Identifier)) - displaySlice := toIfaceSlice(display) + displaySlice := toAnySlice(display) if len(displaySlice) > 0 { rule.DisplayName = displaySlice[0].(*ast.StringLit) } @@ -2696,50 +2696,50 @@ func (c *current) onRule1(name, display, expr interface{}) (interface{}, error) return rule, nil } -func (p *parser) callonRule1() (interface{}, error) { +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 interface{}) (interface{}, error) { - recoverExprSlice := toIfaceSlice(recoverExprs) +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.([]interface{})[7].(ast.Expression) - r.Labels = sl.([]interface{})[3].([]ast.FailureLabel) + r.RecoverExpr = sl.([]any)[7].(ast.Expression) + r.Labels = sl.([]any)[3].([]ast.FailureLabel) recover = r } return recover, nil } -func (p *parser) callonRecoveryExpr1() (interface{}, error) { +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 interface{}) (interface{}, error) { +func (c *current) onLabels1(label, labels any) (any, error) { failureLabels := []ast.FailureLabel{ast.FailureLabel(label.(*ast.Identifier).Val)} - labelSlice := toIfaceSlice(labels) + labelSlice := toAnySlice(labels) for _, fl := range labelSlice { - failureLabels = append(failureLabels, ast.FailureLabel(fl.([]interface{})[3].(*ast.Identifier).Val)) + failureLabels = append(failureLabels, ast.FailureLabel(fl.([]any)[3].(*ast.Identifier).Val)) } return failureLabels, nil } -func (p *parser) callonLabels1() (interface{}, error) { +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 interface{}) (interface{}, error) { - restSlice := toIfaceSlice(rest) +func (c *current) onChoiceExpr1(first, rest any) (any, error) { + restSlice := toAnySlice(rest) if len(restSlice) == 0 { return first, nil } @@ -2748,18 +2748,18 @@ func (c *current) onChoiceExpr1(first, rest interface{}) (interface{}, error) { choice := ast.NewChoiceExpr(pos) choice.Alternatives = []ast.Expression{first.(ast.Expression)} for _, sl := range restSlice { - choice.Alternatives = append(choice.Alternatives, sl.([]interface{})[3].(ast.Expression)) + choice.Alternatives = append(choice.Alternatives, sl.([]any)[3].(ast.Expression)) } return choice, nil } -func (p *parser) callonChoiceExpr1() (interface{}, error) { +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 interface{}) (interface{}, error) { +func (c *current) onActionExpr1(expr, code any) (any, error) { if code == nil { return expr, nil } @@ -2767,38 +2767,38 @@ func (c *current) onActionExpr1(expr, code interface{}) (interface{}, error) { pos := c.astPos() act := ast.NewActionExpr(pos) act.Expr = expr.(ast.Expression) - codeSlice := toIfaceSlice(code) + codeSlice := toAnySlice(code) act.Code = codeSlice[1].(*ast.CodeBlock) return act, nil } -func (p *parser) callonActionExpr1() (interface{}, error) { +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 interface{}) (interface{}, error) { - restSlice := toIfaceSlice(rest) +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.([]interface{})[1].(ast.Expression)) + seq.Exprs = append(seq.Exprs, sl.([]any)[1].(ast.Expression)) } return seq, nil } -func (p *parser) callonSeqExpr1() (interface{}, error) { +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 interface{}) (interface{}, error) { +func (c *current) onLabeledExpr2(label, expr any) (any, error) { pos := c.astPos() lab := ast.NewLabeledExpr(pos) lab.Label = label.(*ast.Identifier) @@ -2806,13 +2806,13 @@ func (c *current) onLabeledExpr2(label, expr interface{}) (interface{}, error) { return lab, nil } -func (p *parser) callonLabeledExpr2() (interface{}, error) { +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 interface{}) (interface{}, error) { +func (c *current) onPrefixedExpr2(op, expr any) (any, error) { pos := c.astPos() opStr := op.(string) if opStr == "&" { @@ -2825,23 +2825,23 @@ func (c *current) onPrefixedExpr2(op, expr interface{}) (interface{}, error) { return not, nil } -func (p *parser) callonPrefixedExpr2() (interface{}, error) { +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() (interface{}, error) { +func (c *current) onPrefixedOp1() (any, error) { return string(c.text), nil } -func (p *parser) callonPrefixedOp1() (interface{}, error) { +func (p *parser) callonPrefixedOp1() (any, error) { stack := p.vstack[len(p.vstack)-1] _ = stack return p.cur.onPrefixedOp1() } -func (c *current) onSuffixedExpr2(expr, op interface{}) (interface{}, error) { +func (c *current) onSuffixedExpr2(expr, op any) (any, error) { pos := c.astPos() opStr := op.(string) switch opStr { @@ -2862,45 +2862,45 @@ func (c *current) onSuffixedExpr2(expr, op interface{}) (interface{}, error) { } } -func (p *parser) callonSuffixedExpr2() (interface{}, error) { +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() (interface{}, error) { +func (c *current) onSuffixedOp1() (any, error) { return string(c.text), nil } -func (p *parser) callonSuffixedOp1() (interface{}, error) { +func (p *parser) callonSuffixedOp1() (any, error) { stack := p.vstack[len(p.vstack)-1] _ = stack return p.cur.onSuffixedOp1() } -func (c *current) onPrimaryExpr7(expr interface{}) (interface{}, error) { +func (c *current) onPrimaryExpr7(expr any) (any, error) { return expr, nil } -func (p *parser) callonPrimaryExpr7() (interface{}, error) { +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 interface{}) (interface{}, error) { +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() (interface{}, error) { +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 interface{}) (interface{}, error) { +func (c *current) onSemanticPredExpr1(op, code any) (any, error) { switch op.(string) { case "#": state := ast.NewStateCodeExpr(c.astPos()) @@ -2921,23 +2921,23 @@ func (c *current) onSemanticPredExpr1(op, code interface{}) (interface{}, error) } } -func (p *parser) callonSemanticPredExpr1() (interface{}, error) { +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() (interface{}, error) { +func (c *current) onSemanticPredOp1() (any, error) { return string(c.text), nil } -func (p *parser) callonSemanticPredOp1() (interface{}, error) { +func (p *parser) callonSemanticPredOp1() (any, error) { stack := p.vstack[len(p.vstack)-1] _ = stack return p.cur.onSemanticPredOp1() } -func (c *current) onIdentifier1(ident interface{}) (interface{}, error) { +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") @@ -2945,23 +2945,23 @@ func (c *current) onIdentifier1(ident interface{}) (interface{}, error) { return astIdent, nil } -func (p *parser) callonIdentifier1() (interface{}, error) { +func (p *parser) callonIdentifier1() (any, error) { stack := p.vstack[len(p.vstack)-1] _ = stack return p.cur.onIdentifier1(stack["ident"]) } -func (c *current) onIdentifierName1() (interface{}, error) { +func (c *current) onIdentifierName1() (any, error) { return ast.NewIdentifier(c.astPos(), string(c.text)), nil } -func (p *parser) callonIdentifierName1() (interface{}, error) { +func (p *parser) callonIdentifierName1() (any, error) { stack := p.vstack[len(p.vstack)-1] _ = stack return p.cur.onIdentifierName1() } -func (c *current) onLitMatcher1(lit, ignore interface{}) (interface{}, error) { +func (c *current) onLitMatcher1(lit, ignore any) (any, error) { rawStr := lit.(*ast.StringLit).Val s, err := strconv.Unquote(rawStr) if err != nil { @@ -2975,157 +2975,157 @@ func (c *current) onLitMatcher1(lit, ignore interface{}) (interface{}, error) { return m, nil } -func (p *parser) callonLitMatcher1() (interface{}, error) { +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() (interface{}, error) { +func (c *current) onStringLiteral2() (any, error) { return ast.NewStringLit(c.astPos(), string(c.text)), nil } -func (p *parser) callonStringLiteral2() (interface{}, error) { +func (p *parser) callonStringLiteral2() (any, error) { stack := p.vstack[len(p.vstack)-1] _ = stack return p.cur.onStringLiteral2() } -func (c *current) onStringLiteral18() (interface{}, error) { +func (c *current) onStringLiteral18() (any, error) { return ast.NewStringLit(c.astPos(), "``"), errors.New("string literal not terminated") } -func (p *parser) callonStringLiteral18() (interface{}, error) { +func (p *parser) callonStringLiteral18() (any, error) { stack := p.vstack[len(p.vstack)-1] _ = stack return p.cur.onStringLiteral18() } -func (c *current) onDoubleStringEscape5() (interface{}, error) { +func (c *current) onDoubleStringEscape5() (any, error) { return nil, errors.New("invalid escape character") } -func (p *parser) callonDoubleStringEscape5() (interface{}, error) { +func (p *parser) callonDoubleStringEscape5() (any, error) { stack := p.vstack[len(p.vstack)-1] _ = stack return p.cur.onDoubleStringEscape5() } -func (c *current) onSingleStringEscape5() (interface{}, error) { +func (c *current) onSingleStringEscape5() (any, error) { return nil, errors.New("invalid escape character") } -func (p *parser) callonSingleStringEscape5() (interface{}, error) { +func (p *parser) callonSingleStringEscape5() (any, error) { stack := p.vstack[len(p.vstack)-1] _ = stack return p.cur.onSingleStringEscape5() } -func (c *current) onOctalEscape6() (interface{}, error) { +func (c *current) onOctalEscape6() (any, error) { return nil, errors.New("invalid octal escape") } -func (p *parser) callonOctalEscape6() (interface{}, error) { +func (p *parser) callonOctalEscape6() (any, error) { stack := p.vstack[len(p.vstack)-1] _ = stack return p.cur.onOctalEscape6() } -func (c *current) onHexEscape6() (interface{}, error) { +func (c *current) onHexEscape6() (any, error) { return nil, errors.New("invalid hexadecimal escape") } -func (p *parser) callonHexEscape6() (interface{}, error) { +func (p *parser) callonHexEscape6() (any, error) { stack := p.vstack[len(p.vstack)-1] _ = stack return p.cur.onHexEscape6() } -func (c *current) onLongUnicodeEscape2() (interface{}, error) { +func (c *current) onLongUnicodeEscape2() (any, error) { return validateUnicodeEscape(string(c.text), "invalid Unicode escape") } -func (p *parser) callonLongUnicodeEscape2() (interface{}, error) { +func (p *parser) callonLongUnicodeEscape2() (any, error) { stack := p.vstack[len(p.vstack)-1] _ = stack return p.cur.onLongUnicodeEscape2() } -func (c *current) onLongUnicodeEscape13() (interface{}, error) { +func (c *current) onLongUnicodeEscape13() (any, error) { return nil, errors.New("invalid Unicode escape") } -func (p *parser) callonLongUnicodeEscape13() (interface{}, error) { +func (p *parser) callonLongUnicodeEscape13() (any, error) { stack := p.vstack[len(p.vstack)-1] _ = stack return p.cur.onLongUnicodeEscape13() } -func (c *current) onShortUnicodeEscape2() (interface{}, error) { +func (c *current) onShortUnicodeEscape2() (any, error) { return validateUnicodeEscape(string(c.text), "invalid Unicode escape") } -func (p *parser) callonShortUnicodeEscape2() (interface{}, error) { +func (p *parser) callonShortUnicodeEscape2() (any, error) { stack := p.vstack[len(p.vstack)-1] _ = stack return p.cur.onShortUnicodeEscape2() } -func (c *current) onShortUnicodeEscape9() (interface{}, error) { +func (c *current) onShortUnicodeEscape9() (any, error) { return nil, errors.New("invalid Unicode escape") } -func (p *parser) callonShortUnicodeEscape9() (interface{}, error) { +func (p *parser) callonShortUnicodeEscape9() (any, error) { stack := p.vstack[len(p.vstack)-1] _ = stack return p.cur.onShortUnicodeEscape9() } -func (c *current) onCharClassMatcher2() (interface{}, error) { +func (c *current) onCharClassMatcher2() (any, error) { pos := c.astPos() cc := ast.NewCharClassMatcher(pos, string(c.text)) return cc, nil } -func (p *parser) callonCharClassMatcher2() (interface{}, error) { +func (p *parser) callonCharClassMatcher2() (any, error) { stack := p.vstack[len(p.vstack)-1] _ = stack return p.cur.onCharClassMatcher2() } -func (c *current) onCharClassMatcher15() (interface{}, error) { +func (c *current) onCharClassMatcher15() (any, error) { return ast.NewCharClassMatcher(c.astPos(), "[]"), errors.New("character class not terminated") } -func (p *parser) callonCharClassMatcher15() (interface{}, error) { +func (p *parser) callonCharClassMatcher15() (any, error) { stack := p.vstack[len(p.vstack)-1] _ = stack return p.cur.onCharClassMatcher15() } -func (c *current) onCharClassEscape5() (interface{}, error) { +func (c *current) onCharClassEscape5() (any, error) { return nil, errors.New("invalid escape character") } -func (p *parser) callonCharClassEscape5() (interface{}, error) { +func (p *parser) callonCharClassEscape5() (any, error) { stack := p.vstack[len(p.vstack)-1] _ = stack return p.cur.onCharClassEscape5() } -func (c *current) onUnicodeClassEscape5() (interface{}, error) { +func (c *current) onUnicodeClassEscape5() (any, error) { return nil, errors.New("invalid Unicode class escape") } -func (p *parser) callonUnicodeClassEscape5() (interface{}, error) { +func (p *parser) callonUnicodeClassEscape5() (any, error) { stack := p.vstack[len(p.vstack)-1] _ = stack return p.cur.onUnicodeClassEscape5() } -func (c *current) onUnicodeClassEscape13(ident interface{}) (interface{}, error) { +func (c *current) onUnicodeClassEscape13(ident any) (any, error) { if !unicodeClasses[ident.(*ast.Identifier).Val] { return nil, errors.New("invalid Unicode class escape") } @@ -3133,73 +3133,73 @@ func (c *current) onUnicodeClassEscape13(ident interface{}) (interface{}, error) } -func (p *parser) callonUnicodeClassEscape13() (interface{}, error) { +func (p *parser) callonUnicodeClassEscape13() (any, error) { stack := p.vstack[len(p.vstack)-1] _ = stack return p.cur.onUnicodeClassEscape13(stack["ident"]) } -func (c *current) onUnicodeClassEscape19() (interface{}, error) { +func (c *current) onUnicodeClassEscape19() (any, error) { return nil, errors.New("Unicode class not terminated") } -func (p *parser) callonUnicodeClassEscape19() (interface{}, error) { +func (p *parser) callonUnicodeClassEscape19() (any, error) { stack := p.vstack[len(p.vstack)-1] _ = stack return p.cur.onUnicodeClassEscape19() } -func (c *current) onAnyMatcher1() (interface{}, error) { +func (c *current) onAnyMatcher1() (any, error) { any := ast.NewAnyMatcher(c.astPos(), ".") return any, nil } -func (p *parser) callonAnyMatcher1() (interface{}, error) { +func (p *parser) callonAnyMatcher1() (any, error) { stack := p.vstack[len(p.vstack)-1] _ = stack return p.cur.onAnyMatcher1() } -func (c *current) onThrowExpr2(label interface{}) (interface{}, error) { +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() (interface{}, error) { +func (p *parser) callonThrowExpr2() (any, error) { stack := p.vstack[len(p.vstack)-1] _ = stack return p.cur.onThrowExpr2(stack["label"]) } -func (c *current) onThrowExpr9() (interface{}, error) { +func (c *current) onThrowExpr9() (any, error) { return nil, errors.New("throw expression not terminated") } -func (p *parser) callonThrowExpr9() (interface{}, error) { +func (p *parser) callonThrowExpr9() (any, error) { stack := p.vstack[len(p.vstack)-1] _ = stack return p.cur.onThrowExpr9() } -func (c *current) onCodeBlock2() (interface{}, error) { +func (c *current) onCodeBlock2() (any, error) { pos := c.astPos() cb := ast.NewCodeBlock(pos, string(c.text)) return cb, nil } -func (p *parser) callonCodeBlock2() (interface{}, error) { +func (p *parser) callonCodeBlock2() (any, error) { stack := p.vstack[len(p.vstack)-1] _ = stack return p.cur.onCodeBlock2() } -func (c *current) onCodeBlock7() (interface{}, error) { +func (c *current) onCodeBlock7() (any, error) { return nil, errors.New("code block not terminated") } -func (p *parser) callonCodeBlock7() (interface{}, error) { +func (p *parser) callonCodeBlock7() (any, error) { stack := p.vstack[len(p.vstack)-1] _ = stack return p.cur.onCodeBlock7() @@ -3343,7 +3343,7 @@ func Recover(b bool) Option { // GlobalStore creates an Option to set a key to a certain value in // the globalStore. -func GlobalStore(key string, value interface{}) Option { +func GlobalStore(key string, value any) Option { return func(p *parser) Option { old := p.cur.globalStore[key] p.cur.globalStore[key] = value @@ -3353,7 +3353,7 @@ func GlobalStore(key string, value interface{}) Option { // InitState creates an Option to set a key to a certain value in // the global "state" store. -func InitState(key string, value interface{}) Option { +func InitState(key string, value any) Option { return func(p *parser) Option { old := p.cur.state[key] p.cur.state[key] = value @@ -3362,7 +3362,7 @@ func InitState(key string, value interface{}) Option { } // ParseFile parses the file identified by filename. -func ParseFile(filename string, opts ...Option) (i interface{}, err error) { // nolint: deadcode +func ParseFile(filename string, opts ...Option) (i any, err error) { // nolint: deadcode f, err := os.Open(filename) if err != nil { return nil, err @@ -3377,7 +3377,7 @@ func ParseFile(filename string, opts ...Option) (i interface{}, err error) { // // ParseReader parses the data from r using filename as information in the // error messages. -func ParseReader(filename string, r io.Reader, opts ...Option) (interface{}, error) { // nolint: deadcode +func ParseReader(filename string, r io.Reader, opts ...Option) (any, error) { // nolint: deadcode b, err := io.ReadAll(r) if err != nil { return nil, err @@ -3388,7 +3388,7 @@ func ParseReader(filename string, r io.Reader, opts ...Option) (interface{}, err // Parse parses the data from b using filename as information in the // error messages. -func Parse(filename string, b []byte, opts ...Option) (interface{}, error) { +func Parse(filename string, b []byte, opts ...Option) (any, error) { return newParser(filename, b, opts...).parse(g) } @@ -3426,7 +3426,7 @@ type current struct { globalStore storeDict } -type storeDict map[string]interface{} +type storeDict map[string]any // the AST types... @@ -3441,34 +3441,34 @@ type rule struct { pos position name string displayName string - expr interface{} + expr any } // nolint: structcheck type choiceExpr struct { pos position - alternatives []interface{} + alternatives []any } // nolint: structcheck type actionExpr struct { pos position - expr interface{} - run func(*parser) (interface{}, error) + expr any + run func(*parser) (any, error) } // nolint: structcheck type recoveryExpr struct { pos position - expr interface{} - recoverExpr interface{} + expr any + recoverExpr any failureLabel []string } // nolint: structcheck type seqExpr struct { pos position - exprs []interface{} + exprs []any } // nolint: structcheck @@ -3481,20 +3481,22 @@ type throwExpr struct { type labeledExpr struct { pos position label string - expr interface{} + expr any } // nolint: structcheck type expr struct { pos position - expr interface{} + expr any } -type andExpr expr // nolint: structcheck -type notExpr expr // nolint: structcheck -type zeroOrOneExpr expr // nolint: structcheck -type zeroOrMoreExpr expr // nolint: structcheck -type oneOrMoreExpr expr // nolint: structcheck +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 { @@ -3642,7 +3644,7 @@ func (p *parser) setOptions(opts []Option) { // nolint: structcheck,deadcode type resultTuple struct { - v interface{} + v any b bool end savepoint } @@ -3688,12 +3690,12 @@ type parser struct { memoize bool // memoization table for the packrat algorithm: // map[offset in source] map[expression or rule] {value, match} - memo map[int]map[interface{}]resultTuple + 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]interface{} + vstack []map[string]any // rule stack, allows identification of the current rule in errors rstack []*rule @@ -3713,7 +3715,7 @@ type parser struct { choiceNoMatch string // recovery expression stack, keeps track of the currently available recovery expression, these are traversed in reverse - recoveryStack []map[string]interface{} + recoveryStack []map[string]any } // push a variable set on the vstack. @@ -3733,7 +3735,7 @@ func (p *parser) pushV() { return } - m = make(map[string]interface{}) + m = make(map[string]any) p.vstack[len(p.vstack)-1] = m } @@ -3749,7 +3751,7 @@ func (p *parser) popV() { } // push a recovery expression with its labels to the recoveryStack -func (p *parser) pushRecovery(labels []string, expr interface{}) { +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) @@ -3758,7 +3760,7 @@ func (p *parser) pushRecovery(labels []string, expr interface{}) { p.recoveryStack = p.recoveryStack[:len(p.recoveryStack)+1] } - m := make(map[string]interface{}, len(labels)) + m := make(map[string]any, len(labels)) for _, fl := range labels { m[fl] = expr } @@ -3878,11 +3880,11 @@ func (p *parser) restore(pt savepoint) { // copies of the state to allow the parser to properly restore the state in // the case of backtracking. type Cloner interface { - Clone() interface{} + Clone() any } var statePool = &sync.Pool{ - New: func() interface{} { return make(storeDict) }, + New: func() any { return make(storeDict) }, } func (sd storeDict) Discard() { @@ -3924,7 +3926,7 @@ func (p *parser) sliceFrom(start savepoint) []byte { return p.data[start.position.offset:p.pt.position.offset] } -func (p *parser) getMemoized(node interface{}) (resultTuple, bool) { +func (p *parser) getMemoized(node any) (resultTuple, bool) { if len(p.memo) == 0 { return resultTuple{}, false } @@ -3936,13 +3938,13 @@ func (p *parser) getMemoized(node interface{}) (resultTuple, bool) { return res, ok } -func (p *parser) setMemoized(pt savepoint, node interface{}, tuple resultTuple) { +func (p *parser) setMemoized(pt savepoint, node any, tuple resultTuple) { if p.memo == nil { - p.memo = make(map[int]map[interface{}]resultTuple) + p.memo = make(map[int]map[any]resultTuple) } m := p.memo[pt.offset] if m == nil { - m = make(map[interface{}]resultTuple) + m = make(map[any]resultTuple) p.memo[pt.offset] = m } m[node] = tuple @@ -3956,7 +3958,7 @@ func (p *parser) buildRulesTable(g *grammar) { } // nolint: gocyclo -func (p *parser) parse(g *grammar) (val interface{}, err error) { +func (p *parser) parse(g *grammar) (val any, err error) { if len(g.rules) == 0 { p.addErr(errNoRule) return nil, p.errs.err() @@ -4033,7 +4035,7 @@ func listJoin(list []string, sep string, lastSep string) string { } } -func (p *parser) parseRule(rule *rule) (interface{}, bool) { +func (p *parser) parseRule(rule *rule) (any, bool) { if p.debug { defer p.out(p.in("parseRule " + rule.name)) } @@ -4063,7 +4065,7 @@ func (p *parser) parseRule(rule *rule) (interface{}, bool) { } // nolint: gocyclo -func (p *parser) parseExpr(expr interface{}) (interface{}, bool) { +func (p *parser) parseExpr(expr any) (any, bool) { var pt savepoint if p.memoize { @@ -4080,7 +4082,7 @@ func (p *parser) parseExpr(expr interface{}) (interface{}, bool) { panic(errMaxExprCnt) } - var val interface{} + var val any var ok bool switch expr := expr.(type) { case *actionExpr: @@ -4128,7 +4130,7 @@ func (p *parser) parseExpr(expr interface{}) (interface{}, bool) { return val, ok } -func (p *parser) parseActionExpr(act *actionExpr) (interface{}, bool) { +func (p *parser) parseActionExpr(act *actionExpr) (any, bool) { if p.debug { defer p.out(p.in("parseActionExpr")) } @@ -4153,7 +4155,7 @@ func (p *parser) parseActionExpr(act *actionExpr) (interface{}, bool) { return val, ok } -func (p *parser) parseAndCodeExpr(and *andCodeExpr) (interface{}, bool) { +func (p *parser) parseAndCodeExpr(and *andCodeExpr) (any, bool) { if p.debug { defer p.out(p.in("parseAndCodeExpr")) } @@ -4169,7 +4171,7 @@ func (p *parser) parseAndCodeExpr(and *andCodeExpr) (interface{}, bool) { return nil, ok } -func (p *parser) parseAndExpr(and *andExpr) (interface{}, bool) { +func (p *parser) parseAndExpr(and *andExpr) (any, bool) { if p.debug { defer p.out(p.in("parseAndExpr")) } @@ -4185,7 +4187,7 @@ func (p *parser) parseAndExpr(and *andExpr) (interface{}, bool) { return nil, ok } -func (p *parser) parseAnyMatcher(any *anyMatcher) (interface{}, bool) { +func (p *parser) parseAnyMatcher(any *anyMatcher) (any, bool) { if p.debug { defer p.out(p.in("parseAnyMatcher")) } @@ -4202,7 +4204,7 @@ func (p *parser) parseAnyMatcher(any *anyMatcher) (interface{}, bool) { } // nolint: gocyclo -func (p *parser) parseCharClassMatcher(chr *charClassMatcher) (interface{}, bool) { +func (p *parser) parseCharClassMatcher(chr *charClassMatcher) (any, bool) { if p.debug { defer p.out(p.in("parseCharClassMatcher")) } @@ -4283,7 +4285,7 @@ func (p *parser) incChoiceAltCnt(ch *choiceExpr, altI int) { m[alt]++ } -func (p *parser) parseChoiceExpr(ch *choiceExpr) (interface{}, bool) { +func (p *parser) parseChoiceExpr(ch *choiceExpr) (any, bool) { if p.debug { defer p.out(p.in("parseChoiceExpr")) } @@ -4307,7 +4309,7 @@ func (p *parser) parseChoiceExpr(ch *choiceExpr) (interface{}, bool) { return nil, false } -func (p *parser) parseLabeledExpr(lab *labeledExpr) (interface{}, bool) { +func (p *parser) parseLabeledExpr(lab *labeledExpr) (any, bool) { if p.debug { defer p.out(p.in("parseLabeledExpr")) } @@ -4322,7 +4324,7 @@ func (p *parser) parseLabeledExpr(lab *labeledExpr) (interface{}, bool) { return val, ok } -func (p *parser) parseLitMatcher(lit *litMatcher) (interface{}, bool) { +func (p *parser) parseLitMatcher(lit *litMatcher) (any, bool) { if p.debug { defer p.out(p.in("parseLitMatcher")) } @@ -4344,7 +4346,7 @@ func (p *parser) parseLitMatcher(lit *litMatcher) (interface{}, bool) { return p.sliceFrom(start), true } -func (p *parser) parseNotCodeExpr(not *notCodeExpr) (interface{}, bool) { +func (p *parser) parseNotCodeExpr(not *notCodeExpr) (any, bool) { if p.debug { defer p.out(p.in("parseNotCodeExpr")) } @@ -4360,7 +4362,7 @@ func (p *parser) parseNotCodeExpr(not *notCodeExpr) (interface{}, bool) { return nil, !ok } -func (p *parser) parseNotExpr(not *notExpr) (interface{}, bool) { +func (p *parser) parseNotExpr(not *notExpr) (any, bool) { if p.debug { defer p.out(p.in("parseNotExpr")) } @@ -4378,12 +4380,12 @@ func (p *parser) parseNotExpr(not *notExpr) (interface{}, bool) { return nil, !ok } -func (p *parser) parseOneOrMoreExpr(expr *oneOrMoreExpr) (interface{}, bool) { +func (p *parser) parseOneOrMoreExpr(expr *oneOrMoreExpr) (any, bool) { if p.debug { defer p.out(p.in("parseOneOrMoreExpr")) } - var vals []interface{} + var vals []any for { p.pushV() @@ -4400,7 +4402,7 @@ func (p *parser) parseOneOrMoreExpr(expr *oneOrMoreExpr) (interface{}, bool) { } } -func (p *parser) parseRecoveryExpr(recover *recoveryExpr) (interface{}, bool) { +func (p *parser) parseRecoveryExpr(recover *recoveryExpr) (any, bool) { if p.debug { defer p.out(p.in("parseRecoveryExpr (" + strings.Join(recover.failureLabel, ",") + ")")) } @@ -4412,7 +4414,7 @@ func (p *parser) parseRecoveryExpr(recover *recoveryExpr) (interface{}, bool) { return val, ok } -func (p *parser) parseRuleRefExpr(ref *ruleRefExpr) (interface{}, bool) { +func (p *parser) parseRuleRefExpr(ref *ruleRefExpr) (any, bool) { if p.debug { defer p.out(p.in("parseRuleRefExpr " + ref.name)) } @@ -4429,12 +4431,12 @@ func (p *parser) parseRuleRefExpr(ref *ruleRefExpr) (interface{}, bool) { return p.parseRule(rule) } -func (p *parser) parseSeqExpr(seq *seqExpr) (interface{}, bool) { +func (p *parser) parseSeqExpr(seq *seqExpr) (any, bool) { if p.debug { defer p.out(p.in("parseSeqExpr")) } - vals := make([]interface{}, 0, len(seq.exprs)) + vals := make([]any, 0, len(seq.exprs)) pt := p.pt state := p.cloneState() @@ -4450,7 +4452,7 @@ func (p *parser) parseSeqExpr(seq *seqExpr) (interface{}, bool) { return vals, true } -func (p *parser) parseStateCodeExpr(state *stateCodeExpr) (interface{}, bool) { +func (p *parser) parseStateCodeExpr(state *stateCodeExpr) (any, bool) { if p.debug { defer p.out(p.in("parseStateCodeExpr")) } @@ -4462,7 +4464,7 @@ func (p *parser) parseStateCodeExpr(state *stateCodeExpr) (interface{}, bool) { return nil, true } -func (p *parser) parseThrowExpr(expr *throwExpr) (interface{}, bool) { +func (p *parser) parseThrowExpr(expr *throwExpr) (any, bool) { if p.debug { defer p.out(p.in("parseThrowExpr")) } @@ -4478,12 +4480,12 @@ func (p *parser) parseThrowExpr(expr *throwExpr) (interface{}, bool) { return nil, false } -func (p *parser) parseZeroOrMoreExpr(expr *zeroOrMoreExpr) (interface{}, bool) { +func (p *parser) parseZeroOrMoreExpr(expr *zeroOrMoreExpr) (any, bool) { if p.debug { defer p.out(p.in("parseZeroOrMoreExpr")) } - var vals []interface{} + var vals []any for { p.pushV() @@ -4496,7 +4498,7 @@ func (p *parser) parseZeroOrMoreExpr(expr *zeroOrMoreExpr) (interface{}, bool) { } } -func (p *parser) parseZeroOrOneExpr(expr *zeroOrOneExpr) (interface{}, bool) { +func (p *parser) parseZeroOrOneExpr(expr *zeroOrOneExpr) (any, bool) { if p.debug { defer p.out(p.in("parseZeroOrOneExpr")) } diff --git a/targeted_test.go b/targeted_test.go index 971ba1b1..de2ee9bf 100644 --- a/targeted_test.go +++ b/targeted_test.go @@ -54,7 +54,7 @@ func TestParseAnyMatcher(t *testing.T) { // advance to the first rune p.read() - var want interface{} + var want any var match bool if tc.out != nil { want = tc.out @@ -109,7 +109,7 @@ func TestParseLitMatcher(t *testing.T) { // advance to the first rune p.read() - var want interface{} + var want any var match bool if tc.out != nil { match = true @@ -239,7 +239,7 @@ func TestParseCharClassMatcher(t *testing.T) { // advance to the first rune p.read() - var want interface{} + var want any var match bool if tc.out != nil { want = tc.out @@ -293,7 +293,7 @@ func TestParseZeroOrOneExpr(t *testing.T) { // advance to the first rune p.read() - var want interface{} + var want any if tc.out != nil { want = tc.out } @@ -344,7 +344,7 @@ func TestParseZeroOrMoreExpr(t *testing.T) { // advance to the first rune p.read() - want := make([]interface{}, len(tc.out)) + want := make([]any, len(tc.out)) for i, v := range tc.out { want[i] = []byte(v) } @@ -402,10 +402,10 @@ func TestParseOneOrMoreExpr(t *testing.T) { // advance to the first rune p.read() - var want interface{} + var want any var match bool if tc.out != nil { - vals := make([]interface{}, len(tc.out)) + vals := make([]any, len(tc.out)) for i, v := range tc.out { vals[i] = []byte(v) } @@ -452,10 +452,10 @@ func TestParseSeqExpr(t *testing.T) { // advance to the first rune p.read() - var want interface{} + var want any var match bool if tc.out != nil { - var vals []interface{} + var vals []any for _, v := range tc.out { vals = append(vals, []byte(v)) } @@ -463,11 +463,11 @@ func TestParseSeqExpr(t *testing.T) { match = true } if tc.lits == nil { - want = make([]interface{}, 0) // empty seq (impossible case via the parser) always matches + want = make([]any, 0) // empty seq (impossible case via the parser) always matches } lbl := fmt.Sprintf("%v: %q", tc.lits, tc.in) - lits := make([]interface{}, len(tc.lits)) + lits := make([]any, len(tc.lits)) for i, l := range tc.lits { lits[i] = &litMatcher{val: l} } @@ -705,7 +705,7 @@ func TestParseLabeledExpr(t *testing.T) { p.read() p.pushV() - var want interface{} + var want any var match bool if tc.out != nil { match = true @@ -771,7 +771,7 @@ func TestParseChoiceExpr(t *testing.T) { // advance to the first rune p.read() - var want interface{} + var want any var match bool if tc.out != nil { want = tc.out @@ -779,7 +779,7 @@ func TestParseChoiceExpr(t *testing.T) { } lbl := fmt.Sprintf("%v: %q", tc.lits, tc.in) - lits := make([]interface{}, len(tc.lits)) + lits := make([]any, len(tc.lits)) for i, l := range tc.lits { lits[i] = &litMatcher{val: l} } @@ -801,7 +801,7 @@ func TestParseActionExpr(t *testing.T) { cases := []struct { in string lit string - v interface{} + v any err error }{ {"", "", 1, nil}, // empty string always matches @@ -816,7 +816,7 @@ func TestParseActionExpr(t *testing.T) { for _, tc := range cases { called := false - fn := func(_ *parser) (interface{}, error) { + fn := func(_ *parser) (any, error) { called = true return tc.v, tc.err } diff --git a/test/alternate_entrypoint/altentry.go b/test/alternate_entrypoint/altentry.go index 460950f3..fbe986e0 100644 --- a/test/alternate_entrypoint/altentry.go +++ b/test/alternate_entrypoint/altentry.go @@ -27,7 +27,7 @@ var g = &grammar{ run: (*parser).callonEntry11, expr: &seqExpr{ pos: position{line: 5, col: 11, offset: 34}, - exprs: []interface{}{ + exprs: []any{ &oneOrMoreExpr{ pos: position{line: 17, col: 6, offset: 159}, expr: &litMatcher{ @@ -68,7 +68,7 @@ var g = &grammar{ run: (*parser).callonEntry21, expr: &seqExpr{ pos: position{line: 9, col: 11, offset: 78}, - exprs: []interface{}{ + exprs: []any{ &oneOrMoreExpr{ pos: position{line: 18, col: 6, offset: 169}, expr: &litMatcher{ @@ -109,7 +109,7 @@ var g = &grammar{ run: (*parser).callonEntry31, expr: &seqExpr{ pos: position{line: 13, col: 11, offset: 122}, - exprs: []interface{}{ + exprs: []any{ &actionExpr{ pos: position{line: 19, col: 6, offset: 179}, run: (*parser).callonEntry33, @@ -153,71 +153,71 @@ var g = &grammar{ }, } -func (c *current) onEntry15() (interface{}, error) { +func (c *current) onEntry15() (any, error) { return c.text, nil } -func (p *parser) callonEntry15() (interface{}, error) { +func (p *parser) callonEntry15() (any, error) { stack := p.vstack[len(p.vstack)-1] _ = stack return p.cur.onEntry15() } -func (c *current) onEntry11() (interface{}, error) { +func (c *current) onEntry11() (any, error) { return c.text, nil } -func (p *parser) callonEntry11() (interface{}, error) { +func (p *parser) callonEntry11() (any, error) { stack := p.vstack[len(p.vstack)-1] _ = stack return p.cur.onEntry11() } -func (c *current) onEntry25() (interface{}, error) { +func (c *current) onEntry25() (any, error) { return c.text, nil } -func (p *parser) callonEntry25() (interface{}, error) { +func (p *parser) callonEntry25() (any, error) { stack := p.vstack[len(p.vstack)-1] _ = stack return p.cur.onEntry25() } -func (c *current) onEntry21() (interface{}, error) { +func (c *current) onEntry21() (any, error) { return c.text, nil } -func (p *parser) callonEntry21() (interface{}, error) { +func (p *parser) callonEntry21() (any, error) { stack := p.vstack[len(p.vstack)-1] _ = stack return p.cur.onEntry21() } -func (c *current) onEntry33() (interface{}, error) { +func (c *current) onEntry33() (any, error) { return c.text, nil } -func (p *parser) callonEntry33() (interface{}, error) { +func (p *parser) callonEntry33() (any, error) { stack := p.vstack[len(p.vstack)-1] _ = stack return p.cur.onEntry33() } -func (c *current) onEntry31() (interface{}, error) { +func (c *current) onEntry31() (any, error) { return c.text, nil } -func (p *parser) callonEntry31() (interface{}, error) { +func (p *parser) callonEntry31() (any, error) { stack := p.vstack[len(p.vstack)-1] _ = stack return p.cur.onEntry31() } -func (c *current) onC1() (interface{}, error) { +func (c *current) onC1() (any, error) { return c.text, nil } -func (p *parser) callonC1() (interface{}, error) { +func (p *parser) callonC1() (any, error) { stack := p.vstack[len(p.vstack)-1] _ = stack return p.cur.onC1() @@ -361,7 +361,7 @@ func Recover(b bool) Option { // GlobalStore creates an Option to set a key to a certain value in // the globalStore. -func GlobalStore(key string, value interface{}) Option { +func GlobalStore(key string, value any) Option { return func(p *parser) Option { old := p.cur.globalStore[key] p.cur.globalStore[key] = value @@ -371,7 +371,7 @@ func GlobalStore(key string, value interface{}) Option { // InitState creates an Option to set a key to a certain value in // the global "state" store. -func InitState(key string, value interface{}) Option { +func InitState(key string, value any) Option { return func(p *parser) Option { old := p.cur.state[key] p.cur.state[key] = value @@ -380,7 +380,7 @@ func InitState(key string, value interface{}) Option { } // ParseFile parses the file identified by filename. -func ParseFile(filename string, opts ...Option) (i interface{}, err error) { // nolint: deadcode +func ParseFile(filename string, opts ...Option) (i any, err error) { // nolint: deadcode f, err := os.Open(filename) if err != nil { return nil, err @@ -395,7 +395,7 @@ func ParseFile(filename string, opts ...Option) (i interface{}, err error) { // // ParseReader parses the data from r using filename as information in the // error messages. -func ParseReader(filename string, r io.Reader, opts ...Option) (interface{}, error) { // nolint: deadcode +func ParseReader(filename string, r io.Reader, opts ...Option) (any, error) { // nolint: deadcode b, err := io.ReadAll(r) if err != nil { return nil, err @@ -406,7 +406,7 @@ func ParseReader(filename string, r io.Reader, opts ...Option) (interface{}, err // Parse parses the data from b using filename as information in the // error messages. -func Parse(filename string, b []byte, opts ...Option) (interface{}, error) { +func Parse(filename string, b []byte, opts ...Option) (any, error) { return newParser(filename, b, opts...).parse(g) } @@ -444,7 +444,7 @@ type current struct { globalStore storeDict } -type storeDict map[string]interface{} +type storeDict map[string]any // the AST types... @@ -459,34 +459,34 @@ type rule struct { pos position name string displayName string - expr interface{} + expr any } // nolint: structcheck type choiceExpr struct { pos position - alternatives []interface{} + alternatives []any } // nolint: structcheck type actionExpr struct { pos position - expr interface{} - run func(*parser) (interface{}, error) + expr any + run func(*parser) (any, error) } // nolint: structcheck type recoveryExpr struct { pos position - expr interface{} - recoverExpr interface{} + expr any + recoverExpr any failureLabel []string } // nolint: structcheck type seqExpr struct { pos position - exprs []interface{} + exprs []any } // nolint: structcheck @@ -499,20 +499,22 @@ type throwExpr struct { type labeledExpr struct { pos position label string - expr interface{} + expr any } // nolint: structcheck type expr struct { pos position - expr interface{} + expr any } -type andExpr expr // nolint: structcheck -type notExpr expr // nolint: structcheck -type zeroOrOneExpr expr // nolint: structcheck -type zeroOrMoreExpr expr // nolint: structcheck -type oneOrMoreExpr expr // nolint: structcheck +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 { @@ -660,7 +662,7 @@ func (p *parser) setOptions(opts []Option) { // nolint: structcheck,deadcode type resultTuple struct { - v interface{} + v any b bool end savepoint } @@ -706,12 +708,12 @@ type parser struct { memoize bool // memoization table for the packrat algorithm: // map[offset in source] map[expression or rule] {value, match} - memo map[int]map[interface{}]resultTuple + 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]interface{} + vstack []map[string]any // rule stack, allows identification of the current rule in errors rstack []*rule @@ -731,7 +733,7 @@ type parser struct { choiceNoMatch string // recovery expression stack, keeps track of the currently available recovery expression, these are traversed in reverse - recoveryStack []map[string]interface{} + recoveryStack []map[string]any } // push a variable set on the vstack. @@ -751,7 +753,7 @@ func (p *parser) pushV() { return } - m = make(map[string]interface{}) + m = make(map[string]any) p.vstack[len(p.vstack)-1] = m } @@ -767,7 +769,7 @@ func (p *parser) popV() { } // push a recovery expression with its labels to the recoveryStack -func (p *parser) pushRecovery(labels []string, expr interface{}) { +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) @@ -776,7 +778,7 @@ func (p *parser) pushRecovery(labels []string, expr interface{}) { p.recoveryStack = p.recoveryStack[:len(p.recoveryStack)+1] } - m := make(map[string]interface{}, len(labels)) + m := make(map[string]any, len(labels)) for _, fl := range labels { m[fl] = expr } @@ -896,11 +898,11 @@ func (p *parser) restore(pt savepoint) { // copies of the state to allow the parser to properly restore the state in // the case of backtracking. type Cloner interface { - Clone() interface{} + Clone() any } var statePool = &sync.Pool{ - New: func() interface{} { return make(storeDict) }, + New: func() any { return make(storeDict) }, } func (sd storeDict) Discard() { @@ -942,7 +944,7 @@ func (p *parser) sliceFrom(start savepoint) []byte { return p.data[start.position.offset:p.pt.position.offset] } -func (p *parser) getMemoized(node interface{}) (resultTuple, bool) { +func (p *parser) getMemoized(node any) (resultTuple, bool) { if len(p.memo) == 0 { return resultTuple{}, false } @@ -954,13 +956,13 @@ func (p *parser) getMemoized(node interface{}) (resultTuple, bool) { return res, ok } -func (p *parser) setMemoized(pt savepoint, node interface{}, tuple resultTuple) { +func (p *parser) setMemoized(pt savepoint, node any, tuple resultTuple) { if p.memo == nil { - p.memo = make(map[int]map[interface{}]resultTuple) + p.memo = make(map[int]map[any]resultTuple) } m := p.memo[pt.offset] if m == nil { - m = make(map[interface{}]resultTuple) + m = make(map[any]resultTuple) p.memo[pt.offset] = m } m[node] = tuple @@ -974,7 +976,7 @@ func (p *parser) buildRulesTable(g *grammar) { } // nolint: gocyclo -func (p *parser) parse(g *grammar) (val interface{}, err error) { +func (p *parser) parse(g *grammar) (val any, err error) { if len(g.rules) == 0 { p.addErr(errNoRule) return nil, p.errs.err() @@ -1051,7 +1053,7 @@ func listJoin(list []string, sep string, lastSep string) string { } } -func (p *parser) parseRule(rule *rule) (interface{}, bool) { +func (p *parser) parseRule(rule *rule) (any, bool) { if p.debug { defer p.out(p.in("parseRule " + rule.name)) } @@ -1081,7 +1083,7 @@ func (p *parser) parseRule(rule *rule) (interface{}, bool) { } // nolint: gocyclo -func (p *parser) parseExpr(expr interface{}) (interface{}, bool) { +func (p *parser) parseExpr(expr any) (any, bool) { var pt savepoint if p.memoize { @@ -1098,7 +1100,7 @@ func (p *parser) parseExpr(expr interface{}) (interface{}, bool) { panic(errMaxExprCnt) } - var val interface{} + var val any var ok bool switch expr := expr.(type) { case *actionExpr: @@ -1146,7 +1148,7 @@ func (p *parser) parseExpr(expr interface{}) (interface{}, bool) { return val, ok } -func (p *parser) parseActionExpr(act *actionExpr) (interface{}, bool) { +func (p *parser) parseActionExpr(act *actionExpr) (any, bool) { if p.debug { defer p.out(p.in("parseActionExpr")) } @@ -1171,7 +1173,7 @@ func (p *parser) parseActionExpr(act *actionExpr) (interface{}, bool) { return val, ok } -func (p *parser) parseAndCodeExpr(and *andCodeExpr) (interface{}, bool) { +func (p *parser) parseAndCodeExpr(and *andCodeExpr) (any, bool) { if p.debug { defer p.out(p.in("parseAndCodeExpr")) } @@ -1187,7 +1189,7 @@ func (p *parser) parseAndCodeExpr(and *andCodeExpr) (interface{}, bool) { return nil, ok } -func (p *parser) parseAndExpr(and *andExpr) (interface{}, bool) { +func (p *parser) parseAndExpr(and *andExpr) (any, bool) { if p.debug { defer p.out(p.in("parseAndExpr")) } @@ -1203,7 +1205,7 @@ func (p *parser) parseAndExpr(and *andExpr) (interface{}, bool) { return nil, ok } -func (p *parser) parseAnyMatcher(any *anyMatcher) (interface{}, bool) { +func (p *parser) parseAnyMatcher(any *anyMatcher) (any, bool) { if p.debug { defer p.out(p.in("parseAnyMatcher")) } @@ -1220,7 +1222,7 @@ func (p *parser) parseAnyMatcher(any *anyMatcher) (interface{}, bool) { } // nolint: gocyclo -func (p *parser) parseCharClassMatcher(chr *charClassMatcher) (interface{}, bool) { +func (p *parser) parseCharClassMatcher(chr *charClassMatcher) (any, bool) { if p.debug { defer p.out(p.in("parseCharClassMatcher")) } @@ -1301,7 +1303,7 @@ func (p *parser) incChoiceAltCnt(ch *choiceExpr, altI int) { m[alt]++ } -func (p *parser) parseChoiceExpr(ch *choiceExpr) (interface{}, bool) { +func (p *parser) parseChoiceExpr(ch *choiceExpr) (any, bool) { if p.debug { defer p.out(p.in("parseChoiceExpr")) } @@ -1325,7 +1327,7 @@ func (p *parser) parseChoiceExpr(ch *choiceExpr) (interface{}, bool) { return nil, false } -func (p *parser) parseLabeledExpr(lab *labeledExpr) (interface{}, bool) { +func (p *parser) parseLabeledExpr(lab *labeledExpr) (any, bool) { if p.debug { defer p.out(p.in("parseLabeledExpr")) } @@ -1340,7 +1342,7 @@ func (p *parser) parseLabeledExpr(lab *labeledExpr) (interface{}, bool) { return val, ok } -func (p *parser) parseLitMatcher(lit *litMatcher) (interface{}, bool) { +func (p *parser) parseLitMatcher(lit *litMatcher) (any, bool) { if p.debug { defer p.out(p.in("parseLitMatcher")) } @@ -1362,7 +1364,7 @@ func (p *parser) parseLitMatcher(lit *litMatcher) (interface{}, bool) { return p.sliceFrom(start), true } -func (p *parser) parseNotCodeExpr(not *notCodeExpr) (interface{}, bool) { +func (p *parser) parseNotCodeExpr(not *notCodeExpr) (any, bool) { if p.debug { defer p.out(p.in("parseNotCodeExpr")) } @@ -1378,7 +1380,7 @@ func (p *parser) parseNotCodeExpr(not *notCodeExpr) (interface{}, bool) { return nil, !ok } -func (p *parser) parseNotExpr(not *notExpr) (interface{}, bool) { +func (p *parser) parseNotExpr(not *notExpr) (any, bool) { if p.debug { defer p.out(p.in("parseNotExpr")) } @@ -1396,12 +1398,12 @@ func (p *parser) parseNotExpr(not *notExpr) (interface{}, bool) { return nil, !ok } -func (p *parser) parseOneOrMoreExpr(expr *oneOrMoreExpr) (interface{}, bool) { +func (p *parser) parseOneOrMoreExpr(expr *oneOrMoreExpr) (any, bool) { if p.debug { defer p.out(p.in("parseOneOrMoreExpr")) } - var vals []interface{} + var vals []any for { p.pushV() @@ -1418,7 +1420,7 @@ func (p *parser) parseOneOrMoreExpr(expr *oneOrMoreExpr) (interface{}, bool) { } } -func (p *parser) parseRecoveryExpr(recover *recoveryExpr) (interface{}, bool) { +func (p *parser) parseRecoveryExpr(recover *recoveryExpr) (any, bool) { if p.debug { defer p.out(p.in("parseRecoveryExpr (" + strings.Join(recover.failureLabel, ",") + ")")) } @@ -1430,7 +1432,7 @@ func (p *parser) parseRecoveryExpr(recover *recoveryExpr) (interface{}, bool) { return val, ok } -func (p *parser) parseRuleRefExpr(ref *ruleRefExpr) (interface{}, bool) { +func (p *parser) parseRuleRefExpr(ref *ruleRefExpr) (any, bool) { if p.debug { defer p.out(p.in("parseRuleRefExpr " + ref.name)) } @@ -1447,12 +1449,12 @@ func (p *parser) parseRuleRefExpr(ref *ruleRefExpr) (interface{}, bool) { return p.parseRule(rule) } -func (p *parser) parseSeqExpr(seq *seqExpr) (interface{}, bool) { +func (p *parser) parseSeqExpr(seq *seqExpr) (any, bool) { if p.debug { defer p.out(p.in("parseSeqExpr")) } - vals := make([]interface{}, 0, len(seq.exprs)) + vals := make([]any, 0, len(seq.exprs)) pt := p.pt state := p.cloneState() @@ -1468,7 +1470,7 @@ func (p *parser) parseSeqExpr(seq *seqExpr) (interface{}, bool) { return vals, true } -func (p *parser) parseStateCodeExpr(state *stateCodeExpr) (interface{}, bool) { +func (p *parser) parseStateCodeExpr(state *stateCodeExpr) (any, bool) { if p.debug { defer p.out(p.in("parseStateCodeExpr")) } @@ -1480,7 +1482,7 @@ func (p *parser) parseStateCodeExpr(state *stateCodeExpr) (interface{}, bool) { return nil, true } -func (p *parser) parseThrowExpr(expr *throwExpr) (interface{}, bool) { +func (p *parser) parseThrowExpr(expr *throwExpr) (any, bool) { if p.debug { defer p.out(p.in("parseThrowExpr")) } @@ -1496,12 +1498,12 @@ func (p *parser) parseThrowExpr(expr *throwExpr) (interface{}, bool) { return nil, false } -func (p *parser) parseZeroOrMoreExpr(expr *zeroOrMoreExpr) (interface{}, bool) { +func (p *parser) parseZeroOrMoreExpr(expr *zeroOrMoreExpr) (any, bool) { if p.debug { defer p.out(p.in("parseZeroOrMoreExpr")) } - var vals []interface{} + var vals []any for { p.pushV() @@ -1514,7 +1516,7 @@ func (p *parser) parseZeroOrMoreExpr(expr *zeroOrMoreExpr) (interface{}, bool) { } } -func (p *parser) parseZeroOrOneExpr(expr *zeroOrOneExpr) (interface{}, bool) { +func (p *parser) parseZeroOrOneExpr(expr *zeroOrOneExpr) (any, bool) { if p.debug { defer p.out(p.in("parseZeroOrOneExpr")) } diff --git a/test/andnot/andnot.go b/test/andnot/andnot.go index ca43fc16..b0da4b84 100644 --- a/test/andnot/andnot.go +++ b/test/andnot/andnot.go @@ -17,8 +17,8 @@ import ( "unicode/utf8" ) -func toString(v interface{}) string { - ifSl := v.([]interface{}) +func toString(v any) string { + ifSl := v.([]any) var res string for _, s := range ifSl { res += string(s.([]byte)) @@ -30,24 +30,24 @@ var g = &grammar{ rules: []*rule{ { name: "Input", - pos: position{line: 14, col: 1, offset: 194}, + pos: position{line: 14, col: 1, offset: 178}, expr: &seqExpr{ - pos: position{line: 14, col: 9, offset: 204}, - exprs: []interface{}{ + pos: position{line: 14, col: 9, offset: 188}, + exprs: []any{ &ruleRefExpr{ - pos: position{line: 14, col: 9, offset: 204}, + pos: position{line: 14, col: 9, offset: 188}, name: "_", }, &ruleRefExpr{ - pos: position{line: 14, col: 11, offset: 206}, + pos: position{line: 14, col: 11, offset: 190}, name: "AB", }, &ruleRefExpr{ - pos: position{line: 14, col: 14, offset: 209}, + pos: position{line: 14, col: 14, offset: 193}, name: "_", }, &ruleRefExpr{ - pos: position{line: 14, col: 16, offset: 211}, + pos: position{line: 14, col: 16, offset: 195}, name: "EOF", }, }, @@ -55,20 +55,20 @@ var g = &grammar{ }, { name: "AB", - pos: position{line: 16, col: 1, offset: 216}, + pos: position{line: 16, col: 1, offset: 200}, expr: &choiceExpr{ - pos: position{line: 16, col: 6, offset: 223}, - alternatives: []interface{}{ + pos: position{line: 16, col: 6, offset: 207}, + alternatives: []any{ &seqExpr{ - pos: position{line: 16, col: 6, offset: 223}, - exprs: []interface{}{ + pos: position{line: 16, col: 6, offset: 207}, + exprs: []any{ &labeledExpr{ - pos: position{line: 16, col: 6, offset: 223}, + pos: position{line: 16, col: 6, offset: 207}, label: "abees", expr: &oneOrMoreExpr{ - pos: position{line: 16, col: 12, offset: 229}, + pos: position{line: 16, col: 12, offset: 213}, expr: &charClassMatcher{ - pos: position{line: 16, col: 12, offset: 229}, + pos: position{line: 16, col: 12, offset: 213}, val: "[ab]", chars: []rune{'a', 'b'}, ignoreCase: false, @@ -77,13 +77,13 @@ var g = &grammar{ }, }, &andCodeExpr{ - pos: position{line: 16, col: 18, offset: 235}, + pos: position{line: 16, col: 18, offset: 219}, run: (*parser).callonAB6, }, }, }, &ruleRefExpr{ - pos: position{line: 16, col: 77, offset: 294}, + pos: position{line: 16, col: 77, offset: 278}, name: "CD", }, }, @@ -91,17 +91,17 @@ var g = &grammar{ }, { name: "CD", - pos: position{line: 17, col: 1, offset: 297}, + pos: position{line: 17, col: 1, offset: 281}, expr: &seqExpr{ - pos: position{line: 17, col: 6, offset: 304}, - exprs: []interface{}{ + pos: position{line: 17, col: 6, offset: 288}, + exprs: []any{ &labeledExpr{ - pos: position{line: 17, col: 6, offset: 304}, + pos: position{line: 17, col: 6, offset: 288}, label: "ceedees", expr: &oneOrMoreExpr{ - pos: position{line: 17, col: 14, offset: 312}, + pos: position{line: 17, col: 14, offset: 296}, expr: &charClassMatcher{ - pos: position{line: 17, col: 14, offset: 312}, + pos: position{line: 17, col: 14, offset: 296}, val: "[cd]", chars: []rune{'c', 'd'}, ignoreCase: false, @@ -110,7 +110,7 @@ var g = &grammar{ }, }, ¬CodeExpr{ - pos: position{line: 17, col: 20, offset: 318}, + pos: position{line: 17, col: 20, offset: 302}, run: (*parser).callonCD5, }, }, @@ -118,11 +118,11 @@ var g = &grammar{ }, { name: "_", - pos: position{line: 19, col: 1, offset: 378}, + pos: position{line: 19, col: 1, offset: 362}, expr: &zeroOrMoreExpr{ - pos: position{line: 19, col: 5, offset: 384}, + pos: position{line: 19, col: 5, offset: 368}, expr: &charClassMatcher{ - pos: position{line: 19, col: 5, offset: 384}, + pos: position{line: 19, col: 5, offset: 368}, val: "[ \\t\\n\\r]", chars: []rune{' ', '\t', '\n', '\r'}, ignoreCase: false, @@ -132,18 +132,18 @@ var g = &grammar{ }, { name: "EOF", - pos: position{line: 20, col: 1, offset: 395}, + pos: position{line: 20, col: 1, offset: 379}, expr: ¬Expr{ - pos: position{line: 20, col: 7, offset: 403}, + pos: position{line: 20, col: 7, offset: 387}, expr: &anyMatcher{ - line: 20, col: 8, offset: 404, + line: 20, col: 8, offset: 388, }, }, }, }, } -func (c *current) onAB6(abees interface{}) (bool, error) { +func (c *current) onAB6(abees any) (bool, error) { return strings.HasSuffix(toString(abees), "b"), nil } @@ -153,7 +153,7 @@ func (p *parser) callonAB6() (bool, error) { return p.cur.onAB6(stack["abees"]) } -func (c *current) onCD5(ceedees interface{}) (bool, error) { +func (c *current) onCD5(ceedees any) (bool, error) { return strings.HasSuffix(toString(ceedees), "c"), nil } @@ -301,7 +301,7 @@ func Recover(b bool) Option { // GlobalStore creates an Option to set a key to a certain value in // the globalStore. -func GlobalStore(key string, value interface{}) Option { +func GlobalStore(key string, value any) Option { return func(p *parser) Option { old := p.cur.globalStore[key] p.cur.globalStore[key] = value @@ -311,7 +311,7 @@ func GlobalStore(key string, value interface{}) Option { // InitState creates an Option to set a key to a certain value in // the global "state" store. -func InitState(key string, value interface{}) Option { +func InitState(key string, value any) Option { return func(p *parser) Option { old := p.cur.state[key] p.cur.state[key] = value @@ -320,7 +320,7 @@ func InitState(key string, value interface{}) Option { } // ParseFile parses the file identified by filename. -func ParseFile(filename string, opts ...Option) (i interface{}, err error) { // nolint: deadcode +func ParseFile(filename string, opts ...Option) (i any, err error) { // nolint: deadcode f, err := os.Open(filename) if err != nil { return nil, err @@ -335,7 +335,7 @@ func ParseFile(filename string, opts ...Option) (i interface{}, err error) { // // ParseReader parses the data from r using filename as information in the // error messages. -func ParseReader(filename string, r io.Reader, opts ...Option) (interface{}, error) { // nolint: deadcode +func ParseReader(filename string, r io.Reader, opts ...Option) (any, error) { // nolint: deadcode b, err := io.ReadAll(r) if err != nil { return nil, err @@ -346,7 +346,7 @@ func ParseReader(filename string, r io.Reader, opts ...Option) (interface{}, err // Parse parses the data from b using filename as information in the // error messages. -func Parse(filename string, b []byte, opts ...Option) (interface{}, error) { +func Parse(filename string, b []byte, opts ...Option) (any, error) { return newParser(filename, b, opts...).parse(g) } @@ -384,7 +384,7 @@ type current struct { globalStore storeDict } -type storeDict map[string]interface{} +type storeDict map[string]any // the AST types... @@ -399,34 +399,34 @@ type rule struct { pos position name string displayName string - expr interface{} + expr any } // nolint: structcheck type choiceExpr struct { pos position - alternatives []interface{} + alternatives []any } // nolint: structcheck type actionExpr struct { pos position - expr interface{} - run func(*parser) (interface{}, error) + expr any + run func(*parser) (any, error) } // nolint: structcheck type recoveryExpr struct { pos position - expr interface{} - recoverExpr interface{} + expr any + recoverExpr any failureLabel []string } // nolint: structcheck type seqExpr struct { pos position - exprs []interface{} + exprs []any } // nolint: structcheck @@ -439,20 +439,22 @@ type throwExpr struct { type labeledExpr struct { pos position label string - expr interface{} + expr any } // nolint: structcheck type expr struct { pos position - expr interface{} + expr any } -type andExpr expr // nolint: structcheck -type notExpr expr // nolint: structcheck -type zeroOrOneExpr expr // nolint: structcheck -type zeroOrMoreExpr expr // nolint: structcheck -type oneOrMoreExpr expr // nolint: structcheck +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 { @@ -600,7 +602,7 @@ func (p *parser) setOptions(opts []Option) { // nolint: structcheck,deadcode type resultTuple struct { - v interface{} + v any b bool end savepoint } @@ -646,12 +648,12 @@ type parser struct { memoize bool // memoization table for the packrat algorithm: // map[offset in source] map[expression or rule] {value, match} - memo map[int]map[interface{}]resultTuple + 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]interface{} + vstack []map[string]any // rule stack, allows identification of the current rule in errors rstack []*rule @@ -671,7 +673,7 @@ type parser struct { choiceNoMatch string // recovery expression stack, keeps track of the currently available recovery expression, these are traversed in reverse - recoveryStack []map[string]interface{} + recoveryStack []map[string]any } // push a variable set on the vstack. @@ -691,7 +693,7 @@ func (p *parser) pushV() { return } - m = make(map[string]interface{}) + m = make(map[string]any) p.vstack[len(p.vstack)-1] = m } @@ -707,7 +709,7 @@ func (p *parser) popV() { } // push a recovery expression with its labels to the recoveryStack -func (p *parser) pushRecovery(labels []string, expr interface{}) { +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) @@ -716,7 +718,7 @@ func (p *parser) pushRecovery(labels []string, expr interface{}) { p.recoveryStack = p.recoveryStack[:len(p.recoveryStack)+1] } - m := make(map[string]interface{}, len(labels)) + m := make(map[string]any, len(labels)) for _, fl := range labels { m[fl] = expr } @@ -836,11 +838,11 @@ func (p *parser) restore(pt savepoint) { // copies of the state to allow the parser to properly restore the state in // the case of backtracking. type Cloner interface { - Clone() interface{} + Clone() any } var statePool = &sync.Pool{ - New: func() interface{} { return make(storeDict) }, + New: func() any { return make(storeDict) }, } func (sd storeDict) Discard() { @@ -882,7 +884,7 @@ func (p *parser) sliceFrom(start savepoint) []byte { return p.data[start.position.offset:p.pt.position.offset] } -func (p *parser) getMemoized(node interface{}) (resultTuple, bool) { +func (p *parser) getMemoized(node any) (resultTuple, bool) { if len(p.memo) == 0 { return resultTuple{}, false } @@ -894,13 +896,13 @@ func (p *parser) getMemoized(node interface{}) (resultTuple, bool) { return res, ok } -func (p *parser) setMemoized(pt savepoint, node interface{}, tuple resultTuple) { +func (p *parser) setMemoized(pt savepoint, node any, tuple resultTuple) { if p.memo == nil { - p.memo = make(map[int]map[interface{}]resultTuple) + p.memo = make(map[int]map[any]resultTuple) } m := p.memo[pt.offset] if m == nil { - m = make(map[interface{}]resultTuple) + m = make(map[any]resultTuple) p.memo[pt.offset] = m } m[node] = tuple @@ -914,7 +916,7 @@ func (p *parser) buildRulesTable(g *grammar) { } // nolint: gocyclo -func (p *parser) parse(g *grammar) (val interface{}, err error) { +func (p *parser) parse(g *grammar) (val any, err error) { if len(g.rules) == 0 { p.addErr(errNoRule) return nil, p.errs.err() @@ -991,7 +993,7 @@ func listJoin(list []string, sep string, lastSep string) string { } } -func (p *parser) parseRule(rule *rule) (interface{}, bool) { +func (p *parser) parseRule(rule *rule) (any, bool) { if p.debug { defer p.out(p.in("parseRule " + rule.name)) } @@ -1021,7 +1023,7 @@ func (p *parser) parseRule(rule *rule) (interface{}, bool) { } // nolint: gocyclo -func (p *parser) parseExpr(expr interface{}) (interface{}, bool) { +func (p *parser) parseExpr(expr any) (any, bool) { var pt savepoint if p.memoize { @@ -1038,7 +1040,7 @@ func (p *parser) parseExpr(expr interface{}) (interface{}, bool) { panic(errMaxExprCnt) } - var val interface{} + var val any var ok bool switch expr := expr.(type) { case *actionExpr: @@ -1086,7 +1088,7 @@ func (p *parser) parseExpr(expr interface{}) (interface{}, bool) { return val, ok } -func (p *parser) parseActionExpr(act *actionExpr) (interface{}, bool) { +func (p *parser) parseActionExpr(act *actionExpr) (any, bool) { if p.debug { defer p.out(p.in("parseActionExpr")) } @@ -1111,7 +1113,7 @@ func (p *parser) parseActionExpr(act *actionExpr) (interface{}, bool) { return val, ok } -func (p *parser) parseAndCodeExpr(and *andCodeExpr) (interface{}, bool) { +func (p *parser) parseAndCodeExpr(and *andCodeExpr) (any, bool) { if p.debug { defer p.out(p.in("parseAndCodeExpr")) } @@ -1127,7 +1129,7 @@ func (p *parser) parseAndCodeExpr(and *andCodeExpr) (interface{}, bool) { return nil, ok } -func (p *parser) parseAndExpr(and *andExpr) (interface{}, bool) { +func (p *parser) parseAndExpr(and *andExpr) (any, bool) { if p.debug { defer p.out(p.in("parseAndExpr")) } @@ -1143,7 +1145,7 @@ func (p *parser) parseAndExpr(and *andExpr) (interface{}, bool) { return nil, ok } -func (p *parser) parseAnyMatcher(any *anyMatcher) (interface{}, bool) { +func (p *parser) parseAnyMatcher(any *anyMatcher) (any, bool) { if p.debug { defer p.out(p.in("parseAnyMatcher")) } @@ -1160,7 +1162,7 @@ func (p *parser) parseAnyMatcher(any *anyMatcher) (interface{}, bool) { } // nolint: gocyclo -func (p *parser) parseCharClassMatcher(chr *charClassMatcher) (interface{}, bool) { +func (p *parser) parseCharClassMatcher(chr *charClassMatcher) (any, bool) { if p.debug { defer p.out(p.in("parseCharClassMatcher")) } @@ -1241,7 +1243,7 @@ func (p *parser) incChoiceAltCnt(ch *choiceExpr, altI int) { m[alt]++ } -func (p *parser) parseChoiceExpr(ch *choiceExpr) (interface{}, bool) { +func (p *parser) parseChoiceExpr(ch *choiceExpr) (any, bool) { if p.debug { defer p.out(p.in("parseChoiceExpr")) } @@ -1265,7 +1267,7 @@ func (p *parser) parseChoiceExpr(ch *choiceExpr) (interface{}, bool) { return nil, false } -func (p *parser) parseLabeledExpr(lab *labeledExpr) (interface{}, bool) { +func (p *parser) parseLabeledExpr(lab *labeledExpr) (any, bool) { if p.debug { defer p.out(p.in("parseLabeledExpr")) } @@ -1280,7 +1282,7 @@ func (p *parser) parseLabeledExpr(lab *labeledExpr) (interface{}, bool) { return val, ok } -func (p *parser) parseLitMatcher(lit *litMatcher) (interface{}, bool) { +func (p *parser) parseLitMatcher(lit *litMatcher) (any, bool) { if p.debug { defer p.out(p.in("parseLitMatcher")) } @@ -1302,7 +1304,7 @@ func (p *parser) parseLitMatcher(lit *litMatcher) (interface{}, bool) { return p.sliceFrom(start), true } -func (p *parser) parseNotCodeExpr(not *notCodeExpr) (interface{}, bool) { +func (p *parser) parseNotCodeExpr(not *notCodeExpr) (any, bool) { if p.debug { defer p.out(p.in("parseNotCodeExpr")) } @@ -1318,7 +1320,7 @@ func (p *parser) parseNotCodeExpr(not *notCodeExpr) (interface{}, bool) { return nil, !ok } -func (p *parser) parseNotExpr(not *notExpr) (interface{}, bool) { +func (p *parser) parseNotExpr(not *notExpr) (any, bool) { if p.debug { defer p.out(p.in("parseNotExpr")) } @@ -1336,12 +1338,12 @@ func (p *parser) parseNotExpr(not *notExpr) (interface{}, bool) { return nil, !ok } -func (p *parser) parseOneOrMoreExpr(expr *oneOrMoreExpr) (interface{}, bool) { +func (p *parser) parseOneOrMoreExpr(expr *oneOrMoreExpr) (any, bool) { if p.debug { defer p.out(p.in("parseOneOrMoreExpr")) } - var vals []interface{} + var vals []any for { p.pushV() @@ -1358,7 +1360,7 @@ func (p *parser) parseOneOrMoreExpr(expr *oneOrMoreExpr) (interface{}, bool) { } } -func (p *parser) parseRecoveryExpr(recover *recoveryExpr) (interface{}, bool) { +func (p *parser) parseRecoveryExpr(recover *recoveryExpr) (any, bool) { if p.debug { defer p.out(p.in("parseRecoveryExpr (" + strings.Join(recover.failureLabel, ",") + ")")) } @@ -1370,7 +1372,7 @@ func (p *parser) parseRecoveryExpr(recover *recoveryExpr) (interface{}, bool) { return val, ok } -func (p *parser) parseRuleRefExpr(ref *ruleRefExpr) (interface{}, bool) { +func (p *parser) parseRuleRefExpr(ref *ruleRefExpr) (any, bool) { if p.debug { defer p.out(p.in("parseRuleRefExpr " + ref.name)) } @@ -1387,12 +1389,12 @@ func (p *parser) parseRuleRefExpr(ref *ruleRefExpr) (interface{}, bool) { return p.parseRule(rule) } -func (p *parser) parseSeqExpr(seq *seqExpr) (interface{}, bool) { +func (p *parser) parseSeqExpr(seq *seqExpr) (any, bool) { if p.debug { defer p.out(p.in("parseSeqExpr")) } - vals := make([]interface{}, 0, len(seq.exprs)) + vals := make([]any, 0, len(seq.exprs)) pt := p.pt state := p.cloneState() @@ -1408,7 +1410,7 @@ func (p *parser) parseSeqExpr(seq *seqExpr) (interface{}, bool) { return vals, true } -func (p *parser) parseStateCodeExpr(state *stateCodeExpr) (interface{}, bool) { +func (p *parser) parseStateCodeExpr(state *stateCodeExpr) (any, bool) { if p.debug { defer p.out(p.in("parseStateCodeExpr")) } @@ -1420,7 +1422,7 @@ func (p *parser) parseStateCodeExpr(state *stateCodeExpr) (interface{}, bool) { return nil, true } -func (p *parser) parseThrowExpr(expr *throwExpr) (interface{}, bool) { +func (p *parser) parseThrowExpr(expr *throwExpr) (any, bool) { if p.debug { defer p.out(p.in("parseThrowExpr")) } @@ -1436,12 +1438,12 @@ func (p *parser) parseThrowExpr(expr *throwExpr) (interface{}, bool) { return nil, false } -func (p *parser) parseZeroOrMoreExpr(expr *zeroOrMoreExpr) (interface{}, bool) { +func (p *parser) parseZeroOrMoreExpr(expr *zeroOrMoreExpr) (any, bool) { if p.debug { defer p.out(p.in("parseZeroOrMoreExpr")) } - var vals []interface{} + var vals []any for { p.pushV() @@ -1454,7 +1456,7 @@ func (p *parser) parseZeroOrMoreExpr(expr *zeroOrMoreExpr) (interface{}, bool) { } } -func (p *parser) parseZeroOrOneExpr(expr *zeroOrOneExpr) (interface{}, bool) { +func (p *parser) parseZeroOrOneExpr(expr *zeroOrOneExpr) (any, bool) { if p.debug { defer p.out(p.in("parseZeroOrOneExpr")) } diff --git a/test/andnot/andnot.peg b/test/andnot/andnot.peg index 3f610a5d..7c728908 100644 --- a/test/andnot/andnot.peg +++ b/test/andnot/andnot.peg @@ -1,8 +1,8 @@ { package andnot -func toString(v interface{}) string { - ifSl := v.([]interface{}) +func toString(v any) string { + ifSl := v.([]any) var res string for _, s := range ifSl { res += string(s.([]byte)) diff --git a/test/emptystate/emptystate.go b/test/emptystate/emptystate.go index 05101c99..e4573aff 100644 --- a/test/emptystate/emptystate.go +++ b/test/emptystate/emptystate.go @@ -27,7 +27,7 @@ var g = &grammar{ run: (*parser).callonstart1, expr: &seqExpr{ pos: position{line: 5, col: 10, offset: 35}, - exprs: []interface{}{ + exprs: []any{ &stateCodeExpr{ pos: position{line: 5, col: 10, offset: 35}, run: (*parser).callonstart3, @@ -75,7 +75,7 @@ var g = &grammar{ pos: position{line: 16, col: 1, offset: 224}, expr: &seqExpr{ pos: position{line: 16, col: 6, offset: 229}, - exprs: []interface{}{ + exprs: []any{ &litMatcher{ pos: position{line: 16, col: 6, offset: 229}, val: "b", @@ -108,7 +108,7 @@ var g = &grammar{ pos: position{line: 29, col: 1, offset: 484}, expr: &seqExpr{ pos: position{line: 29, col: 6, offset: 489}, - exprs: []interface{}{ + exprs: []any{ &litMatcher{ pos: position{line: 29, col: 6, offset: 489}, val: "d", @@ -149,24 +149,24 @@ func (p *parser) callonstart3() error { return p.cur.onstart3() } -func (c *current) onstart1() (interface{}, error) { +func (c *current) onstart1() (any, error) { return c.state, nil } -func (p *parser) callonstart1() (interface{}, error) { +func (p *parser) callonstart1() (any, error) { stack := p.vstack[len(p.vstack)-1] _ = stack return p.cur.onstart1() } -func (c *current) ona1() (interface{}, error) { +func (c *current) ona1() (any, error) { // action code block forces the clone/restore of state, so p.cur.state === p.emptyState return nil, nil } -func (p *parser) callona1() (interface{}, error) { +func (p *parser) callona1() (any, error) { stack := p.vstack[len(p.vstack)-1] _ = stack return p.cur.ona1() @@ -185,13 +185,13 @@ func (p *parser) callonb3() error { return p.cur.onb3() } -func (c *current) onc1() (interface{}, error) { +func (c *current) onc1() (any, error) { // code block forces clone/restore of state, so p.cur.state !== p.emptyState, but both are now non-empty return nil, nil } -func (p *parser) callonc1() (interface{}, error) { +func (p *parser) callonc1() (any, error) { stack := p.vstack[len(p.vstack)-1] _ = stack return p.cur.onc1() @@ -210,14 +210,14 @@ func (p *parser) callond3() error { return p.cur.ond3() } -func (c *current) one1() (interface{}, error) { +func (c *current) one1() (any, error) { // code block forces a clone, but c.state is empty so it returns p.emptyState, and then on restore // c.state is set to that p.emptyState, which is not empty. return nil, nil } -func (p *parser) callone1() (interface{}, error) { +func (p *parser) callone1() (any, error) { stack := p.vstack[len(p.vstack)-1] _ = stack return p.cur.one1() @@ -361,7 +361,7 @@ func Recover(b bool) Option { // GlobalStore creates an Option to set a key to a certain value in // the globalStore. -func GlobalStore(key string, value interface{}) Option { +func GlobalStore(key string, value any) Option { return func(p *parser) Option { old := p.cur.globalStore[key] p.cur.globalStore[key] = value @@ -371,7 +371,7 @@ func GlobalStore(key string, value interface{}) Option { // InitState creates an Option to set a key to a certain value in // the global "state" store. -func InitState(key string, value interface{}) Option { +func InitState(key string, value any) Option { return func(p *parser) Option { old := p.cur.state[key] p.cur.state[key] = value @@ -380,7 +380,7 @@ func InitState(key string, value interface{}) Option { } // ParseFile parses the file identified by filename. -func ParseFile(filename string, opts ...Option) (i interface{}, err error) { // nolint: deadcode +func ParseFile(filename string, opts ...Option) (i any, err error) { // nolint: deadcode f, err := os.Open(filename) if err != nil { return nil, err @@ -395,7 +395,7 @@ func ParseFile(filename string, opts ...Option) (i interface{}, err error) { // // ParseReader parses the data from r using filename as information in the // error messages. -func ParseReader(filename string, r io.Reader, opts ...Option) (interface{}, error) { // nolint: deadcode +func ParseReader(filename string, r io.Reader, opts ...Option) (any, error) { // nolint: deadcode b, err := io.ReadAll(r) if err != nil { return nil, err @@ -406,7 +406,7 @@ func ParseReader(filename string, r io.Reader, opts ...Option) (interface{}, err // Parse parses the data from b using filename as information in the // error messages. -func Parse(filename string, b []byte, opts ...Option) (interface{}, error) { +func Parse(filename string, b []byte, opts ...Option) (any, error) { return newParser(filename, b, opts...).parse(g) } @@ -444,7 +444,7 @@ type current struct { globalStore storeDict } -type storeDict map[string]interface{} +type storeDict map[string]any // the AST types... @@ -459,34 +459,34 @@ type rule struct { pos position name string displayName string - expr interface{} + expr any } // nolint: structcheck type choiceExpr struct { pos position - alternatives []interface{} + alternatives []any } // nolint: structcheck type actionExpr struct { pos position - expr interface{} - run func(*parser) (interface{}, error) + expr any + run func(*parser) (any, error) } // nolint: structcheck type recoveryExpr struct { pos position - expr interface{} - recoverExpr interface{} + expr any + recoverExpr any failureLabel []string } // nolint: structcheck type seqExpr struct { pos position - exprs []interface{} + exprs []any } // nolint: structcheck @@ -499,20 +499,22 @@ type throwExpr struct { type labeledExpr struct { pos position label string - expr interface{} + expr any } // nolint: structcheck type expr struct { pos position - expr interface{} + expr any } -type andExpr expr // nolint: structcheck -type notExpr expr // nolint: structcheck -type zeroOrOneExpr expr // nolint: structcheck -type zeroOrMoreExpr expr // nolint: structcheck -type oneOrMoreExpr expr // nolint: structcheck +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 { @@ -660,7 +662,7 @@ func (p *parser) setOptions(opts []Option) { // nolint: structcheck,deadcode type resultTuple struct { - v interface{} + v any b bool end savepoint } @@ -706,12 +708,12 @@ type parser struct { memoize bool // memoization table for the packrat algorithm: // map[offset in source] map[expression or rule] {value, match} - memo map[int]map[interface{}]resultTuple + 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]interface{} + vstack []map[string]any // rule stack, allows identification of the current rule in errors rstack []*rule @@ -731,7 +733,7 @@ type parser struct { choiceNoMatch string // recovery expression stack, keeps track of the currently available recovery expression, these are traversed in reverse - recoveryStack []map[string]interface{} + recoveryStack []map[string]any } // push a variable set on the vstack. @@ -751,7 +753,7 @@ func (p *parser) pushV() { return } - m = make(map[string]interface{}) + m = make(map[string]any) p.vstack[len(p.vstack)-1] = m } @@ -767,7 +769,7 @@ func (p *parser) popV() { } // push a recovery expression with its labels to the recoveryStack -func (p *parser) pushRecovery(labels []string, expr interface{}) { +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) @@ -776,7 +778,7 @@ func (p *parser) pushRecovery(labels []string, expr interface{}) { p.recoveryStack = p.recoveryStack[:len(p.recoveryStack)+1] } - m := make(map[string]interface{}, len(labels)) + m := make(map[string]any, len(labels)) for _, fl := range labels { m[fl] = expr } @@ -896,11 +898,11 @@ func (p *parser) restore(pt savepoint) { // copies of the state to allow the parser to properly restore the state in // the case of backtracking. type Cloner interface { - Clone() interface{} + Clone() any } var statePool = &sync.Pool{ - New: func() interface{} { return make(storeDict) }, + New: func() any { return make(storeDict) }, } func (sd storeDict) Discard() { @@ -942,7 +944,7 @@ func (p *parser) sliceFrom(start savepoint) []byte { return p.data[start.position.offset:p.pt.position.offset] } -func (p *parser) getMemoized(node interface{}) (resultTuple, bool) { +func (p *parser) getMemoized(node any) (resultTuple, bool) { if len(p.memo) == 0 { return resultTuple{}, false } @@ -954,13 +956,13 @@ func (p *parser) getMemoized(node interface{}) (resultTuple, bool) { return res, ok } -func (p *parser) setMemoized(pt savepoint, node interface{}, tuple resultTuple) { +func (p *parser) setMemoized(pt savepoint, node any, tuple resultTuple) { if p.memo == nil { - p.memo = make(map[int]map[interface{}]resultTuple) + p.memo = make(map[int]map[any]resultTuple) } m := p.memo[pt.offset] if m == nil { - m = make(map[interface{}]resultTuple) + m = make(map[any]resultTuple) p.memo[pt.offset] = m } m[node] = tuple @@ -974,7 +976,7 @@ func (p *parser) buildRulesTable(g *grammar) { } // nolint: gocyclo -func (p *parser) parse(g *grammar) (val interface{}, err error) { +func (p *parser) parse(g *grammar) (val any, err error) { if len(g.rules) == 0 { p.addErr(errNoRule) return nil, p.errs.err() @@ -1051,7 +1053,7 @@ func listJoin(list []string, sep string, lastSep string) string { } } -func (p *parser) parseRule(rule *rule) (interface{}, bool) { +func (p *parser) parseRule(rule *rule) (any, bool) { if p.debug { defer p.out(p.in("parseRule " + rule.name)) } @@ -1081,7 +1083,7 @@ func (p *parser) parseRule(rule *rule) (interface{}, bool) { } // nolint: gocyclo -func (p *parser) parseExpr(expr interface{}) (interface{}, bool) { +func (p *parser) parseExpr(expr any) (any, bool) { var pt savepoint if p.memoize { @@ -1098,7 +1100,7 @@ func (p *parser) parseExpr(expr interface{}) (interface{}, bool) { panic(errMaxExprCnt) } - var val interface{} + var val any var ok bool switch expr := expr.(type) { case *actionExpr: @@ -1146,7 +1148,7 @@ func (p *parser) parseExpr(expr interface{}) (interface{}, bool) { return val, ok } -func (p *parser) parseActionExpr(act *actionExpr) (interface{}, bool) { +func (p *parser) parseActionExpr(act *actionExpr) (any, bool) { if p.debug { defer p.out(p.in("parseActionExpr")) } @@ -1171,7 +1173,7 @@ func (p *parser) parseActionExpr(act *actionExpr) (interface{}, bool) { return val, ok } -func (p *parser) parseAndCodeExpr(and *andCodeExpr) (interface{}, bool) { +func (p *parser) parseAndCodeExpr(and *andCodeExpr) (any, bool) { if p.debug { defer p.out(p.in("parseAndCodeExpr")) } @@ -1187,7 +1189,7 @@ func (p *parser) parseAndCodeExpr(and *andCodeExpr) (interface{}, bool) { return nil, ok } -func (p *parser) parseAndExpr(and *andExpr) (interface{}, bool) { +func (p *parser) parseAndExpr(and *andExpr) (any, bool) { if p.debug { defer p.out(p.in("parseAndExpr")) } @@ -1203,7 +1205,7 @@ func (p *parser) parseAndExpr(and *andExpr) (interface{}, bool) { return nil, ok } -func (p *parser) parseAnyMatcher(any *anyMatcher) (interface{}, bool) { +func (p *parser) parseAnyMatcher(any *anyMatcher) (any, bool) { if p.debug { defer p.out(p.in("parseAnyMatcher")) } @@ -1220,7 +1222,7 @@ func (p *parser) parseAnyMatcher(any *anyMatcher) (interface{}, bool) { } // nolint: gocyclo -func (p *parser) parseCharClassMatcher(chr *charClassMatcher) (interface{}, bool) { +func (p *parser) parseCharClassMatcher(chr *charClassMatcher) (any, bool) { if p.debug { defer p.out(p.in("parseCharClassMatcher")) } @@ -1301,7 +1303,7 @@ func (p *parser) incChoiceAltCnt(ch *choiceExpr, altI int) { m[alt]++ } -func (p *parser) parseChoiceExpr(ch *choiceExpr) (interface{}, bool) { +func (p *parser) parseChoiceExpr(ch *choiceExpr) (any, bool) { if p.debug { defer p.out(p.in("parseChoiceExpr")) } @@ -1325,7 +1327,7 @@ func (p *parser) parseChoiceExpr(ch *choiceExpr) (interface{}, bool) { return nil, false } -func (p *parser) parseLabeledExpr(lab *labeledExpr) (interface{}, bool) { +func (p *parser) parseLabeledExpr(lab *labeledExpr) (any, bool) { if p.debug { defer p.out(p.in("parseLabeledExpr")) } @@ -1340,7 +1342,7 @@ func (p *parser) parseLabeledExpr(lab *labeledExpr) (interface{}, bool) { return val, ok } -func (p *parser) parseLitMatcher(lit *litMatcher) (interface{}, bool) { +func (p *parser) parseLitMatcher(lit *litMatcher) (any, bool) { if p.debug { defer p.out(p.in("parseLitMatcher")) } @@ -1362,7 +1364,7 @@ func (p *parser) parseLitMatcher(lit *litMatcher) (interface{}, bool) { return p.sliceFrom(start), true } -func (p *parser) parseNotCodeExpr(not *notCodeExpr) (interface{}, bool) { +func (p *parser) parseNotCodeExpr(not *notCodeExpr) (any, bool) { if p.debug { defer p.out(p.in("parseNotCodeExpr")) } @@ -1378,7 +1380,7 @@ func (p *parser) parseNotCodeExpr(not *notCodeExpr) (interface{}, bool) { return nil, !ok } -func (p *parser) parseNotExpr(not *notExpr) (interface{}, bool) { +func (p *parser) parseNotExpr(not *notExpr) (any, bool) { if p.debug { defer p.out(p.in("parseNotExpr")) } @@ -1396,12 +1398,12 @@ func (p *parser) parseNotExpr(not *notExpr) (interface{}, bool) { return nil, !ok } -func (p *parser) parseOneOrMoreExpr(expr *oneOrMoreExpr) (interface{}, bool) { +func (p *parser) parseOneOrMoreExpr(expr *oneOrMoreExpr) (any, bool) { if p.debug { defer p.out(p.in("parseOneOrMoreExpr")) } - var vals []interface{} + var vals []any for { p.pushV() @@ -1418,7 +1420,7 @@ func (p *parser) parseOneOrMoreExpr(expr *oneOrMoreExpr) (interface{}, bool) { } } -func (p *parser) parseRecoveryExpr(recover *recoveryExpr) (interface{}, bool) { +func (p *parser) parseRecoveryExpr(recover *recoveryExpr) (any, bool) { if p.debug { defer p.out(p.in("parseRecoveryExpr (" + strings.Join(recover.failureLabel, ",") + ")")) } @@ -1430,7 +1432,7 @@ func (p *parser) parseRecoveryExpr(recover *recoveryExpr) (interface{}, bool) { return val, ok } -func (p *parser) parseRuleRefExpr(ref *ruleRefExpr) (interface{}, bool) { +func (p *parser) parseRuleRefExpr(ref *ruleRefExpr) (any, bool) { if p.debug { defer p.out(p.in("parseRuleRefExpr " + ref.name)) } @@ -1447,12 +1449,12 @@ func (p *parser) parseRuleRefExpr(ref *ruleRefExpr) (interface{}, bool) { return p.parseRule(rule) } -func (p *parser) parseSeqExpr(seq *seqExpr) (interface{}, bool) { +func (p *parser) parseSeqExpr(seq *seqExpr) (any, bool) { if p.debug { defer p.out(p.in("parseSeqExpr")) } - vals := make([]interface{}, 0, len(seq.exprs)) + vals := make([]any, 0, len(seq.exprs)) pt := p.pt state := p.cloneState() @@ -1468,7 +1470,7 @@ func (p *parser) parseSeqExpr(seq *seqExpr) (interface{}, bool) { return vals, true } -func (p *parser) parseStateCodeExpr(state *stateCodeExpr) (interface{}, bool) { +func (p *parser) parseStateCodeExpr(state *stateCodeExpr) (any, bool) { if p.debug { defer p.out(p.in("parseStateCodeExpr")) } @@ -1480,7 +1482,7 @@ func (p *parser) parseStateCodeExpr(state *stateCodeExpr) (interface{}, bool) { return nil, true } -func (p *parser) parseThrowExpr(expr *throwExpr) (interface{}, bool) { +func (p *parser) parseThrowExpr(expr *throwExpr) (any, bool) { if p.debug { defer p.out(p.in("parseThrowExpr")) } @@ -1496,12 +1498,12 @@ func (p *parser) parseThrowExpr(expr *throwExpr) (interface{}, bool) { return nil, false } -func (p *parser) parseZeroOrMoreExpr(expr *zeroOrMoreExpr) (interface{}, bool) { +func (p *parser) parseZeroOrMoreExpr(expr *zeroOrMoreExpr) (any, bool) { if p.debug { defer p.out(p.in("parseZeroOrMoreExpr")) } - var vals []interface{} + var vals []any for { p.pushV() @@ -1514,7 +1516,7 @@ func (p *parser) parseZeroOrMoreExpr(expr *zeroOrMoreExpr) (interface{}, bool) { } } -func (p *parser) parseZeroOrOneExpr(expr *zeroOrOneExpr) (interface{}, bool) { +func (p *parser) parseZeroOrOneExpr(expr *zeroOrOneExpr) (any, bool) { if p.debug { defer p.out(p.in("parseZeroOrOneExpr")) } diff --git a/test/errorpos/errorpos.go b/test/errorpos/errorpos.go index 1011e123..0cda4812 100644 --- a/test/errorpos/errorpos.go +++ b/test/errorpos/errorpos.go @@ -24,14 +24,14 @@ var g = &grammar{ pos: position{line: 5, col: 1, offset: 22}, expr: &seqExpr{ pos: position{line: 5, col: 9, offset: 32}, - exprs: []interface{}{ + exprs: []any{ &ruleRefExpr{ pos: position{line: 5, col: 9, offset: 32}, name: "_", }, &choiceExpr{ pos: position{line: 5, col: 12, offset: 35}, - alternatives: []interface{}{ + alternatives: []any{ &ruleRefExpr{ pos: position{line: 5, col: 12, offset: 35}, name: "case01", @@ -90,7 +90,7 @@ var g = &grammar{ pos: position{line: 7, col: 1, offset: 138}, expr: &seqExpr{ pos: position{line: 7, col: 10, offset: 149}, - exprs: []interface{}{ + exprs: []any{ &litMatcher{ pos: position{line: 7, col: 10, offset: 149}, val: "case01", @@ -105,10 +105,10 @@ var g = &grammar{ pos: position{line: 7, col: 21, offset: 160}, expr: &seqExpr{ pos: position{line: 7, col: 22, offset: 161}, - exprs: []interface{}{ + exprs: []any{ &choiceExpr{ pos: position{line: 7, col: 23, offset: 162}, - alternatives: []interface{}{ + alternatives: []any{ &ruleRefExpr{ pos: position{line: 7, col: 23, offset: 162}, name: "increment", @@ -138,7 +138,7 @@ var g = &grammar{ pos: position{line: 8, col: 1, offset: 197}, expr: &seqExpr{ pos: position{line: 8, col: 10, offset: 208}, - exprs: []interface{}{ + exprs: []any{ &litMatcher{ pos: position{line: 8, col: 10, offset: 208}, val: "case02", @@ -167,7 +167,7 @@ var g = &grammar{ pos: position{line: 9, col: 1, offset: 228}, expr: &seqExpr{ pos: position{line: 9, col: 10, offset: 239}, - exprs: []interface{}{ + exprs: []any{ &litMatcher{ pos: position{line: 9, col: 10, offset: 239}, val: "case03", @@ -202,7 +202,7 @@ var g = &grammar{ pos: position{line: 10, col: 1, offset: 262}, expr: &seqExpr{ pos: position{line: 10, col: 10, offset: 273}, - exprs: []interface{}{ + exprs: []any{ &litMatcher{ pos: position{line: 10, col: 10, offset: 273}, val: "case04", @@ -249,7 +249,7 @@ var g = &grammar{ pos: position{line: 11, col: 1, offset: 323}, expr: &seqExpr{ pos: position{line: 11, col: 10, offset: 334}, - exprs: []interface{}{ + exprs: []any{ &litMatcher{ pos: position{line: 11, col: 10, offset: 334}, val: "case05", @@ -283,7 +283,7 @@ var g = &grammar{ pos: position{line: 12, col: 1, offset: 359}, expr: &seqExpr{ pos: position{line: 12, col: 10, offset: 370}, - exprs: []interface{}{ + exprs: []any{ &litMatcher{ pos: position{line: 12, col: 10, offset: 370}, val: "case06", @@ -318,7 +318,7 @@ var g = &grammar{ pos: position{line: 13, col: 1, offset: 393}, expr: &seqExpr{ pos: position{line: 13, col: 10, offset: 404}, - exprs: []interface{}{ + exprs: []any{ &litMatcher{ pos: position{line: 13, col: 10, offset: 404}, val: "case07", @@ -333,7 +333,7 @@ var g = &grammar{ pos: position{line: 13, col: 22, offset: 416}, expr: &choiceExpr{ pos: position{line: 13, col: 24, offset: 418}, - alternatives: []interface{}{ + alternatives: []any{ &litMatcher{ pos: position{line: 13, col: 24, offset: 418}, val: "abc", @@ -372,7 +372,7 @@ var g = &grammar{ pos: position{line: 14, col: 1, offset: 449}, expr: &seqExpr{ pos: position{line: 14, col: 10, offset: 460}, - exprs: []interface{}{ + exprs: []any{ &litMatcher{ pos: position{line: 14, col: 10, offset: 460}, val: "case08", @@ -403,7 +403,7 @@ var g = &grammar{ pos: position{line: 15, col: 1, offset: 480}, expr: &seqExpr{ pos: position{line: 15, col: 10, offset: 491}, - exprs: []interface{}{ + exprs: []any{ &litMatcher{ pos: position{line: 15, col: 10, offset: 491}, val: "case09", @@ -435,7 +435,7 @@ var g = &grammar{ pos: position{line: 16, col: 1, offset: 512}, expr: &seqExpr{ pos: position{line: 16, col: 10, offset: 523}, - exprs: []interface{}{ + exprs: []any{ &litMatcher{ pos: position{line: 16, col: 10, offset: 523}, val: "case10", @@ -450,7 +450,7 @@ var g = &grammar{ pos: position{line: 16, col: 22, offset: 535}, expr: &choiceExpr{ pos: position{line: 16, col: 24, offset: 537}, - alternatives: []interface{}{ + alternatives: []any{ &litMatcher{ pos: position{line: 16, col: 24, offset: 537}, val: "0", @@ -492,7 +492,7 @@ var g = &grammar{ pos: position{line: 17, col: 1, offset: 568}, expr: &seqExpr{ pos: position{line: 17, col: 10, offset: 579}, - exprs: []interface{}{ + exprs: []any{ &litMatcher{ pos: position{line: 17, col: 10, offset: 579}, val: "case11", @@ -740,7 +740,7 @@ func Recover(b bool) Option { // GlobalStore creates an Option to set a key to a certain value in // the globalStore. -func GlobalStore(key string, value interface{}) Option { +func GlobalStore(key string, value any) Option { return func(p *parser) Option { old := p.cur.globalStore[key] p.cur.globalStore[key] = value @@ -750,7 +750,7 @@ func GlobalStore(key string, value interface{}) Option { // InitState creates an Option to set a key to a certain value in // the global "state" store. -func InitState(key string, value interface{}) Option { +func InitState(key string, value any) Option { return func(p *parser) Option { old := p.cur.state[key] p.cur.state[key] = value @@ -759,7 +759,7 @@ func InitState(key string, value interface{}) Option { } // ParseFile parses the file identified by filename. -func ParseFile(filename string, opts ...Option) (i interface{}, err error) { // nolint: deadcode +func ParseFile(filename string, opts ...Option) (i any, err error) { // nolint: deadcode f, err := os.Open(filename) if err != nil { return nil, err @@ -774,7 +774,7 @@ func ParseFile(filename string, opts ...Option) (i interface{}, err error) { // // ParseReader parses the data from r using filename as information in the // error messages. -func ParseReader(filename string, r io.Reader, opts ...Option) (interface{}, error) { // nolint: deadcode +func ParseReader(filename string, r io.Reader, opts ...Option) (any, error) { // nolint: deadcode b, err := io.ReadAll(r) if err != nil { return nil, err @@ -785,7 +785,7 @@ func ParseReader(filename string, r io.Reader, opts ...Option) (interface{}, err // Parse parses the data from b using filename as information in the // error messages. -func Parse(filename string, b []byte, opts ...Option) (interface{}, error) { +func Parse(filename string, b []byte, opts ...Option) (any, error) { return newParser(filename, b, opts...).parse(g) } @@ -823,7 +823,7 @@ type current struct { globalStore storeDict } -type storeDict map[string]interface{} +type storeDict map[string]any // the AST types... @@ -838,34 +838,34 @@ type rule struct { pos position name string displayName string - expr interface{} + expr any } // nolint: structcheck type choiceExpr struct { pos position - alternatives []interface{} + alternatives []any } // nolint: structcheck type actionExpr struct { pos position - expr interface{} - run func(*parser) (interface{}, error) + expr any + run func(*parser) (any, error) } // nolint: structcheck type recoveryExpr struct { pos position - expr interface{} - recoverExpr interface{} + expr any + recoverExpr any failureLabel []string } // nolint: structcheck type seqExpr struct { pos position - exprs []interface{} + exprs []any } // nolint: structcheck @@ -878,20 +878,22 @@ type throwExpr struct { type labeledExpr struct { pos position label string - expr interface{} + expr any } // nolint: structcheck type expr struct { pos position - expr interface{} + expr any } -type andExpr expr // nolint: structcheck -type notExpr expr // nolint: structcheck -type zeroOrOneExpr expr // nolint: structcheck -type zeroOrMoreExpr expr // nolint: structcheck -type oneOrMoreExpr expr // nolint: structcheck +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 { @@ -1039,7 +1041,7 @@ func (p *parser) setOptions(opts []Option) { // nolint: structcheck,deadcode type resultTuple struct { - v interface{} + v any b bool end savepoint } @@ -1085,12 +1087,12 @@ type parser struct { memoize bool // memoization table for the packrat algorithm: // map[offset in source] map[expression or rule] {value, match} - memo map[int]map[interface{}]resultTuple + 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]interface{} + vstack []map[string]any // rule stack, allows identification of the current rule in errors rstack []*rule @@ -1110,7 +1112,7 @@ type parser struct { choiceNoMatch string // recovery expression stack, keeps track of the currently available recovery expression, these are traversed in reverse - recoveryStack []map[string]interface{} + recoveryStack []map[string]any } // push a variable set on the vstack. @@ -1130,7 +1132,7 @@ func (p *parser) pushV() { return } - m = make(map[string]interface{}) + m = make(map[string]any) p.vstack[len(p.vstack)-1] = m } @@ -1146,7 +1148,7 @@ func (p *parser) popV() { } // push a recovery expression with its labels to the recoveryStack -func (p *parser) pushRecovery(labels []string, expr interface{}) { +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) @@ -1155,7 +1157,7 @@ func (p *parser) pushRecovery(labels []string, expr interface{}) { p.recoveryStack = p.recoveryStack[:len(p.recoveryStack)+1] } - m := make(map[string]interface{}, len(labels)) + m := make(map[string]any, len(labels)) for _, fl := range labels { m[fl] = expr } @@ -1275,11 +1277,11 @@ func (p *parser) restore(pt savepoint) { // copies of the state to allow the parser to properly restore the state in // the case of backtracking. type Cloner interface { - Clone() interface{} + Clone() any } var statePool = &sync.Pool{ - New: func() interface{} { return make(storeDict) }, + New: func() any { return make(storeDict) }, } func (sd storeDict) Discard() { @@ -1321,7 +1323,7 @@ func (p *parser) sliceFrom(start savepoint) []byte { return p.data[start.position.offset:p.pt.position.offset] } -func (p *parser) getMemoized(node interface{}) (resultTuple, bool) { +func (p *parser) getMemoized(node any) (resultTuple, bool) { if len(p.memo) == 0 { return resultTuple{}, false } @@ -1333,13 +1335,13 @@ func (p *parser) getMemoized(node interface{}) (resultTuple, bool) { return res, ok } -func (p *parser) setMemoized(pt savepoint, node interface{}, tuple resultTuple) { +func (p *parser) setMemoized(pt savepoint, node any, tuple resultTuple) { if p.memo == nil { - p.memo = make(map[int]map[interface{}]resultTuple) + p.memo = make(map[int]map[any]resultTuple) } m := p.memo[pt.offset] if m == nil { - m = make(map[interface{}]resultTuple) + m = make(map[any]resultTuple) p.memo[pt.offset] = m } m[node] = tuple @@ -1353,7 +1355,7 @@ func (p *parser) buildRulesTable(g *grammar) { } // nolint: gocyclo -func (p *parser) parse(g *grammar) (val interface{}, err error) { +func (p *parser) parse(g *grammar) (val any, err error) { if len(g.rules) == 0 { p.addErr(errNoRule) return nil, p.errs.err() @@ -1430,7 +1432,7 @@ func listJoin(list []string, sep string, lastSep string) string { } } -func (p *parser) parseRule(rule *rule) (interface{}, bool) { +func (p *parser) parseRule(rule *rule) (any, bool) { if p.debug { defer p.out(p.in("parseRule " + rule.name)) } @@ -1460,7 +1462,7 @@ func (p *parser) parseRule(rule *rule) (interface{}, bool) { } // nolint: gocyclo -func (p *parser) parseExpr(expr interface{}) (interface{}, bool) { +func (p *parser) parseExpr(expr any) (any, bool) { var pt savepoint if p.memoize { @@ -1477,7 +1479,7 @@ func (p *parser) parseExpr(expr interface{}) (interface{}, bool) { panic(errMaxExprCnt) } - var val interface{} + var val any var ok bool switch expr := expr.(type) { case *actionExpr: @@ -1525,7 +1527,7 @@ func (p *parser) parseExpr(expr interface{}) (interface{}, bool) { return val, ok } -func (p *parser) parseActionExpr(act *actionExpr) (interface{}, bool) { +func (p *parser) parseActionExpr(act *actionExpr) (any, bool) { if p.debug { defer p.out(p.in("parseActionExpr")) } @@ -1550,7 +1552,7 @@ func (p *parser) parseActionExpr(act *actionExpr) (interface{}, bool) { return val, ok } -func (p *parser) parseAndCodeExpr(and *andCodeExpr) (interface{}, bool) { +func (p *parser) parseAndCodeExpr(and *andCodeExpr) (any, bool) { if p.debug { defer p.out(p.in("parseAndCodeExpr")) } @@ -1566,7 +1568,7 @@ func (p *parser) parseAndCodeExpr(and *andCodeExpr) (interface{}, bool) { return nil, ok } -func (p *parser) parseAndExpr(and *andExpr) (interface{}, bool) { +func (p *parser) parseAndExpr(and *andExpr) (any, bool) { if p.debug { defer p.out(p.in("parseAndExpr")) } @@ -1582,7 +1584,7 @@ func (p *parser) parseAndExpr(and *andExpr) (interface{}, bool) { return nil, ok } -func (p *parser) parseAnyMatcher(any *anyMatcher) (interface{}, bool) { +func (p *parser) parseAnyMatcher(any *anyMatcher) (any, bool) { if p.debug { defer p.out(p.in("parseAnyMatcher")) } @@ -1599,7 +1601,7 @@ func (p *parser) parseAnyMatcher(any *anyMatcher) (interface{}, bool) { } // nolint: gocyclo -func (p *parser) parseCharClassMatcher(chr *charClassMatcher) (interface{}, bool) { +func (p *parser) parseCharClassMatcher(chr *charClassMatcher) (any, bool) { if p.debug { defer p.out(p.in("parseCharClassMatcher")) } @@ -1680,7 +1682,7 @@ func (p *parser) incChoiceAltCnt(ch *choiceExpr, altI int) { m[alt]++ } -func (p *parser) parseChoiceExpr(ch *choiceExpr) (interface{}, bool) { +func (p *parser) parseChoiceExpr(ch *choiceExpr) (any, bool) { if p.debug { defer p.out(p.in("parseChoiceExpr")) } @@ -1704,7 +1706,7 @@ func (p *parser) parseChoiceExpr(ch *choiceExpr) (interface{}, bool) { return nil, false } -func (p *parser) parseLabeledExpr(lab *labeledExpr) (interface{}, bool) { +func (p *parser) parseLabeledExpr(lab *labeledExpr) (any, bool) { if p.debug { defer p.out(p.in("parseLabeledExpr")) } @@ -1719,7 +1721,7 @@ func (p *parser) parseLabeledExpr(lab *labeledExpr) (interface{}, bool) { return val, ok } -func (p *parser) parseLitMatcher(lit *litMatcher) (interface{}, bool) { +func (p *parser) parseLitMatcher(lit *litMatcher) (any, bool) { if p.debug { defer p.out(p.in("parseLitMatcher")) } @@ -1741,7 +1743,7 @@ func (p *parser) parseLitMatcher(lit *litMatcher) (interface{}, bool) { return p.sliceFrom(start), true } -func (p *parser) parseNotCodeExpr(not *notCodeExpr) (interface{}, bool) { +func (p *parser) parseNotCodeExpr(not *notCodeExpr) (any, bool) { if p.debug { defer p.out(p.in("parseNotCodeExpr")) } @@ -1757,7 +1759,7 @@ func (p *parser) parseNotCodeExpr(not *notCodeExpr) (interface{}, bool) { return nil, !ok } -func (p *parser) parseNotExpr(not *notExpr) (interface{}, bool) { +func (p *parser) parseNotExpr(not *notExpr) (any, bool) { if p.debug { defer p.out(p.in("parseNotExpr")) } @@ -1775,12 +1777,12 @@ func (p *parser) parseNotExpr(not *notExpr) (interface{}, bool) { return nil, !ok } -func (p *parser) parseOneOrMoreExpr(expr *oneOrMoreExpr) (interface{}, bool) { +func (p *parser) parseOneOrMoreExpr(expr *oneOrMoreExpr) (any, bool) { if p.debug { defer p.out(p.in("parseOneOrMoreExpr")) } - var vals []interface{} + var vals []any for { p.pushV() @@ -1797,7 +1799,7 @@ func (p *parser) parseOneOrMoreExpr(expr *oneOrMoreExpr) (interface{}, bool) { } } -func (p *parser) parseRecoveryExpr(recover *recoveryExpr) (interface{}, bool) { +func (p *parser) parseRecoveryExpr(recover *recoveryExpr) (any, bool) { if p.debug { defer p.out(p.in("parseRecoveryExpr (" + strings.Join(recover.failureLabel, ",") + ")")) } @@ -1809,7 +1811,7 @@ func (p *parser) parseRecoveryExpr(recover *recoveryExpr) (interface{}, bool) { return val, ok } -func (p *parser) parseRuleRefExpr(ref *ruleRefExpr) (interface{}, bool) { +func (p *parser) parseRuleRefExpr(ref *ruleRefExpr) (any, bool) { if p.debug { defer p.out(p.in("parseRuleRefExpr " + ref.name)) } @@ -1826,12 +1828,12 @@ func (p *parser) parseRuleRefExpr(ref *ruleRefExpr) (interface{}, bool) { return p.parseRule(rule) } -func (p *parser) parseSeqExpr(seq *seqExpr) (interface{}, bool) { +func (p *parser) parseSeqExpr(seq *seqExpr) (any, bool) { if p.debug { defer p.out(p.in("parseSeqExpr")) } - vals := make([]interface{}, 0, len(seq.exprs)) + vals := make([]any, 0, len(seq.exprs)) pt := p.pt state := p.cloneState() @@ -1847,7 +1849,7 @@ func (p *parser) parseSeqExpr(seq *seqExpr) (interface{}, bool) { return vals, true } -func (p *parser) parseStateCodeExpr(state *stateCodeExpr) (interface{}, bool) { +func (p *parser) parseStateCodeExpr(state *stateCodeExpr) (any, bool) { if p.debug { defer p.out(p.in("parseStateCodeExpr")) } @@ -1859,7 +1861,7 @@ func (p *parser) parseStateCodeExpr(state *stateCodeExpr) (interface{}, bool) { return nil, true } -func (p *parser) parseThrowExpr(expr *throwExpr) (interface{}, bool) { +func (p *parser) parseThrowExpr(expr *throwExpr) (any, bool) { if p.debug { defer p.out(p.in("parseThrowExpr")) } @@ -1875,12 +1877,12 @@ func (p *parser) parseThrowExpr(expr *throwExpr) (interface{}, bool) { return nil, false } -func (p *parser) parseZeroOrMoreExpr(expr *zeroOrMoreExpr) (interface{}, bool) { +func (p *parser) parseZeroOrMoreExpr(expr *zeroOrMoreExpr) (any, bool) { if p.debug { defer p.out(p.in("parseZeroOrMoreExpr")) } - var vals []interface{} + var vals []any for { p.pushV() @@ -1893,7 +1895,7 @@ func (p *parser) parseZeroOrMoreExpr(expr *zeroOrMoreExpr) (interface{}, bool) { } } -func (p *parser) parseZeroOrOneExpr(expr *zeroOrOneExpr) (interface{}, bool) { +func (p *parser) parseZeroOrOneExpr(expr *zeroOrOneExpr) (any, bool) { if p.debug { defer p.out(p.in("parseZeroOrOneExpr")) } diff --git a/test/global_store/global_store.go b/test/global_store/global_store.go index bf4f9398..8768cdee 100644 --- a/test/global_store/global_store.go +++ b/test/global_store/global_store.go @@ -27,7 +27,7 @@ var g = &grammar{ run: (*parser).callonInput1, expr: &seqExpr{ pos: position{line: 5, col: 9, offset: 35}, - exprs: []interface{}{ + exprs: []any{ &andCodeExpr{ pos: position{line: 5, col: 9, offset: 35}, run: (*parser).callonInput3, @@ -36,7 +36,7 @@ var g = &grammar{ pos: position{line: 5, col: 89, offset: 115}, expr: &choiceExpr{ pos: position{line: 5, col: 90, offset: 116}, - alternatives: []interface{}{ + alternatives: []any{ &ruleRefExpr{ pos: position{line: 5, col: 90, offset: 116}, name: "increment", @@ -65,7 +65,7 @@ var g = &grammar{ pos: position{line: 7, col: 1, offset: 198}, expr: &seqExpr{ pos: position{line: 7, col: 13, offset: 212}, - exprs: []interface{}{ + exprs: []any{ &litMatcher{ pos: position{line: 7, col: 13, offset: 212}, val: "i", @@ -84,7 +84,7 @@ var g = &grammar{ pos: position{line: 8, col: 1, offset: 299}, expr: &seqExpr{ pos: position{line: 8, col: 13, offset: 313}, - exprs: []interface{}{ + exprs: []any{ &litMatcher{ pos: position{line: 8, col: 13, offset: 313}, val: "d", @@ -103,7 +103,7 @@ var g = &grammar{ pos: position{line: 9, col: 1, offset: 400}, expr: &seqExpr{ pos: position{line: 9, col: 8, offset: 409}, - exprs: []interface{}{ + exprs: []any{ &litMatcher{ pos: position{line: 9, col: 8, offset: 409}, val: "z", @@ -141,11 +141,11 @@ func (p *parser) callonInput3() (bool, error) { return p.cur.onInput3() } -func (c *current) onInput1() (interface{}, error) { +func (c *current) onInput1() (any, error) { return c.globalStore["result"].(int), nil } -func (p *parser) callonInput1() (interface{}, error) { +func (p *parser) callonInput1() (any, error) { stack := p.vstack[len(p.vstack)-1] _ = stack return p.cur.onInput1() @@ -322,7 +322,7 @@ func Recover(b bool) Option { // GlobalStore creates an Option to set a key to a certain value in // the globalStore. -func GlobalStore(key string, value interface{}) Option { +func GlobalStore(key string, value any) Option { return func(p *parser) Option { old := p.cur.globalStore[key] p.cur.globalStore[key] = value @@ -332,7 +332,7 @@ func GlobalStore(key string, value interface{}) Option { // InitState creates an Option to set a key to a certain value in // the global "state" store. -func InitState(key string, value interface{}) Option { +func InitState(key string, value any) Option { return func(p *parser) Option { old := p.cur.state[key] p.cur.state[key] = value @@ -341,7 +341,7 @@ func InitState(key string, value interface{}) Option { } // ParseFile parses the file identified by filename. -func ParseFile(filename string, opts ...Option) (i interface{}, err error) { // nolint: deadcode +func ParseFile(filename string, opts ...Option) (i any, err error) { // nolint: deadcode f, err := os.Open(filename) if err != nil { return nil, err @@ -356,7 +356,7 @@ func ParseFile(filename string, opts ...Option) (i interface{}, err error) { // // ParseReader parses the data from r using filename as information in the // error messages. -func ParseReader(filename string, r io.Reader, opts ...Option) (interface{}, error) { // nolint: deadcode +func ParseReader(filename string, r io.Reader, opts ...Option) (any, error) { // nolint: deadcode b, err := io.ReadAll(r) if err != nil { return nil, err @@ -367,7 +367,7 @@ func ParseReader(filename string, r io.Reader, opts ...Option) (interface{}, err // Parse parses the data from b using filename as information in the // error messages. -func Parse(filename string, b []byte, opts ...Option) (interface{}, error) { +func Parse(filename string, b []byte, opts ...Option) (any, error) { return newParser(filename, b, opts...).parse(g) } @@ -405,7 +405,7 @@ type current struct { globalStore storeDict } -type storeDict map[string]interface{} +type storeDict map[string]any // the AST types... @@ -420,34 +420,34 @@ type rule struct { pos position name string displayName string - expr interface{} + expr any } // nolint: structcheck type choiceExpr struct { pos position - alternatives []interface{} + alternatives []any } // nolint: structcheck type actionExpr struct { pos position - expr interface{} - run func(*parser) (interface{}, error) + expr any + run func(*parser) (any, error) } // nolint: structcheck type recoveryExpr struct { pos position - expr interface{} - recoverExpr interface{} + expr any + recoverExpr any failureLabel []string } // nolint: structcheck type seqExpr struct { pos position - exprs []interface{} + exprs []any } // nolint: structcheck @@ -460,20 +460,22 @@ type throwExpr struct { type labeledExpr struct { pos position label string - expr interface{} + expr any } // nolint: structcheck type expr struct { pos position - expr interface{} + expr any } -type andExpr expr // nolint: structcheck -type notExpr expr // nolint: structcheck -type zeroOrOneExpr expr // nolint: structcheck -type zeroOrMoreExpr expr // nolint: structcheck -type oneOrMoreExpr expr // nolint: structcheck +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 { @@ -621,7 +623,7 @@ func (p *parser) setOptions(opts []Option) { // nolint: structcheck,deadcode type resultTuple struct { - v interface{} + v any b bool end savepoint } @@ -667,12 +669,12 @@ type parser struct { memoize bool // memoization table for the packrat algorithm: // map[offset in source] map[expression or rule] {value, match} - memo map[int]map[interface{}]resultTuple + 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]interface{} + vstack []map[string]any // rule stack, allows identification of the current rule in errors rstack []*rule @@ -692,7 +694,7 @@ type parser struct { choiceNoMatch string // recovery expression stack, keeps track of the currently available recovery expression, these are traversed in reverse - recoveryStack []map[string]interface{} + recoveryStack []map[string]any } // push a variable set on the vstack. @@ -712,7 +714,7 @@ func (p *parser) pushV() { return } - m = make(map[string]interface{}) + m = make(map[string]any) p.vstack[len(p.vstack)-1] = m } @@ -728,7 +730,7 @@ func (p *parser) popV() { } // push a recovery expression with its labels to the recoveryStack -func (p *parser) pushRecovery(labels []string, expr interface{}) { +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) @@ -737,7 +739,7 @@ func (p *parser) pushRecovery(labels []string, expr interface{}) { p.recoveryStack = p.recoveryStack[:len(p.recoveryStack)+1] } - m := make(map[string]interface{}, len(labels)) + m := make(map[string]any, len(labels)) for _, fl := range labels { m[fl] = expr } @@ -857,11 +859,11 @@ func (p *parser) restore(pt savepoint) { // copies of the state to allow the parser to properly restore the state in // the case of backtracking. type Cloner interface { - Clone() interface{} + Clone() any } var statePool = &sync.Pool{ - New: func() interface{} { return make(storeDict) }, + New: func() any { return make(storeDict) }, } func (sd storeDict) Discard() { @@ -903,7 +905,7 @@ func (p *parser) sliceFrom(start savepoint) []byte { return p.data[start.position.offset:p.pt.position.offset] } -func (p *parser) getMemoized(node interface{}) (resultTuple, bool) { +func (p *parser) getMemoized(node any) (resultTuple, bool) { if len(p.memo) == 0 { return resultTuple{}, false } @@ -915,13 +917,13 @@ func (p *parser) getMemoized(node interface{}) (resultTuple, bool) { return res, ok } -func (p *parser) setMemoized(pt savepoint, node interface{}, tuple resultTuple) { +func (p *parser) setMemoized(pt savepoint, node any, tuple resultTuple) { if p.memo == nil { - p.memo = make(map[int]map[interface{}]resultTuple) + p.memo = make(map[int]map[any]resultTuple) } m := p.memo[pt.offset] if m == nil { - m = make(map[interface{}]resultTuple) + m = make(map[any]resultTuple) p.memo[pt.offset] = m } m[node] = tuple @@ -935,7 +937,7 @@ func (p *parser) buildRulesTable(g *grammar) { } // nolint: gocyclo -func (p *parser) parse(g *grammar) (val interface{}, err error) { +func (p *parser) parse(g *grammar) (val any, err error) { if len(g.rules) == 0 { p.addErr(errNoRule) return nil, p.errs.err() @@ -1012,7 +1014,7 @@ func listJoin(list []string, sep string, lastSep string) string { } } -func (p *parser) parseRule(rule *rule) (interface{}, bool) { +func (p *parser) parseRule(rule *rule) (any, bool) { if p.debug { defer p.out(p.in("parseRule " + rule.name)) } @@ -1042,7 +1044,7 @@ func (p *parser) parseRule(rule *rule) (interface{}, bool) { } // nolint: gocyclo -func (p *parser) parseExpr(expr interface{}) (interface{}, bool) { +func (p *parser) parseExpr(expr any) (any, bool) { var pt savepoint if p.memoize { @@ -1059,7 +1061,7 @@ func (p *parser) parseExpr(expr interface{}) (interface{}, bool) { panic(errMaxExprCnt) } - var val interface{} + var val any var ok bool switch expr := expr.(type) { case *actionExpr: @@ -1107,7 +1109,7 @@ func (p *parser) parseExpr(expr interface{}) (interface{}, bool) { return val, ok } -func (p *parser) parseActionExpr(act *actionExpr) (interface{}, bool) { +func (p *parser) parseActionExpr(act *actionExpr) (any, bool) { if p.debug { defer p.out(p.in("parseActionExpr")) } @@ -1132,7 +1134,7 @@ func (p *parser) parseActionExpr(act *actionExpr) (interface{}, bool) { return val, ok } -func (p *parser) parseAndCodeExpr(and *andCodeExpr) (interface{}, bool) { +func (p *parser) parseAndCodeExpr(and *andCodeExpr) (any, bool) { if p.debug { defer p.out(p.in("parseAndCodeExpr")) } @@ -1148,7 +1150,7 @@ func (p *parser) parseAndCodeExpr(and *andCodeExpr) (interface{}, bool) { return nil, ok } -func (p *parser) parseAndExpr(and *andExpr) (interface{}, bool) { +func (p *parser) parseAndExpr(and *andExpr) (any, bool) { if p.debug { defer p.out(p.in("parseAndExpr")) } @@ -1164,7 +1166,7 @@ func (p *parser) parseAndExpr(and *andExpr) (interface{}, bool) { return nil, ok } -func (p *parser) parseAnyMatcher(any *anyMatcher) (interface{}, bool) { +func (p *parser) parseAnyMatcher(any *anyMatcher) (any, bool) { if p.debug { defer p.out(p.in("parseAnyMatcher")) } @@ -1181,7 +1183,7 @@ func (p *parser) parseAnyMatcher(any *anyMatcher) (interface{}, bool) { } // nolint: gocyclo -func (p *parser) parseCharClassMatcher(chr *charClassMatcher) (interface{}, bool) { +func (p *parser) parseCharClassMatcher(chr *charClassMatcher) (any, bool) { if p.debug { defer p.out(p.in("parseCharClassMatcher")) } @@ -1262,7 +1264,7 @@ func (p *parser) incChoiceAltCnt(ch *choiceExpr, altI int) { m[alt]++ } -func (p *parser) parseChoiceExpr(ch *choiceExpr) (interface{}, bool) { +func (p *parser) parseChoiceExpr(ch *choiceExpr) (any, bool) { if p.debug { defer p.out(p.in("parseChoiceExpr")) } @@ -1286,7 +1288,7 @@ func (p *parser) parseChoiceExpr(ch *choiceExpr) (interface{}, bool) { return nil, false } -func (p *parser) parseLabeledExpr(lab *labeledExpr) (interface{}, bool) { +func (p *parser) parseLabeledExpr(lab *labeledExpr) (any, bool) { if p.debug { defer p.out(p.in("parseLabeledExpr")) } @@ -1301,7 +1303,7 @@ func (p *parser) parseLabeledExpr(lab *labeledExpr) (interface{}, bool) { return val, ok } -func (p *parser) parseLitMatcher(lit *litMatcher) (interface{}, bool) { +func (p *parser) parseLitMatcher(lit *litMatcher) (any, bool) { if p.debug { defer p.out(p.in("parseLitMatcher")) } @@ -1323,7 +1325,7 @@ func (p *parser) parseLitMatcher(lit *litMatcher) (interface{}, bool) { return p.sliceFrom(start), true } -func (p *parser) parseNotCodeExpr(not *notCodeExpr) (interface{}, bool) { +func (p *parser) parseNotCodeExpr(not *notCodeExpr) (any, bool) { if p.debug { defer p.out(p.in("parseNotCodeExpr")) } @@ -1339,7 +1341,7 @@ func (p *parser) parseNotCodeExpr(not *notCodeExpr) (interface{}, bool) { return nil, !ok } -func (p *parser) parseNotExpr(not *notExpr) (interface{}, bool) { +func (p *parser) parseNotExpr(not *notExpr) (any, bool) { if p.debug { defer p.out(p.in("parseNotExpr")) } @@ -1357,12 +1359,12 @@ func (p *parser) parseNotExpr(not *notExpr) (interface{}, bool) { return nil, !ok } -func (p *parser) parseOneOrMoreExpr(expr *oneOrMoreExpr) (interface{}, bool) { +func (p *parser) parseOneOrMoreExpr(expr *oneOrMoreExpr) (any, bool) { if p.debug { defer p.out(p.in("parseOneOrMoreExpr")) } - var vals []interface{} + var vals []any for { p.pushV() @@ -1379,7 +1381,7 @@ func (p *parser) parseOneOrMoreExpr(expr *oneOrMoreExpr) (interface{}, bool) { } } -func (p *parser) parseRecoveryExpr(recover *recoveryExpr) (interface{}, bool) { +func (p *parser) parseRecoveryExpr(recover *recoveryExpr) (any, bool) { if p.debug { defer p.out(p.in("parseRecoveryExpr (" + strings.Join(recover.failureLabel, ",") + ")")) } @@ -1391,7 +1393,7 @@ func (p *parser) parseRecoveryExpr(recover *recoveryExpr) (interface{}, bool) { return val, ok } -func (p *parser) parseRuleRefExpr(ref *ruleRefExpr) (interface{}, bool) { +func (p *parser) parseRuleRefExpr(ref *ruleRefExpr) (any, bool) { if p.debug { defer p.out(p.in("parseRuleRefExpr " + ref.name)) } @@ -1408,12 +1410,12 @@ func (p *parser) parseRuleRefExpr(ref *ruleRefExpr) (interface{}, bool) { return p.parseRule(rule) } -func (p *parser) parseSeqExpr(seq *seqExpr) (interface{}, bool) { +func (p *parser) parseSeqExpr(seq *seqExpr) (any, bool) { if p.debug { defer p.out(p.in("parseSeqExpr")) } - vals := make([]interface{}, 0, len(seq.exprs)) + vals := make([]any, 0, len(seq.exprs)) pt := p.pt state := p.cloneState() @@ -1429,7 +1431,7 @@ func (p *parser) parseSeqExpr(seq *seqExpr) (interface{}, bool) { return vals, true } -func (p *parser) parseStateCodeExpr(state *stateCodeExpr) (interface{}, bool) { +func (p *parser) parseStateCodeExpr(state *stateCodeExpr) (any, bool) { if p.debug { defer p.out(p.in("parseStateCodeExpr")) } @@ -1441,7 +1443,7 @@ func (p *parser) parseStateCodeExpr(state *stateCodeExpr) (interface{}, bool) { return nil, true } -func (p *parser) parseThrowExpr(expr *throwExpr) (interface{}, bool) { +func (p *parser) parseThrowExpr(expr *throwExpr) (any, bool) { if p.debug { defer p.out(p.in("parseThrowExpr")) } @@ -1457,12 +1459,12 @@ func (p *parser) parseThrowExpr(expr *throwExpr) (interface{}, bool) { return nil, false } -func (p *parser) parseZeroOrMoreExpr(expr *zeroOrMoreExpr) (interface{}, bool) { +func (p *parser) parseZeroOrMoreExpr(expr *zeroOrMoreExpr) (any, bool) { if p.debug { defer p.out(p.in("parseZeroOrMoreExpr")) } - var vals []interface{} + var vals []any for { p.pushV() @@ -1475,7 +1477,7 @@ func (p *parser) parseZeroOrMoreExpr(expr *zeroOrMoreExpr) (interface{}, bool) { } } -func (p *parser) parseZeroOrOneExpr(expr *zeroOrOneExpr) (interface{}, bool) { +func (p *parser) parseZeroOrOneExpr(expr *zeroOrOneExpr) (any, bool) { if p.debug { defer p.out(p.in("parseZeroOrOneExpr")) } diff --git a/test/goto/goto.go b/test/goto/goto.go index c904be5e..94e07c11 100644 --- a/test/goto/goto.go +++ b/test/goto/goto.go @@ -28,41 +28,41 @@ import ( "unicode/utf8" ) -func toIfaceSlice(v interface{}) []interface{} { +func toAnySlice(v any) []any { if v == nil { return nil } - return v.([]interface{}) + return v.([]any) } var g = &grammar{ rules: []*rule{ { name: "Program", - pos: position{line: 23, col: 1, offset: 567}, + pos: position{line: 23, col: 1, offset: 541}, expr: &actionExpr{ - pos: position{line: 23, col: 11, offset: 579}, + pos: position{line: 23, col: 11, offset: 553}, run: (*parser).callonProgram1, expr: &seqExpr{ - pos: position{line: 23, col: 11, offset: 579}, - exprs: []interface{}{ + pos: position{line: 23, col: 11, offset: 553}, + exprs: []any{ &labeledExpr{ - pos: position{line: 23, col: 11, offset: 579}, + pos: position{line: 23, col: 11, offset: 553}, label: "lines", expr: &zeroOrMoreExpr{ - pos: position{line: 23, col: 17, offset: 585}, + pos: position{line: 23, col: 17, offset: 559}, expr: &ruleRefExpr{ - pos: position{line: 23, col: 17, offset: 585}, + pos: position{line: 23, col: 17, offset: 559}, name: "Line", }, }, }, &ruleRefExpr{ - pos: position{line: 23, col: 23, offset: 591}, + pos: position{line: 23, col: 23, offset: 565}, name: "EOF", }, &andCodeExpr{ - pos: position{line: 23, col: 27, offset: 595}, + pos: position{line: 23, col: 27, offset: 569}, run: (*parser).callonProgram7, }, }, @@ -71,38 +71,38 @@ var g = &grammar{ }, { name: "Line", - pos: position{line: 32, col: 1, offset: 819}, + pos: position{line: 32, col: 1, offset: 791}, expr: &actionExpr{ - pos: position{line: 32, col: 8, offset: 828}, + pos: position{line: 32, col: 8, offset: 800}, run: (*parser).callonLine1, expr: &seqExpr{ - pos: position{line: 32, col: 8, offset: 828}, - exprs: []interface{}{ + pos: position{line: 32, col: 8, offset: 800}, + exprs: []any{ &ruleRefExpr{ - pos: position{line: 32, col: 8, offset: 828}, + pos: position{line: 32, col: 8, offset: 800}, name: "_", }, &labeledExpr{ - pos: position{line: 32, col: 10, offset: 830}, + pos: position{line: 32, col: 10, offset: 802}, label: "inst", expr: &ruleRefExpr{ - pos: position{line: 32, col: 15, offset: 835}, + pos: position{line: 32, col: 15, offset: 807}, name: "Instruction", }, }, &ruleRefExpr{ - pos: position{line: 32, col: 27, offset: 847}, + pos: position{line: 32, col: 27, offset: 819}, name: "_", }, &choiceExpr{ - pos: position{line: 32, col: 30, offset: 850}, - alternatives: []interface{}{ + pos: position{line: 32, col: 30, offset: 822}, + alternatives: []any{ &ruleRefExpr{ - pos: position{line: 32, col: 30, offset: 850}, + pos: position{line: 32, col: 30, offset: 822}, name: "nl", }, &ruleRefExpr{ - pos: position{line: 32, col: 35, offset: 855}, + pos: position{line: 32, col: 35, offset: 827}, name: "EOF", }, }, @@ -113,36 +113,36 @@ var g = &grammar{ }, { name: "Instruction", - pos: position{line: 36, col: 1, offset: 884}, + pos: position{line: 36, col: 1, offset: 856}, expr: &actionExpr{ - pos: position{line: 36, col: 15, offset: 900}, + pos: position{line: 36, col: 15, offset: 872}, run: (*parser).callonInstruction1, expr: &seqExpr{ - pos: position{line: 36, col: 15, offset: 900}, - exprs: []interface{}{ + pos: position{line: 36, col: 15, offset: 872}, + exprs: []any{ &zeroOrOneExpr{ - pos: position{line: 36, col: 15, offset: 900}, + pos: position{line: 36, col: 15, offset: 872}, expr: &ruleRefExpr{ - pos: position{line: 36, col: 15, offset: 900}, + pos: position{line: 36, col: 15, offset: 872}, name: "Label", }, }, &ruleRefExpr{ - pos: position{line: 36, col: 22, offset: 907}, + pos: position{line: 36, col: 22, offset: 879}, name: "_", }, &labeledExpr{ - pos: position{line: 36, col: 24, offset: 909}, + pos: position{line: 36, col: 24, offset: 881}, label: "op", expr: &choiceExpr{ - pos: position{line: 36, col: 29, offset: 914}, - alternatives: []interface{}{ + pos: position{line: 36, col: 29, offset: 886}, + alternatives: []any{ &ruleRefExpr{ - pos: position{line: 36, col: 29, offset: 914}, + pos: position{line: 36, col: 29, offset: 886}, name: "Noop", }, &ruleRefExpr{ - pos: position{line: 36, col: 36, offset: 921}, + pos: position{line: 36, col: 36, offset: 893}, name: "Jump", }, }, @@ -154,23 +154,23 @@ var g = &grammar{ }, { name: "Label", - pos: position{line: 40, col: 1, offset: 950}, + pos: position{line: 40, col: 1, offset: 922}, expr: &actionExpr{ - pos: position{line: 40, col: 9, offset: 960}, + pos: position{line: 40, col: 9, offset: 932}, run: (*parser).callonLabel1, expr: &seqExpr{ - pos: position{line: 40, col: 9, offset: 960}, - exprs: []interface{}{ + pos: position{line: 40, col: 9, offset: 932}, + exprs: []any{ &labeledExpr{ - pos: position{line: 40, col: 9, offset: 960}, + pos: position{line: 40, col: 9, offset: 932}, label: "l", expr: &ruleRefExpr{ - pos: position{line: 40, col: 11, offset: 962}, + pos: position{line: 40, col: 11, offset: 934}, name: "labelIdentifier", }, }, &litMatcher{ - pos: position{line: 40, col: 27, offset: 978}, + pos: position{line: 40, col: 27, offset: 950}, val: ":", ignoreCase: false, want: "\":\"", @@ -181,24 +181,24 @@ var g = &grammar{ }, { name: "labelIdentifier", - pos: position{line: 46, col: 1, offset: 1042}, + pos: position{line: 46, col: 1, offset: 1014}, expr: &actionExpr{ - pos: position{line: 46, col: 19, offset: 1062}, + pos: position{line: 46, col: 19, offset: 1034}, run: (*parser).callonlabelIdentifier1, expr: &seqExpr{ - pos: position{line: 46, col: 19, offset: 1062}, - exprs: []interface{}{ + pos: position{line: 46, col: 19, offset: 1034}, + exprs: []any{ &charClassMatcher{ - pos: position{line: 46, col: 19, offset: 1062}, + pos: position{line: 46, col: 19, offset: 1034}, val: "[a-z]", ranges: []rune{'a', 'z'}, ignoreCase: false, inverted: false, }, &zeroOrMoreExpr{ - pos: position{line: 46, col: 24, offset: 1067}, + pos: position{line: 46, col: 24, offset: 1039}, expr: &charClassMatcher{ - pos: position{line: 46, col: 24, offset: 1067}, + pos: position{line: 46, col: 24, offset: 1039}, val: "[a-z0-9]", ranges: []rune{'a', 'z', '0', '9'}, ignoreCase: false, @@ -211,12 +211,12 @@ var g = &grammar{ }, { name: "Noop", - pos: position{line: 50, col: 1, offset: 1111}, + pos: position{line: 50, col: 1, offset: 1083}, expr: &actionExpr{ - pos: position{line: 50, col: 8, offset: 1120}, + pos: position{line: 50, col: 8, offset: 1092}, run: (*parser).callonNoop1, expr: &litMatcher{ - pos: position{line: 50, col: 8, offset: 1120}, + pos: position{line: 50, col: 8, offset: 1092}, val: "noop", ignoreCase: false, want: "\"noop\"", @@ -225,28 +225,28 @@ var g = &grammar{ }, { name: "Jump", - pos: position{line: 54, col: 1, offset: 1153}, + pos: position{line: 54, col: 1, offset: 1125}, expr: &actionExpr{ - pos: position{line: 54, col: 8, offset: 1162}, + pos: position{line: 54, col: 8, offset: 1134}, run: (*parser).callonJump1, expr: &seqExpr{ - pos: position{line: 54, col: 8, offset: 1162}, - exprs: []interface{}{ + pos: position{line: 54, col: 8, offset: 1134}, + exprs: []any{ &litMatcher{ - pos: position{line: 54, col: 8, offset: 1162}, + pos: position{line: 54, col: 8, offset: 1134}, val: "jump", ignoreCase: false, want: "\"jump\"", }, &ruleRefExpr{ - pos: position{line: 54, col: 15, offset: 1169}, + pos: position{line: 54, col: 15, offset: 1141}, name: "__", }, &labeledExpr{ - pos: position{line: 54, col: 18, offset: 1172}, + pos: position{line: 54, col: 18, offset: 1144}, label: "label", expr: &ruleRefExpr{ - pos: position{line: 54, col: 24, offset: 1178}, + pos: position{line: 54, col: 24, offset: 1150}, name: "labelIdentifier", }, }, @@ -257,11 +257,11 @@ var g = &grammar{ { name: "nl", displayName: "\"newline\"", - pos: position{line: 60, col: 1, offset: 1268}, + pos: position{line: 60, col: 1, offset: 1240}, expr: &oneOrMoreExpr{ - pos: position{line: 60, col: 16, offset: 1285}, + pos: position{line: 60, col: 16, offset: 1257}, expr: &charClassMatcher{ - pos: position{line: 60, col: 16, offset: 1285}, + pos: position{line: 60, col: 16, offset: 1257}, val: "[\\n\\r]", chars: []rune{'\n', '\r'}, ignoreCase: false, @@ -272,11 +272,11 @@ var g = &grammar{ { name: "__", displayName: "\"whitespace\"", - pos: position{line: 62, col: 1, offset: 1294}, + pos: position{line: 62, col: 1, offset: 1266}, expr: &oneOrMoreExpr{ - pos: position{line: 62, col: 19, offset: 1314}, + pos: position{line: 62, col: 19, offset: 1286}, expr: &charClassMatcher{ - pos: position{line: 62, col: 19, offset: 1314}, + pos: position{line: 62, col: 19, offset: 1286}, val: "[ \\t]", chars: []rune{' ', '\t'}, ignoreCase: false, @@ -287,11 +287,11 @@ var g = &grammar{ { name: "_", displayName: "\"optional whitespace\"", - pos: position{line: 64, col: 1, offset: 1322}, + pos: position{line: 64, col: 1, offset: 1294}, expr: &zeroOrMoreExpr{ - pos: position{line: 64, col: 27, offset: 1350}, + pos: position{line: 64, col: 27, offset: 1322}, expr: &charClassMatcher{ - pos: position{line: 64, col: 27, offset: 1350}, + pos: position{line: 64, col: 27, offset: 1322}, val: "[ \\t]", chars: []rune{' ', '\t'}, ignoreCase: false, @@ -301,18 +301,18 @@ var g = &grammar{ }, { name: "EOF", - pos: position{line: 66, col: 1, offset: 1358}, + pos: position{line: 66, col: 1, offset: 1330}, expr: ¬Expr{ - pos: position{line: 66, col: 7, offset: 1366}, + pos: position{line: 66, col: 7, offset: 1338}, expr: &anyMatcher{ - line: 66, col: 8, offset: 1367, + line: 66, col: 8, offset: 1339, }, }, }, }, } -func (c *current) onProgram7(lines interface{}) (bool, error) { +func (c *current) onProgram7(lines any) (bool, error) { return labelCheck(c) } @@ -322,8 +322,8 @@ func (p *parser) callonProgram7() (bool, error) { return p.cur.onProgram7(stack["lines"]) } -func (c *current) onProgram1(lines interface{}) (interface{}, error) { - lines0 := toIfaceSlice(lines) +func (c *current) onProgram1(lines any) (any, error) { + lines0 := toAnySlice(lines) asmLines := make([]Instruction, 0, len(lines0)) for _, line := range lines0 { asmLines = append(asmLines, line.(Instruction)) @@ -331,71 +331,71 @@ func (c *current) onProgram1(lines interface{}) (interface{}, error) { return asmLines, nil } -func (p *parser) callonProgram1() (interface{}, error) { +func (p *parser) callonProgram1() (any, error) { stack := p.vstack[len(p.vstack)-1] _ = stack return p.cur.onProgram1(stack["lines"]) } -func (c *current) onLine1(inst interface{}) (interface{}, error) { +func (c *current) onLine1(inst any) (any, error) { return inst, nil } -func (p *parser) callonLine1() (interface{}, error) { +func (p *parser) callonLine1() (any, error) { stack := p.vstack[len(p.vstack)-1] _ = stack return p.cur.onLine1(stack["inst"]) } -func (c *current) onInstruction1(op interface{}) (interface{}, error) { +func (c *current) onInstruction1(op any) (any, error) { return op, nil } -func (p *parser) callonInstruction1() (interface{}, error) { +func (p *parser) callonInstruction1() (any, error) { stack := p.vstack[len(p.vstack)-1] _ = stack return p.cur.onInstruction1(stack["op"]) } -func (c *current) onLabel1(l interface{}) (interface{}, error) { +func (c *current) onLabel1(l any) (any, error) { l0 := l.(string) addLabel(c, l0) return nil, nil } -func (p *parser) callonLabel1() (interface{}, error) { +func (p *parser) callonLabel1() (any, error) { stack := p.vstack[len(p.vstack)-1] _ = stack return p.cur.onLabel1(stack["l"]) } -func (c *current) onlabelIdentifier1() (interface{}, error) { +func (c *current) onlabelIdentifier1() (any, error) { return string(c.text), nil } -func (p *parser) callonlabelIdentifier1() (interface{}, error) { +func (p *parser) callonlabelIdentifier1() (any, error) { stack := p.vstack[len(p.vstack)-1] _ = stack return p.cur.onlabelIdentifier1() } -func (c *current) onNoop1() (interface{}, error) { +func (c *current) onNoop1() (any, error) { return Noop{}, nil } -func (p *parser) callonNoop1() (interface{}, error) { +func (p *parser) callonNoop1() (any, error) { stack := p.vstack[len(p.vstack)-1] _ = stack return p.cur.onNoop1() } -func (c *current) onJump1(label interface{}) (interface{}, error) { +func (c *current) onJump1(label any) (any, error) { label0 := label.(string) j := addJump(c, label0) return j, nil } -func (p *parser) callonJump1() (interface{}, error) { +func (p *parser) callonJump1() (any, error) { stack := p.vstack[len(p.vstack)-1] _ = stack return p.cur.onJump1(stack["label"]) @@ -539,7 +539,7 @@ func Recover(b bool) Option { // GlobalStore creates an Option to set a key to a certain value in // the globalStore. -func GlobalStore(key string, value interface{}) Option { +func GlobalStore(key string, value any) Option { return func(p *parser) Option { old := p.cur.globalStore[key] p.cur.globalStore[key] = value @@ -549,7 +549,7 @@ func GlobalStore(key string, value interface{}) Option { // InitState creates an Option to set a key to a certain value in // the global "state" store. -func InitState(key string, value interface{}) Option { +func InitState(key string, value any) Option { return func(p *parser) Option { old := p.cur.state[key] p.cur.state[key] = value @@ -558,7 +558,7 @@ func InitState(key string, value interface{}) Option { } // ParseFile parses the file identified by filename. -func ParseFile(filename string, opts ...Option) (i interface{}, err error) { // nolint: deadcode +func ParseFile(filename string, opts ...Option) (i any, err error) { // nolint: deadcode f, err := os.Open(filename) if err != nil { return nil, err @@ -573,7 +573,7 @@ func ParseFile(filename string, opts ...Option) (i interface{}, err error) { // // ParseReader parses the data from r using filename as information in the // error messages. -func ParseReader(filename string, r io.Reader, opts ...Option) (interface{}, error) { // nolint: deadcode +func ParseReader(filename string, r io.Reader, opts ...Option) (any, error) { // nolint: deadcode b, err := io.ReadAll(r) if err != nil { return nil, err @@ -584,7 +584,7 @@ func ParseReader(filename string, r io.Reader, opts ...Option) (interface{}, err // Parse parses the data from b using filename as information in the // error messages. -func Parse(filename string, b []byte, opts ...Option) (interface{}, error) { +func Parse(filename string, b []byte, opts ...Option) (any, error) { return newParser(filename, b, opts...).parse(g) } @@ -622,7 +622,7 @@ type current struct { globalStore storeDict } -type storeDict map[string]interface{} +type storeDict map[string]any // the AST types... @@ -637,34 +637,34 @@ type rule struct { pos position name string displayName string - expr interface{} + expr any } // nolint: structcheck type choiceExpr struct { pos position - alternatives []interface{} + alternatives []any } // nolint: structcheck type actionExpr struct { pos position - expr interface{} - run func(*parser) (interface{}, error) + expr any + run func(*parser) (any, error) } // nolint: structcheck type recoveryExpr struct { pos position - expr interface{} - recoverExpr interface{} + expr any + recoverExpr any failureLabel []string } // nolint: structcheck type seqExpr struct { pos position - exprs []interface{} + exprs []any } // nolint: structcheck @@ -677,20 +677,22 @@ type throwExpr struct { type labeledExpr struct { pos position label string - expr interface{} + expr any } // nolint: structcheck type expr struct { pos position - expr interface{} + expr any } -type andExpr expr // nolint: structcheck -type notExpr expr // nolint: structcheck -type zeroOrOneExpr expr // nolint: structcheck -type zeroOrMoreExpr expr // nolint: structcheck -type oneOrMoreExpr expr // nolint: structcheck +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 { @@ -838,7 +840,7 @@ func (p *parser) setOptions(opts []Option) { // nolint: structcheck,deadcode type resultTuple struct { - v interface{} + v any b bool end savepoint } @@ -884,12 +886,12 @@ type parser struct { memoize bool // memoization table for the packrat algorithm: // map[offset in source] map[expression or rule] {value, match} - memo map[int]map[interface{}]resultTuple + 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]interface{} + vstack []map[string]any // rule stack, allows identification of the current rule in errors rstack []*rule @@ -909,7 +911,7 @@ type parser struct { choiceNoMatch string // recovery expression stack, keeps track of the currently available recovery expression, these are traversed in reverse - recoveryStack []map[string]interface{} + recoveryStack []map[string]any } // push a variable set on the vstack. @@ -929,7 +931,7 @@ func (p *parser) pushV() { return } - m = make(map[string]interface{}) + m = make(map[string]any) p.vstack[len(p.vstack)-1] = m } @@ -945,7 +947,7 @@ func (p *parser) popV() { } // push a recovery expression with its labels to the recoveryStack -func (p *parser) pushRecovery(labels []string, expr interface{}) { +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) @@ -954,7 +956,7 @@ func (p *parser) pushRecovery(labels []string, expr interface{}) { p.recoveryStack = p.recoveryStack[:len(p.recoveryStack)+1] } - m := make(map[string]interface{}, len(labels)) + m := make(map[string]any, len(labels)) for _, fl := range labels { m[fl] = expr } @@ -1074,11 +1076,11 @@ func (p *parser) restore(pt savepoint) { // copies of the state to allow the parser to properly restore the state in // the case of backtracking. type Cloner interface { - Clone() interface{} + Clone() any } var statePool = &sync.Pool{ - New: func() interface{} { return make(storeDict) }, + New: func() any { return make(storeDict) }, } func (sd storeDict) Discard() { @@ -1120,7 +1122,7 @@ func (p *parser) sliceFrom(start savepoint) []byte { return p.data[start.position.offset:p.pt.position.offset] } -func (p *parser) getMemoized(node interface{}) (resultTuple, bool) { +func (p *parser) getMemoized(node any) (resultTuple, bool) { if len(p.memo) == 0 { return resultTuple{}, false } @@ -1132,13 +1134,13 @@ func (p *parser) getMemoized(node interface{}) (resultTuple, bool) { return res, ok } -func (p *parser) setMemoized(pt savepoint, node interface{}, tuple resultTuple) { +func (p *parser) setMemoized(pt savepoint, node any, tuple resultTuple) { if p.memo == nil { - p.memo = make(map[int]map[interface{}]resultTuple) + p.memo = make(map[int]map[any]resultTuple) } m := p.memo[pt.offset] if m == nil { - m = make(map[interface{}]resultTuple) + m = make(map[any]resultTuple) p.memo[pt.offset] = m } m[node] = tuple @@ -1152,7 +1154,7 @@ func (p *parser) buildRulesTable(g *grammar) { } // nolint: gocyclo -func (p *parser) parse(g *grammar) (val interface{}, err error) { +func (p *parser) parse(g *grammar) (val any, err error) { if len(g.rules) == 0 { p.addErr(errNoRule) return nil, p.errs.err() @@ -1229,7 +1231,7 @@ func listJoin(list []string, sep string, lastSep string) string { } } -func (p *parser) parseRule(rule *rule) (interface{}, bool) { +func (p *parser) parseRule(rule *rule) (any, bool) { if p.debug { defer p.out(p.in("parseRule " + rule.name)) } @@ -1259,7 +1261,7 @@ func (p *parser) parseRule(rule *rule) (interface{}, bool) { } // nolint: gocyclo -func (p *parser) parseExpr(expr interface{}) (interface{}, bool) { +func (p *parser) parseExpr(expr any) (any, bool) { var pt savepoint if p.memoize { @@ -1276,7 +1278,7 @@ func (p *parser) parseExpr(expr interface{}) (interface{}, bool) { panic(errMaxExprCnt) } - var val interface{} + var val any var ok bool switch expr := expr.(type) { case *actionExpr: @@ -1324,7 +1326,7 @@ func (p *parser) parseExpr(expr interface{}) (interface{}, bool) { return val, ok } -func (p *parser) parseActionExpr(act *actionExpr) (interface{}, bool) { +func (p *parser) parseActionExpr(act *actionExpr) (any, bool) { if p.debug { defer p.out(p.in("parseActionExpr")) } @@ -1349,7 +1351,7 @@ func (p *parser) parseActionExpr(act *actionExpr) (interface{}, bool) { return val, ok } -func (p *parser) parseAndCodeExpr(and *andCodeExpr) (interface{}, bool) { +func (p *parser) parseAndCodeExpr(and *andCodeExpr) (any, bool) { if p.debug { defer p.out(p.in("parseAndCodeExpr")) } @@ -1365,7 +1367,7 @@ func (p *parser) parseAndCodeExpr(and *andCodeExpr) (interface{}, bool) { return nil, ok } -func (p *parser) parseAndExpr(and *andExpr) (interface{}, bool) { +func (p *parser) parseAndExpr(and *andExpr) (any, bool) { if p.debug { defer p.out(p.in("parseAndExpr")) } @@ -1381,7 +1383,7 @@ func (p *parser) parseAndExpr(and *andExpr) (interface{}, bool) { return nil, ok } -func (p *parser) parseAnyMatcher(any *anyMatcher) (interface{}, bool) { +func (p *parser) parseAnyMatcher(any *anyMatcher) (any, bool) { if p.debug { defer p.out(p.in("parseAnyMatcher")) } @@ -1398,7 +1400,7 @@ func (p *parser) parseAnyMatcher(any *anyMatcher) (interface{}, bool) { } // nolint: gocyclo -func (p *parser) parseCharClassMatcher(chr *charClassMatcher) (interface{}, bool) { +func (p *parser) parseCharClassMatcher(chr *charClassMatcher) (any, bool) { if p.debug { defer p.out(p.in("parseCharClassMatcher")) } @@ -1479,7 +1481,7 @@ func (p *parser) incChoiceAltCnt(ch *choiceExpr, altI int) { m[alt]++ } -func (p *parser) parseChoiceExpr(ch *choiceExpr) (interface{}, bool) { +func (p *parser) parseChoiceExpr(ch *choiceExpr) (any, bool) { if p.debug { defer p.out(p.in("parseChoiceExpr")) } @@ -1503,7 +1505,7 @@ func (p *parser) parseChoiceExpr(ch *choiceExpr) (interface{}, bool) { return nil, false } -func (p *parser) parseLabeledExpr(lab *labeledExpr) (interface{}, bool) { +func (p *parser) parseLabeledExpr(lab *labeledExpr) (any, bool) { if p.debug { defer p.out(p.in("parseLabeledExpr")) } @@ -1518,7 +1520,7 @@ func (p *parser) parseLabeledExpr(lab *labeledExpr) (interface{}, bool) { return val, ok } -func (p *parser) parseLitMatcher(lit *litMatcher) (interface{}, bool) { +func (p *parser) parseLitMatcher(lit *litMatcher) (any, bool) { if p.debug { defer p.out(p.in("parseLitMatcher")) } @@ -1540,7 +1542,7 @@ func (p *parser) parseLitMatcher(lit *litMatcher) (interface{}, bool) { return p.sliceFrom(start), true } -func (p *parser) parseNotCodeExpr(not *notCodeExpr) (interface{}, bool) { +func (p *parser) parseNotCodeExpr(not *notCodeExpr) (any, bool) { if p.debug { defer p.out(p.in("parseNotCodeExpr")) } @@ -1556,7 +1558,7 @@ func (p *parser) parseNotCodeExpr(not *notCodeExpr) (interface{}, bool) { return nil, !ok } -func (p *parser) parseNotExpr(not *notExpr) (interface{}, bool) { +func (p *parser) parseNotExpr(not *notExpr) (any, bool) { if p.debug { defer p.out(p.in("parseNotExpr")) } @@ -1574,12 +1576,12 @@ func (p *parser) parseNotExpr(not *notExpr) (interface{}, bool) { return nil, !ok } -func (p *parser) parseOneOrMoreExpr(expr *oneOrMoreExpr) (interface{}, bool) { +func (p *parser) parseOneOrMoreExpr(expr *oneOrMoreExpr) (any, bool) { if p.debug { defer p.out(p.in("parseOneOrMoreExpr")) } - var vals []interface{} + var vals []any for { p.pushV() @@ -1596,7 +1598,7 @@ func (p *parser) parseOneOrMoreExpr(expr *oneOrMoreExpr) (interface{}, bool) { } } -func (p *parser) parseRecoveryExpr(recover *recoveryExpr) (interface{}, bool) { +func (p *parser) parseRecoveryExpr(recover *recoveryExpr) (any, bool) { if p.debug { defer p.out(p.in("parseRecoveryExpr (" + strings.Join(recover.failureLabel, ",") + ")")) } @@ -1608,7 +1610,7 @@ func (p *parser) parseRecoveryExpr(recover *recoveryExpr) (interface{}, bool) { return val, ok } -func (p *parser) parseRuleRefExpr(ref *ruleRefExpr) (interface{}, bool) { +func (p *parser) parseRuleRefExpr(ref *ruleRefExpr) (any, bool) { if p.debug { defer p.out(p.in("parseRuleRefExpr " + ref.name)) } @@ -1625,12 +1627,12 @@ func (p *parser) parseRuleRefExpr(ref *ruleRefExpr) (interface{}, bool) { return p.parseRule(rule) } -func (p *parser) parseSeqExpr(seq *seqExpr) (interface{}, bool) { +func (p *parser) parseSeqExpr(seq *seqExpr) (any, bool) { if p.debug { defer p.out(p.in("parseSeqExpr")) } - vals := make([]interface{}, 0, len(seq.exprs)) + vals := make([]any, 0, len(seq.exprs)) pt := p.pt state := p.cloneState() @@ -1646,7 +1648,7 @@ func (p *parser) parseSeqExpr(seq *seqExpr) (interface{}, bool) { return vals, true } -func (p *parser) parseStateCodeExpr(state *stateCodeExpr) (interface{}, bool) { +func (p *parser) parseStateCodeExpr(state *stateCodeExpr) (any, bool) { if p.debug { defer p.out(p.in("parseStateCodeExpr")) } @@ -1658,7 +1660,7 @@ func (p *parser) parseStateCodeExpr(state *stateCodeExpr) (interface{}, bool) { return nil, true } -func (p *parser) parseThrowExpr(expr *throwExpr) (interface{}, bool) { +func (p *parser) parseThrowExpr(expr *throwExpr) (any, bool) { if p.debug { defer p.out(p.in("parseThrowExpr")) } @@ -1674,12 +1676,12 @@ func (p *parser) parseThrowExpr(expr *throwExpr) (interface{}, bool) { return nil, false } -func (p *parser) parseZeroOrMoreExpr(expr *zeroOrMoreExpr) (interface{}, bool) { +func (p *parser) parseZeroOrMoreExpr(expr *zeroOrMoreExpr) (any, bool) { if p.debug { defer p.out(p.in("parseZeroOrMoreExpr")) } - var vals []interface{} + var vals []any for { p.pushV() @@ -1692,7 +1694,7 @@ func (p *parser) parseZeroOrMoreExpr(expr *zeroOrMoreExpr) (interface{}, bool) { } } -func (p *parser) parseZeroOrOneExpr(expr *zeroOrOneExpr) (interface{}, bool) { +func (p *parser) parseZeroOrOneExpr(expr *zeroOrOneExpr) (any, bool) { if p.debug { defer p.out(p.in("parseZeroOrOneExpr")) } diff --git a/test/goto/goto.peg b/test/goto/goto.peg index 214ac162..9e790c66 100644 --- a/test/goto/goto.peg +++ b/test/goto/goto.peg @@ -12,16 +12,16 @@ // package asmgoto -func toIfaceSlice(v interface{}) []interface{} { +func toAnySlice(v any) []any { if v == nil { return nil } - return v.([]interface{}) + return v.([]any) } } Program ← lines:Line* EOF &{ return labelCheck(c) } { - lines0 := toIfaceSlice(lines) + lines0 := toAnySlice(lines) asmLines := make([]Instruction, 0, len(lines0)) for _, line := range lines0 { asmLines = append(asmLines, line.(Instruction)) diff --git a/test/goto_state/goto_state.go b/test/goto_state/goto_state.go index f22c5215..3797cb42 100644 --- a/test/goto_state/goto_state.go +++ b/test/goto_state/goto_state.go @@ -28,45 +28,45 @@ import ( "unicode/utf8" ) -func toIfaceSlice(v interface{}) []interface{} { +func toAnySlice(v any) []any { if v == nil { return nil } - return v.([]interface{}) + return v.([]any) } var g = &grammar{ rules: []*rule{ { name: "Program", - pos: position{line: 23, col: 1, offset: 598}, + pos: position{line: 23, col: 1, offset: 572}, expr: &actionExpr{ - pos: position{line: 23, col: 11, offset: 610}, + pos: position{line: 23, col: 11, offset: 584}, run: (*parser).callonProgram1, expr: &seqExpr{ - pos: position{line: 23, col: 11, offset: 610}, - exprs: []interface{}{ + pos: position{line: 23, col: 11, offset: 584}, + exprs: []any{ &stateCodeExpr{ - pos: position{line: 23, col: 11, offset: 610}, + pos: position{line: 23, col: 11, offset: 584}, run: (*parser).callonProgram3, }, &labeledExpr{ - pos: position{line: 23, col: 126, offset: 725}, + pos: position{line: 23, col: 126, offset: 699}, label: "lines", expr: &zeroOrMoreExpr{ - pos: position{line: 23, col: 132, offset: 731}, + pos: position{line: 23, col: 132, offset: 705}, expr: &ruleRefExpr{ - pos: position{line: 23, col: 132, offset: 731}, + pos: position{line: 23, col: 132, offset: 705}, name: "Line", }, }, }, &ruleRefExpr{ - pos: position{line: 23, col: 138, offset: 737}, + pos: position{line: 23, col: 138, offset: 711}, name: "EOF", }, &andCodeExpr{ - pos: position{line: 23, col: 142, offset: 741}, + pos: position{line: 23, col: 142, offset: 715}, run: (*parser).callonProgram8, }, }, @@ -75,38 +75,38 @@ var g = &grammar{ }, { name: "Line", - pos: position{line: 32, col: 1, offset: 965}, + pos: position{line: 32, col: 1, offset: 937}, expr: &actionExpr{ - pos: position{line: 32, col: 8, offset: 974}, + pos: position{line: 32, col: 8, offset: 946}, run: (*parser).callonLine1, expr: &seqExpr{ - pos: position{line: 32, col: 8, offset: 974}, - exprs: []interface{}{ + pos: position{line: 32, col: 8, offset: 946}, + exprs: []any{ &ruleRefExpr{ - pos: position{line: 32, col: 8, offset: 974}, + pos: position{line: 32, col: 8, offset: 946}, name: "_", }, &labeledExpr{ - pos: position{line: 32, col: 10, offset: 976}, + pos: position{line: 32, col: 10, offset: 948}, label: "inst", expr: &ruleRefExpr{ - pos: position{line: 32, col: 15, offset: 981}, + pos: position{line: 32, col: 15, offset: 953}, name: "Instruction", }, }, &ruleRefExpr{ - pos: position{line: 32, col: 27, offset: 993}, + pos: position{line: 32, col: 27, offset: 965}, name: "_", }, &choiceExpr{ - pos: position{line: 32, col: 30, offset: 996}, - alternatives: []interface{}{ + pos: position{line: 32, col: 30, offset: 968}, + alternatives: []any{ &ruleRefExpr{ - pos: position{line: 32, col: 30, offset: 996}, + pos: position{line: 32, col: 30, offset: 968}, name: "nl", }, &ruleRefExpr{ - pos: position{line: 32, col: 35, offset: 1001}, + pos: position{line: 32, col: 35, offset: 973}, name: "EOF", }, }, @@ -117,36 +117,36 @@ var g = &grammar{ }, { name: "Instruction", - pos: position{line: 36, col: 1, offset: 1030}, + pos: position{line: 36, col: 1, offset: 1002}, expr: &actionExpr{ - pos: position{line: 36, col: 15, offset: 1046}, + pos: position{line: 36, col: 15, offset: 1018}, run: (*parser).callonInstruction1, expr: &seqExpr{ - pos: position{line: 36, col: 15, offset: 1046}, - exprs: []interface{}{ + pos: position{line: 36, col: 15, offset: 1018}, + exprs: []any{ &zeroOrOneExpr{ - pos: position{line: 36, col: 15, offset: 1046}, + pos: position{line: 36, col: 15, offset: 1018}, expr: &ruleRefExpr{ - pos: position{line: 36, col: 15, offset: 1046}, + pos: position{line: 36, col: 15, offset: 1018}, name: "Label", }, }, &ruleRefExpr{ - pos: position{line: 36, col: 22, offset: 1053}, + pos: position{line: 36, col: 22, offset: 1025}, name: "_", }, &labeledExpr{ - pos: position{line: 36, col: 24, offset: 1055}, + pos: position{line: 36, col: 24, offset: 1027}, label: "op", expr: &choiceExpr{ - pos: position{line: 36, col: 29, offset: 1060}, - alternatives: []interface{}{ + pos: position{line: 36, col: 29, offset: 1032}, + alternatives: []any{ &ruleRefExpr{ - pos: position{line: 36, col: 29, offset: 1060}, + pos: position{line: 36, col: 29, offset: 1032}, name: "Noop", }, &ruleRefExpr{ - pos: position{line: 36, col: 36, offset: 1067}, + pos: position{line: 36, col: 36, offset: 1039}, name: "Jump", }, }, @@ -158,24 +158,24 @@ var g = &grammar{ }, { name: "Label", - pos: position{line: 40, col: 1, offset: 1096}, + pos: position{line: 40, col: 1, offset: 1068}, expr: &seqExpr{ - pos: position{line: 40, col: 9, offset: 1106}, - exprs: []interface{}{ + pos: position{line: 40, col: 9, offset: 1078}, + exprs: []any{ &labeledExpr{ - pos: position{line: 40, col: 9, offset: 1106}, + pos: position{line: 40, col: 9, offset: 1078}, label: "label", expr: &ruleRefExpr{ - pos: position{line: 40, col: 15, offset: 1112}, + pos: position{line: 40, col: 15, offset: 1084}, name: "labelIdentifier", }, }, &stateCodeExpr{ - pos: position{line: 40, col: 31, offset: 1128}, + pos: position{line: 40, col: 31, offset: 1100}, run: (*parser).callonLabel4, }, &litMatcher{ - pos: position{line: 40, col: 71, offset: 1168}, + pos: position{line: 40, col: 71, offset: 1140}, val: ":", ignoreCase: false, want: "\":\"", @@ -185,24 +185,24 @@ var g = &grammar{ }, { name: "labelIdentifier", - pos: position{line: 42, col: 1, offset: 1173}, + pos: position{line: 42, col: 1, offset: 1145}, expr: &actionExpr{ - pos: position{line: 42, col: 19, offset: 1193}, + pos: position{line: 42, col: 19, offset: 1165}, run: (*parser).callonlabelIdentifier1, expr: &seqExpr{ - pos: position{line: 42, col: 19, offset: 1193}, - exprs: []interface{}{ + pos: position{line: 42, col: 19, offset: 1165}, + exprs: []any{ &charClassMatcher{ - pos: position{line: 42, col: 19, offset: 1193}, + pos: position{line: 42, col: 19, offset: 1165}, val: "[a-z]", ranges: []rune{'a', 'z'}, ignoreCase: false, inverted: false, }, &zeroOrMoreExpr{ - pos: position{line: 42, col: 24, offset: 1198}, + pos: position{line: 42, col: 24, offset: 1170}, expr: &charClassMatcher{ - pos: position{line: 42, col: 24, offset: 1198}, + pos: position{line: 42, col: 24, offset: 1170}, val: "[a-z0-9]", ranges: []rune{'a', 'z', '0', '9'}, ignoreCase: false, @@ -215,12 +215,12 @@ var g = &grammar{ }, { name: "Noop", - pos: position{line: 46, col: 1, offset: 1242}, + pos: position{line: 46, col: 1, offset: 1214}, expr: &actionExpr{ - pos: position{line: 46, col: 8, offset: 1251}, + pos: position{line: 46, col: 8, offset: 1223}, run: (*parser).callonNoop1, expr: &litMatcher{ - pos: position{line: 46, col: 8, offset: 1251}, + pos: position{line: 46, col: 8, offset: 1223}, val: "noop", ignoreCase: false, want: "\"noop\"", @@ -229,33 +229,33 @@ var g = &grammar{ }, { name: "Jump", - pos: position{line: 50, col: 1, offset: 1284}, + pos: position{line: 50, col: 1, offset: 1256}, expr: &actionExpr{ - pos: position{line: 50, col: 8, offset: 1293}, + pos: position{line: 50, col: 8, offset: 1265}, run: (*parser).callonJump1, expr: &seqExpr{ - pos: position{line: 50, col: 8, offset: 1293}, - exprs: []interface{}{ + pos: position{line: 50, col: 8, offset: 1265}, + exprs: []any{ &litMatcher{ - pos: position{line: 50, col: 8, offset: 1293}, + pos: position{line: 50, col: 8, offset: 1265}, val: "jump", ignoreCase: false, want: "\"jump\"", }, &ruleRefExpr{ - pos: position{line: 50, col: 15, offset: 1300}, + pos: position{line: 50, col: 15, offset: 1272}, name: "__", }, &labeledExpr{ - pos: position{line: 50, col: 18, offset: 1303}, + pos: position{line: 50, col: 18, offset: 1275}, label: "label", expr: &ruleRefExpr{ - pos: position{line: 50, col: 24, offset: 1309}, + pos: position{line: 50, col: 24, offset: 1281}, name: "labelIdentifier", }, }, &stateCodeExpr{ - pos: position{line: 50, col: 40, offset: 1325}, + pos: position{line: 50, col: 40, offset: 1297}, run: (*parser).callonJump7, }, }, @@ -265,11 +265,11 @@ var g = &grammar{ { name: "nl", displayName: "\"newline\"", - pos: position{line: 54, col: 1, offset: 1392}, + pos: position{line: 54, col: 1, offset: 1364}, expr: &oneOrMoreExpr{ - pos: position{line: 54, col: 16, offset: 1409}, + pos: position{line: 54, col: 16, offset: 1381}, expr: &charClassMatcher{ - pos: position{line: 54, col: 16, offset: 1409}, + pos: position{line: 54, col: 16, offset: 1381}, val: "[\\n\\r]", chars: []rune{'\n', '\r'}, ignoreCase: false, @@ -280,11 +280,11 @@ var g = &grammar{ { name: "__", displayName: "\"whitespace\"", - pos: position{line: 56, col: 1, offset: 1418}, + pos: position{line: 56, col: 1, offset: 1390}, expr: &oneOrMoreExpr{ - pos: position{line: 56, col: 19, offset: 1438}, + pos: position{line: 56, col: 19, offset: 1410}, expr: &charClassMatcher{ - pos: position{line: 56, col: 19, offset: 1438}, + pos: position{line: 56, col: 19, offset: 1410}, val: "[ \\t]", chars: []rune{' ', '\t'}, ignoreCase: false, @@ -295,11 +295,11 @@ var g = &grammar{ { name: "_", displayName: "\"optional whitespace\"", - pos: position{line: 58, col: 1, offset: 1446}, + pos: position{line: 58, col: 1, offset: 1418}, expr: &zeroOrMoreExpr{ - pos: position{line: 58, col: 27, offset: 1474}, + pos: position{line: 58, col: 27, offset: 1446}, expr: &charClassMatcher{ - pos: position{line: 58, col: 27, offset: 1474}, + pos: position{line: 58, col: 27, offset: 1446}, val: "[ \\t]", chars: []rune{' ', '\t'}, ignoreCase: false, @@ -309,11 +309,11 @@ var g = &grammar{ }, { name: "EOF", - pos: position{line: 60, col: 1, offset: 1482}, + pos: position{line: 60, col: 1, offset: 1454}, expr: ¬Expr{ - pos: position{line: 60, col: 7, offset: 1490}, + pos: position{line: 60, col: 7, offset: 1462}, expr: &anyMatcher{ - line: 60, col: 8, offset: 1491, + line: 60, col: 8, offset: 1463, }, }, }, @@ -334,7 +334,7 @@ func (p *parser) callonProgram3() error { return p.cur.onProgram3() } -func (c *current) onProgram8(lines interface{}) (bool, error) { +func (c *current) onProgram8(lines any) (bool, error) { return labelCheck(c) } @@ -344,8 +344,8 @@ func (p *parser) callonProgram8() (bool, error) { return p.cur.onProgram8(stack["lines"]) } -func (c *current) onProgram1(lines interface{}) (interface{}, error) { - lines0 := toIfaceSlice(lines) +func (c *current) onProgram1(lines any) (any, error) { + lines0 := toAnySlice(lines) asmLines := make([]Instruction, 0, len(lines0)) for _, line := range lines0 { asmLines = append(asmLines, line.(Instruction)) @@ -353,33 +353,33 @@ func (c *current) onProgram1(lines interface{}) (interface{}, error) { return asmLines, nil } -func (p *parser) callonProgram1() (interface{}, error) { +func (p *parser) callonProgram1() (any, error) { stack := p.vstack[len(p.vstack)-1] _ = stack return p.cur.onProgram1(stack["lines"]) } -func (c *current) onLine1(inst interface{}) (interface{}, error) { +func (c *current) onLine1(inst any) (any, error) { return inst, nil } -func (p *parser) callonLine1() (interface{}, error) { +func (p *parser) callonLine1() (any, error) { stack := p.vstack[len(p.vstack)-1] _ = stack return p.cur.onLine1(stack["inst"]) } -func (c *current) onInstruction1(op interface{}) (interface{}, error) { +func (c *current) onInstruction1(op any) (any, error) { return op, nil } -func (p *parser) callonInstruction1() (interface{}, error) { +func (p *parser) callonInstruction1() (any, error) { stack := p.vstack[len(p.vstack)-1] _ = stack return p.cur.onInstruction1(stack["op"]) } -func (c *current) onLabel4(label interface{}) error { +func (c *current) onLabel4(label any) error { return addLabel(c, label.(string)) } @@ -389,27 +389,27 @@ func (p *parser) callonLabel4() error { return p.cur.onLabel4(stack["label"]) } -func (c *current) onlabelIdentifier1() (interface{}, error) { +func (c *current) onlabelIdentifier1() (any, error) { return string(c.text), nil } -func (p *parser) callonlabelIdentifier1() (interface{}, error) { +func (p *parser) callonlabelIdentifier1() (any, error) { stack := p.vstack[len(p.vstack)-1] _ = stack return p.cur.onlabelIdentifier1() } -func (c *current) onNoop1() (interface{}, error) { +func (c *current) onNoop1() (any, error) { return Noop{}, nil } -func (p *parser) callonNoop1() (interface{}, error) { +func (p *parser) callonNoop1() (any, error) { stack := p.vstack[len(p.vstack)-1] _ = stack return p.cur.onNoop1() } -func (c *current) onJump7(label interface{}) error { +func (c *current) onJump7(label any) error { return addJump(c, label.(string)) } @@ -419,11 +419,11 @@ func (p *parser) callonJump7() error { return p.cur.onJump7(stack["label"]) } -func (c *current) onJump1(label interface{}) (interface{}, error) { +func (c *current) onJump1(label any) (any, error) { return getCurJump(c) } -func (p *parser) callonJump1() (interface{}, error) { +func (p *parser) callonJump1() (any, error) { stack := p.vstack[len(p.vstack)-1] _ = stack return p.cur.onJump1(stack["label"]) @@ -567,7 +567,7 @@ func Recover(b bool) Option { // GlobalStore creates an Option to set a key to a certain value in // the globalStore. -func GlobalStore(key string, value interface{}) Option { +func GlobalStore(key string, value any) Option { return func(p *parser) Option { old := p.cur.globalStore[key] p.cur.globalStore[key] = value @@ -577,7 +577,7 @@ func GlobalStore(key string, value interface{}) Option { // InitState creates an Option to set a key to a certain value in // the global "state" store. -func InitState(key string, value interface{}) Option { +func InitState(key string, value any) Option { return func(p *parser) Option { old := p.cur.state[key] p.cur.state[key] = value @@ -586,7 +586,7 @@ func InitState(key string, value interface{}) Option { } // ParseFile parses the file identified by filename. -func ParseFile(filename string, opts ...Option) (i interface{}, err error) { // nolint: deadcode +func ParseFile(filename string, opts ...Option) (i any, err error) { // nolint: deadcode f, err := os.Open(filename) if err != nil { return nil, err @@ -601,7 +601,7 @@ func ParseFile(filename string, opts ...Option) (i interface{}, err error) { // // ParseReader parses the data from r using filename as information in the // error messages. -func ParseReader(filename string, r io.Reader, opts ...Option) (interface{}, error) { // nolint: deadcode +func ParseReader(filename string, r io.Reader, opts ...Option) (any, error) { // nolint: deadcode b, err := io.ReadAll(r) if err != nil { return nil, err @@ -612,7 +612,7 @@ func ParseReader(filename string, r io.Reader, opts ...Option) (interface{}, err // Parse parses the data from b using filename as information in the // error messages. -func Parse(filename string, b []byte, opts ...Option) (interface{}, error) { +func Parse(filename string, b []byte, opts ...Option) (any, error) { return newParser(filename, b, opts...).parse(g) } @@ -650,7 +650,7 @@ type current struct { globalStore storeDict } -type storeDict map[string]interface{} +type storeDict map[string]any // the AST types... @@ -665,34 +665,34 @@ type rule struct { pos position name string displayName string - expr interface{} + expr any } // nolint: structcheck type choiceExpr struct { pos position - alternatives []interface{} + alternatives []any } // nolint: structcheck type actionExpr struct { pos position - expr interface{} - run func(*parser) (interface{}, error) + expr any + run func(*parser) (any, error) } // nolint: structcheck type recoveryExpr struct { pos position - expr interface{} - recoverExpr interface{} + expr any + recoverExpr any failureLabel []string } // nolint: structcheck type seqExpr struct { pos position - exprs []interface{} + exprs []any } // nolint: structcheck @@ -705,20 +705,22 @@ type throwExpr struct { type labeledExpr struct { pos position label string - expr interface{} + expr any } // nolint: structcheck type expr struct { pos position - expr interface{} + expr any } -type andExpr expr // nolint: structcheck -type notExpr expr // nolint: structcheck -type zeroOrOneExpr expr // nolint: structcheck -type zeroOrMoreExpr expr // nolint: structcheck -type oneOrMoreExpr expr // nolint: structcheck +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 { @@ -866,7 +868,7 @@ func (p *parser) setOptions(opts []Option) { // nolint: structcheck,deadcode type resultTuple struct { - v interface{} + v any b bool end savepoint } @@ -912,12 +914,12 @@ type parser struct { memoize bool // memoization table for the packrat algorithm: // map[offset in source] map[expression or rule] {value, match} - memo map[int]map[interface{}]resultTuple + 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]interface{} + vstack []map[string]any // rule stack, allows identification of the current rule in errors rstack []*rule @@ -937,7 +939,7 @@ type parser struct { choiceNoMatch string // recovery expression stack, keeps track of the currently available recovery expression, these are traversed in reverse - recoveryStack []map[string]interface{} + recoveryStack []map[string]any } // push a variable set on the vstack. @@ -957,7 +959,7 @@ func (p *parser) pushV() { return } - m = make(map[string]interface{}) + m = make(map[string]any) p.vstack[len(p.vstack)-1] = m } @@ -973,7 +975,7 @@ func (p *parser) popV() { } // push a recovery expression with its labels to the recoveryStack -func (p *parser) pushRecovery(labels []string, expr interface{}) { +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) @@ -982,7 +984,7 @@ func (p *parser) pushRecovery(labels []string, expr interface{}) { p.recoveryStack = p.recoveryStack[:len(p.recoveryStack)+1] } - m := make(map[string]interface{}, len(labels)) + m := make(map[string]any, len(labels)) for _, fl := range labels { m[fl] = expr } @@ -1102,11 +1104,11 @@ func (p *parser) restore(pt savepoint) { // copies of the state to allow the parser to properly restore the state in // the case of backtracking. type Cloner interface { - Clone() interface{} + Clone() any } var statePool = &sync.Pool{ - New: func() interface{} { return make(storeDict) }, + New: func() any { return make(storeDict) }, } func (sd storeDict) Discard() { @@ -1148,7 +1150,7 @@ func (p *parser) sliceFrom(start savepoint) []byte { return p.data[start.position.offset:p.pt.position.offset] } -func (p *parser) getMemoized(node interface{}) (resultTuple, bool) { +func (p *parser) getMemoized(node any) (resultTuple, bool) { if len(p.memo) == 0 { return resultTuple{}, false } @@ -1160,13 +1162,13 @@ func (p *parser) getMemoized(node interface{}) (resultTuple, bool) { return res, ok } -func (p *parser) setMemoized(pt savepoint, node interface{}, tuple resultTuple) { +func (p *parser) setMemoized(pt savepoint, node any, tuple resultTuple) { if p.memo == nil { - p.memo = make(map[int]map[interface{}]resultTuple) + p.memo = make(map[int]map[any]resultTuple) } m := p.memo[pt.offset] if m == nil { - m = make(map[interface{}]resultTuple) + m = make(map[any]resultTuple) p.memo[pt.offset] = m } m[node] = tuple @@ -1180,7 +1182,7 @@ func (p *parser) buildRulesTable(g *grammar) { } // nolint: gocyclo -func (p *parser) parse(g *grammar) (val interface{}, err error) { +func (p *parser) parse(g *grammar) (val any, err error) { if len(g.rules) == 0 { p.addErr(errNoRule) return nil, p.errs.err() @@ -1257,7 +1259,7 @@ func listJoin(list []string, sep string, lastSep string) string { } } -func (p *parser) parseRule(rule *rule) (interface{}, bool) { +func (p *parser) parseRule(rule *rule) (any, bool) { if p.debug { defer p.out(p.in("parseRule " + rule.name)) } @@ -1287,7 +1289,7 @@ func (p *parser) parseRule(rule *rule) (interface{}, bool) { } // nolint: gocyclo -func (p *parser) parseExpr(expr interface{}) (interface{}, bool) { +func (p *parser) parseExpr(expr any) (any, bool) { var pt savepoint if p.memoize { @@ -1304,7 +1306,7 @@ func (p *parser) parseExpr(expr interface{}) (interface{}, bool) { panic(errMaxExprCnt) } - var val interface{} + var val any var ok bool switch expr := expr.(type) { case *actionExpr: @@ -1352,7 +1354,7 @@ func (p *parser) parseExpr(expr interface{}) (interface{}, bool) { return val, ok } -func (p *parser) parseActionExpr(act *actionExpr) (interface{}, bool) { +func (p *parser) parseActionExpr(act *actionExpr) (any, bool) { if p.debug { defer p.out(p.in("parseActionExpr")) } @@ -1377,7 +1379,7 @@ func (p *parser) parseActionExpr(act *actionExpr) (interface{}, bool) { return val, ok } -func (p *parser) parseAndCodeExpr(and *andCodeExpr) (interface{}, bool) { +func (p *parser) parseAndCodeExpr(and *andCodeExpr) (any, bool) { if p.debug { defer p.out(p.in("parseAndCodeExpr")) } @@ -1393,7 +1395,7 @@ func (p *parser) parseAndCodeExpr(and *andCodeExpr) (interface{}, bool) { return nil, ok } -func (p *parser) parseAndExpr(and *andExpr) (interface{}, bool) { +func (p *parser) parseAndExpr(and *andExpr) (any, bool) { if p.debug { defer p.out(p.in("parseAndExpr")) } @@ -1409,7 +1411,7 @@ func (p *parser) parseAndExpr(and *andExpr) (interface{}, bool) { return nil, ok } -func (p *parser) parseAnyMatcher(any *anyMatcher) (interface{}, bool) { +func (p *parser) parseAnyMatcher(any *anyMatcher) (any, bool) { if p.debug { defer p.out(p.in("parseAnyMatcher")) } @@ -1426,7 +1428,7 @@ func (p *parser) parseAnyMatcher(any *anyMatcher) (interface{}, bool) { } // nolint: gocyclo -func (p *parser) parseCharClassMatcher(chr *charClassMatcher) (interface{}, bool) { +func (p *parser) parseCharClassMatcher(chr *charClassMatcher) (any, bool) { if p.debug { defer p.out(p.in("parseCharClassMatcher")) } @@ -1507,7 +1509,7 @@ func (p *parser) incChoiceAltCnt(ch *choiceExpr, altI int) { m[alt]++ } -func (p *parser) parseChoiceExpr(ch *choiceExpr) (interface{}, bool) { +func (p *parser) parseChoiceExpr(ch *choiceExpr) (any, bool) { if p.debug { defer p.out(p.in("parseChoiceExpr")) } @@ -1531,7 +1533,7 @@ func (p *parser) parseChoiceExpr(ch *choiceExpr) (interface{}, bool) { return nil, false } -func (p *parser) parseLabeledExpr(lab *labeledExpr) (interface{}, bool) { +func (p *parser) parseLabeledExpr(lab *labeledExpr) (any, bool) { if p.debug { defer p.out(p.in("parseLabeledExpr")) } @@ -1546,7 +1548,7 @@ func (p *parser) parseLabeledExpr(lab *labeledExpr) (interface{}, bool) { return val, ok } -func (p *parser) parseLitMatcher(lit *litMatcher) (interface{}, bool) { +func (p *parser) parseLitMatcher(lit *litMatcher) (any, bool) { if p.debug { defer p.out(p.in("parseLitMatcher")) } @@ -1568,7 +1570,7 @@ func (p *parser) parseLitMatcher(lit *litMatcher) (interface{}, bool) { return p.sliceFrom(start), true } -func (p *parser) parseNotCodeExpr(not *notCodeExpr) (interface{}, bool) { +func (p *parser) parseNotCodeExpr(not *notCodeExpr) (any, bool) { if p.debug { defer p.out(p.in("parseNotCodeExpr")) } @@ -1584,7 +1586,7 @@ func (p *parser) parseNotCodeExpr(not *notCodeExpr) (interface{}, bool) { return nil, !ok } -func (p *parser) parseNotExpr(not *notExpr) (interface{}, bool) { +func (p *parser) parseNotExpr(not *notExpr) (any, bool) { if p.debug { defer p.out(p.in("parseNotExpr")) } @@ -1602,12 +1604,12 @@ func (p *parser) parseNotExpr(not *notExpr) (interface{}, bool) { return nil, !ok } -func (p *parser) parseOneOrMoreExpr(expr *oneOrMoreExpr) (interface{}, bool) { +func (p *parser) parseOneOrMoreExpr(expr *oneOrMoreExpr) (any, bool) { if p.debug { defer p.out(p.in("parseOneOrMoreExpr")) } - var vals []interface{} + var vals []any for { p.pushV() @@ -1624,7 +1626,7 @@ func (p *parser) parseOneOrMoreExpr(expr *oneOrMoreExpr) (interface{}, bool) { } } -func (p *parser) parseRecoveryExpr(recover *recoveryExpr) (interface{}, bool) { +func (p *parser) parseRecoveryExpr(recover *recoveryExpr) (any, bool) { if p.debug { defer p.out(p.in("parseRecoveryExpr (" + strings.Join(recover.failureLabel, ",") + ")")) } @@ -1636,7 +1638,7 @@ func (p *parser) parseRecoveryExpr(recover *recoveryExpr) (interface{}, bool) { return val, ok } -func (p *parser) parseRuleRefExpr(ref *ruleRefExpr) (interface{}, bool) { +func (p *parser) parseRuleRefExpr(ref *ruleRefExpr) (any, bool) { if p.debug { defer p.out(p.in("parseRuleRefExpr " + ref.name)) } @@ -1653,12 +1655,12 @@ func (p *parser) parseRuleRefExpr(ref *ruleRefExpr) (interface{}, bool) { return p.parseRule(rule) } -func (p *parser) parseSeqExpr(seq *seqExpr) (interface{}, bool) { +func (p *parser) parseSeqExpr(seq *seqExpr) (any, bool) { if p.debug { defer p.out(p.in("parseSeqExpr")) } - vals := make([]interface{}, 0, len(seq.exprs)) + vals := make([]any, 0, len(seq.exprs)) pt := p.pt state := p.cloneState() @@ -1674,7 +1676,7 @@ func (p *parser) parseSeqExpr(seq *seqExpr) (interface{}, bool) { return vals, true } -func (p *parser) parseStateCodeExpr(state *stateCodeExpr) (interface{}, bool) { +func (p *parser) parseStateCodeExpr(state *stateCodeExpr) (any, bool) { if p.debug { defer p.out(p.in("parseStateCodeExpr")) } @@ -1686,7 +1688,7 @@ func (p *parser) parseStateCodeExpr(state *stateCodeExpr) (interface{}, bool) { return nil, true } -func (p *parser) parseThrowExpr(expr *throwExpr) (interface{}, bool) { +func (p *parser) parseThrowExpr(expr *throwExpr) (any, bool) { if p.debug { defer p.out(p.in("parseThrowExpr")) } @@ -1702,12 +1704,12 @@ func (p *parser) parseThrowExpr(expr *throwExpr) (interface{}, bool) { return nil, false } -func (p *parser) parseZeroOrMoreExpr(expr *zeroOrMoreExpr) (interface{}, bool) { +func (p *parser) parseZeroOrMoreExpr(expr *zeroOrMoreExpr) (any, bool) { if p.debug { defer p.out(p.in("parseZeroOrMoreExpr")) } - var vals []interface{} + var vals []any for { p.pushV() @@ -1720,7 +1722,7 @@ func (p *parser) parseZeroOrMoreExpr(expr *zeroOrMoreExpr) (interface{}, bool) { } } -func (p *parser) parseZeroOrOneExpr(expr *zeroOrOneExpr) (interface{}, bool) { +func (p *parser) parseZeroOrOneExpr(expr *zeroOrOneExpr) (any, bool) { if p.debug { defer p.out(p.in("parseZeroOrOneExpr")) } diff --git a/test/goto_state/goto_state.peg b/test/goto_state/goto_state.peg index e6d0a5cc..bb93e967 100644 --- a/test/goto_state/goto_state.peg +++ b/test/goto_state/goto_state.peg @@ -12,16 +12,16 @@ // package asmgotostate -func toIfaceSlice(v interface{}) []interface{} { +func toAnySlice(v any) []any { if v == nil { return nil } - return v.([]interface{}) + return v.([]any) } } Program ← #{ if _, ok := c.state["labelLookup"]; !ok { ll := make(labelLookup); c.state["labelLookup"] = ll; }; return nil } lines:Line* EOF &{ return labelCheck(c) } { - lines0 := toIfaceSlice(lines) + lines0 := toAnySlice(lines) asmLines := make([]Instruction, 0, len(lines0)) for _, line := range lines0 { asmLines = append(asmLines, line.(Instruction)) diff --git a/test/issue_1/issue_1.go b/test/issue_1/issue_1.go index 9fafeb38..66f1b7a0 100644 --- a/test/issue_1/issue_1.go +++ b/test/issue_1/issue_1.go @@ -27,7 +27,7 @@ var g = &grammar{ run: (*parser).callonTableRef1, expr: &seqExpr{ pos: position{line: 5, col: 13, offset: 32}, - exprs: []interface{}{ + exprs: []any{ &labeledExpr{ pos: position{line: 5, col: 13, offset: 32}, label: "database", @@ -35,7 +35,7 @@ var g = &grammar{ pos: position{line: 5, col: 22, offset: 41}, expr: &seqExpr{ pos: position{line: 5, col: 23, offset: 42}, - exprs: []interface{}{ + exprs: []any{ &ruleRefExpr{ pos: position{line: 5, col: 23, offset: 42}, name: "ID", @@ -83,21 +83,21 @@ var g = &grammar{ }, } -func (c *current) onTableRef1(database, table interface{}) (interface{}, error) { +func (c *current) onTableRef1(database, table any) (any, error) { return fmt.Sprintf("%v.%s", database, table), nil } -func (p *parser) callonTableRef1() (interface{}, error) { +func (p *parser) callonTableRef1() (any, error) { stack := p.vstack[len(p.vstack)-1] _ = stack return p.cur.onTableRef1(stack["database"], stack["table"]) } -func (c *current) onID1() (interface{}, error) { +func (c *current) onID1() (any, error) { return c.text, nil } -func (p *parser) callonID1() (interface{}, error) { +func (p *parser) callonID1() (any, error) { stack := p.vstack[len(p.vstack)-1] _ = stack return p.cur.onID1() @@ -241,7 +241,7 @@ func Recover(b bool) Option { // GlobalStore creates an Option to set a key to a certain value in // the globalStore. -func GlobalStore(key string, value interface{}) Option { +func GlobalStore(key string, value any) Option { return func(p *parser) Option { old := p.cur.globalStore[key] p.cur.globalStore[key] = value @@ -251,7 +251,7 @@ func GlobalStore(key string, value interface{}) Option { // InitState creates an Option to set a key to a certain value in // the global "state" store. -func InitState(key string, value interface{}) Option { +func InitState(key string, value any) Option { return func(p *parser) Option { old := p.cur.state[key] p.cur.state[key] = value @@ -260,7 +260,7 @@ func InitState(key string, value interface{}) Option { } // ParseFile parses the file identified by filename. -func ParseFile(filename string, opts ...Option) (i interface{}, err error) { // nolint: deadcode +func ParseFile(filename string, opts ...Option) (i any, err error) { // nolint: deadcode f, err := os.Open(filename) if err != nil { return nil, err @@ -275,7 +275,7 @@ func ParseFile(filename string, opts ...Option) (i interface{}, err error) { // // ParseReader parses the data from r using filename as information in the // error messages. -func ParseReader(filename string, r io.Reader, opts ...Option) (interface{}, error) { // nolint: deadcode +func ParseReader(filename string, r io.Reader, opts ...Option) (any, error) { // nolint: deadcode b, err := io.ReadAll(r) if err != nil { return nil, err @@ -286,7 +286,7 @@ func ParseReader(filename string, r io.Reader, opts ...Option) (interface{}, err // Parse parses the data from b using filename as information in the // error messages. -func Parse(filename string, b []byte, opts ...Option) (interface{}, error) { +func Parse(filename string, b []byte, opts ...Option) (any, error) { return newParser(filename, b, opts...).parse(g) } @@ -324,7 +324,7 @@ type current struct { globalStore storeDict } -type storeDict map[string]interface{} +type storeDict map[string]any // the AST types... @@ -339,34 +339,34 @@ type rule struct { pos position name string displayName string - expr interface{} + expr any } // nolint: structcheck type choiceExpr struct { pos position - alternatives []interface{} + alternatives []any } // nolint: structcheck type actionExpr struct { pos position - expr interface{} - run func(*parser) (interface{}, error) + expr any + run func(*parser) (any, error) } // nolint: structcheck type recoveryExpr struct { pos position - expr interface{} - recoverExpr interface{} + expr any + recoverExpr any failureLabel []string } // nolint: structcheck type seqExpr struct { pos position - exprs []interface{} + exprs []any } // nolint: structcheck @@ -379,20 +379,22 @@ type throwExpr struct { type labeledExpr struct { pos position label string - expr interface{} + expr any } // nolint: structcheck type expr struct { pos position - expr interface{} + expr any } -type andExpr expr // nolint: structcheck -type notExpr expr // nolint: structcheck -type zeroOrOneExpr expr // nolint: structcheck -type zeroOrMoreExpr expr // nolint: structcheck -type oneOrMoreExpr expr // nolint: structcheck +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 { @@ -540,7 +542,7 @@ func (p *parser) setOptions(opts []Option) { // nolint: structcheck,deadcode type resultTuple struct { - v interface{} + v any b bool end savepoint } @@ -586,12 +588,12 @@ type parser struct { memoize bool // memoization table for the packrat algorithm: // map[offset in source] map[expression or rule] {value, match} - memo map[int]map[interface{}]resultTuple + 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]interface{} + vstack []map[string]any // rule stack, allows identification of the current rule in errors rstack []*rule @@ -611,7 +613,7 @@ type parser struct { choiceNoMatch string // recovery expression stack, keeps track of the currently available recovery expression, these are traversed in reverse - recoveryStack []map[string]interface{} + recoveryStack []map[string]any } // push a variable set on the vstack. @@ -631,7 +633,7 @@ func (p *parser) pushV() { return } - m = make(map[string]interface{}) + m = make(map[string]any) p.vstack[len(p.vstack)-1] = m } @@ -647,7 +649,7 @@ func (p *parser) popV() { } // push a recovery expression with its labels to the recoveryStack -func (p *parser) pushRecovery(labels []string, expr interface{}) { +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) @@ -656,7 +658,7 @@ func (p *parser) pushRecovery(labels []string, expr interface{}) { p.recoveryStack = p.recoveryStack[:len(p.recoveryStack)+1] } - m := make(map[string]interface{}, len(labels)) + m := make(map[string]any, len(labels)) for _, fl := range labels { m[fl] = expr } @@ -776,11 +778,11 @@ func (p *parser) restore(pt savepoint) { // copies of the state to allow the parser to properly restore the state in // the case of backtracking. type Cloner interface { - Clone() interface{} + Clone() any } var statePool = &sync.Pool{ - New: func() interface{} { return make(storeDict) }, + New: func() any { return make(storeDict) }, } func (sd storeDict) Discard() { @@ -822,7 +824,7 @@ func (p *parser) sliceFrom(start savepoint) []byte { return p.data[start.position.offset:p.pt.position.offset] } -func (p *parser) getMemoized(node interface{}) (resultTuple, bool) { +func (p *parser) getMemoized(node any) (resultTuple, bool) { if len(p.memo) == 0 { return resultTuple{}, false } @@ -834,13 +836,13 @@ func (p *parser) getMemoized(node interface{}) (resultTuple, bool) { return res, ok } -func (p *parser) setMemoized(pt savepoint, node interface{}, tuple resultTuple) { +func (p *parser) setMemoized(pt savepoint, node any, tuple resultTuple) { if p.memo == nil { - p.memo = make(map[int]map[interface{}]resultTuple) + p.memo = make(map[int]map[any]resultTuple) } m := p.memo[pt.offset] if m == nil { - m = make(map[interface{}]resultTuple) + m = make(map[any]resultTuple) p.memo[pt.offset] = m } m[node] = tuple @@ -854,7 +856,7 @@ func (p *parser) buildRulesTable(g *grammar) { } // nolint: gocyclo -func (p *parser) parse(g *grammar) (val interface{}, err error) { +func (p *parser) parse(g *grammar) (val any, err error) { if len(g.rules) == 0 { p.addErr(errNoRule) return nil, p.errs.err() @@ -931,7 +933,7 @@ func listJoin(list []string, sep string, lastSep string) string { } } -func (p *parser) parseRule(rule *rule) (interface{}, bool) { +func (p *parser) parseRule(rule *rule) (any, bool) { if p.debug { defer p.out(p.in("parseRule " + rule.name)) } @@ -961,7 +963,7 @@ func (p *parser) parseRule(rule *rule) (interface{}, bool) { } // nolint: gocyclo -func (p *parser) parseExpr(expr interface{}) (interface{}, bool) { +func (p *parser) parseExpr(expr any) (any, bool) { var pt savepoint if p.memoize { @@ -978,7 +980,7 @@ func (p *parser) parseExpr(expr interface{}) (interface{}, bool) { panic(errMaxExprCnt) } - var val interface{} + var val any var ok bool switch expr := expr.(type) { case *actionExpr: @@ -1026,7 +1028,7 @@ func (p *parser) parseExpr(expr interface{}) (interface{}, bool) { return val, ok } -func (p *parser) parseActionExpr(act *actionExpr) (interface{}, bool) { +func (p *parser) parseActionExpr(act *actionExpr) (any, bool) { if p.debug { defer p.out(p.in("parseActionExpr")) } @@ -1051,7 +1053,7 @@ func (p *parser) parseActionExpr(act *actionExpr) (interface{}, bool) { return val, ok } -func (p *parser) parseAndCodeExpr(and *andCodeExpr) (interface{}, bool) { +func (p *parser) parseAndCodeExpr(and *andCodeExpr) (any, bool) { if p.debug { defer p.out(p.in("parseAndCodeExpr")) } @@ -1067,7 +1069,7 @@ func (p *parser) parseAndCodeExpr(and *andCodeExpr) (interface{}, bool) { return nil, ok } -func (p *parser) parseAndExpr(and *andExpr) (interface{}, bool) { +func (p *parser) parseAndExpr(and *andExpr) (any, bool) { if p.debug { defer p.out(p.in("parseAndExpr")) } @@ -1083,7 +1085,7 @@ func (p *parser) parseAndExpr(and *andExpr) (interface{}, bool) { return nil, ok } -func (p *parser) parseAnyMatcher(any *anyMatcher) (interface{}, bool) { +func (p *parser) parseAnyMatcher(any *anyMatcher) (any, bool) { if p.debug { defer p.out(p.in("parseAnyMatcher")) } @@ -1100,7 +1102,7 @@ func (p *parser) parseAnyMatcher(any *anyMatcher) (interface{}, bool) { } // nolint: gocyclo -func (p *parser) parseCharClassMatcher(chr *charClassMatcher) (interface{}, bool) { +func (p *parser) parseCharClassMatcher(chr *charClassMatcher) (any, bool) { if p.debug { defer p.out(p.in("parseCharClassMatcher")) } @@ -1181,7 +1183,7 @@ func (p *parser) incChoiceAltCnt(ch *choiceExpr, altI int) { m[alt]++ } -func (p *parser) parseChoiceExpr(ch *choiceExpr) (interface{}, bool) { +func (p *parser) parseChoiceExpr(ch *choiceExpr) (any, bool) { if p.debug { defer p.out(p.in("parseChoiceExpr")) } @@ -1205,7 +1207,7 @@ func (p *parser) parseChoiceExpr(ch *choiceExpr) (interface{}, bool) { return nil, false } -func (p *parser) parseLabeledExpr(lab *labeledExpr) (interface{}, bool) { +func (p *parser) parseLabeledExpr(lab *labeledExpr) (any, bool) { if p.debug { defer p.out(p.in("parseLabeledExpr")) } @@ -1220,7 +1222,7 @@ func (p *parser) parseLabeledExpr(lab *labeledExpr) (interface{}, bool) { return val, ok } -func (p *parser) parseLitMatcher(lit *litMatcher) (interface{}, bool) { +func (p *parser) parseLitMatcher(lit *litMatcher) (any, bool) { if p.debug { defer p.out(p.in("parseLitMatcher")) } @@ -1242,7 +1244,7 @@ func (p *parser) parseLitMatcher(lit *litMatcher) (interface{}, bool) { return p.sliceFrom(start), true } -func (p *parser) parseNotCodeExpr(not *notCodeExpr) (interface{}, bool) { +func (p *parser) parseNotCodeExpr(not *notCodeExpr) (any, bool) { if p.debug { defer p.out(p.in("parseNotCodeExpr")) } @@ -1258,7 +1260,7 @@ func (p *parser) parseNotCodeExpr(not *notCodeExpr) (interface{}, bool) { return nil, !ok } -func (p *parser) parseNotExpr(not *notExpr) (interface{}, bool) { +func (p *parser) parseNotExpr(not *notExpr) (any, bool) { if p.debug { defer p.out(p.in("parseNotExpr")) } @@ -1276,12 +1278,12 @@ func (p *parser) parseNotExpr(not *notExpr) (interface{}, bool) { return nil, !ok } -func (p *parser) parseOneOrMoreExpr(expr *oneOrMoreExpr) (interface{}, bool) { +func (p *parser) parseOneOrMoreExpr(expr *oneOrMoreExpr) (any, bool) { if p.debug { defer p.out(p.in("parseOneOrMoreExpr")) } - var vals []interface{} + var vals []any for { p.pushV() @@ -1298,7 +1300,7 @@ func (p *parser) parseOneOrMoreExpr(expr *oneOrMoreExpr) (interface{}, bool) { } } -func (p *parser) parseRecoveryExpr(recover *recoveryExpr) (interface{}, bool) { +func (p *parser) parseRecoveryExpr(recover *recoveryExpr) (any, bool) { if p.debug { defer p.out(p.in("parseRecoveryExpr (" + strings.Join(recover.failureLabel, ",") + ")")) } @@ -1310,7 +1312,7 @@ func (p *parser) parseRecoveryExpr(recover *recoveryExpr) (interface{}, bool) { return val, ok } -func (p *parser) parseRuleRefExpr(ref *ruleRefExpr) (interface{}, bool) { +func (p *parser) parseRuleRefExpr(ref *ruleRefExpr) (any, bool) { if p.debug { defer p.out(p.in("parseRuleRefExpr " + ref.name)) } @@ -1327,12 +1329,12 @@ func (p *parser) parseRuleRefExpr(ref *ruleRefExpr) (interface{}, bool) { return p.parseRule(rule) } -func (p *parser) parseSeqExpr(seq *seqExpr) (interface{}, bool) { +func (p *parser) parseSeqExpr(seq *seqExpr) (any, bool) { if p.debug { defer p.out(p.in("parseSeqExpr")) } - vals := make([]interface{}, 0, len(seq.exprs)) + vals := make([]any, 0, len(seq.exprs)) pt := p.pt state := p.cloneState() @@ -1348,7 +1350,7 @@ func (p *parser) parseSeqExpr(seq *seqExpr) (interface{}, bool) { return vals, true } -func (p *parser) parseStateCodeExpr(state *stateCodeExpr) (interface{}, bool) { +func (p *parser) parseStateCodeExpr(state *stateCodeExpr) (any, bool) { if p.debug { defer p.out(p.in("parseStateCodeExpr")) } @@ -1360,7 +1362,7 @@ func (p *parser) parseStateCodeExpr(state *stateCodeExpr) (interface{}, bool) { return nil, true } -func (p *parser) parseThrowExpr(expr *throwExpr) (interface{}, bool) { +func (p *parser) parseThrowExpr(expr *throwExpr) (any, bool) { if p.debug { defer p.out(p.in("parseThrowExpr")) } @@ -1376,12 +1378,12 @@ func (p *parser) parseThrowExpr(expr *throwExpr) (interface{}, bool) { return nil, false } -func (p *parser) parseZeroOrMoreExpr(expr *zeroOrMoreExpr) (interface{}, bool) { +func (p *parser) parseZeroOrMoreExpr(expr *zeroOrMoreExpr) (any, bool) { if p.debug { defer p.out(p.in("parseZeroOrMoreExpr")) } - var vals []interface{} + var vals []any for { p.pushV() @@ -1394,7 +1396,7 @@ func (p *parser) parseZeroOrMoreExpr(expr *zeroOrMoreExpr) (interface{}, bool) { } } -func (p *parser) parseZeroOrOneExpr(expr *zeroOrOneExpr) (interface{}, bool) { +func (p *parser) parseZeroOrOneExpr(expr *zeroOrOneExpr) (any, bool) { if p.debug { defer p.out(p.in("parseZeroOrOneExpr")) } diff --git a/test/issue_1/issue_1_test.go b/test/issue_1/issue_1_test.go index f1310e57..748dd2ca 100644 --- a/test/issue_1/issue_1_test.go +++ b/test/issue_1/issue_1_test.go @@ -16,10 +16,10 @@ func TestRunIssue1(t *testing.T) { // Since go1.7: The Method and NumMethod methods of Type and Value no longer return or count unexported methods. func TestIssue1(t *testing.T) { - var cur interface{} = ¤t{} + var cur any = ¤t{} _, ok := cur.(interface { - onTableRef1(interface{}, interface{}) (interface{}, error) - onID1() (interface{}, error) + onTableRef1(any, any) (any, error) + onID1() (any, error) }) if !ok { t.Errorf("want *current to have expected methods") diff --git a/test/issue_18/issue_18.go b/test/issue_18/issue_18.go index 60cbb3ce..ba7e9e7c 100644 --- a/test/issue_18/issue_18.go +++ b/test/issue_18/issue_18.go @@ -49,7 +49,7 @@ var g = &grammar{ pos: position{line: 32, col: 1, offset: 321}, expr: &seqExpr{ pos: position{line: 32, col: 12, offset: 332}, - exprs: []interface{}{ + exprs: []any{ &ruleRefExpr{ pos: position{line: 32, col: 12, offset: 332}, name: "_", @@ -58,7 +58,7 @@ var g = &grammar{ pos: position{line: 32, col: 14, offset: 334}, expr: &seqExpr{ pos: position{line: 32, col: 15, offset: 335}, - exprs: []interface{}{ + exprs: []any{ &ruleRefExpr{ pos: position{line: 32, col: 15, offset: 335}, name: "X", @@ -258,7 +258,7 @@ func Recover(b bool) Option { // GlobalStore creates an Option to set a key to a certain value in // the globalStore. -func GlobalStore(key string, value interface{}) Option { +func GlobalStore(key string, value any) Option { return func(p *parser) Option { old := p.cur.globalStore[key] p.cur.globalStore[key] = value @@ -268,7 +268,7 @@ func GlobalStore(key string, value interface{}) Option { // InitState creates an Option to set a key to a certain value in // the global "state" store. -func InitState(key string, value interface{}) Option { +func InitState(key string, value any) Option { return func(p *parser) Option { old := p.cur.state[key] p.cur.state[key] = value @@ -277,7 +277,7 @@ func InitState(key string, value interface{}) Option { } // ParseFile parses the file identified by filename. -func ParseFile(filename string, opts ...Option) (i interface{}, err error) { // nolint: deadcode +func ParseFile(filename string, opts ...Option) (i any, err error) { // nolint: deadcode f, err := os.Open(filename) if err != nil { return nil, err @@ -292,7 +292,7 @@ func ParseFile(filename string, opts ...Option) (i interface{}, err error) { // // ParseReader parses the data from r using filename as information in the // error messages. -func ParseReader(filename string, r io.Reader, opts ...Option) (interface{}, error) { // nolint: deadcode +func ParseReader(filename string, r io.Reader, opts ...Option) (any, error) { // nolint: deadcode b, err := io.ReadAll(r) if err != nil { return nil, err @@ -303,7 +303,7 @@ func ParseReader(filename string, r io.Reader, opts ...Option) (interface{}, err // Parse parses the data from b using filename as information in the // error messages. -func Parse(filename string, b []byte, opts ...Option) (interface{}, error) { +func Parse(filename string, b []byte, opts ...Option) (any, error) { return newParser(filename, b, opts...).parse(g) } @@ -341,7 +341,7 @@ type current struct { globalStore storeDict } -type storeDict map[string]interface{} +type storeDict map[string]any // the AST types... @@ -356,34 +356,34 @@ type rule struct { pos position name string displayName string - expr interface{} + expr any } // nolint: structcheck type choiceExpr struct { pos position - alternatives []interface{} + alternatives []any } // nolint: structcheck type actionExpr struct { pos position - expr interface{} - run func(*parser) (interface{}, error) + expr any + run func(*parser) (any, error) } // nolint: structcheck type recoveryExpr struct { pos position - expr interface{} - recoverExpr interface{} + expr any + recoverExpr any failureLabel []string } // nolint: structcheck type seqExpr struct { pos position - exprs []interface{} + exprs []any } // nolint: structcheck @@ -396,20 +396,22 @@ type throwExpr struct { type labeledExpr struct { pos position label string - expr interface{} + expr any } // nolint: structcheck type expr struct { pos position - expr interface{} + expr any } -type andExpr expr // nolint: structcheck -type notExpr expr // nolint: structcheck -type zeroOrOneExpr expr // nolint: structcheck -type zeroOrMoreExpr expr // nolint: structcheck -type oneOrMoreExpr expr // nolint: structcheck +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 { @@ -557,7 +559,7 @@ func (p *parser) setOptions(opts []Option) { // nolint: structcheck,deadcode type resultTuple struct { - v interface{} + v any b bool end savepoint } @@ -603,12 +605,12 @@ type parser struct { memoize bool // memoization table for the packrat algorithm: // map[offset in source] map[expression or rule] {value, match} - memo map[int]map[interface{}]resultTuple + 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]interface{} + vstack []map[string]any // rule stack, allows identification of the current rule in errors rstack []*rule @@ -628,7 +630,7 @@ type parser struct { choiceNoMatch string // recovery expression stack, keeps track of the currently available recovery expression, these are traversed in reverse - recoveryStack []map[string]interface{} + recoveryStack []map[string]any } // push a variable set on the vstack. @@ -648,7 +650,7 @@ func (p *parser) pushV() { return } - m = make(map[string]interface{}) + m = make(map[string]any) p.vstack[len(p.vstack)-1] = m } @@ -664,7 +666,7 @@ func (p *parser) popV() { } // push a recovery expression with its labels to the recoveryStack -func (p *parser) pushRecovery(labels []string, expr interface{}) { +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) @@ -673,7 +675,7 @@ func (p *parser) pushRecovery(labels []string, expr interface{}) { p.recoveryStack = p.recoveryStack[:len(p.recoveryStack)+1] } - m := make(map[string]interface{}, len(labels)) + m := make(map[string]any, len(labels)) for _, fl := range labels { m[fl] = expr } @@ -793,11 +795,11 @@ func (p *parser) restore(pt savepoint) { // copies of the state to allow the parser to properly restore the state in // the case of backtracking. type Cloner interface { - Clone() interface{} + Clone() any } var statePool = &sync.Pool{ - New: func() interface{} { return make(storeDict) }, + New: func() any { return make(storeDict) }, } func (sd storeDict) Discard() { @@ -839,7 +841,7 @@ func (p *parser) sliceFrom(start savepoint) []byte { return p.data[start.position.offset:p.pt.position.offset] } -func (p *parser) getMemoized(node interface{}) (resultTuple, bool) { +func (p *parser) getMemoized(node any) (resultTuple, bool) { if len(p.memo) == 0 { return resultTuple{}, false } @@ -851,13 +853,13 @@ func (p *parser) getMemoized(node interface{}) (resultTuple, bool) { return res, ok } -func (p *parser) setMemoized(pt savepoint, node interface{}, tuple resultTuple) { +func (p *parser) setMemoized(pt savepoint, node any, tuple resultTuple) { if p.memo == nil { - p.memo = make(map[int]map[interface{}]resultTuple) + p.memo = make(map[int]map[any]resultTuple) } m := p.memo[pt.offset] if m == nil { - m = make(map[interface{}]resultTuple) + m = make(map[any]resultTuple) p.memo[pt.offset] = m } m[node] = tuple @@ -871,7 +873,7 @@ func (p *parser) buildRulesTable(g *grammar) { } // nolint: gocyclo -func (p *parser) parse(g *grammar) (val interface{}, err error) { +func (p *parser) parse(g *grammar) (val any, err error) { if len(g.rules) == 0 { p.addErr(errNoRule) return nil, p.errs.err() @@ -948,7 +950,7 @@ func listJoin(list []string, sep string, lastSep string) string { } } -func (p *parser) parseRule(rule *rule) (interface{}, bool) { +func (p *parser) parseRule(rule *rule) (any, bool) { if p.debug { defer p.out(p.in("parseRule " + rule.name)) } @@ -978,7 +980,7 @@ func (p *parser) parseRule(rule *rule) (interface{}, bool) { } // nolint: gocyclo -func (p *parser) parseExpr(expr interface{}) (interface{}, bool) { +func (p *parser) parseExpr(expr any) (any, bool) { var pt savepoint if p.memoize { @@ -995,7 +997,7 @@ func (p *parser) parseExpr(expr interface{}) (interface{}, bool) { panic(errMaxExprCnt) } - var val interface{} + var val any var ok bool switch expr := expr.(type) { case *actionExpr: @@ -1043,7 +1045,7 @@ func (p *parser) parseExpr(expr interface{}) (interface{}, bool) { return val, ok } -func (p *parser) parseActionExpr(act *actionExpr) (interface{}, bool) { +func (p *parser) parseActionExpr(act *actionExpr) (any, bool) { if p.debug { defer p.out(p.in("parseActionExpr")) } @@ -1068,7 +1070,7 @@ func (p *parser) parseActionExpr(act *actionExpr) (interface{}, bool) { return val, ok } -func (p *parser) parseAndCodeExpr(and *andCodeExpr) (interface{}, bool) { +func (p *parser) parseAndCodeExpr(and *andCodeExpr) (any, bool) { if p.debug { defer p.out(p.in("parseAndCodeExpr")) } @@ -1084,7 +1086,7 @@ func (p *parser) parseAndCodeExpr(and *andCodeExpr) (interface{}, bool) { return nil, ok } -func (p *parser) parseAndExpr(and *andExpr) (interface{}, bool) { +func (p *parser) parseAndExpr(and *andExpr) (any, bool) { if p.debug { defer p.out(p.in("parseAndExpr")) } @@ -1100,7 +1102,7 @@ func (p *parser) parseAndExpr(and *andExpr) (interface{}, bool) { return nil, ok } -func (p *parser) parseAnyMatcher(any *anyMatcher) (interface{}, bool) { +func (p *parser) parseAnyMatcher(any *anyMatcher) (any, bool) { if p.debug { defer p.out(p.in("parseAnyMatcher")) } @@ -1117,7 +1119,7 @@ func (p *parser) parseAnyMatcher(any *anyMatcher) (interface{}, bool) { } // nolint: gocyclo -func (p *parser) parseCharClassMatcher(chr *charClassMatcher) (interface{}, bool) { +func (p *parser) parseCharClassMatcher(chr *charClassMatcher) (any, bool) { if p.debug { defer p.out(p.in("parseCharClassMatcher")) } @@ -1198,7 +1200,7 @@ func (p *parser) incChoiceAltCnt(ch *choiceExpr, altI int) { m[alt]++ } -func (p *parser) parseChoiceExpr(ch *choiceExpr) (interface{}, bool) { +func (p *parser) parseChoiceExpr(ch *choiceExpr) (any, bool) { if p.debug { defer p.out(p.in("parseChoiceExpr")) } @@ -1222,7 +1224,7 @@ func (p *parser) parseChoiceExpr(ch *choiceExpr) (interface{}, bool) { return nil, false } -func (p *parser) parseLabeledExpr(lab *labeledExpr) (interface{}, bool) { +func (p *parser) parseLabeledExpr(lab *labeledExpr) (any, bool) { if p.debug { defer p.out(p.in("parseLabeledExpr")) } @@ -1237,7 +1239,7 @@ func (p *parser) parseLabeledExpr(lab *labeledExpr) (interface{}, bool) { return val, ok } -func (p *parser) parseLitMatcher(lit *litMatcher) (interface{}, bool) { +func (p *parser) parseLitMatcher(lit *litMatcher) (any, bool) { if p.debug { defer p.out(p.in("parseLitMatcher")) } @@ -1259,7 +1261,7 @@ func (p *parser) parseLitMatcher(lit *litMatcher) (interface{}, bool) { return p.sliceFrom(start), true } -func (p *parser) parseNotCodeExpr(not *notCodeExpr) (interface{}, bool) { +func (p *parser) parseNotCodeExpr(not *notCodeExpr) (any, bool) { if p.debug { defer p.out(p.in("parseNotCodeExpr")) } @@ -1275,7 +1277,7 @@ func (p *parser) parseNotCodeExpr(not *notCodeExpr) (interface{}, bool) { return nil, !ok } -func (p *parser) parseNotExpr(not *notExpr) (interface{}, bool) { +func (p *parser) parseNotExpr(not *notExpr) (any, bool) { if p.debug { defer p.out(p.in("parseNotExpr")) } @@ -1293,12 +1295,12 @@ func (p *parser) parseNotExpr(not *notExpr) (interface{}, bool) { return nil, !ok } -func (p *parser) parseOneOrMoreExpr(expr *oneOrMoreExpr) (interface{}, bool) { +func (p *parser) parseOneOrMoreExpr(expr *oneOrMoreExpr) (any, bool) { if p.debug { defer p.out(p.in("parseOneOrMoreExpr")) } - var vals []interface{} + var vals []any for { p.pushV() @@ -1315,7 +1317,7 @@ func (p *parser) parseOneOrMoreExpr(expr *oneOrMoreExpr) (interface{}, bool) { } } -func (p *parser) parseRecoveryExpr(recover *recoveryExpr) (interface{}, bool) { +func (p *parser) parseRecoveryExpr(recover *recoveryExpr) (any, bool) { if p.debug { defer p.out(p.in("parseRecoveryExpr (" + strings.Join(recover.failureLabel, ",") + ")")) } @@ -1327,7 +1329,7 @@ func (p *parser) parseRecoveryExpr(recover *recoveryExpr) (interface{}, bool) { return val, ok } -func (p *parser) parseRuleRefExpr(ref *ruleRefExpr) (interface{}, bool) { +func (p *parser) parseRuleRefExpr(ref *ruleRefExpr) (any, bool) { if p.debug { defer p.out(p.in("parseRuleRefExpr " + ref.name)) } @@ -1344,12 +1346,12 @@ func (p *parser) parseRuleRefExpr(ref *ruleRefExpr) (interface{}, bool) { return p.parseRule(rule) } -func (p *parser) parseSeqExpr(seq *seqExpr) (interface{}, bool) { +func (p *parser) parseSeqExpr(seq *seqExpr) (any, bool) { if p.debug { defer p.out(p.in("parseSeqExpr")) } - vals := make([]interface{}, 0, len(seq.exprs)) + vals := make([]any, 0, len(seq.exprs)) pt := p.pt state := p.cloneState() @@ -1365,7 +1367,7 @@ func (p *parser) parseSeqExpr(seq *seqExpr) (interface{}, bool) { return vals, true } -func (p *parser) parseStateCodeExpr(state *stateCodeExpr) (interface{}, bool) { +func (p *parser) parseStateCodeExpr(state *stateCodeExpr) (any, bool) { if p.debug { defer p.out(p.in("parseStateCodeExpr")) } @@ -1377,7 +1379,7 @@ func (p *parser) parseStateCodeExpr(state *stateCodeExpr) (interface{}, bool) { return nil, true } -func (p *parser) parseThrowExpr(expr *throwExpr) (interface{}, bool) { +func (p *parser) parseThrowExpr(expr *throwExpr) (any, bool) { if p.debug { defer p.out(p.in("parseThrowExpr")) } @@ -1393,12 +1395,12 @@ func (p *parser) parseThrowExpr(expr *throwExpr) (interface{}, bool) { return nil, false } -func (p *parser) parseZeroOrMoreExpr(expr *zeroOrMoreExpr) (interface{}, bool) { +func (p *parser) parseZeroOrMoreExpr(expr *zeroOrMoreExpr) (any, bool) { if p.debug { defer p.out(p.in("parseZeroOrMoreExpr")) } - var vals []interface{} + var vals []any for { p.pushV() @@ -1411,7 +1413,7 @@ func (p *parser) parseZeroOrMoreExpr(expr *zeroOrMoreExpr) (interface{}, bool) { } } -func (p *parser) parseZeroOrOneExpr(expr *zeroOrOneExpr) (interface{}, bool) { +func (p *parser) parseZeroOrOneExpr(expr *zeroOrOneExpr) (any, bool) { if p.debug { defer p.out(p.in("parseZeroOrOneExpr")) } diff --git a/test/issue_65/issue_65.go b/test/issue_65/issue_65.go index deb811f0..b41c24f8 100644 --- a/test/issue_65/issue_65.go +++ b/test/issue_65/issue_65.go @@ -24,7 +24,7 @@ var g = &grammar{ pos: position{line: 5, col: 1, offset: 23}, expr: &seqExpr{ pos: position{line: 5, col: 10, offset: 32}, - exprs: []interface{}{ + exprs: []any{ &ruleRefExpr{ pos: position{line: 5, col: 10, offset: 32}, name: "List", @@ -43,7 +43,7 @@ var g = &grammar{ pos: position{line: 6, col: 1, offset: 40}, expr: &seqExpr{ pos: position{line: 6, col: 9, offset: 48}, - exprs: []interface{}{ + exprs: []any{ &ruleRefExpr{ pos: position{line: 6, col: 9, offset: 48}, name: "X", @@ -52,7 +52,7 @@ var g = &grammar{ pos: position{line: 6, col: 11, offset: 50}, expr: &seqExpr{ pos: position{line: 6, col: 13, offset: 52}, - exprs: []interface{}{ + exprs: []any{ &litMatcher{ pos: position{line: 6, col: 13, offset: 52}, val: ",", @@ -74,7 +74,7 @@ var g = &grammar{ pos: position{line: 7, col: 1, offset: 61}, expr: &seqExpr{ pos: position{line: 7, col: 6, offset: 66}, - exprs: []interface{}{ + exprs: []any{ &litMatcher{ pos: position{line: 7, col: 6, offset: 66}, val: "X", @@ -108,12 +108,12 @@ var g = &grammar{ }, } -func (c *current) onY1() (interface{}, error) { +func (c *current) onY1() (any, error) { return nil, errors.New("YY") } -func (p *parser) callonY1() (interface{}, error) { +func (p *parser) callonY1() (any, error) { stack := p.vstack[len(p.vstack)-1] _ = stack return p.cur.onY1() @@ -257,7 +257,7 @@ func Recover(b bool) Option { // GlobalStore creates an Option to set a key to a certain value in // the globalStore. -func GlobalStore(key string, value interface{}) Option { +func GlobalStore(key string, value any) Option { return func(p *parser) Option { old := p.cur.globalStore[key] p.cur.globalStore[key] = value @@ -267,7 +267,7 @@ func GlobalStore(key string, value interface{}) Option { // InitState creates an Option to set a key to a certain value in // the global "state" store. -func InitState(key string, value interface{}) Option { +func InitState(key string, value any) Option { return func(p *parser) Option { old := p.cur.state[key] p.cur.state[key] = value @@ -276,7 +276,7 @@ func InitState(key string, value interface{}) Option { } // ParseFile parses the file identified by filename. -func ParseFile(filename string, opts ...Option) (i interface{}, err error) { // nolint: deadcode +func ParseFile(filename string, opts ...Option) (i any, err error) { // nolint: deadcode f, err := os.Open(filename) if err != nil { return nil, err @@ -291,7 +291,7 @@ func ParseFile(filename string, opts ...Option) (i interface{}, err error) { // // ParseReader parses the data from r using filename as information in the // error messages. -func ParseReader(filename string, r io.Reader, opts ...Option) (interface{}, error) { // nolint: deadcode +func ParseReader(filename string, r io.Reader, opts ...Option) (any, error) { // nolint: deadcode b, err := io.ReadAll(r) if err != nil { return nil, err @@ -302,7 +302,7 @@ func ParseReader(filename string, r io.Reader, opts ...Option) (interface{}, err // Parse parses the data from b using filename as information in the // error messages. -func Parse(filename string, b []byte, opts ...Option) (interface{}, error) { +func Parse(filename string, b []byte, opts ...Option) (any, error) { return newParser(filename, b, opts...).parse(g) } @@ -340,7 +340,7 @@ type current struct { globalStore storeDict } -type storeDict map[string]interface{} +type storeDict map[string]any // the AST types... @@ -355,34 +355,34 @@ type rule struct { pos position name string displayName string - expr interface{} + expr any } // nolint: structcheck type choiceExpr struct { pos position - alternatives []interface{} + alternatives []any } // nolint: structcheck type actionExpr struct { pos position - expr interface{} - run func(*parser) (interface{}, error) + expr any + run func(*parser) (any, error) } // nolint: structcheck type recoveryExpr struct { pos position - expr interface{} - recoverExpr interface{} + expr any + recoverExpr any failureLabel []string } // nolint: structcheck type seqExpr struct { pos position - exprs []interface{} + exprs []any } // nolint: structcheck @@ -395,20 +395,22 @@ type throwExpr struct { type labeledExpr struct { pos position label string - expr interface{} + expr any } // nolint: structcheck type expr struct { pos position - expr interface{} + expr any } -type andExpr expr // nolint: structcheck -type notExpr expr // nolint: structcheck -type zeroOrOneExpr expr // nolint: structcheck -type zeroOrMoreExpr expr // nolint: structcheck -type oneOrMoreExpr expr // nolint: structcheck +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 { @@ -556,7 +558,7 @@ func (p *parser) setOptions(opts []Option) { // nolint: structcheck,deadcode type resultTuple struct { - v interface{} + v any b bool end savepoint } @@ -602,12 +604,12 @@ type parser struct { memoize bool // memoization table for the packrat algorithm: // map[offset in source] map[expression or rule] {value, match} - memo map[int]map[interface{}]resultTuple + 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]interface{} + vstack []map[string]any // rule stack, allows identification of the current rule in errors rstack []*rule @@ -627,7 +629,7 @@ type parser struct { choiceNoMatch string // recovery expression stack, keeps track of the currently available recovery expression, these are traversed in reverse - recoveryStack []map[string]interface{} + recoveryStack []map[string]any } // push a variable set on the vstack. @@ -647,7 +649,7 @@ func (p *parser) pushV() { return } - m = make(map[string]interface{}) + m = make(map[string]any) p.vstack[len(p.vstack)-1] = m } @@ -663,7 +665,7 @@ func (p *parser) popV() { } // push a recovery expression with its labels to the recoveryStack -func (p *parser) pushRecovery(labels []string, expr interface{}) { +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) @@ -672,7 +674,7 @@ func (p *parser) pushRecovery(labels []string, expr interface{}) { p.recoveryStack = p.recoveryStack[:len(p.recoveryStack)+1] } - m := make(map[string]interface{}, len(labels)) + m := make(map[string]any, len(labels)) for _, fl := range labels { m[fl] = expr } @@ -792,11 +794,11 @@ func (p *parser) restore(pt savepoint) { // copies of the state to allow the parser to properly restore the state in // the case of backtracking. type Cloner interface { - Clone() interface{} + Clone() any } var statePool = &sync.Pool{ - New: func() interface{} { return make(storeDict) }, + New: func() any { return make(storeDict) }, } func (sd storeDict) Discard() { @@ -838,7 +840,7 @@ func (p *parser) sliceFrom(start savepoint) []byte { return p.data[start.position.offset:p.pt.position.offset] } -func (p *parser) getMemoized(node interface{}) (resultTuple, bool) { +func (p *parser) getMemoized(node any) (resultTuple, bool) { if len(p.memo) == 0 { return resultTuple{}, false } @@ -850,13 +852,13 @@ func (p *parser) getMemoized(node interface{}) (resultTuple, bool) { return res, ok } -func (p *parser) setMemoized(pt savepoint, node interface{}, tuple resultTuple) { +func (p *parser) setMemoized(pt savepoint, node any, tuple resultTuple) { if p.memo == nil { - p.memo = make(map[int]map[interface{}]resultTuple) + p.memo = make(map[int]map[any]resultTuple) } m := p.memo[pt.offset] if m == nil { - m = make(map[interface{}]resultTuple) + m = make(map[any]resultTuple) p.memo[pt.offset] = m } m[node] = tuple @@ -870,7 +872,7 @@ func (p *parser) buildRulesTable(g *grammar) { } // nolint: gocyclo -func (p *parser) parse(g *grammar) (val interface{}, err error) { +func (p *parser) parse(g *grammar) (val any, err error) { if len(g.rules) == 0 { p.addErr(errNoRule) return nil, p.errs.err() @@ -947,7 +949,7 @@ func listJoin(list []string, sep string, lastSep string) string { } } -func (p *parser) parseRule(rule *rule) (interface{}, bool) { +func (p *parser) parseRule(rule *rule) (any, bool) { if p.debug { defer p.out(p.in("parseRule " + rule.name)) } @@ -977,7 +979,7 @@ func (p *parser) parseRule(rule *rule) (interface{}, bool) { } // nolint: gocyclo -func (p *parser) parseExpr(expr interface{}) (interface{}, bool) { +func (p *parser) parseExpr(expr any) (any, bool) { var pt savepoint if p.memoize { @@ -994,7 +996,7 @@ func (p *parser) parseExpr(expr interface{}) (interface{}, bool) { panic(errMaxExprCnt) } - var val interface{} + var val any var ok bool switch expr := expr.(type) { case *actionExpr: @@ -1042,7 +1044,7 @@ func (p *parser) parseExpr(expr interface{}) (interface{}, bool) { return val, ok } -func (p *parser) parseActionExpr(act *actionExpr) (interface{}, bool) { +func (p *parser) parseActionExpr(act *actionExpr) (any, bool) { if p.debug { defer p.out(p.in("parseActionExpr")) } @@ -1067,7 +1069,7 @@ func (p *parser) parseActionExpr(act *actionExpr) (interface{}, bool) { return val, ok } -func (p *parser) parseAndCodeExpr(and *andCodeExpr) (interface{}, bool) { +func (p *parser) parseAndCodeExpr(and *andCodeExpr) (any, bool) { if p.debug { defer p.out(p.in("parseAndCodeExpr")) } @@ -1083,7 +1085,7 @@ func (p *parser) parseAndCodeExpr(and *andCodeExpr) (interface{}, bool) { return nil, ok } -func (p *parser) parseAndExpr(and *andExpr) (interface{}, bool) { +func (p *parser) parseAndExpr(and *andExpr) (any, bool) { if p.debug { defer p.out(p.in("parseAndExpr")) } @@ -1099,7 +1101,7 @@ func (p *parser) parseAndExpr(and *andExpr) (interface{}, bool) { return nil, ok } -func (p *parser) parseAnyMatcher(any *anyMatcher) (interface{}, bool) { +func (p *parser) parseAnyMatcher(any *anyMatcher) (any, bool) { if p.debug { defer p.out(p.in("parseAnyMatcher")) } @@ -1116,7 +1118,7 @@ func (p *parser) parseAnyMatcher(any *anyMatcher) (interface{}, bool) { } // nolint: gocyclo -func (p *parser) parseCharClassMatcher(chr *charClassMatcher) (interface{}, bool) { +func (p *parser) parseCharClassMatcher(chr *charClassMatcher) (any, bool) { if p.debug { defer p.out(p.in("parseCharClassMatcher")) } @@ -1197,7 +1199,7 @@ func (p *parser) incChoiceAltCnt(ch *choiceExpr, altI int) { m[alt]++ } -func (p *parser) parseChoiceExpr(ch *choiceExpr) (interface{}, bool) { +func (p *parser) parseChoiceExpr(ch *choiceExpr) (any, bool) { if p.debug { defer p.out(p.in("parseChoiceExpr")) } @@ -1221,7 +1223,7 @@ func (p *parser) parseChoiceExpr(ch *choiceExpr) (interface{}, bool) { return nil, false } -func (p *parser) parseLabeledExpr(lab *labeledExpr) (interface{}, bool) { +func (p *parser) parseLabeledExpr(lab *labeledExpr) (any, bool) { if p.debug { defer p.out(p.in("parseLabeledExpr")) } @@ -1236,7 +1238,7 @@ func (p *parser) parseLabeledExpr(lab *labeledExpr) (interface{}, bool) { return val, ok } -func (p *parser) parseLitMatcher(lit *litMatcher) (interface{}, bool) { +func (p *parser) parseLitMatcher(lit *litMatcher) (any, bool) { if p.debug { defer p.out(p.in("parseLitMatcher")) } @@ -1258,7 +1260,7 @@ func (p *parser) parseLitMatcher(lit *litMatcher) (interface{}, bool) { return p.sliceFrom(start), true } -func (p *parser) parseNotCodeExpr(not *notCodeExpr) (interface{}, bool) { +func (p *parser) parseNotCodeExpr(not *notCodeExpr) (any, bool) { if p.debug { defer p.out(p.in("parseNotCodeExpr")) } @@ -1274,7 +1276,7 @@ func (p *parser) parseNotCodeExpr(not *notCodeExpr) (interface{}, bool) { return nil, !ok } -func (p *parser) parseNotExpr(not *notExpr) (interface{}, bool) { +func (p *parser) parseNotExpr(not *notExpr) (any, bool) { if p.debug { defer p.out(p.in("parseNotExpr")) } @@ -1292,12 +1294,12 @@ func (p *parser) parseNotExpr(not *notExpr) (interface{}, bool) { return nil, !ok } -func (p *parser) parseOneOrMoreExpr(expr *oneOrMoreExpr) (interface{}, bool) { +func (p *parser) parseOneOrMoreExpr(expr *oneOrMoreExpr) (any, bool) { if p.debug { defer p.out(p.in("parseOneOrMoreExpr")) } - var vals []interface{} + var vals []any for { p.pushV() @@ -1314,7 +1316,7 @@ func (p *parser) parseOneOrMoreExpr(expr *oneOrMoreExpr) (interface{}, bool) { } } -func (p *parser) parseRecoveryExpr(recover *recoveryExpr) (interface{}, bool) { +func (p *parser) parseRecoveryExpr(recover *recoveryExpr) (any, bool) { if p.debug { defer p.out(p.in("parseRecoveryExpr (" + strings.Join(recover.failureLabel, ",") + ")")) } @@ -1326,7 +1328,7 @@ func (p *parser) parseRecoveryExpr(recover *recoveryExpr) (interface{}, bool) { return val, ok } -func (p *parser) parseRuleRefExpr(ref *ruleRefExpr) (interface{}, bool) { +func (p *parser) parseRuleRefExpr(ref *ruleRefExpr) (any, bool) { if p.debug { defer p.out(p.in("parseRuleRefExpr " + ref.name)) } @@ -1343,12 +1345,12 @@ func (p *parser) parseRuleRefExpr(ref *ruleRefExpr) (interface{}, bool) { return p.parseRule(rule) } -func (p *parser) parseSeqExpr(seq *seqExpr) (interface{}, bool) { +func (p *parser) parseSeqExpr(seq *seqExpr) (any, bool) { if p.debug { defer p.out(p.in("parseSeqExpr")) } - vals := make([]interface{}, 0, len(seq.exprs)) + vals := make([]any, 0, len(seq.exprs)) pt := p.pt state := p.cloneState() @@ -1364,7 +1366,7 @@ func (p *parser) parseSeqExpr(seq *seqExpr) (interface{}, bool) { return vals, true } -func (p *parser) parseStateCodeExpr(state *stateCodeExpr) (interface{}, bool) { +func (p *parser) parseStateCodeExpr(state *stateCodeExpr) (any, bool) { if p.debug { defer p.out(p.in("parseStateCodeExpr")) } @@ -1376,7 +1378,7 @@ func (p *parser) parseStateCodeExpr(state *stateCodeExpr) (interface{}, bool) { return nil, true } -func (p *parser) parseThrowExpr(expr *throwExpr) (interface{}, bool) { +func (p *parser) parseThrowExpr(expr *throwExpr) (any, bool) { if p.debug { defer p.out(p.in("parseThrowExpr")) } @@ -1392,12 +1394,12 @@ func (p *parser) parseThrowExpr(expr *throwExpr) (interface{}, bool) { return nil, false } -func (p *parser) parseZeroOrMoreExpr(expr *zeroOrMoreExpr) (interface{}, bool) { +func (p *parser) parseZeroOrMoreExpr(expr *zeroOrMoreExpr) (any, bool) { if p.debug { defer p.out(p.in("parseZeroOrMoreExpr")) } - var vals []interface{} + var vals []any for { p.pushV() @@ -1410,7 +1412,7 @@ func (p *parser) parseZeroOrMoreExpr(expr *zeroOrMoreExpr) (interface{}, bool) { } } -func (p *parser) parseZeroOrOneExpr(expr *zeroOrOneExpr) (interface{}, bool) { +func (p *parser) parseZeroOrOneExpr(expr *zeroOrOneExpr) (any, bool) { if p.debug { defer p.out(p.in("parseZeroOrOneExpr")) } diff --git a/test/issue_65/issue_65_test.go b/test/issue_65/issue_65_test.go index 60bd3434..36d10372 100644 --- a/test/issue_65/issue_65_test.go +++ b/test/issue_65/issue_65_test.go @@ -22,7 +22,7 @@ func TestOptimizeGrammar(t *testing.T) { {"X,XY,X", "YY"}, } - type parser func(string) (interface{}, error) + type parser func(string) (any, error) parsers := map[string]parser{ "standard": parseStd, "optimized": parseOpt, @@ -47,14 +47,14 @@ func TestOptimizeGrammar(t *testing.T) { } } -func parseStd(input string) (interface{}, error) { +func parseStd(input string) (any, error) { return Parse("", []byte(input)) } -func parseOpt(input string) (interface{}, error) { +func parseOpt(input string) (any, error) { return optimized.Parse("", []byte(input)) } -func parseOptGrammar(input string) (interface{}, error) { +func parseOptGrammar(input string) (any, error) { return optimizedgrammar.Parse("", []byte(input)) } diff --git a/test/issue_65/optimized-grammar/issue_65.go b/test/issue_65/optimized-grammar/issue_65.go index 1398b2eb..2cbacf1b 100644 --- a/test/issue_65/optimized-grammar/issue_65.go +++ b/test/issue_65/optimized-grammar/issue_65.go @@ -24,7 +24,7 @@ var g = &grammar{ pos: position{line: 5, col: 1, offset: 23}, expr: &seqExpr{ pos: position{line: 5, col: 10, offset: 32}, - exprs: []interface{}{ + exprs: []any{ &litMatcher{ pos: position{line: 7, col: 6, offset: 66}, val: "X", @@ -48,7 +48,7 @@ var g = &grammar{ pos: position{line: 6, col: 11, offset: 50}, expr: &seqExpr{ pos: position{line: 6, col: 13, offset: 52}, - exprs: []interface{}{ + exprs: []any{ &litMatcher{ pos: position{line: 6, col: 13, offset: 52}, val: ",X", @@ -83,23 +83,23 @@ var g = &grammar{ }, } -func (c *current) onStart4() (interface{}, error) { +func (c *current) onStart4() (any, error) { return nil, errors.New("YY") } -func (p *parser) callonStart4() (interface{}, error) { +func (p *parser) callonStart4() (any, error) { stack := p.vstack[len(p.vstack)-1] _ = stack return p.cur.onStart4() } -func (c *current) onStart10() (interface{}, error) { +func (c *current) onStart10() (any, error) { return nil, errors.New("YY") } -func (p *parser) callonStart10() (interface{}, error) { +func (p *parser) callonStart10() (any, error) { stack := p.vstack[len(p.vstack)-1] _ = stack return p.cur.onStart10() @@ -243,7 +243,7 @@ func Recover(b bool) Option { // GlobalStore creates an Option to set a key to a certain value in // the globalStore. -func GlobalStore(key string, value interface{}) Option { +func GlobalStore(key string, value any) Option { return func(p *parser) Option { old := p.cur.globalStore[key] p.cur.globalStore[key] = value @@ -253,7 +253,7 @@ func GlobalStore(key string, value interface{}) Option { // InitState creates an Option to set a key to a certain value in // the global "state" store. -func InitState(key string, value interface{}) Option { +func InitState(key string, value any) Option { return func(p *parser) Option { old := p.cur.state[key] p.cur.state[key] = value @@ -262,7 +262,7 @@ func InitState(key string, value interface{}) Option { } // ParseFile parses the file identified by filename. -func ParseFile(filename string, opts ...Option) (i interface{}, err error) { // nolint: deadcode +func ParseFile(filename string, opts ...Option) (i any, err error) { // nolint: deadcode f, err := os.Open(filename) if err != nil { return nil, err @@ -277,7 +277,7 @@ func ParseFile(filename string, opts ...Option) (i interface{}, err error) { // // ParseReader parses the data from r using filename as information in the // error messages. -func ParseReader(filename string, r io.Reader, opts ...Option) (interface{}, error) { // nolint: deadcode +func ParseReader(filename string, r io.Reader, opts ...Option) (any, error) { // nolint: deadcode b, err := io.ReadAll(r) if err != nil { return nil, err @@ -288,7 +288,7 @@ func ParseReader(filename string, r io.Reader, opts ...Option) (interface{}, err // Parse parses the data from b using filename as information in the // error messages. -func Parse(filename string, b []byte, opts ...Option) (interface{}, error) { +func Parse(filename string, b []byte, opts ...Option) (any, error) { return newParser(filename, b, opts...).parse(g) } @@ -326,7 +326,7 @@ type current struct { globalStore storeDict } -type storeDict map[string]interface{} +type storeDict map[string]any // the AST types... @@ -341,34 +341,34 @@ type rule struct { pos position name string displayName string - expr interface{} + expr any } // nolint: structcheck type choiceExpr struct { pos position - alternatives []interface{} + alternatives []any } // nolint: structcheck type actionExpr struct { pos position - expr interface{} - run func(*parser) (interface{}, error) + expr any + run func(*parser) (any, error) } // nolint: structcheck type recoveryExpr struct { pos position - expr interface{} - recoverExpr interface{} + expr any + recoverExpr any failureLabel []string } // nolint: structcheck type seqExpr struct { pos position - exprs []interface{} + exprs []any } // nolint: structcheck @@ -381,20 +381,22 @@ type throwExpr struct { type labeledExpr struct { pos position label string - expr interface{} + expr any } // nolint: structcheck type expr struct { pos position - expr interface{} + expr any } -type andExpr expr // nolint: structcheck -type notExpr expr // nolint: structcheck -type zeroOrOneExpr expr // nolint: structcheck -type zeroOrMoreExpr expr // nolint: structcheck -type oneOrMoreExpr expr // nolint: structcheck +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 { @@ -542,7 +544,7 @@ func (p *parser) setOptions(opts []Option) { // nolint: structcheck,deadcode type resultTuple struct { - v interface{} + v any b bool end savepoint } @@ -588,12 +590,12 @@ type parser struct { memoize bool // memoization table for the packrat algorithm: // map[offset in source] map[expression or rule] {value, match} - memo map[int]map[interface{}]resultTuple + 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]interface{} + vstack []map[string]any // rule stack, allows identification of the current rule in errors rstack []*rule @@ -613,7 +615,7 @@ type parser struct { choiceNoMatch string // recovery expression stack, keeps track of the currently available recovery expression, these are traversed in reverse - recoveryStack []map[string]interface{} + recoveryStack []map[string]any } // push a variable set on the vstack. @@ -633,7 +635,7 @@ func (p *parser) pushV() { return } - m = make(map[string]interface{}) + m = make(map[string]any) p.vstack[len(p.vstack)-1] = m } @@ -649,7 +651,7 @@ func (p *parser) popV() { } // push a recovery expression with its labels to the recoveryStack -func (p *parser) pushRecovery(labels []string, expr interface{}) { +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) @@ -658,7 +660,7 @@ func (p *parser) pushRecovery(labels []string, expr interface{}) { p.recoveryStack = p.recoveryStack[:len(p.recoveryStack)+1] } - m := make(map[string]interface{}, len(labels)) + m := make(map[string]any, len(labels)) for _, fl := range labels { m[fl] = expr } @@ -778,11 +780,11 @@ func (p *parser) restore(pt savepoint) { // copies of the state to allow the parser to properly restore the state in // the case of backtracking. type Cloner interface { - Clone() interface{} + Clone() any } var statePool = &sync.Pool{ - New: func() interface{} { return make(storeDict) }, + New: func() any { return make(storeDict) }, } func (sd storeDict) Discard() { @@ -824,7 +826,7 @@ func (p *parser) sliceFrom(start savepoint) []byte { return p.data[start.position.offset:p.pt.position.offset] } -func (p *parser) getMemoized(node interface{}) (resultTuple, bool) { +func (p *parser) getMemoized(node any) (resultTuple, bool) { if len(p.memo) == 0 { return resultTuple{}, false } @@ -836,13 +838,13 @@ func (p *parser) getMemoized(node interface{}) (resultTuple, bool) { return res, ok } -func (p *parser) setMemoized(pt savepoint, node interface{}, tuple resultTuple) { +func (p *parser) setMemoized(pt savepoint, node any, tuple resultTuple) { if p.memo == nil { - p.memo = make(map[int]map[interface{}]resultTuple) + p.memo = make(map[int]map[any]resultTuple) } m := p.memo[pt.offset] if m == nil { - m = make(map[interface{}]resultTuple) + m = make(map[any]resultTuple) p.memo[pt.offset] = m } m[node] = tuple @@ -856,7 +858,7 @@ func (p *parser) buildRulesTable(g *grammar) { } // nolint: gocyclo -func (p *parser) parse(g *grammar) (val interface{}, err error) { +func (p *parser) parse(g *grammar) (val any, err error) { if len(g.rules) == 0 { p.addErr(errNoRule) return nil, p.errs.err() @@ -933,7 +935,7 @@ func listJoin(list []string, sep string, lastSep string) string { } } -func (p *parser) parseRule(rule *rule) (interface{}, bool) { +func (p *parser) parseRule(rule *rule) (any, bool) { if p.debug { defer p.out(p.in("parseRule " + rule.name)) } @@ -963,7 +965,7 @@ func (p *parser) parseRule(rule *rule) (interface{}, bool) { } // nolint: gocyclo -func (p *parser) parseExpr(expr interface{}) (interface{}, bool) { +func (p *parser) parseExpr(expr any) (any, bool) { var pt savepoint if p.memoize { @@ -980,7 +982,7 @@ func (p *parser) parseExpr(expr interface{}) (interface{}, bool) { panic(errMaxExprCnt) } - var val interface{} + var val any var ok bool switch expr := expr.(type) { case *actionExpr: @@ -1028,7 +1030,7 @@ func (p *parser) parseExpr(expr interface{}) (interface{}, bool) { return val, ok } -func (p *parser) parseActionExpr(act *actionExpr) (interface{}, bool) { +func (p *parser) parseActionExpr(act *actionExpr) (any, bool) { if p.debug { defer p.out(p.in("parseActionExpr")) } @@ -1053,7 +1055,7 @@ func (p *parser) parseActionExpr(act *actionExpr) (interface{}, bool) { return val, ok } -func (p *parser) parseAndCodeExpr(and *andCodeExpr) (interface{}, bool) { +func (p *parser) parseAndCodeExpr(and *andCodeExpr) (any, bool) { if p.debug { defer p.out(p.in("parseAndCodeExpr")) } @@ -1069,7 +1071,7 @@ func (p *parser) parseAndCodeExpr(and *andCodeExpr) (interface{}, bool) { return nil, ok } -func (p *parser) parseAndExpr(and *andExpr) (interface{}, bool) { +func (p *parser) parseAndExpr(and *andExpr) (any, bool) { if p.debug { defer p.out(p.in("parseAndExpr")) } @@ -1085,7 +1087,7 @@ func (p *parser) parseAndExpr(and *andExpr) (interface{}, bool) { return nil, ok } -func (p *parser) parseAnyMatcher(any *anyMatcher) (interface{}, bool) { +func (p *parser) parseAnyMatcher(any *anyMatcher) (any, bool) { if p.debug { defer p.out(p.in("parseAnyMatcher")) } @@ -1102,7 +1104,7 @@ func (p *parser) parseAnyMatcher(any *anyMatcher) (interface{}, bool) { } // nolint: gocyclo -func (p *parser) parseCharClassMatcher(chr *charClassMatcher) (interface{}, bool) { +func (p *parser) parseCharClassMatcher(chr *charClassMatcher) (any, bool) { if p.debug { defer p.out(p.in("parseCharClassMatcher")) } @@ -1183,7 +1185,7 @@ func (p *parser) incChoiceAltCnt(ch *choiceExpr, altI int) { m[alt]++ } -func (p *parser) parseChoiceExpr(ch *choiceExpr) (interface{}, bool) { +func (p *parser) parseChoiceExpr(ch *choiceExpr) (any, bool) { if p.debug { defer p.out(p.in("parseChoiceExpr")) } @@ -1207,7 +1209,7 @@ func (p *parser) parseChoiceExpr(ch *choiceExpr) (interface{}, bool) { return nil, false } -func (p *parser) parseLabeledExpr(lab *labeledExpr) (interface{}, bool) { +func (p *parser) parseLabeledExpr(lab *labeledExpr) (any, bool) { if p.debug { defer p.out(p.in("parseLabeledExpr")) } @@ -1222,7 +1224,7 @@ func (p *parser) parseLabeledExpr(lab *labeledExpr) (interface{}, bool) { return val, ok } -func (p *parser) parseLitMatcher(lit *litMatcher) (interface{}, bool) { +func (p *parser) parseLitMatcher(lit *litMatcher) (any, bool) { if p.debug { defer p.out(p.in("parseLitMatcher")) } @@ -1244,7 +1246,7 @@ func (p *parser) parseLitMatcher(lit *litMatcher) (interface{}, bool) { return p.sliceFrom(start), true } -func (p *parser) parseNotCodeExpr(not *notCodeExpr) (interface{}, bool) { +func (p *parser) parseNotCodeExpr(not *notCodeExpr) (any, bool) { if p.debug { defer p.out(p.in("parseNotCodeExpr")) } @@ -1260,7 +1262,7 @@ func (p *parser) parseNotCodeExpr(not *notCodeExpr) (interface{}, bool) { return nil, !ok } -func (p *parser) parseNotExpr(not *notExpr) (interface{}, bool) { +func (p *parser) parseNotExpr(not *notExpr) (any, bool) { if p.debug { defer p.out(p.in("parseNotExpr")) } @@ -1278,12 +1280,12 @@ func (p *parser) parseNotExpr(not *notExpr) (interface{}, bool) { return nil, !ok } -func (p *parser) parseOneOrMoreExpr(expr *oneOrMoreExpr) (interface{}, bool) { +func (p *parser) parseOneOrMoreExpr(expr *oneOrMoreExpr) (any, bool) { if p.debug { defer p.out(p.in("parseOneOrMoreExpr")) } - var vals []interface{} + var vals []any for { p.pushV() @@ -1300,7 +1302,7 @@ func (p *parser) parseOneOrMoreExpr(expr *oneOrMoreExpr) (interface{}, bool) { } } -func (p *parser) parseRecoveryExpr(recover *recoveryExpr) (interface{}, bool) { +func (p *parser) parseRecoveryExpr(recover *recoveryExpr) (any, bool) { if p.debug { defer p.out(p.in("parseRecoveryExpr (" + strings.Join(recover.failureLabel, ",") + ")")) } @@ -1312,7 +1314,7 @@ func (p *parser) parseRecoveryExpr(recover *recoveryExpr) (interface{}, bool) { return val, ok } -func (p *parser) parseRuleRefExpr(ref *ruleRefExpr) (interface{}, bool) { +func (p *parser) parseRuleRefExpr(ref *ruleRefExpr) (any, bool) { if p.debug { defer p.out(p.in("parseRuleRefExpr " + ref.name)) } @@ -1329,12 +1331,12 @@ func (p *parser) parseRuleRefExpr(ref *ruleRefExpr) (interface{}, bool) { return p.parseRule(rule) } -func (p *parser) parseSeqExpr(seq *seqExpr) (interface{}, bool) { +func (p *parser) parseSeqExpr(seq *seqExpr) (any, bool) { if p.debug { defer p.out(p.in("parseSeqExpr")) } - vals := make([]interface{}, 0, len(seq.exprs)) + vals := make([]any, 0, len(seq.exprs)) pt := p.pt state := p.cloneState() @@ -1350,7 +1352,7 @@ func (p *parser) parseSeqExpr(seq *seqExpr) (interface{}, bool) { return vals, true } -func (p *parser) parseStateCodeExpr(state *stateCodeExpr) (interface{}, bool) { +func (p *parser) parseStateCodeExpr(state *stateCodeExpr) (any, bool) { if p.debug { defer p.out(p.in("parseStateCodeExpr")) } @@ -1362,7 +1364,7 @@ func (p *parser) parseStateCodeExpr(state *stateCodeExpr) (interface{}, bool) { return nil, true } -func (p *parser) parseThrowExpr(expr *throwExpr) (interface{}, bool) { +func (p *parser) parseThrowExpr(expr *throwExpr) (any, bool) { if p.debug { defer p.out(p.in("parseThrowExpr")) } @@ -1378,12 +1380,12 @@ func (p *parser) parseThrowExpr(expr *throwExpr) (interface{}, bool) { return nil, false } -func (p *parser) parseZeroOrMoreExpr(expr *zeroOrMoreExpr) (interface{}, bool) { +func (p *parser) parseZeroOrMoreExpr(expr *zeroOrMoreExpr) (any, bool) { if p.debug { defer p.out(p.in("parseZeroOrMoreExpr")) } - var vals []interface{} + var vals []any for { p.pushV() @@ -1396,7 +1398,7 @@ func (p *parser) parseZeroOrMoreExpr(expr *zeroOrMoreExpr) (interface{}, bool) { } } -func (p *parser) parseZeroOrOneExpr(expr *zeroOrOneExpr) (interface{}, bool) { +func (p *parser) parseZeroOrOneExpr(expr *zeroOrOneExpr) (any, bool) { if p.debug { defer p.out(p.in("parseZeroOrOneExpr")) } diff --git a/test/issue_65/optimized/issue_65.go b/test/issue_65/optimized/issue_65.go index a25490f3..81f882b3 100644 --- a/test/issue_65/optimized/issue_65.go +++ b/test/issue_65/optimized/issue_65.go @@ -23,7 +23,7 @@ var g = &grammar{ pos: position{line: 5, col: 1, offset: 23}, expr: &seqExpr{ pos: position{line: 5, col: 10, offset: 32}, - exprs: []interface{}{ + exprs: []any{ &ruleRefExpr{ pos: position{line: 5, col: 10, offset: 32}, name: "List", @@ -42,7 +42,7 @@ var g = &grammar{ pos: position{line: 6, col: 1, offset: 40}, expr: &seqExpr{ pos: position{line: 6, col: 9, offset: 48}, - exprs: []interface{}{ + exprs: []any{ &ruleRefExpr{ pos: position{line: 6, col: 9, offset: 48}, name: "X", @@ -51,7 +51,7 @@ var g = &grammar{ pos: position{line: 6, col: 11, offset: 50}, expr: &seqExpr{ pos: position{line: 6, col: 13, offset: 52}, - exprs: []interface{}{ + exprs: []any{ &litMatcher{ pos: position{line: 6, col: 13, offset: 52}, val: ",", @@ -73,7 +73,7 @@ var g = &grammar{ pos: position{line: 7, col: 1, offset: 61}, expr: &seqExpr{ pos: position{line: 7, col: 6, offset: 66}, - exprs: []interface{}{ + exprs: []any{ &litMatcher{ pos: position{line: 7, col: 6, offset: 66}, val: "X", @@ -107,12 +107,12 @@ var g = &grammar{ }, } -func (c *current) onY1() (interface{}, error) { +func (c *current) onY1() (any, error) { return nil, errors.New("YY") } -func (p *parser) callonY1() (interface{}, error) { +func (p *parser) callonY1() (any, error) { stack := p.vstack[len(p.vstack)-1] _ = stack return p.cur.onY1() @@ -200,7 +200,7 @@ func Recover(b bool) Option { // GlobalStore creates an Option to set a key to a certain value in // the globalStore. -func GlobalStore(key string, value interface{}) Option { +func GlobalStore(key string, value any) Option { return func(p *parser) Option { old := p.cur.globalStore[key] p.cur.globalStore[key] = value @@ -209,7 +209,7 @@ func GlobalStore(key string, value interface{}) Option { } // ParseFile parses the file identified by filename. -func ParseFile(filename string, opts ...Option) (i interface{}, err error) { // nolint: deadcode +func ParseFile(filename string, opts ...Option) (i any, err error) { // nolint: deadcode f, err := os.Open(filename) if err != nil { return nil, err @@ -224,7 +224,7 @@ func ParseFile(filename string, opts ...Option) (i interface{}, err error) { // // ParseReader parses the data from r using filename as information in the // error messages. -func ParseReader(filename string, r io.Reader, opts ...Option) (interface{}, error) { // nolint: deadcode +func ParseReader(filename string, r io.Reader, opts ...Option) (any, error) { // nolint: deadcode b, err := io.ReadAll(r) if err != nil { return nil, err @@ -235,7 +235,7 @@ func ParseReader(filename string, r io.Reader, opts ...Option) (interface{}, err // Parse parses the data from b using filename as information in the // error messages. -func Parse(filename string, b []byte, opts ...Option) (interface{}, error) { +func Parse(filename string, b []byte, opts ...Option) (any, error) { return newParser(filename, b, opts...).parse(g) } @@ -268,7 +268,7 @@ type current struct { globalStore storeDict } -type storeDict map[string]interface{} +type storeDict map[string]any // the AST types... @@ -283,34 +283,34 @@ type rule struct { pos position name string displayName string - expr interface{} + expr any } // nolint: structcheck type choiceExpr struct { pos position - alternatives []interface{} + alternatives []any } // nolint: structcheck type actionExpr struct { pos position - expr interface{} - run func(*parser) (interface{}, error) + expr any + run func(*parser) (any, error) } // nolint: structcheck type recoveryExpr struct { pos position - expr interface{} - recoverExpr interface{} + expr any + recoverExpr any failureLabel []string } // nolint: structcheck type seqExpr struct { pos position - exprs []interface{} + exprs []any } // nolint: structcheck @@ -323,20 +323,22 @@ type throwExpr struct { type labeledExpr struct { pos position label string - expr interface{} + expr any } // nolint: structcheck type expr struct { pos position - expr interface{} + expr any } -type andExpr expr // nolint: structcheck -type notExpr expr // nolint: structcheck -type zeroOrOneExpr expr // nolint: structcheck -type zeroOrMoreExpr expr // nolint: structcheck -type oneOrMoreExpr expr // nolint: structcheck +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 { @@ -477,7 +479,7 @@ func (p *parser) setOptions(opts []Option) { // nolint: structcheck,deadcode type resultTuple struct { - v interface{} + v any b bool end savepoint } @@ -522,7 +524,7 @@ type parser struct { // rules table, maps the rule identifier to the rule node rules map[string]*rule // variables stack, map of label to value - vstack []map[string]interface{} + vstack []map[string]any // rule stack, allows identification of the current rule in errors rstack []*rule @@ -542,7 +544,7 @@ type parser struct { choiceNoMatch string // recovery expression stack, keeps track of the currently available recovery expression, these are traversed in reverse - recoveryStack []map[string]interface{} + recoveryStack []map[string]any } // push a variable set on the vstack. @@ -562,7 +564,7 @@ func (p *parser) pushV() { return } - m = make(map[string]interface{}) + m = make(map[string]any) p.vstack[len(p.vstack)-1] = m } @@ -578,7 +580,7 @@ func (p *parser) popV() { } // push a recovery expression with its labels to the recoveryStack -func (p *parser) pushRecovery(labels []string, expr interface{}) { +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) @@ -587,7 +589,7 @@ func (p *parser) pushRecovery(labels []string, expr interface{}) { p.recoveryStack = p.recoveryStack[:len(p.recoveryStack)+1] } - m := make(map[string]interface{}, len(labels)) + m := make(map[string]any, len(labels)) for _, fl := range labels { m[fl] = expr } @@ -689,7 +691,7 @@ func (p *parser) buildRulesTable(g *grammar) { } // nolint: gocyclo -func (p *parser) parse(g *grammar) (val interface{}, err error) { +func (p *parser) parse(g *grammar) (val any, err error) { if len(g.rules) == 0 { p.addErr(errNoRule) return nil, p.errs.err() @@ -763,7 +765,7 @@ func listJoin(list []string, sep string, lastSep string) string { } } -func (p *parser) parseRule(rule *rule) (interface{}, bool) { +func (p *parser) parseRule(rule *rule) (any, bool) { p.rstack = append(p.rstack, rule) p.pushV() val, ok := p.parseExpr(rule.expr) @@ -773,14 +775,14 @@ func (p *parser) parseRule(rule *rule) (interface{}, bool) { } // nolint: gocyclo -func (p *parser) parseExpr(expr interface{}) (interface{}, bool) { +func (p *parser) parseExpr(expr any) (any, bool) { p.ExprCnt++ if p.ExprCnt > p.maxExprCnt { panic(errMaxExprCnt) } - var val interface{} + var val any var ok bool switch expr := expr.(type) { case *actionExpr: @@ -823,7 +825,7 @@ func (p *parser) parseExpr(expr interface{}) (interface{}, bool) { return val, ok } -func (p *parser) parseActionExpr(act *actionExpr) (interface{}, bool) { +func (p *parser) parseActionExpr(act *actionExpr) (any, bool) { start := p.pt val, ok := p.parseExpr(act.expr) if ok { @@ -839,7 +841,7 @@ func (p *parser) parseActionExpr(act *actionExpr) (interface{}, bool) { return val, ok } -func (p *parser) parseAndCodeExpr(and *andCodeExpr) (interface{}, bool) { +func (p *parser) parseAndCodeExpr(and *andCodeExpr) (any, bool) { ok, err := and.run(p) if err != nil { @@ -849,7 +851,7 @@ func (p *parser) parseAndCodeExpr(and *andCodeExpr) (interface{}, bool) { return nil, ok } -func (p *parser) parseAndExpr(and *andExpr) (interface{}, bool) { +func (p *parser) parseAndExpr(and *andExpr) (any, bool) { pt := p.pt p.pushV() _, ok := p.parseExpr(and.expr) @@ -859,7 +861,7 @@ func (p *parser) parseAndExpr(and *andExpr) (interface{}, bool) { return nil, ok } -func (p *parser) parseAnyMatcher(any *anyMatcher) (interface{}, bool) { +func (p *parser) parseAnyMatcher(any *anyMatcher) (any, bool) { if p.pt.rn == utf8.RuneError && p.pt.w == 0 { // EOF - see utf8.DecodeRune p.failAt(false, p.pt.position, ".") @@ -872,7 +874,7 @@ func (p *parser) parseAnyMatcher(any *anyMatcher) (interface{}, bool) { } // nolint: gocyclo -func (p *parser) parseCharClassMatcher(chr *charClassMatcher) (interface{}, bool) { +func (p *parser) parseCharClassMatcher(chr *charClassMatcher) (any, bool) { cur := p.pt.rn start := p.pt @@ -944,7 +946,7 @@ func (p *parser) parseCharClassMatcher(chr *charClassMatcher) (interface{}, bool return nil, false } -func (p *parser) parseChoiceExpr(ch *choiceExpr) (interface{}, bool) { +func (p *parser) parseChoiceExpr(ch *choiceExpr) (any, bool) { for altI, alt := range ch.alternatives { // dummy assignment to prevent compile error if optimized _ = altI @@ -959,7 +961,7 @@ func (p *parser) parseChoiceExpr(ch *choiceExpr) (interface{}, bool) { return nil, false } -func (p *parser) parseLabeledExpr(lab *labeledExpr) (interface{}, bool) { +func (p *parser) parseLabeledExpr(lab *labeledExpr) (any, bool) { p.pushV() val, ok := p.parseExpr(lab.expr) p.popV() @@ -970,7 +972,7 @@ func (p *parser) parseLabeledExpr(lab *labeledExpr) (interface{}, bool) { return val, ok } -func (p *parser) parseLitMatcher(lit *litMatcher) (interface{}, bool) { +func (p *parser) parseLitMatcher(lit *litMatcher) (any, bool) { start := p.pt for _, want := range lit.val { cur := p.pt.rn @@ -988,7 +990,7 @@ func (p *parser) parseLitMatcher(lit *litMatcher) (interface{}, bool) { return p.sliceFrom(start), true } -func (p *parser) parseNotCodeExpr(not *notCodeExpr) (interface{}, bool) { +func (p *parser) parseNotCodeExpr(not *notCodeExpr) (any, bool) { ok, err := not.run(p) if err != nil { p.addErr(err) @@ -997,7 +999,7 @@ func (p *parser) parseNotCodeExpr(not *notCodeExpr) (interface{}, bool) { return nil, !ok } -func (p *parser) parseNotExpr(not *notExpr) (interface{}, bool) { +func (p *parser) parseNotExpr(not *notExpr) (any, bool) { pt := p.pt p.pushV() p.maxFailInvertExpected = !p.maxFailInvertExpected @@ -1009,8 +1011,8 @@ func (p *parser) parseNotExpr(not *notExpr) (interface{}, bool) { return nil, !ok } -func (p *parser) parseOneOrMoreExpr(expr *oneOrMoreExpr) (interface{}, bool) { - var vals []interface{} +func (p *parser) parseOneOrMoreExpr(expr *oneOrMoreExpr) (any, bool) { + var vals []any for { p.pushV() @@ -1027,7 +1029,7 @@ func (p *parser) parseOneOrMoreExpr(expr *oneOrMoreExpr) (interface{}, bool) { } } -func (p *parser) parseRecoveryExpr(recover *recoveryExpr) (interface{}, bool) { +func (p *parser) parseRecoveryExpr(recover *recoveryExpr) (any, bool) { p.pushRecovery(recover.failureLabel, recover.recoverExpr) val, ok := p.parseExpr(recover.expr) @@ -1036,7 +1038,7 @@ func (p *parser) parseRecoveryExpr(recover *recoveryExpr) (interface{}, bool) { return val, ok } -func (p *parser) parseRuleRefExpr(ref *ruleRefExpr) (interface{}, bool) { +func (p *parser) parseRuleRefExpr(ref *ruleRefExpr) (any, bool) { if ref.name == "" { panic(fmt.Sprintf("%s: invalid rule: missing name", ref.pos)) } @@ -1049,8 +1051,8 @@ func (p *parser) parseRuleRefExpr(ref *ruleRefExpr) (interface{}, bool) { return p.parseRule(rule) } -func (p *parser) parseSeqExpr(seq *seqExpr) (interface{}, bool) { - vals := make([]interface{}, 0, len(seq.exprs)) +func (p *parser) parseSeqExpr(seq *seqExpr) (any, bool) { + vals := make([]any, 0, len(seq.exprs)) pt := p.pt for _, expr := range seq.exprs { @@ -1064,7 +1066,7 @@ func (p *parser) parseSeqExpr(seq *seqExpr) (interface{}, bool) { return vals, true } -func (p *parser) parseThrowExpr(expr *throwExpr) (interface{}, bool) { +func (p *parser) parseThrowExpr(expr *throwExpr) (any, bool) { for i := len(p.recoveryStack) - 1; i >= 0; i-- { if recoverExpr, ok := p.recoveryStack[i][expr.label]; ok { @@ -1077,8 +1079,8 @@ func (p *parser) parseThrowExpr(expr *throwExpr) (interface{}, bool) { return nil, false } -func (p *parser) parseZeroOrMoreExpr(expr *zeroOrMoreExpr) (interface{}, bool) { - var vals []interface{} +func (p *parser) parseZeroOrMoreExpr(expr *zeroOrMoreExpr) (any, bool) { + var vals []any for { p.pushV() @@ -1091,7 +1093,7 @@ func (p *parser) parseZeroOrMoreExpr(expr *zeroOrMoreExpr) (interface{}, bool) { } } -func (p *parser) parseZeroOrOneExpr(expr *zeroOrOneExpr) (interface{}, bool) { +func (p *parser) parseZeroOrOneExpr(expr *zeroOrOneExpr) (any, bool) { p.pushV() val, _ := p.parseExpr(expr.expr) p.popV() diff --git a/test/issue_70/issue_70.go b/test/issue_70/issue_70.go index 72616c64..4e2b1c3d 100644 --- a/test/issue_70/issue_70.go +++ b/test/issue_70/issue_70.go @@ -27,7 +27,7 @@ var g = &grammar{ run: (*parser).callonX1, expr: &seqExpr{ pos: position{line: 5, col: 5, offset: 27}, - exprs: []interface{}{ + exprs: []any{ &labeledExpr{ pos: position{line: 5, col: 5, offset: 27}, label: "a", @@ -74,21 +74,21 @@ var g = &grammar{ }, } -func (c *current) onX1(a interface{}) (interface{}, error) { +func (c *current) onX1(a any) (any, error) { return a, nil } -func (p *parser) callonX1() (interface{}, error) { +func (p *parser) callonX1() (any, error) { stack := p.vstack[len(p.vstack)-1] _ = stack return p.cur.onX1(stack["a"]) } -func (c *current) onZ2() (interface{}, error) { +func (c *current) onZ2() (any, error) { return "Z", nil } -func (p *parser) callonZ2() (interface{}, error) { +func (p *parser) callonZ2() (any, error) { stack := p.vstack[len(p.vstack)-1] _ = stack return p.cur.onZ2() @@ -232,7 +232,7 @@ func Recover(b bool) Option { // GlobalStore creates an Option to set a key to a certain value in // the globalStore. -func GlobalStore(key string, value interface{}) Option { +func GlobalStore(key string, value any) Option { return func(p *parser) Option { old := p.cur.globalStore[key] p.cur.globalStore[key] = value @@ -242,7 +242,7 @@ func GlobalStore(key string, value interface{}) Option { // InitState creates an Option to set a key to a certain value in // the global "state" store. -func InitState(key string, value interface{}) Option { +func InitState(key string, value any) Option { return func(p *parser) Option { old := p.cur.state[key] p.cur.state[key] = value @@ -251,7 +251,7 @@ func InitState(key string, value interface{}) Option { } // ParseFile parses the file identified by filename. -func ParseFile(filename string, opts ...Option) (i interface{}, err error) { // nolint: deadcode +func ParseFile(filename string, opts ...Option) (i any, err error) { // nolint: deadcode f, err := os.Open(filename) if err != nil { return nil, err @@ -266,7 +266,7 @@ func ParseFile(filename string, opts ...Option) (i interface{}, err error) { // // ParseReader parses the data from r using filename as information in the // error messages. -func ParseReader(filename string, r io.Reader, opts ...Option) (interface{}, error) { // nolint: deadcode +func ParseReader(filename string, r io.Reader, opts ...Option) (any, error) { // nolint: deadcode b, err := io.ReadAll(r) if err != nil { return nil, err @@ -277,7 +277,7 @@ func ParseReader(filename string, r io.Reader, opts ...Option) (interface{}, err // Parse parses the data from b using filename as information in the // error messages. -func Parse(filename string, b []byte, opts ...Option) (interface{}, error) { +func Parse(filename string, b []byte, opts ...Option) (any, error) { return newParser(filename, b, opts...).parse(g) } @@ -315,7 +315,7 @@ type current struct { globalStore storeDict } -type storeDict map[string]interface{} +type storeDict map[string]any // the AST types... @@ -330,34 +330,34 @@ type rule struct { pos position name string displayName string - expr interface{} + expr any } // nolint: structcheck type choiceExpr struct { pos position - alternatives []interface{} + alternatives []any } // nolint: structcheck type actionExpr struct { pos position - expr interface{} - run func(*parser) (interface{}, error) + expr any + run func(*parser) (any, error) } // nolint: structcheck type recoveryExpr struct { pos position - expr interface{} - recoverExpr interface{} + expr any + recoverExpr any failureLabel []string } // nolint: structcheck type seqExpr struct { pos position - exprs []interface{} + exprs []any } // nolint: structcheck @@ -370,20 +370,22 @@ type throwExpr struct { type labeledExpr struct { pos position label string - expr interface{} + expr any } // nolint: structcheck type expr struct { pos position - expr interface{} + expr any } -type andExpr expr // nolint: structcheck -type notExpr expr // nolint: structcheck -type zeroOrOneExpr expr // nolint: structcheck -type zeroOrMoreExpr expr // nolint: structcheck -type oneOrMoreExpr expr // nolint: structcheck +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 { @@ -531,7 +533,7 @@ func (p *parser) setOptions(opts []Option) { // nolint: structcheck,deadcode type resultTuple struct { - v interface{} + v any b bool end savepoint } @@ -577,12 +579,12 @@ type parser struct { memoize bool // memoization table for the packrat algorithm: // map[offset in source] map[expression or rule] {value, match} - memo map[int]map[interface{}]resultTuple + 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]interface{} + vstack []map[string]any // rule stack, allows identification of the current rule in errors rstack []*rule @@ -602,7 +604,7 @@ type parser struct { choiceNoMatch string // recovery expression stack, keeps track of the currently available recovery expression, these are traversed in reverse - recoveryStack []map[string]interface{} + recoveryStack []map[string]any } // push a variable set on the vstack. @@ -622,7 +624,7 @@ func (p *parser) pushV() { return } - m = make(map[string]interface{}) + m = make(map[string]any) p.vstack[len(p.vstack)-1] = m } @@ -638,7 +640,7 @@ func (p *parser) popV() { } // push a recovery expression with its labels to the recoveryStack -func (p *parser) pushRecovery(labels []string, expr interface{}) { +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) @@ -647,7 +649,7 @@ func (p *parser) pushRecovery(labels []string, expr interface{}) { p.recoveryStack = p.recoveryStack[:len(p.recoveryStack)+1] } - m := make(map[string]interface{}, len(labels)) + m := make(map[string]any, len(labels)) for _, fl := range labels { m[fl] = expr } @@ -767,11 +769,11 @@ func (p *parser) restore(pt savepoint) { // copies of the state to allow the parser to properly restore the state in // the case of backtracking. type Cloner interface { - Clone() interface{} + Clone() any } var statePool = &sync.Pool{ - New: func() interface{} { return make(storeDict) }, + New: func() any { return make(storeDict) }, } func (sd storeDict) Discard() { @@ -813,7 +815,7 @@ func (p *parser) sliceFrom(start savepoint) []byte { return p.data[start.position.offset:p.pt.position.offset] } -func (p *parser) getMemoized(node interface{}) (resultTuple, bool) { +func (p *parser) getMemoized(node any) (resultTuple, bool) { if len(p.memo) == 0 { return resultTuple{}, false } @@ -825,13 +827,13 @@ func (p *parser) getMemoized(node interface{}) (resultTuple, bool) { return res, ok } -func (p *parser) setMemoized(pt savepoint, node interface{}, tuple resultTuple) { +func (p *parser) setMemoized(pt savepoint, node any, tuple resultTuple) { if p.memo == nil { - p.memo = make(map[int]map[interface{}]resultTuple) + p.memo = make(map[int]map[any]resultTuple) } m := p.memo[pt.offset] if m == nil { - m = make(map[interface{}]resultTuple) + m = make(map[any]resultTuple) p.memo[pt.offset] = m } m[node] = tuple @@ -845,7 +847,7 @@ func (p *parser) buildRulesTable(g *grammar) { } // nolint: gocyclo -func (p *parser) parse(g *grammar) (val interface{}, err error) { +func (p *parser) parse(g *grammar) (val any, err error) { if len(g.rules) == 0 { p.addErr(errNoRule) return nil, p.errs.err() @@ -922,7 +924,7 @@ func listJoin(list []string, sep string, lastSep string) string { } } -func (p *parser) parseRule(rule *rule) (interface{}, bool) { +func (p *parser) parseRule(rule *rule) (any, bool) { if p.debug { defer p.out(p.in("parseRule " + rule.name)) } @@ -952,7 +954,7 @@ func (p *parser) parseRule(rule *rule) (interface{}, bool) { } // nolint: gocyclo -func (p *parser) parseExpr(expr interface{}) (interface{}, bool) { +func (p *parser) parseExpr(expr any) (any, bool) { var pt savepoint if p.memoize { @@ -969,7 +971,7 @@ func (p *parser) parseExpr(expr interface{}) (interface{}, bool) { panic(errMaxExprCnt) } - var val interface{} + var val any var ok bool switch expr := expr.(type) { case *actionExpr: @@ -1017,7 +1019,7 @@ func (p *parser) parseExpr(expr interface{}) (interface{}, bool) { return val, ok } -func (p *parser) parseActionExpr(act *actionExpr) (interface{}, bool) { +func (p *parser) parseActionExpr(act *actionExpr) (any, bool) { if p.debug { defer p.out(p.in("parseActionExpr")) } @@ -1042,7 +1044,7 @@ func (p *parser) parseActionExpr(act *actionExpr) (interface{}, bool) { return val, ok } -func (p *parser) parseAndCodeExpr(and *andCodeExpr) (interface{}, bool) { +func (p *parser) parseAndCodeExpr(and *andCodeExpr) (any, bool) { if p.debug { defer p.out(p.in("parseAndCodeExpr")) } @@ -1058,7 +1060,7 @@ func (p *parser) parseAndCodeExpr(and *andCodeExpr) (interface{}, bool) { return nil, ok } -func (p *parser) parseAndExpr(and *andExpr) (interface{}, bool) { +func (p *parser) parseAndExpr(and *andExpr) (any, bool) { if p.debug { defer p.out(p.in("parseAndExpr")) } @@ -1074,7 +1076,7 @@ func (p *parser) parseAndExpr(and *andExpr) (interface{}, bool) { return nil, ok } -func (p *parser) parseAnyMatcher(any *anyMatcher) (interface{}, bool) { +func (p *parser) parseAnyMatcher(any *anyMatcher) (any, bool) { if p.debug { defer p.out(p.in("parseAnyMatcher")) } @@ -1091,7 +1093,7 @@ func (p *parser) parseAnyMatcher(any *anyMatcher) (interface{}, bool) { } // nolint: gocyclo -func (p *parser) parseCharClassMatcher(chr *charClassMatcher) (interface{}, bool) { +func (p *parser) parseCharClassMatcher(chr *charClassMatcher) (any, bool) { if p.debug { defer p.out(p.in("parseCharClassMatcher")) } @@ -1172,7 +1174,7 @@ func (p *parser) incChoiceAltCnt(ch *choiceExpr, altI int) { m[alt]++ } -func (p *parser) parseChoiceExpr(ch *choiceExpr) (interface{}, bool) { +func (p *parser) parseChoiceExpr(ch *choiceExpr) (any, bool) { if p.debug { defer p.out(p.in("parseChoiceExpr")) } @@ -1196,7 +1198,7 @@ func (p *parser) parseChoiceExpr(ch *choiceExpr) (interface{}, bool) { return nil, false } -func (p *parser) parseLabeledExpr(lab *labeledExpr) (interface{}, bool) { +func (p *parser) parseLabeledExpr(lab *labeledExpr) (any, bool) { if p.debug { defer p.out(p.in("parseLabeledExpr")) } @@ -1211,7 +1213,7 @@ func (p *parser) parseLabeledExpr(lab *labeledExpr) (interface{}, bool) { return val, ok } -func (p *parser) parseLitMatcher(lit *litMatcher) (interface{}, bool) { +func (p *parser) parseLitMatcher(lit *litMatcher) (any, bool) { if p.debug { defer p.out(p.in("parseLitMatcher")) } @@ -1233,7 +1235,7 @@ func (p *parser) parseLitMatcher(lit *litMatcher) (interface{}, bool) { return p.sliceFrom(start), true } -func (p *parser) parseNotCodeExpr(not *notCodeExpr) (interface{}, bool) { +func (p *parser) parseNotCodeExpr(not *notCodeExpr) (any, bool) { if p.debug { defer p.out(p.in("parseNotCodeExpr")) } @@ -1249,7 +1251,7 @@ func (p *parser) parseNotCodeExpr(not *notCodeExpr) (interface{}, bool) { return nil, !ok } -func (p *parser) parseNotExpr(not *notExpr) (interface{}, bool) { +func (p *parser) parseNotExpr(not *notExpr) (any, bool) { if p.debug { defer p.out(p.in("parseNotExpr")) } @@ -1267,12 +1269,12 @@ func (p *parser) parseNotExpr(not *notExpr) (interface{}, bool) { return nil, !ok } -func (p *parser) parseOneOrMoreExpr(expr *oneOrMoreExpr) (interface{}, bool) { +func (p *parser) parseOneOrMoreExpr(expr *oneOrMoreExpr) (any, bool) { if p.debug { defer p.out(p.in("parseOneOrMoreExpr")) } - var vals []interface{} + var vals []any for { p.pushV() @@ -1289,7 +1291,7 @@ func (p *parser) parseOneOrMoreExpr(expr *oneOrMoreExpr) (interface{}, bool) { } } -func (p *parser) parseRecoveryExpr(recover *recoveryExpr) (interface{}, bool) { +func (p *parser) parseRecoveryExpr(recover *recoveryExpr) (any, bool) { if p.debug { defer p.out(p.in("parseRecoveryExpr (" + strings.Join(recover.failureLabel, ",") + ")")) } @@ -1301,7 +1303,7 @@ func (p *parser) parseRecoveryExpr(recover *recoveryExpr) (interface{}, bool) { return val, ok } -func (p *parser) parseRuleRefExpr(ref *ruleRefExpr) (interface{}, bool) { +func (p *parser) parseRuleRefExpr(ref *ruleRefExpr) (any, bool) { if p.debug { defer p.out(p.in("parseRuleRefExpr " + ref.name)) } @@ -1318,12 +1320,12 @@ func (p *parser) parseRuleRefExpr(ref *ruleRefExpr) (interface{}, bool) { return p.parseRule(rule) } -func (p *parser) parseSeqExpr(seq *seqExpr) (interface{}, bool) { +func (p *parser) parseSeqExpr(seq *seqExpr) (any, bool) { if p.debug { defer p.out(p.in("parseSeqExpr")) } - vals := make([]interface{}, 0, len(seq.exprs)) + vals := make([]any, 0, len(seq.exprs)) pt := p.pt state := p.cloneState() @@ -1339,7 +1341,7 @@ func (p *parser) parseSeqExpr(seq *seqExpr) (interface{}, bool) { return vals, true } -func (p *parser) parseStateCodeExpr(state *stateCodeExpr) (interface{}, bool) { +func (p *parser) parseStateCodeExpr(state *stateCodeExpr) (any, bool) { if p.debug { defer p.out(p.in("parseStateCodeExpr")) } @@ -1351,7 +1353,7 @@ func (p *parser) parseStateCodeExpr(state *stateCodeExpr) (interface{}, bool) { return nil, true } -func (p *parser) parseThrowExpr(expr *throwExpr) (interface{}, bool) { +func (p *parser) parseThrowExpr(expr *throwExpr) (any, bool) { if p.debug { defer p.out(p.in("parseThrowExpr")) } @@ -1367,12 +1369,12 @@ func (p *parser) parseThrowExpr(expr *throwExpr) (interface{}, bool) { return nil, false } -func (p *parser) parseZeroOrMoreExpr(expr *zeroOrMoreExpr) (interface{}, bool) { +func (p *parser) parseZeroOrMoreExpr(expr *zeroOrMoreExpr) (any, bool) { if p.debug { defer p.out(p.in("parseZeroOrMoreExpr")) } - var vals []interface{} + var vals []any for { p.pushV() @@ -1385,7 +1387,7 @@ func (p *parser) parseZeroOrMoreExpr(expr *zeroOrMoreExpr) (interface{}, bool) { } } -func (p *parser) parseZeroOrOneExpr(expr *zeroOrOneExpr) (interface{}, bool) { +func (p *parser) parseZeroOrOneExpr(expr *zeroOrOneExpr) (any, bool) { if p.debug { defer p.out(p.in("parseZeroOrOneExpr")) } diff --git a/test/issue_70/issue_70_test.go b/test/issue_70/issue_70_test.go index e0114300..a13f827d 100644 --- a/test/issue_70/issue_70_test.go +++ b/test/issue_70/issue_70_test.go @@ -19,7 +19,7 @@ func TestOptimizeGrammar(t *testing.T) { {"Y", "Z", errors.New("no match found")}, } - type parser func(string) (interface{}, error) + type parser func(string) (any, error) parsers := map[string]parser{ "standard": parseStd, "optimized": parseOpt, @@ -48,14 +48,14 @@ func TestOptimizeGrammar(t *testing.T) { } } -func parseStd(input string) (interface{}, error) { +func parseStd(input string) (any, error) { return Parse("", []byte(input)) } -func parseOpt(input string) (interface{}, error) { +func parseOpt(input string) (any, error) { return optimized.Parse("", []byte(input)) } -func parseOptGrammar(input string) (interface{}, error) { +func parseOptGrammar(input string) (any, error) { return optimizedgrammar.Parse("", []byte(input)) } diff --git a/test/issue_70/optimized-grammar/issue_70.go b/test/issue_70/optimized-grammar/issue_70.go index a1c65f78..59ff1536 100644 --- a/test/issue_70/optimized-grammar/issue_70.go +++ b/test/issue_70/optimized-grammar/issue_70.go @@ -27,7 +27,7 @@ var g = &grammar{ run: (*parser).callonX1, expr: &seqExpr{ pos: position{line: 5, col: 5, offset: 27}, - exprs: []interface{}{ + exprs: []any{ &labeledExpr{ pos: position{line: 5, col: 5, offset: 27}, label: "a", @@ -58,21 +58,21 @@ var g = &grammar{ }, } -func (c *current) onX5() (interface{}, error) { +func (c *current) onX5() (any, error) { return "Z", nil } -func (p *parser) callonX5() (interface{}, error) { +func (p *parser) callonX5() (any, error) { stack := p.vstack[len(p.vstack)-1] _ = stack return p.cur.onX5() } -func (c *current) onX1(a interface{}) (interface{}, error) { +func (c *current) onX1(a any) (any, error) { return a, nil } -func (p *parser) callonX1() (interface{}, error) { +func (p *parser) callonX1() (any, error) { stack := p.vstack[len(p.vstack)-1] _ = stack return p.cur.onX1(stack["a"]) @@ -216,7 +216,7 @@ func Recover(b bool) Option { // GlobalStore creates an Option to set a key to a certain value in // the globalStore. -func GlobalStore(key string, value interface{}) Option { +func GlobalStore(key string, value any) Option { return func(p *parser) Option { old := p.cur.globalStore[key] p.cur.globalStore[key] = value @@ -226,7 +226,7 @@ func GlobalStore(key string, value interface{}) Option { // InitState creates an Option to set a key to a certain value in // the global "state" store. -func InitState(key string, value interface{}) Option { +func InitState(key string, value any) Option { return func(p *parser) Option { old := p.cur.state[key] p.cur.state[key] = value @@ -235,7 +235,7 @@ func InitState(key string, value interface{}) Option { } // ParseFile parses the file identified by filename. -func ParseFile(filename string, opts ...Option) (i interface{}, err error) { // nolint: deadcode +func ParseFile(filename string, opts ...Option) (i any, err error) { // nolint: deadcode f, err := os.Open(filename) if err != nil { return nil, err @@ -250,7 +250,7 @@ func ParseFile(filename string, opts ...Option) (i interface{}, err error) { // // ParseReader parses the data from r using filename as information in the // error messages. -func ParseReader(filename string, r io.Reader, opts ...Option) (interface{}, error) { // nolint: deadcode +func ParseReader(filename string, r io.Reader, opts ...Option) (any, error) { // nolint: deadcode b, err := io.ReadAll(r) if err != nil { return nil, err @@ -261,7 +261,7 @@ func ParseReader(filename string, r io.Reader, opts ...Option) (interface{}, err // Parse parses the data from b using filename as information in the // error messages. -func Parse(filename string, b []byte, opts ...Option) (interface{}, error) { +func Parse(filename string, b []byte, opts ...Option) (any, error) { return newParser(filename, b, opts...).parse(g) } @@ -299,7 +299,7 @@ type current struct { globalStore storeDict } -type storeDict map[string]interface{} +type storeDict map[string]any // the AST types... @@ -314,34 +314,34 @@ type rule struct { pos position name string displayName string - expr interface{} + expr any } // nolint: structcheck type choiceExpr struct { pos position - alternatives []interface{} + alternatives []any } // nolint: structcheck type actionExpr struct { pos position - expr interface{} - run func(*parser) (interface{}, error) + expr any + run func(*parser) (any, error) } // nolint: structcheck type recoveryExpr struct { pos position - expr interface{} - recoverExpr interface{} + expr any + recoverExpr any failureLabel []string } // nolint: structcheck type seqExpr struct { pos position - exprs []interface{} + exprs []any } // nolint: structcheck @@ -354,20 +354,22 @@ type throwExpr struct { type labeledExpr struct { pos position label string - expr interface{} + expr any } // nolint: structcheck type expr struct { pos position - expr interface{} + expr any } -type andExpr expr // nolint: structcheck -type notExpr expr // nolint: structcheck -type zeroOrOneExpr expr // nolint: structcheck -type zeroOrMoreExpr expr // nolint: structcheck -type oneOrMoreExpr expr // nolint: structcheck +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 { @@ -515,7 +517,7 @@ func (p *parser) setOptions(opts []Option) { // nolint: structcheck,deadcode type resultTuple struct { - v interface{} + v any b bool end savepoint } @@ -561,12 +563,12 @@ type parser struct { memoize bool // memoization table for the packrat algorithm: // map[offset in source] map[expression or rule] {value, match} - memo map[int]map[interface{}]resultTuple + 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]interface{} + vstack []map[string]any // rule stack, allows identification of the current rule in errors rstack []*rule @@ -586,7 +588,7 @@ type parser struct { choiceNoMatch string // recovery expression stack, keeps track of the currently available recovery expression, these are traversed in reverse - recoveryStack []map[string]interface{} + recoveryStack []map[string]any } // push a variable set on the vstack. @@ -606,7 +608,7 @@ func (p *parser) pushV() { return } - m = make(map[string]interface{}) + m = make(map[string]any) p.vstack[len(p.vstack)-1] = m } @@ -622,7 +624,7 @@ func (p *parser) popV() { } // push a recovery expression with its labels to the recoveryStack -func (p *parser) pushRecovery(labels []string, expr interface{}) { +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) @@ -631,7 +633,7 @@ func (p *parser) pushRecovery(labels []string, expr interface{}) { p.recoveryStack = p.recoveryStack[:len(p.recoveryStack)+1] } - m := make(map[string]interface{}, len(labels)) + m := make(map[string]any, len(labels)) for _, fl := range labels { m[fl] = expr } @@ -751,11 +753,11 @@ func (p *parser) restore(pt savepoint) { // copies of the state to allow the parser to properly restore the state in // the case of backtracking. type Cloner interface { - Clone() interface{} + Clone() any } var statePool = &sync.Pool{ - New: func() interface{} { return make(storeDict) }, + New: func() any { return make(storeDict) }, } func (sd storeDict) Discard() { @@ -797,7 +799,7 @@ func (p *parser) sliceFrom(start savepoint) []byte { return p.data[start.position.offset:p.pt.position.offset] } -func (p *parser) getMemoized(node interface{}) (resultTuple, bool) { +func (p *parser) getMemoized(node any) (resultTuple, bool) { if len(p.memo) == 0 { return resultTuple{}, false } @@ -809,13 +811,13 @@ func (p *parser) getMemoized(node interface{}) (resultTuple, bool) { return res, ok } -func (p *parser) setMemoized(pt savepoint, node interface{}, tuple resultTuple) { +func (p *parser) setMemoized(pt savepoint, node any, tuple resultTuple) { if p.memo == nil { - p.memo = make(map[int]map[interface{}]resultTuple) + p.memo = make(map[int]map[any]resultTuple) } m := p.memo[pt.offset] if m == nil { - m = make(map[interface{}]resultTuple) + m = make(map[any]resultTuple) p.memo[pt.offset] = m } m[node] = tuple @@ -829,7 +831,7 @@ func (p *parser) buildRulesTable(g *grammar) { } // nolint: gocyclo -func (p *parser) parse(g *grammar) (val interface{}, err error) { +func (p *parser) parse(g *grammar) (val any, err error) { if len(g.rules) == 0 { p.addErr(errNoRule) return nil, p.errs.err() @@ -906,7 +908,7 @@ func listJoin(list []string, sep string, lastSep string) string { } } -func (p *parser) parseRule(rule *rule) (interface{}, bool) { +func (p *parser) parseRule(rule *rule) (any, bool) { if p.debug { defer p.out(p.in("parseRule " + rule.name)) } @@ -936,7 +938,7 @@ func (p *parser) parseRule(rule *rule) (interface{}, bool) { } // nolint: gocyclo -func (p *parser) parseExpr(expr interface{}) (interface{}, bool) { +func (p *parser) parseExpr(expr any) (any, bool) { var pt savepoint if p.memoize { @@ -953,7 +955,7 @@ func (p *parser) parseExpr(expr interface{}) (interface{}, bool) { panic(errMaxExprCnt) } - var val interface{} + var val any var ok bool switch expr := expr.(type) { case *actionExpr: @@ -1001,7 +1003,7 @@ func (p *parser) parseExpr(expr interface{}) (interface{}, bool) { return val, ok } -func (p *parser) parseActionExpr(act *actionExpr) (interface{}, bool) { +func (p *parser) parseActionExpr(act *actionExpr) (any, bool) { if p.debug { defer p.out(p.in("parseActionExpr")) } @@ -1026,7 +1028,7 @@ func (p *parser) parseActionExpr(act *actionExpr) (interface{}, bool) { return val, ok } -func (p *parser) parseAndCodeExpr(and *andCodeExpr) (interface{}, bool) { +func (p *parser) parseAndCodeExpr(and *andCodeExpr) (any, bool) { if p.debug { defer p.out(p.in("parseAndCodeExpr")) } @@ -1042,7 +1044,7 @@ func (p *parser) parseAndCodeExpr(and *andCodeExpr) (interface{}, bool) { return nil, ok } -func (p *parser) parseAndExpr(and *andExpr) (interface{}, bool) { +func (p *parser) parseAndExpr(and *andExpr) (any, bool) { if p.debug { defer p.out(p.in("parseAndExpr")) } @@ -1058,7 +1060,7 @@ func (p *parser) parseAndExpr(and *andExpr) (interface{}, bool) { return nil, ok } -func (p *parser) parseAnyMatcher(any *anyMatcher) (interface{}, bool) { +func (p *parser) parseAnyMatcher(any *anyMatcher) (any, bool) { if p.debug { defer p.out(p.in("parseAnyMatcher")) } @@ -1075,7 +1077,7 @@ func (p *parser) parseAnyMatcher(any *anyMatcher) (interface{}, bool) { } // nolint: gocyclo -func (p *parser) parseCharClassMatcher(chr *charClassMatcher) (interface{}, bool) { +func (p *parser) parseCharClassMatcher(chr *charClassMatcher) (any, bool) { if p.debug { defer p.out(p.in("parseCharClassMatcher")) } @@ -1156,7 +1158,7 @@ func (p *parser) incChoiceAltCnt(ch *choiceExpr, altI int) { m[alt]++ } -func (p *parser) parseChoiceExpr(ch *choiceExpr) (interface{}, bool) { +func (p *parser) parseChoiceExpr(ch *choiceExpr) (any, bool) { if p.debug { defer p.out(p.in("parseChoiceExpr")) } @@ -1180,7 +1182,7 @@ func (p *parser) parseChoiceExpr(ch *choiceExpr) (interface{}, bool) { return nil, false } -func (p *parser) parseLabeledExpr(lab *labeledExpr) (interface{}, bool) { +func (p *parser) parseLabeledExpr(lab *labeledExpr) (any, bool) { if p.debug { defer p.out(p.in("parseLabeledExpr")) } @@ -1195,7 +1197,7 @@ func (p *parser) parseLabeledExpr(lab *labeledExpr) (interface{}, bool) { return val, ok } -func (p *parser) parseLitMatcher(lit *litMatcher) (interface{}, bool) { +func (p *parser) parseLitMatcher(lit *litMatcher) (any, bool) { if p.debug { defer p.out(p.in("parseLitMatcher")) } @@ -1217,7 +1219,7 @@ func (p *parser) parseLitMatcher(lit *litMatcher) (interface{}, bool) { return p.sliceFrom(start), true } -func (p *parser) parseNotCodeExpr(not *notCodeExpr) (interface{}, bool) { +func (p *parser) parseNotCodeExpr(not *notCodeExpr) (any, bool) { if p.debug { defer p.out(p.in("parseNotCodeExpr")) } @@ -1233,7 +1235,7 @@ func (p *parser) parseNotCodeExpr(not *notCodeExpr) (interface{}, bool) { return nil, !ok } -func (p *parser) parseNotExpr(not *notExpr) (interface{}, bool) { +func (p *parser) parseNotExpr(not *notExpr) (any, bool) { if p.debug { defer p.out(p.in("parseNotExpr")) } @@ -1251,12 +1253,12 @@ func (p *parser) parseNotExpr(not *notExpr) (interface{}, bool) { return nil, !ok } -func (p *parser) parseOneOrMoreExpr(expr *oneOrMoreExpr) (interface{}, bool) { +func (p *parser) parseOneOrMoreExpr(expr *oneOrMoreExpr) (any, bool) { if p.debug { defer p.out(p.in("parseOneOrMoreExpr")) } - var vals []interface{} + var vals []any for { p.pushV() @@ -1273,7 +1275,7 @@ func (p *parser) parseOneOrMoreExpr(expr *oneOrMoreExpr) (interface{}, bool) { } } -func (p *parser) parseRecoveryExpr(recover *recoveryExpr) (interface{}, bool) { +func (p *parser) parseRecoveryExpr(recover *recoveryExpr) (any, bool) { if p.debug { defer p.out(p.in("parseRecoveryExpr (" + strings.Join(recover.failureLabel, ",") + ")")) } @@ -1285,7 +1287,7 @@ func (p *parser) parseRecoveryExpr(recover *recoveryExpr) (interface{}, bool) { return val, ok } -func (p *parser) parseRuleRefExpr(ref *ruleRefExpr) (interface{}, bool) { +func (p *parser) parseRuleRefExpr(ref *ruleRefExpr) (any, bool) { if p.debug { defer p.out(p.in("parseRuleRefExpr " + ref.name)) } @@ -1302,12 +1304,12 @@ func (p *parser) parseRuleRefExpr(ref *ruleRefExpr) (interface{}, bool) { return p.parseRule(rule) } -func (p *parser) parseSeqExpr(seq *seqExpr) (interface{}, bool) { +func (p *parser) parseSeqExpr(seq *seqExpr) (any, bool) { if p.debug { defer p.out(p.in("parseSeqExpr")) } - vals := make([]interface{}, 0, len(seq.exprs)) + vals := make([]any, 0, len(seq.exprs)) pt := p.pt state := p.cloneState() @@ -1323,7 +1325,7 @@ func (p *parser) parseSeqExpr(seq *seqExpr) (interface{}, bool) { return vals, true } -func (p *parser) parseStateCodeExpr(state *stateCodeExpr) (interface{}, bool) { +func (p *parser) parseStateCodeExpr(state *stateCodeExpr) (any, bool) { if p.debug { defer p.out(p.in("parseStateCodeExpr")) } @@ -1335,7 +1337,7 @@ func (p *parser) parseStateCodeExpr(state *stateCodeExpr) (interface{}, bool) { return nil, true } -func (p *parser) parseThrowExpr(expr *throwExpr) (interface{}, bool) { +func (p *parser) parseThrowExpr(expr *throwExpr) (any, bool) { if p.debug { defer p.out(p.in("parseThrowExpr")) } @@ -1351,12 +1353,12 @@ func (p *parser) parseThrowExpr(expr *throwExpr) (interface{}, bool) { return nil, false } -func (p *parser) parseZeroOrMoreExpr(expr *zeroOrMoreExpr) (interface{}, bool) { +func (p *parser) parseZeroOrMoreExpr(expr *zeroOrMoreExpr) (any, bool) { if p.debug { defer p.out(p.in("parseZeroOrMoreExpr")) } - var vals []interface{} + var vals []any for { p.pushV() @@ -1369,7 +1371,7 @@ func (p *parser) parseZeroOrMoreExpr(expr *zeroOrMoreExpr) (interface{}, bool) { } } -func (p *parser) parseZeroOrOneExpr(expr *zeroOrOneExpr) (interface{}, bool) { +func (p *parser) parseZeroOrOneExpr(expr *zeroOrOneExpr) (any, bool) { if p.debug { defer p.out(p.in("parseZeroOrOneExpr")) } diff --git a/test/issue_70/optimized/issue_70.go b/test/issue_70/optimized/issue_70.go index e0f772a2..b7012fde 100644 --- a/test/issue_70/optimized/issue_70.go +++ b/test/issue_70/optimized/issue_70.go @@ -26,7 +26,7 @@ var g = &grammar{ run: (*parser).callonX1, expr: &seqExpr{ pos: position{line: 5, col: 5, offset: 27}, - exprs: []interface{}{ + exprs: []any{ &labeledExpr{ pos: position{line: 5, col: 5, offset: 27}, label: "a", @@ -73,21 +73,21 @@ var g = &grammar{ }, } -func (c *current) onX1(a interface{}) (interface{}, error) { +func (c *current) onX1(a any) (any, error) { return a, nil } -func (p *parser) callonX1() (interface{}, error) { +func (p *parser) callonX1() (any, error) { stack := p.vstack[len(p.vstack)-1] _ = stack return p.cur.onX1(stack["a"]) } -func (c *current) onZ2() (interface{}, error) { +func (c *current) onZ2() (any, error) { return "Z", nil } -func (p *parser) callonZ2() (interface{}, error) { +func (p *parser) callonZ2() (any, error) { stack := p.vstack[len(p.vstack)-1] _ = stack return p.cur.onZ2() @@ -175,7 +175,7 @@ func Recover(b bool) Option { // GlobalStore creates an Option to set a key to a certain value in // the globalStore. -func GlobalStore(key string, value interface{}) Option { +func GlobalStore(key string, value any) Option { return func(p *parser) Option { old := p.cur.globalStore[key] p.cur.globalStore[key] = value @@ -184,7 +184,7 @@ func GlobalStore(key string, value interface{}) Option { } // ParseFile parses the file identified by filename. -func ParseFile(filename string, opts ...Option) (i interface{}, err error) { // nolint: deadcode +func ParseFile(filename string, opts ...Option) (i any, err error) { // nolint: deadcode f, err := os.Open(filename) if err != nil { return nil, err @@ -199,7 +199,7 @@ func ParseFile(filename string, opts ...Option) (i interface{}, err error) { // // ParseReader parses the data from r using filename as information in the // error messages. -func ParseReader(filename string, r io.Reader, opts ...Option) (interface{}, error) { // nolint: deadcode +func ParseReader(filename string, r io.Reader, opts ...Option) (any, error) { // nolint: deadcode b, err := io.ReadAll(r) if err != nil { return nil, err @@ -210,7 +210,7 @@ func ParseReader(filename string, r io.Reader, opts ...Option) (interface{}, err // Parse parses the data from b using filename as information in the // error messages. -func Parse(filename string, b []byte, opts ...Option) (interface{}, error) { +func Parse(filename string, b []byte, opts ...Option) (any, error) { return newParser(filename, b, opts...).parse(g) } @@ -243,7 +243,7 @@ type current struct { globalStore storeDict } -type storeDict map[string]interface{} +type storeDict map[string]any // the AST types... @@ -258,34 +258,34 @@ type rule struct { pos position name string displayName string - expr interface{} + expr any } // nolint: structcheck type choiceExpr struct { pos position - alternatives []interface{} + alternatives []any } // nolint: structcheck type actionExpr struct { pos position - expr interface{} - run func(*parser) (interface{}, error) + expr any + run func(*parser) (any, error) } // nolint: structcheck type recoveryExpr struct { pos position - expr interface{} - recoverExpr interface{} + expr any + recoverExpr any failureLabel []string } // nolint: structcheck type seqExpr struct { pos position - exprs []interface{} + exprs []any } // nolint: structcheck @@ -298,20 +298,22 @@ type throwExpr struct { type labeledExpr struct { pos position label string - expr interface{} + expr any } // nolint: structcheck type expr struct { pos position - expr interface{} + expr any } -type andExpr expr // nolint: structcheck -type notExpr expr // nolint: structcheck -type zeroOrOneExpr expr // nolint: structcheck -type zeroOrMoreExpr expr // nolint: structcheck -type oneOrMoreExpr expr // nolint: structcheck +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 { @@ -452,7 +454,7 @@ func (p *parser) setOptions(opts []Option) { // nolint: structcheck,deadcode type resultTuple struct { - v interface{} + v any b bool end savepoint } @@ -497,7 +499,7 @@ type parser struct { // rules table, maps the rule identifier to the rule node rules map[string]*rule // variables stack, map of label to value - vstack []map[string]interface{} + vstack []map[string]any // rule stack, allows identification of the current rule in errors rstack []*rule @@ -517,7 +519,7 @@ type parser struct { choiceNoMatch string // recovery expression stack, keeps track of the currently available recovery expression, these are traversed in reverse - recoveryStack []map[string]interface{} + recoveryStack []map[string]any } // push a variable set on the vstack. @@ -537,7 +539,7 @@ func (p *parser) pushV() { return } - m = make(map[string]interface{}) + m = make(map[string]any) p.vstack[len(p.vstack)-1] = m } @@ -553,7 +555,7 @@ func (p *parser) popV() { } // push a recovery expression with its labels to the recoveryStack -func (p *parser) pushRecovery(labels []string, expr interface{}) { +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) @@ -562,7 +564,7 @@ func (p *parser) pushRecovery(labels []string, expr interface{}) { p.recoveryStack = p.recoveryStack[:len(p.recoveryStack)+1] } - m := make(map[string]interface{}, len(labels)) + m := make(map[string]any, len(labels)) for _, fl := range labels { m[fl] = expr } @@ -664,7 +666,7 @@ func (p *parser) buildRulesTable(g *grammar) { } // nolint: gocyclo -func (p *parser) parse(g *grammar) (val interface{}, err error) { +func (p *parser) parse(g *grammar) (val any, err error) { if len(g.rules) == 0 { p.addErr(errNoRule) return nil, p.errs.err() @@ -738,7 +740,7 @@ func listJoin(list []string, sep string, lastSep string) string { } } -func (p *parser) parseRule(rule *rule) (interface{}, bool) { +func (p *parser) parseRule(rule *rule) (any, bool) { p.rstack = append(p.rstack, rule) p.pushV() val, ok := p.parseExpr(rule.expr) @@ -748,14 +750,14 @@ func (p *parser) parseRule(rule *rule) (interface{}, bool) { } // nolint: gocyclo -func (p *parser) parseExpr(expr interface{}) (interface{}, bool) { +func (p *parser) parseExpr(expr any) (any, bool) { p.ExprCnt++ if p.ExprCnt > p.maxExprCnt { panic(errMaxExprCnt) } - var val interface{} + var val any var ok bool switch expr := expr.(type) { case *actionExpr: @@ -798,7 +800,7 @@ func (p *parser) parseExpr(expr interface{}) (interface{}, bool) { return val, ok } -func (p *parser) parseActionExpr(act *actionExpr) (interface{}, bool) { +func (p *parser) parseActionExpr(act *actionExpr) (any, bool) { start := p.pt val, ok := p.parseExpr(act.expr) if ok { @@ -814,7 +816,7 @@ func (p *parser) parseActionExpr(act *actionExpr) (interface{}, bool) { return val, ok } -func (p *parser) parseAndCodeExpr(and *andCodeExpr) (interface{}, bool) { +func (p *parser) parseAndCodeExpr(and *andCodeExpr) (any, bool) { ok, err := and.run(p) if err != nil { @@ -824,7 +826,7 @@ func (p *parser) parseAndCodeExpr(and *andCodeExpr) (interface{}, bool) { return nil, ok } -func (p *parser) parseAndExpr(and *andExpr) (interface{}, bool) { +func (p *parser) parseAndExpr(and *andExpr) (any, bool) { pt := p.pt p.pushV() _, ok := p.parseExpr(and.expr) @@ -834,7 +836,7 @@ func (p *parser) parseAndExpr(and *andExpr) (interface{}, bool) { return nil, ok } -func (p *parser) parseAnyMatcher(any *anyMatcher) (interface{}, bool) { +func (p *parser) parseAnyMatcher(any *anyMatcher) (any, bool) { if p.pt.rn == utf8.RuneError && p.pt.w == 0 { // EOF - see utf8.DecodeRune p.failAt(false, p.pt.position, ".") @@ -847,7 +849,7 @@ func (p *parser) parseAnyMatcher(any *anyMatcher) (interface{}, bool) { } // nolint: gocyclo -func (p *parser) parseCharClassMatcher(chr *charClassMatcher) (interface{}, bool) { +func (p *parser) parseCharClassMatcher(chr *charClassMatcher) (any, bool) { cur := p.pt.rn start := p.pt @@ -919,7 +921,7 @@ func (p *parser) parseCharClassMatcher(chr *charClassMatcher) (interface{}, bool return nil, false } -func (p *parser) parseChoiceExpr(ch *choiceExpr) (interface{}, bool) { +func (p *parser) parseChoiceExpr(ch *choiceExpr) (any, bool) { for altI, alt := range ch.alternatives { // dummy assignment to prevent compile error if optimized _ = altI @@ -934,7 +936,7 @@ func (p *parser) parseChoiceExpr(ch *choiceExpr) (interface{}, bool) { return nil, false } -func (p *parser) parseLabeledExpr(lab *labeledExpr) (interface{}, bool) { +func (p *parser) parseLabeledExpr(lab *labeledExpr) (any, bool) { p.pushV() val, ok := p.parseExpr(lab.expr) p.popV() @@ -945,7 +947,7 @@ func (p *parser) parseLabeledExpr(lab *labeledExpr) (interface{}, bool) { return val, ok } -func (p *parser) parseLitMatcher(lit *litMatcher) (interface{}, bool) { +func (p *parser) parseLitMatcher(lit *litMatcher) (any, bool) { start := p.pt for _, want := range lit.val { cur := p.pt.rn @@ -963,7 +965,7 @@ func (p *parser) parseLitMatcher(lit *litMatcher) (interface{}, bool) { return p.sliceFrom(start), true } -func (p *parser) parseNotCodeExpr(not *notCodeExpr) (interface{}, bool) { +func (p *parser) parseNotCodeExpr(not *notCodeExpr) (any, bool) { ok, err := not.run(p) if err != nil { p.addErr(err) @@ -972,7 +974,7 @@ func (p *parser) parseNotCodeExpr(not *notCodeExpr) (interface{}, bool) { return nil, !ok } -func (p *parser) parseNotExpr(not *notExpr) (interface{}, bool) { +func (p *parser) parseNotExpr(not *notExpr) (any, bool) { pt := p.pt p.pushV() p.maxFailInvertExpected = !p.maxFailInvertExpected @@ -984,8 +986,8 @@ func (p *parser) parseNotExpr(not *notExpr) (interface{}, bool) { return nil, !ok } -func (p *parser) parseOneOrMoreExpr(expr *oneOrMoreExpr) (interface{}, bool) { - var vals []interface{} +func (p *parser) parseOneOrMoreExpr(expr *oneOrMoreExpr) (any, bool) { + var vals []any for { p.pushV() @@ -1002,7 +1004,7 @@ func (p *parser) parseOneOrMoreExpr(expr *oneOrMoreExpr) (interface{}, bool) { } } -func (p *parser) parseRecoveryExpr(recover *recoveryExpr) (interface{}, bool) { +func (p *parser) parseRecoveryExpr(recover *recoveryExpr) (any, bool) { p.pushRecovery(recover.failureLabel, recover.recoverExpr) val, ok := p.parseExpr(recover.expr) @@ -1011,7 +1013,7 @@ func (p *parser) parseRecoveryExpr(recover *recoveryExpr) (interface{}, bool) { return val, ok } -func (p *parser) parseRuleRefExpr(ref *ruleRefExpr) (interface{}, bool) { +func (p *parser) parseRuleRefExpr(ref *ruleRefExpr) (any, bool) { if ref.name == "" { panic(fmt.Sprintf("%s: invalid rule: missing name", ref.pos)) } @@ -1024,8 +1026,8 @@ func (p *parser) parseRuleRefExpr(ref *ruleRefExpr) (interface{}, bool) { return p.parseRule(rule) } -func (p *parser) parseSeqExpr(seq *seqExpr) (interface{}, bool) { - vals := make([]interface{}, 0, len(seq.exprs)) +func (p *parser) parseSeqExpr(seq *seqExpr) (any, bool) { + vals := make([]any, 0, len(seq.exprs)) pt := p.pt for _, expr := range seq.exprs { @@ -1039,7 +1041,7 @@ func (p *parser) parseSeqExpr(seq *seqExpr) (interface{}, bool) { return vals, true } -func (p *parser) parseThrowExpr(expr *throwExpr) (interface{}, bool) { +func (p *parser) parseThrowExpr(expr *throwExpr) (any, bool) { for i := len(p.recoveryStack) - 1; i >= 0; i-- { if recoverExpr, ok := p.recoveryStack[i][expr.label]; ok { @@ -1052,8 +1054,8 @@ func (p *parser) parseThrowExpr(expr *throwExpr) (interface{}, bool) { return nil, false } -func (p *parser) parseZeroOrMoreExpr(expr *zeroOrMoreExpr) (interface{}, bool) { - var vals []interface{} +func (p *parser) parseZeroOrMoreExpr(expr *zeroOrMoreExpr) (any, bool) { + var vals []any for { p.pushV() @@ -1066,7 +1068,7 @@ func (p *parser) parseZeroOrMoreExpr(expr *zeroOrMoreExpr) (interface{}, bool) { } } -func (p *parser) parseZeroOrOneExpr(expr *zeroOrOneExpr) (interface{}, bool) { +func (p *parser) parseZeroOrOneExpr(expr *zeroOrOneExpr) (any, bool) { p.pushV() val, _ := p.parseExpr(expr.expr) p.popV() diff --git a/test/issue_70b/issue_70b.go b/test/issue_70b/issue_70b.go index 6a8e1e1d..d6e5b693 100644 --- a/test/issue_70b/issue_70b.go +++ b/test/issue_70b/issue_70b.go @@ -38,7 +38,7 @@ var g = &grammar{ pos: position{line: 9, col: 1, offset: 67}, expr: &choiceExpr{ pos: position{line: 9, col: 6, offset: 72}, - alternatives: []interface{}{ + alternatives: []any{ &zeroOrOneExpr{ pos: position{line: 6, col: 6, offset: 36}, expr: &actionExpr{ @@ -59,21 +59,21 @@ var g = &grammar{ }, } -func (c *current) onA2() (interface{}, error) { +func (c *current) onA2() (any, error) { return nil, nil } -func (p *parser) callonA2() (interface{}, error) { +func (p *parser) callonA2() (any, error) { stack := p.vstack[len(p.vstack)-1] _ = stack return p.cur.onA2() } -func (c *current) onD3() (interface{}, error) { +func (c *current) onD3() (any, error) { return nil, nil } -func (p *parser) callonD3() (interface{}, error) { +func (p *parser) callonD3() (any, error) { stack := p.vstack[len(p.vstack)-1] _ = stack return p.cur.onD3() @@ -217,7 +217,7 @@ func Recover(b bool) Option { // GlobalStore creates an Option to set a key to a certain value in // the globalStore. -func GlobalStore(key string, value interface{}) Option { +func GlobalStore(key string, value any) Option { return func(p *parser) Option { old := p.cur.globalStore[key] p.cur.globalStore[key] = value @@ -227,7 +227,7 @@ func GlobalStore(key string, value interface{}) Option { // InitState creates an Option to set a key to a certain value in // the global "state" store. -func InitState(key string, value interface{}) Option { +func InitState(key string, value any) Option { return func(p *parser) Option { old := p.cur.state[key] p.cur.state[key] = value @@ -236,7 +236,7 @@ func InitState(key string, value interface{}) Option { } // ParseFile parses the file identified by filename. -func ParseFile(filename string, opts ...Option) (i interface{}, err error) { // nolint: deadcode +func ParseFile(filename string, opts ...Option) (i any, err error) { // nolint: deadcode f, err := os.Open(filename) if err != nil { return nil, err @@ -251,7 +251,7 @@ func ParseFile(filename string, opts ...Option) (i interface{}, err error) { // // ParseReader parses the data from r using filename as information in the // error messages. -func ParseReader(filename string, r io.Reader, opts ...Option) (interface{}, error) { // nolint: deadcode +func ParseReader(filename string, r io.Reader, opts ...Option) (any, error) { // nolint: deadcode b, err := io.ReadAll(r) if err != nil { return nil, err @@ -262,7 +262,7 @@ func ParseReader(filename string, r io.Reader, opts ...Option) (interface{}, err // Parse parses the data from b using filename as information in the // error messages. -func Parse(filename string, b []byte, opts ...Option) (interface{}, error) { +func Parse(filename string, b []byte, opts ...Option) (any, error) { return newParser(filename, b, opts...).parse(g) } @@ -300,7 +300,7 @@ type current struct { globalStore storeDict } -type storeDict map[string]interface{} +type storeDict map[string]any // the AST types... @@ -315,34 +315,34 @@ type rule struct { pos position name string displayName string - expr interface{} + expr any } // nolint: structcheck type choiceExpr struct { pos position - alternatives []interface{} + alternatives []any } // nolint: structcheck type actionExpr struct { pos position - expr interface{} - run func(*parser) (interface{}, error) + expr any + run func(*parser) (any, error) } // nolint: structcheck type recoveryExpr struct { pos position - expr interface{} - recoverExpr interface{} + expr any + recoverExpr any failureLabel []string } // nolint: structcheck type seqExpr struct { pos position - exprs []interface{} + exprs []any } // nolint: structcheck @@ -355,20 +355,22 @@ type throwExpr struct { type labeledExpr struct { pos position label string - expr interface{} + expr any } // nolint: structcheck type expr struct { pos position - expr interface{} + expr any } -type andExpr expr // nolint: structcheck -type notExpr expr // nolint: structcheck -type zeroOrOneExpr expr // nolint: structcheck -type zeroOrMoreExpr expr // nolint: structcheck -type oneOrMoreExpr expr // nolint: structcheck +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 { @@ -516,7 +518,7 @@ func (p *parser) setOptions(opts []Option) { // nolint: structcheck,deadcode type resultTuple struct { - v interface{} + v any b bool end savepoint } @@ -562,12 +564,12 @@ type parser struct { memoize bool // memoization table for the packrat algorithm: // map[offset in source] map[expression or rule] {value, match} - memo map[int]map[interface{}]resultTuple + 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]interface{} + vstack []map[string]any // rule stack, allows identification of the current rule in errors rstack []*rule @@ -587,7 +589,7 @@ type parser struct { choiceNoMatch string // recovery expression stack, keeps track of the currently available recovery expression, these are traversed in reverse - recoveryStack []map[string]interface{} + recoveryStack []map[string]any } // push a variable set on the vstack. @@ -607,7 +609,7 @@ func (p *parser) pushV() { return } - m = make(map[string]interface{}) + m = make(map[string]any) p.vstack[len(p.vstack)-1] = m } @@ -623,7 +625,7 @@ func (p *parser) popV() { } // push a recovery expression with its labels to the recoveryStack -func (p *parser) pushRecovery(labels []string, expr interface{}) { +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) @@ -632,7 +634,7 @@ func (p *parser) pushRecovery(labels []string, expr interface{}) { p.recoveryStack = p.recoveryStack[:len(p.recoveryStack)+1] } - m := make(map[string]interface{}, len(labels)) + m := make(map[string]any, len(labels)) for _, fl := range labels { m[fl] = expr } @@ -752,11 +754,11 @@ func (p *parser) restore(pt savepoint) { // copies of the state to allow the parser to properly restore the state in // the case of backtracking. type Cloner interface { - Clone() interface{} + Clone() any } var statePool = &sync.Pool{ - New: func() interface{} { return make(storeDict) }, + New: func() any { return make(storeDict) }, } func (sd storeDict) Discard() { @@ -798,7 +800,7 @@ func (p *parser) sliceFrom(start savepoint) []byte { return p.data[start.position.offset:p.pt.position.offset] } -func (p *parser) getMemoized(node interface{}) (resultTuple, bool) { +func (p *parser) getMemoized(node any) (resultTuple, bool) { if len(p.memo) == 0 { return resultTuple{}, false } @@ -810,13 +812,13 @@ func (p *parser) getMemoized(node interface{}) (resultTuple, bool) { return res, ok } -func (p *parser) setMemoized(pt savepoint, node interface{}, tuple resultTuple) { +func (p *parser) setMemoized(pt savepoint, node any, tuple resultTuple) { if p.memo == nil { - p.memo = make(map[int]map[interface{}]resultTuple) + p.memo = make(map[int]map[any]resultTuple) } m := p.memo[pt.offset] if m == nil { - m = make(map[interface{}]resultTuple) + m = make(map[any]resultTuple) p.memo[pt.offset] = m } m[node] = tuple @@ -830,7 +832,7 @@ func (p *parser) buildRulesTable(g *grammar) { } // nolint: gocyclo -func (p *parser) parse(g *grammar) (val interface{}, err error) { +func (p *parser) parse(g *grammar) (val any, err error) { if len(g.rules) == 0 { p.addErr(errNoRule) return nil, p.errs.err() @@ -907,7 +909,7 @@ func listJoin(list []string, sep string, lastSep string) string { } } -func (p *parser) parseRule(rule *rule) (interface{}, bool) { +func (p *parser) parseRule(rule *rule) (any, bool) { if p.debug { defer p.out(p.in("parseRule " + rule.name)) } @@ -937,7 +939,7 @@ func (p *parser) parseRule(rule *rule) (interface{}, bool) { } // nolint: gocyclo -func (p *parser) parseExpr(expr interface{}) (interface{}, bool) { +func (p *parser) parseExpr(expr any) (any, bool) { var pt savepoint if p.memoize { @@ -954,7 +956,7 @@ func (p *parser) parseExpr(expr interface{}) (interface{}, bool) { panic(errMaxExprCnt) } - var val interface{} + var val any var ok bool switch expr := expr.(type) { case *actionExpr: @@ -1002,7 +1004,7 @@ func (p *parser) parseExpr(expr interface{}) (interface{}, bool) { return val, ok } -func (p *parser) parseActionExpr(act *actionExpr) (interface{}, bool) { +func (p *parser) parseActionExpr(act *actionExpr) (any, bool) { if p.debug { defer p.out(p.in("parseActionExpr")) } @@ -1027,7 +1029,7 @@ func (p *parser) parseActionExpr(act *actionExpr) (interface{}, bool) { return val, ok } -func (p *parser) parseAndCodeExpr(and *andCodeExpr) (interface{}, bool) { +func (p *parser) parseAndCodeExpr(and *andCodeExpr) (any, bool) { if p.debug { defer p.out(p.in("parseAndCodeExpr")) } @@ -1043,7 +1045,7 @@ func (p *parser) parseAndCodeExpr(and *andCodeExpr) (interface{}, bool) { return nil, ok } -func (p *parser) parseAndExpr(and *andExpr) (interface{}, bool) { +func (p *parser) parseAndExpr(and *andExpr) (any, bool) { if p.debug { defer p.out(p.in("parseAndExpr")) } @@ -1059,7 +1061,7 @@ func (p *parser) parseAndExpr(and *andExpr) (interface{}, bool) { return nil, ok } -func (p *parser) parseAnyMatcher(any *anyMatcher) (interface{}, bool) { +func (p *parser) parseAnyMatcher(any *anyMatcher) (any, bool) { if p.debug { defer p.out(p.in("parseAnyMatcher")) } @@ -1076,7 +1078,7 @@ func (p *parser) parseAnyMatcher(any *anyMatcher) (interface{}, bool) { } // nolint: gocyclo -func (p *parser) parseCharClassMatcher(chr *charClassMatcher) (interface{}, bool) { +func (p *parser) parseCharClassMatcher(chr *charClassMatcher) (any, bool) { if p.debug { defer p.out(p.in("parseCharClassMatcher")) } @@ -1157,7 +1159,7 @@ func (p *parser) incChoiceAltCnt(ch *choiceExpr, altI int) { m[alt]++ } -func (p *parser) parseChoiceExpr(ch *choiceExpr) (interface{}, bool) { +func (p *parser) parseChoiceExpr(ch *choiceExpr) (any, bool) { if p.debug { defer p.out(p.in("parseChoiceExpr")) } @@ -1181,7 +1183,7 @@ func (p *parser) parseChoiceExpr(ch *choiceExpr) (interface{}, bool) { return nil, false } -func (p *parser) parseLabeledExpr(lab *labeledExpr) (interface{}, bool) { +func (p *parser) parseLabeledExpr(lab *labeledExpr) (any, bool) { if p.debug { defer p.out(p.in("parseLabeledExpr")) } @@ -1196,7 +1198,7 @@ func (p *parser) parseLabeledExpr(lab *labeledExpr) (interface{}, bool) { return val, ok } -func (p *parser) parseLitMatcher(lit *litMatcher) (interface{}, bool) { +func (p *parser) parseLitMatcher(lit *litMatcher) (any, bool) { if p.debug { defer p.out(p.in("parseLitMatcher")) } @@ -1218,7 +1220,7 @@ func (p *parser) parseLitMatcher(lit *litMatcher) (interface{}, bool) { return p.sliceFrom(start), true } -func (p *parser) parseNotCodeExpr(not *notCodeExpr) (interface{}, bool) { +func (p *parser) parseNotCodeExpr(not *notCodeExpr) (any, bool) { if p.debug { defer p.out(p.in("parseNotCodeExpr")) } @@ -1234,7 +1236,7 @@ func (p *parser) parseNotCodeExpr(not *notCodeExpr) (interface{}, bool) { return nil, !ok } -func (p *parser) parseNotExpr(not *notExpr) (interface{}, bool) { +func (p *parser) parseNotExpr(not *notExpr) (any, bool) { if p.debug { defer p.out(p.in("parseNotExpr")) } @@ -1252,12 +1254,12 @@ func (p *parser) parseNotExpr(not *notExpr) (interface{}, bool) { return nil, !ok } -func (p *parser) parseOneOrMoreExpr(expr *oneOrMoreExpr) (interface{}, bool) { +func (p *parser) parseOneOrMoreExpr(expr *oneOrMoreExpr) (any, bool) { if p.debug { defer p.out(p.in("parseOneOrMoreExpr")) } - var vals []interface{} + var vals []any for { p.pushV() @@ -1274,7 +1276,7 @@ func (p *parser) parseOneOrMoreExpr(expr *oneOrMoreExpr) (interface{}, bool) { } } -func (p *parser) parseRecoveryExpr(recover *recoveryExpr) (interface{}, bool) { +func (p *parser) parseRecoveryExpr(recover *recoveryExpr) (any, bool) { if p.debug { defer p.out(p.in("parseRecoveryExpr (" + strings.Join(recover.failureLabel, ",") + ")")) } @@ -1286,7 +1288,7 @@ func (p *parser) parseRecoveryExpr(recover *recoveryExpr) (interface{}, bool) { return val, ok } -func (p *parser) parseRuleRefExpr(ref *ruleRefExpr) (interface{}, bool) { +func (p *parser) parseRuleRefExpr(ref *ruleRefExpr) (any, bool) { if p.debug { defer p.out(p.in("parseRuleRefExpr " + ref.name)) } @@ -1303,12 +1305,12 @@ func (p *parser) parseRuleRefExpr(ref *ruleRefExpr) (interface{}, bool) { return p.parseRule(rule) } -func (p *parser) parseSeqExpr(seq *seqExpr) (interface{}, bool) { +func (p *parser) parseSeqExpr(seq *seqExpr) (any, bool) { if p.debug { defer p.out(p.in("parseSeqExpr")) } - vals := make([]interface{}, 0, len(seq.exprs)) + vals := make([]any, 0, len(seq.exprs)) pt := p.pt state := p.cloneState() @@ -1324,7 +1326,7 @@ func (p *parser) parseSeqExpr(seq *seqExpr) (interface{}, bool) { return vals, true } -func (p *parser) parseStateCodeExpr(state *stateCodeExpr) (interface{}, bool) { +func (p *parser) parseStateCodeExpr(state *stateCodeExpr) (any, bool) { if p.debug { defer p.out(p.in("parseStateCodeExpr")) } @@ -1336,7 +1338,7 @@ func (p *parser) parseStateCodeExpr(state *stateCodeExpr) (interface{}, bool) { return nil, true } -func (p *parser) parseThrowExpr(expr *throwExpr) (interface{}, bool) { +func (p *parser) parseThrowExpr(expr *throwExpr) (any, bool) { if p.debug { defer p.out(p.in("parseThrowExpr")) } @@ -1352,12 +1354,12 @@ func (p *parser) parseThrowExpr(expr *throwExpr) (interface{}, bool) { return nil, false } -func (p *parser) parseZeroOrMoreExpr(expr *zeroOrMoreExpr) (interface{}, bool) { +func (p *parser) parseZeroOrMoreExpr(expr *zeroOrMoreExpr) (any, bool) { if p.debug { defer p.out(p.in("parseZeroOrMoreExpr")) } - var vals []interface{} + var vals []any for { p.pushV() @@ -1370,7 +1372,7 @@ func (p *parser) parseZeroOrMoreExpr(expr *zeroOrMoreExpr) (interface{}, bool) { } } -func (p *parser) parseZeroOrOneExpr(expr *zeroOrOneExpr) (interface{}, bool) { +func (p *parser) parseZeroOrOneExpr(expr *zeroOrOneExpr) (any, bool) { if p.debug { defer p.out(p.in("parseZeroOrOneExpr")) } diff --git a/test/issue_80/issue_80.go b/test/issue_80/issue_80.go index eae1c9bb..2843b0e1 100644 --- a/test/issue_80/issue_80.go +++ b/test/issue_80/issue_80.go @@ -24,13 +24,13 @@ var g = &grammar{ pos: position{line: 5, col: 1, offset: 22}, expr: &choiceExpr{ pos: position{line: 5, col: 9, offset: 30}, - alternatives: []interface{}{ + alternatives: []any{ &actionExpr{ pos: position{line: 5, col: 9, offset: 30}, run: (*parser).callonValue2, expr: &seqExpr{ pos: position{line: 5, col: 9, offset: 30}, - exprs: []interface{}{ + exprs: []any{ &zeroOrMoreExpr{ pos: position{line: 5, col: 9, offset: 30}, expr: &charClassMatcher{ @@ -53,7 +53,7 @@ var g = &grammar{ run: (*parser).callonValue7, expr: &seqExpr{ pos: position{line: 10, col: 5, offset: 158}, - exprs: []interface{}{ + exprs: []any{ &zeroOrMoreExpr{ pos: position{line: 10, col: 5, offset: 158}, expr: &charClassMatcher{ @@ -87,27 +87,27 @@ var g = &grammar{ }, } -func (c *current) onValue2() (interface{}, error) { +func (c *current) onValue2() (any, error) { // } this comment line should safely be ignored { return strconv.Atoi(string(c.text)) /* } this one too */ } -func (p *parser) callonValue2() (interface{}, error) { +func (p *parser) callonValue2() (any, error) { stack := p.vstack[len(p.vstack)-1] _ = stack return p.cur.onValue2() } -func (c *current) onValue7() (interface{}, error) { +func (c *current) onValue7() (any, error) { // } and this one return string(c.text), nil /* } / "a fake rule" { return nil, nil } */ } -func (p *parser) callonValue7() (interface{}, error) { +func (p *parser) callonValue7() (any, error) { stack := p.vstack[len(p.vstack)-1] _ = stack return p.cur.onValue7() @@ -251,7 +251,7 @@ func Recover(b bool) Option { // GlobalStore creates an Option to set a key to a certain value in // the globalStore. -func GlobalStore(key string, value interface{}) Option { +func GlobalStore(key string, value any) Option { return func(p *parser) Option { old := p.cur.globalStore[key] p.cur.globalStore[key] = value @@ -261,7 +261,7 @@ func GlobalStore(key string, value interface{}) Option { // InitState creates an Option to set a key to a certain value in // the global "state" store. -func InitState(key string, value interface{}) Option { +func InitState(key string, value any) Option { return func(p *parser) Option { old := p.cur.state[key] p.cur.state[key] = value @@ -270,7 +270,7 @@ func InitState(key string, value interface{}) Option { } // ParseFile parses the file identified by filename. -func ParseFile(filename string, opts ...Option) (i interface{}, err error) { // nolint: deadcode +func ParseFile(filename string, opts ...Option) (i any, err error) { // nolint: deadcode f, err := os.Open(filename) if err != nil { return nil, err @@ -285,7 +285,7 @@ func ParseFile(filename string, opts ...Option) (i interface{}, err error) { // // ParseReader parses the data from r using filename as information in the // error messages. -func ParseReader(filename string, r io.Reader, opts ...Option) (interface{}, error) { // nolint: deadcode +func ParseReader(filename string, r io.Reader, opts ...Option) (any, error) { // nolint: deadcode b, err := io.ReadAll(r) if err != nil { return nil, err @@ -296,7 +296,7 @@ func ParseReader(filename string, r io.Reader, opts ...Option) (interface{}, err // Parse parses the data from b using filename as information in the // error messages. -func Parse(filename string, b []byte, opts ...Option) (interface{}, error) { +func Parse(filename string, b []byte, opts ...Option) (any, error) { return newParser(filename, b, opts...).parse(g) } @@ -334,7 +334,7 @@ type current struct { globalStore storeDict } -type storeDict map[string]interface{} +type storeDict map[string]any // the AST types... @@ -349,34 +349,34 @@ type rule struct { pos position name string displayName string - expr interface{} + expr any } // nolint: structcheck type choiceExpr struct { pos position - alternatives []interface{} + alternatives []any } // nolint: structcheck type actionExpr struct { pos position - expr interface{} - run func(*parser) (interface{}, error) + expr any + run func(*parser) (any, error) } // nolint: structcheck type recoveryExpr struct { pos position - expr interface{} - recoverExpr interface{} + expr any + recoverExpr any failureLabel []string } // nolint: structcheck type seqExpr struct { pos position - exprs []interface{} + exprs []any } // nolint: structcheck @@ -389,20 +389,22 @@ type throwExpr struct { type labeledExpr struct { pos position label string - expr interface{} + expr any } // nolint: structcheck type expr struct { pos position - expr interface{} + expr any } -type andExpr expr // nolint: structcheck -type notExpr expr // nolint: structcheck -type zeroOrOneExpr expr // nolint: structcheck -type zeroOrMoreExpr expr // nolint: structcheck -type oneOrMoreExpr expr // nolint: structcheck +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 { @@ -550,7 +552,7 @@ func (p *parser) setOptions(opts []Option) { // nolint: structcheck,deadcode type resultTuple struct { - v interface{} + v any b bool end savepoint } @@ -596,12 +598,12 @@ type parser struct { memoize bool // memoization table for the packrat algorithm: // map[offset in source] map[expression or rule] {value, match} - memo map[int]map[interface{}]resultTuple + 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]interface{} + vstack []map[string]any // rule stack, allows identification of the current rule in errors rstack []*rule @@ -621,7 +623,7 @@ type parser struct { choiceNoMatch string // recovery expression stack, keeps track of the currently available recovery expression, these are traversed in reverse - recoveryStack []map[string]interface{} + recoveryStack []map[string]any } // push a variable set on the vstack. @@ -641,7 +643,7 @@ func (p *parser) pushV() { return } - m = make(map[string]interface{}) + m = make(map[string]any) p.vstack[len(p.vstack)-1] = m } @@ -657,7 +659,7 @@ func (p *parser) popV() { } // push a recovery expression with its labels to the recoveryStack -func (p *parser) pushRecovery(labels []string, expr interface{}) { +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) @@ -666,7 +668,7 @@ func (p *parser) pushRecovery(labels []string, expr interface{}) { p.recoveryStack = p.recoveryStack[:len(p.recoveryStack)+1] } - m := make(map[string]interface{}, len(labels)) + m := make(map[string]any, len(labels)) for _, fl := range labels { m[fl] = expr } @@ -786,11 +788,11 @@ func (p *parser) restore(pt savepoint) { // copies of the state to allow the parser to properly restore the state in // the case of backtracking. type Cloner interface { - Clone() interface{} + Clone() any } var statePool = &sync.Pool{ - New: func() interface{} { return make(storeDict) }, + New: func() any { return make(storeDict) }, } func (sd storeDict) Discard() { @@ -832,7 +834,7 @@ func (p *parser) sliceFrom(start savepoint) []byte { return p.data[start.position.offset:p.pt.position.offset] } -func (p *parser) getMemoized(node interface{}) (resultTuple, bool) { +func (p *parser) getMemoized(node any) (resultTuple, bool) { if len(p.memo) == 0 { return resultTuple{}, false } @@ -844,13 +846,13 @@ func (p *parser) getMemoized(node interface{}) (resultTuple, bool) { return res, ok } -func (p *parser) setMemoized(pt savepoint, node interface{}, tuple resultTuple) { +func (p *parser) setMemoized(pt savepoint, node any, tuple resultTuple) { if p.memo == nil { - p.memo = make(map[int]map[interface{}]resultTuple) + p.memo = make(map[int]map[any]resultTuple) } m := p.memo[pt.offset] if m == nil { - m = make(map[interface{}]resultTuple) + m = make(map[any]resultTuple) p.memo[pt.offset] = m } m[node] = tuple @@ -864,7 +866,7 @@ func (p *parser) buildRulesTable(g *grammar) { } // nolint: gocyclo -func (p *parser) parse(g *grammar) (val interface{}, err error) { +func (p *parser) parse(g *grammar) (val any, err error) { if len(g.rules) == 0 { p.addErr(errNoRule) return nil, p.errs.err() @@ -941,7 +943,7 @@ func listJoin(list []string, sep string, lastSep string) string { } } -func (p *parser) parseRule(rule *rule) (interface{}, bool) { +func (p *parser) parseRule(rule *rule) (any, bool) { if p.debug { defer p.out(p.in("parseRule " + rule.name)) } @@ -971,7 +973,7 @@ func (p *parser) parseRule(rule *rule) (interface{}, bool) { } // nolint: gocyclo -func (p *parser) parseExpr(expr interface{}) (interface{}, bool) { +func (p *parser) parseExpr(expr any) (any, bool) { var pt savepoint if p.memoize { @@ -988,7 +990,7 @@ func (p *parser) parseExpr(expr interface{}) (interface{}, bool) { panic(errMaxExprCnt) } - var val interface{} + var val any var ok bool switch expr := expr.(type) { case *actionExpr: @@ -1036,7 +1038,7 @@ func (p *parser) parseExpr(expr interface{}) (interface{}, bool) { return val, ok } -func (p *parser) parseActionExpr(act *actionExpr) (interface{}, bool) { +func (p *parser) parseActionExpr(act *actionExpr) (any, bool) { if p.debug { defer p.out(p.in("parseActionExpr")) } @@ -1061,7 +1063,7 @@ func (p *parser) parseActionExpr(act *actionExpr) (interface{}, bool) { return val, ok } -func (p *parser) parseAndCodeExpr(and *andCodeExpr) (interface{}, bool) { +func (p *parser) parseAndCodeExpr(and *andCodeExpr) (any, bool) { if p.debug { defer p.out(p.in("parseAndCodeExpr")) } @@ -1077,7 +1079,7 @@ func (p *parser) parseAndCodeExpr(and *andCodeExpr) (interface{}, bool) { return nil, ok } -func (p *parser) parseAndExpr(and *andExpr) (interface{}, bool) { +func (p *parser) parseAndExpr(and *andExpr) (any, bool) { if p.debug { defer p.out(p.in("parseAndExpr")) } @@ -1093,7 +1095,7 @@ func (p *parser) parseAndExpr(and *andExpr) (interface{}, bool) { return nil, ok } -func (p *parser) parseAnyMatcher(any *anyMatcher) (interface{}, bool) { +func (p *parser) parseAnyMatcher(any *anyMatcher) (any, bool) { if p.debug { defer p.out(p.in("parseAnyMatcher")) } @@ -1110,7 +1112,7 @@ func (p *parser) parseAnyMatcher(any *anyMatcher) (interface{}, bool) { } // nolint: gocyclo -func (p *parser) parseCharClassMatcher(chr *charClassMatcher) (interface{}, bool) { +func (p *parser) parseCharClassMatcher(chr *charClassMatcher) (any, bool) { if p.debug { defer p.out(p.in("parseCharClassMatcher")) } @@ -1191,7 +1193,7 @@ func (p *parser) incChoiceAltCnt(ch *choiceExpr, altI int) { m[alt]++ } -func (p *parser) parseChoiceExpr(ch *choiceExpr) (interface{}, bool) { +func (p *parser) parseChoiceExpr(ch *choiceExpr) (any, bool) { if p.debug { defer p.out(p.in("parseChoiceExpr")) } @@ -1215,7 +1217,7 @@ func (p *parser) parseChoiceExpr(ch *choiceExpr) (interface{}, bool) { return nil, false } -func (p *parser) parseLabeledExpr(lab *labeledExpr) (interface{}, bool) { +func (p *parser) parseLabeledExpr(lab *labeledExpr) (any, bool) { if p.debug { defer p.out(p.in("parseLabeledExpr")) } @@ -1230,7 +1232,7 @@ func (p *parser) parseLabeledExpr(lab *labeledExpr) (interface{}, bool) { return val, ok } -func (p *parser) parseLitMatcher(lit *litMatcher) (interface{}, bool) { +func (p *parser) parseLitMatcher(lit *litMatcher) (any, bool) { if p.debug { defer p.out(p.in("parseLitMatcher")) } @@ -1252,7 +1254,7 @@ func (p *parser) parseLitMatcher(lit *litMatcher) (interface{}, bool) { return p.sliceFrom(start), true } -func (p *parser) parseNotCodeExpr(not *notCodeExpr) (interface{}, bool) { +func (p *parser) parseNotCodeExpr(not *notCodeExpr) (any, bool) { if p.debug { defer p.out(p.in("parseNotCodeExpr")) } @@ -1268,7 +1270,7 @@ func (p *parser) parseNotCodeExpr(not *notCodeExpr) (interface{}, bool) { return nil, !ok } -func (p *parser) parseNotExpr(not *notExpr) (interface{}, bool) { +func (p *parser) parseNotExpr(not *notExpr) (any, bool) { if p.debug { defer p.out(p.in("parseNotExpr")) } @@ -1286,12 +1288,12 @@ func (p *parser) parseNotExpr(not *notExpr) (interface{}, bool) { return nil, !ok } -func (p *parser) parseOneOrMoreExpr(expr *oneOrMoreExpr) (interface{}, bool) { +func (p *parser) parseOneOrMoreExpr(expr *oneOrMoreExpr) (any, bool) { if p.debug { defer p.out(p.in("parseOneOrMoreExpr")) } - var vals []interface{} + var vals []any for { p.pushV() @@ -1308,7 +1310,7 @@ func (p *parser) parseOneOrMoreExpr(expr *oneOrMoreExpr) (interface{}, bool) { } } -func (p *parser) parseRecoveryExpr(recover *recoveryExpr) (interface{}, bool) { +func (p *parser) parseRecoveryExpr(recover *recoveryExpr) (any, bool) { if p.debug { defer p.out(p.in("parseRecoveryExpr (" + strings.Join(recover.failureLabel, ",") + ")")) } @@ -1320,7 +1322,7 @@ func (p *parser) parseRecoveryExpr(recover *recoveryExpr) (interface{}, bool) { return val, ok } -func (p *parser) parseRuleRefExpr(ref *ruleRefExpr) (interface{}, bool) { +func (p *parser) parseRuleRefExpr(ref *ruleRefExpr) (any, bool) { if p.debug { defer p.out(p.in("parseRuleRefExpr " + ref.name)) } @@ -1337,12 +1339,12 @@ func (p *parser) parseRuleRefExpr(ref *ruleRefExpr) (interface{}, bool) { return p.parseRule(rule) } -func (p *parser) parseSeqExpr(seq *seqExpr) (interface{}, bool) { +func (p *parser) parseSeqExpr(seq *seqExpr) (any, bool) { if p.debug { defer p.out(p.in("parseSeqExpr")) } - vals := make([]interface{}, 0, len(seq.exprs)) + vals := make([]any, 0, len(seq.exprs)) pt := p.pt state := p.cloneState() @@ -1358,7 +1360,7 @@ func (p *parser) parseSeqExpr(seq *seqExpr) (interface{}, bool) { return vals, true } -func (p *parser) parseStateCodeExpr(state *stateCodeExpr) (interface{}, bool) { +func (p *parser) parseStateCodeExpr(state *stateCodeExpr) (any, bool) { if p.debug { defer p.out(p.in("parseStateCodeExpr")) } @@ -1370,7 +1372,7 @@ func (p *parser) parseStateCodeExpr(state *stateCodeExpr) (interface{}, bool) { return nil, true } -func (p *parser) parseThrowExpr(expr *throwExpr) (interface{}, bool) { +func (p *parser) parseThrowExpr(expr *throwExpr) (any, bool) { if p.debug { defer p.out(p.in("parseThrowExpr")) } @@ -1386,12 +1388,12 @@ func (p *parser) parseThrowExpr(expr *throwExpr) (interface{}, bool) { return nil, false } -func (p *parser) parseZeroOrMoreExpr(expr *zeroOrMoreExpr) (interface{}, bool) { +func (p *parser) parseZeroOrMoreExpr(expr *zeroOrMoreExpr) (any, bool) { if p.debug { defer p.out(p.in("parseZeroOrMoreExpr")) } - var vals []interface{} + var vals []any for { p.pushV() @@ -1404,7 +1406,7 @@ func (p *parser) parseZeroOrMoreExpr(expr *zeroOrMoreExpr) (interface{}, bool) { } } -func (p *parser) parseZeroOrOneExpr(expr *zeroOrOneExpr) (interface{}, bool) { +func (p *parser) parseZeroOrOneExpr(expr *zeroOrOneExpr) (any, bool) { if p.debug { defer p.out(p.in("parseZeroOrOneExpr")) } diff --git a/test/issue_80/issue_80_test.go b/test/issue_80/issue_80_test.go index 430976e3..b30d7edf 100644 --- a/test/issue_80/issue_80_test.go +++ b/test/issue_80/issue_80_test.go @@ -2,9 +2,9 @@ package issue80 import "testing" -var cases = map[string]interface{}{ +var cases = map[string]any{ "12345": 12345, - "asdf": "asdf", + "asdf": "asdf", } func TestIgnoreComments(t *testing.T) { @@ -20,24 +20,22 @@ func TestIgnoreComments(t *testing.T) { got, ok := ret.(int) if !ok { t.Fatalf("incorrect output type %T for case %v, expected %T", - ret, tc, expt) + ret, tc, expt) } - if (expt != got) { + if expt != got { t.Fatalf("incorrect output got %v, expected %v", got, exp) } case string: got, ok := ret.(string) if !ok { t.Fatalf("incorrect output type %T for case %v, expected %T", - ret, tc, expt) + ret, tc, expt) } - if (expt != got) { + if expt != got { t.Fatalf("incorrect output got %v, expected %v", got, exp) } } } } - - diff --git a/test/labeled_failures/labeled_failures.go b/test/labeled_failures/labeled_failures.go index c1ea0397..2c2e6fa6 100644 --- a/test/labeled_failures/labeled_failures.go +++ b/test/labeled_failures/labeled_failures.go @@ -17,13 +17,13 @@ import ( "unicode/utf8" ) -func ids(id, list interface{}) (interface{}, error) { +func ids(id, list any) (any, error) { l := toStringSlice(list) l = append([]string{id.(string)}, l...) return l, nil } -func toStringSlice(v interface{}) []string { +func toStringSlice(v any) []string { if v == nil { return nil } @@ -34,30 +34,30 @@ var g = &grammar{ rules: []*rule{ { name: "S", - pos: position{line: 18, col: 1, offset: 268}, + pos: position{line: 18, col: 1, offset: 244}, expr: &recoveryExpr{ - pos: position{line: 18, col: 5, offset: 274}, + pos: position{line: 18, col: 5, offset: 250}, expr: &recoveryExpr{ - pos: position{line: 18, col: 5, offset: 274}, + pos: position{line: 18, col: 5, offset: 250}, expr: &actionExpr{ - pos: position{line: 18, col: 5, offset: 274}, + pos: position{line: 18, col: 5, offset: 250}, run: (*parser).callonS3, expr: &seqExpr{ - pos: position{line: 18, col: 5, offset: 274}, - exprs: []interface{}{ + pos: position{line: 18, col: 5, offset: 250}, + exprs: []any{ &labeledExpr{ - pos: position{line: 18, col: 5, offset: 274}, + pos: position{line: 18, col: 5, offset: 250}, label: "id", expr: &ruleRefExpr{ - pos: position{line: 18, col: 8, offset: 277}, + pos: position{line: 18, col: 8, offset: 253}, name: "ID", }, }, &labeledExpr{ - pos: position{line: 18, col: 11, offset: 280}, + pos: position{line: 18, col: 11, offset: 256}, label: "list", expr: &ruleRefExpr{ - pos: position{line: 18, col: 16, offset: 285}, + pos: position{line: 18, col: 16, offset: 261}, name: "List", }, }, @@ -65,7 +65,7 @@ var g = &grammar{ }, }, recoverExpr: &ruleRefExpr{ - pos: position{line: 20, col: 16, offset: 332}, + pos: position{line: 20, col: 16, offset: 308}, name: "ErrComma", }, failureLabel: []string{ @@ -73,7 +73,7 @@ var g = &grammar{ }, }, recoverExpr: &ruleRefExpr{ - pos: position{line: 20, col: 35, offset: 351}, + pos: position{line: 20, col: 35, offset: 327}, name: "ErrID", }, failureLabel: []string{ @@ -83,39 +83,39 @@ var g = &grammar{ }, { name: "List", - pos: position{line: 21, col: 1, offset: 357}, + pos: position{line: 21, col: 1, offset: 333}, expr: &choiceExpr{ - pos: position{line: 21, col: 8, offset: 366}, - alternatives: []interface{}{ + pos: position{line: 21, col: 8, offset: 342}, + alternatives: []any{ ¬Expr{ - pos: position{line: 21, col: 8, offset: 366}, + pos: position{line: 21, col: 8, offset: 342}, expr: &anyMatcher{ - line: 21, col: 9, offset: 367, + line: 21, col: 9, offset: 343, }, }, &actionExpr{ - pos: position{line: 21, col: 13, offset: 371}, + pos: position{line: 21, col: 13, offset: 347}, run: (*parser).callonList4, expr: &seqExpr{ - pos: position{line: 21, col: 13, offset: 371}, - exprs: []interface{}{ + pos: position{line: 21, col: 13, offset: 347}, + exprs: []any{ &ruleRefExpr{ - pos: position{line: 21, col: 13, offset: 371}, + pos: position{line: 21, col: 13, offset: 347}, name: "Comma", }, &labeledExpr{ - pos: position{line: 21, col: 19, offset: 377}, + pos: position{line: 21, col: 19, offset: 353}, label: "id", expr: &ruleRefExpr{ - pos: position{line: 21, col: 22, offset: 380}, + pos: position{line: 21, col: 22, offset: 356}, name: "ID", }, }, &labeledExpr{ - pos: position{line: 21, col: 25, offset: 383}, + pos: position{line: 21, col: 25, offset: 359}, label: "list", expr: &ruleRefExpr{ - pos: position{line: 21, col: 30, offset: 388}, + pos: position{line: 21, col: 30, offset: 364}, name: "List", }, }, @@ -127,24 +127,24 @@ var g = &grammar{ }, { name: "ID", - pos: position{line: 24, col: 1, offset: 422}, + pos: position{line: 24, col: 1, offset: 398}, expr: &choiceExpr{ - pos: position{line: 24, col: 6, offset: 429}, - alternatives: []interface{}{ + pos: position{line: 24, col: 6, offset: 405}, + alternatives: []any{ &actionExpr{ - pos: position{line: 24, col: 6, offset: 429}, + pos: position{line: 24, col: 6, offset: 405}, run: (*parser).callonID2, expr: &seqExpr{ - pos: position{line: 24, col: 6, offset: 429}, - exprs: []interface{}{ + pos: position{line: 24, col: 6, offset: 405}, + exprs: []any{ &ruleRefExpr{ - pos: position{line: 24, col: 6, offset: 429}, + pos: position{line: 24, col: 6, offset: 405}, name: "Sp", }, &oneOrMoreExpr{ - pos: position{line: 24, col: 9, offset: 432}, + pos: position{line: 24, col: 9, offset: 408}, expr: &charClassMatcher{ - pos: position{line: 24, col: 9, offset: 432}, + pos: position{line: 24, col: 9, offset: 408}, val: "[a-z]", ranges: []rune{'a', 'z'}, ignoreCase: false, @@ -155,7 +155,7 @@ var g = &grammar{ }, }, &throwExpr{ - pos: position{line: 26, col: 5, offset: 505}, + pos: position{line: 26, col: 5, offset: 481}, label: "errId", }, }, @@ -163,19 +163,19 @@ var g = &grammar{ }, { name: "Comma", - pos: position{line: 27, col: 1, offset: 514}, + pos: position{line: 27, col: 1, offset: 490}, expr: &choiceExpr{ - pos: position{line: 27, col: 9, offset: 524}, - alternatives: []interface{}{ + pos: position{line: 27, col: 9, offset: 500}, + alternatives: []any{ &seqExpr{ - pos: position{line: 27, col: 9, offset: 524}, - exprs: []interface{}{ + pos: position{line: 27, col: 9, offset: 500}, + exprs: []any{ &ruleRefExpr{ - pos: position{line: 27, col: 9, offset: 524}, + pos: position{line: 27, col: 9, offset: 500}, name: "Sp", }, &litMatcher{ - pos: position{line: 27, col: 12, offset: 527}, + pos: position{line: 27, col: 12, offset: 503}, val: ",", ignoreCase: false, want: "\",\"", @@ -183,7 +183,7 @@ var g = &grammar{ }, }, &throwExpr{ - pos: position{line: 27, col: 18, offset: 533}, + pos: position{line: 27, col: 18, offset: 509}, label: "errComma", }, }, @@ -191,11 +191,11 @@ var g = &grammar{ }, { name: "Sp", - pos: position{line: 28, col: 1, offset: 545}, + pos: position{line: 28, col: 1, offset: 521}, expr: &zeroOrMoreExpr{ - pos: position{line: 28, col: 6, offset: 552}, + pos: position{line: 28, col: 6, offset: 528}, expr: &charClassMatcher{ - pos: position{line: 28, col: 6, offset: 552}, + pos: position{line: 28, col: 6, offset: 528}, val: "[ \\t\\r\\n]", chars: []rune{' ', '\t', '\r', '\n'}, ignoreCase: false, @@ -205,25 +205,25 @@ var g = &grammar{ }, { name: "ErrComma", - pos: position{line: 30, col: 1, offset: 564}, + pos: position{line: 30, col: 1, offset: 540}, expr: &seqExpr{ - pos: position{line: 30, col: 12, offset: 577}, - exprs: []interface{}{ + pos: position{line: 30, col: 12, offset: 553}, + exprs: []any{ &stateCodeExpr{ - pos: position{line: 30, col: 12, offset: 577}, + pos: position{line: 30, col: 12, offset: 553}, run: (*parser).callonErrComma2, }, &zeroOrMoreExpr{ - pos: position{line: 32, col: 7, offset: 629}, + pos: position{line: 32, col: 7, offset: 605}, expr: &seqExpr{ - pos: position{line: 32, col: 9, offset: 631}, - exprs: []interface{}{ + pos: position{line: 32, col: 9, offset: 607}, + exprs: []any{ ¬Expr{ - pos: position{line: 32, col: 9, offset: 631}, + pos: position{line: 32, col: 9, offset: 607}, expr: &oneOrMoreExpr{ - pos: position{line: 32, col: 11, offset: 633}, + pos: position{line: 32, col: 11, offset: 609}, expr: &charClassMatcher{ - pos: position{line: 32, col: 11, offset: 633}, + pos: position{line: 32, col: 11, offset: 609}, val: "[a-z]", ranges: []rune{'a', 'z'}, ignoreCase: false, @@ -232,7 +232,7 @@ var g = &grammar{ }, }, &anyMatcher{ - line: 32, col: 19, offset: 641, + line: 32, col: 19, offset: 617, }, }, }, @@ -242,33 +242,33 @@ var g = &grammar{ }, { name: "ErrID", - pos: position{line: 33, col: 1, offset: 645}, + pos: position{line: 33, col: 1, offset: 621}, expr: &actionExpr{ - pos: position{line: 33, col: 9, offset: 655}, + pos: position{line: 33, col: 9, offset: 631}, run: (*parser).callonErrID1, expr: &seqExpr{ - pos: position{line: 33, col: 9, offset: 655}, - exprs: []interface{}{ + pos: position{line: 33, col: 9, offset: 631}, + exprs: []any{ &stateCodeExpr{ - pos: position{line: 33, col: 9, offset: 655}, + pos: position{line: 33, col: 9, offset: 631}, run: (*parser).callonErrID3, }, &zeroOrMoreExpr{ - pos: position{line: 35, col: 7, offset: 717}, + pos: position{line: 35, col: 7, offset: 693}, expr: &seqExpr{ - pos: position{line: 35, col: 9, offset: 719}, - exprs: []interface{}{ + pos: position{line: 35, col: 9, offset: 695}, + exprs: []any{ ¬Expr{ - pos: position{line: 35, col: 9, offset: 719}, + pos: position{line: 35, col: 9, offset: 695}, expr: &litMatcher{ - pos: position{line: 35, col: 11, offset: 721}, + pos: position{line: 35, col: 11, offset: 697}, val: ",", ignoreCase: false, want: "\",\"", }, }, &anyMatcher{ - line: 35, col: 16, offset: 726, + line: 35, col: 16, offset: 702, }, }, }, @@ -280,31 +280,31 @@ var g = &grammar{ }, } -func (c *current) onS3(id, list interface{}) (interface{}, error) { +func (c *current) onS3(id, list any) (any, error) { return ids(id, list) } -func (p *parser) callonS3() (interface{}, error) { +func (p *parser) callonS3() (any, error) { stack := p.vstack[len(p.vstack)-1] _ = stack return p.cur.onS3(stack["id"], stack["list"]) } -func (c *current) onList4(id, list interface{}) (interface{}, error) { +func (c *current) onList4(id, list any) (any, error) { return ids(id, list) } -func (p *parser) callonList4() (interface{}, error) { +func (p *parser) callonList4() (any, error) { stack := p.vstack[len(p.vstack)-1] _ = stack return p.cur.onList4(stack["id"], stack["list"]) } -func (c *current) onID2() (interface{}, error) { +func (c *current) onID2() (any, error) { return strings.TrimLeft(string(c.text), " \t\r\n"), nil } -func (p *parser) callonID2() (interface{}, error) { +func (p *parser) callonID2() (any, error) { stack := p.vstack[len(p.vstack)-1] _ = stack return p.cur.onID2() @@ -332,11 +332,11 @@ func (p *parser) callonErrID3() error { return p.cur.onErrID3() } -func (c *current) onErrID1() (interface{}, error) { +func (c *current) onErrID1() (any, error) { return "NONE", nil } -func (p *parser) callonErrID1() (interface{}, error) { +func (p *parser) callonErrID1() (any, error) { stack := p.vstack[len(p.vstack)-1] _ = stack return p.cur.onErrID1() @@ -480,7 +480,7 @@ func Recover(b bool) Option { // GlobalStore creates an Option to set a key to a certain value in // the globalStore. -func GlobalStore(key string, value interface{}) Option { +func GlobalStore(key string, value any) Option { return func(p *parser) Option { old := p.cur.globalStore[key] p.cur.globalStore[key] = value @@ -490,7 +490,7 @@ func GlobalStore(key string, value interface{}) Option { // InitState creates an Option to set a key to a certain value in // the global "state" store. -func InitState(key string, value interface{}) Option { +func InitState(key string, value any) Option { return func(p *parser) Option { old := p.cur.state[key] p.cur.state[key] = value @@ -499,7 +499,7 @@ func InitState(key string, value interface{}) Option { } // ParseFile parses the file identified by filename. -func ParseFile(filename string, opts ...Option) (i interface{}, err error) { // nolint: deadcode +func ParseFile(filename string, opts ...Option) (i any, err error) { // nolint: deadcode f, err := os.Open(filename) if err != nil { return nil, err @@ -514,7 +514,7 @@ func ParseFile(filename string, opts ...Option) (i interface{}, err error) { // // ParseReader parses the data from r using filename as information in the // error messages. -func ParseReader(filename string, r io.Reader, opts ...Option) (interface{}, error) { // nolint: deadcode +func ParseReader(filename string, r io.Reader, opts ...Option) (any, error) { // nolint: deadcode b, err := io.ReadAll(r) if err != nil { return nil, err @@ -525,7 +525,7 @@ func ParseReader(filename string, r io.Reader, opts ...Option) (interface{}, err // Parse parses the data from b using filename as information in the // error messages. -func Parse(filename string, b []byte, opts ...Option) (interface{}, error) { +func Parse(filename string, b []byte, opts ...Option) (any, error) { return newParser(filename, b, opts...).parse(g) } @@ -563,7 +563,7 @@ type current struct { globalStore storeDict } -type storeDict map[string]interface{} +type storeDict map[string]any // the AST types... @@ -578,34 +578,34 @@ type rule struct { pos position name string displayName string - expr interface{} + expr any } // nolint: structcheck type choiceExpr struct { pos position - alternatives []interface{} + alternatives []any } // nolint: structcheck type actionExpr struct { pos position - expr interface{} - run func(*parser) (interface{}, error) + expr any + run func(*parser) (any, error) } // nolint: structcheck type recoveryExpr struct { pos position - expr interface{} - recoverExpr interface{} + expr any + recoverExpr any failureLabel []string } // nolint: structcheck type seqExpr struct { pos position - exprs []interface{} + exprs []any } // nolint: structcheck @@ -618,20 +618,22 @@ type throwExpr struct { type labeledExpr struct { pos position label string - expr interface{} + expr any } // nolint: structcheck type expr struct { pos position - expr interface{} + expr any } -type andExpr expr // nolint: structcheck -type notExpr expr // nolint: structcheck -type zeroOrOneExpr expr // nolint: structcheck -type zeroOrMoreExpr expr // nolint: structcheck -type oneOrMoreExpr expr // nolint: structcheck +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 { @@ -779,7 +781,7 @@ func (p *parser) setOptions(opts []Option) { // nolint: structcheck,deadcode type resultTuple struct { - v interface{} + v any b bool end savepoint } @@ -825,12 +827,12 @@ type parser struct { memoize bool // memoization table for the packrat algorithm: // map[offset in source] map[expression or rule] {value, match} - memo map[int]map[interface{}]resultTuple + 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]interface{} + vstack []map[string]any // rule stack, allows identification of the current rule in errors rstack []*rule @@ -850,7 +852,7 @@ type parser struct { choiceNoMatch string // recovery expression stack, keeps track of the currently available recovery expression, these are traversed in reverse - recoveryStack []map[string]interface{} + recoveryStack []map[string]any } // push a variable set on the vstack. @@ -870,7 +872,7 @@ func (p *parser) pushV() { return } - m = make(map[string]interface{}) + m = make(map[string]any) p.vstack[len(p.vstack)-1] = m } @@ -886,7 +888,7 @@ func (p *parser) popV() { } // push a recovery expression with its labels to the recoveryStack -func (p *parser) pushRecovery(labels []string, expr interface{}) { +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) @@ -895,7 +897,7 @@ func (p *parser) pushRecovery(labels []string, expr interface{}) { p.recoveryStack = p.recoveryStack[:len(p.recoveryStack)+1] } - m := make(map[string]interface{}, len(labels)) + m := make(map[string]any, len(labels)) for _, fl := range labels { m[fl] = expr } @@ -1015,11 +1017,11 @@ func (p *parser) restore(pt savepoint) { // copies of the state to allow the parser to properly restore the state in // the case of backtracking. type Cloner interface { - Clone() interface{} + Clone() any } var statePool = &sync.Pool{ - New: func() interface{} { return make(storeDict) }, + New: func() any { return make(storeDict) }, } func (sd storeDict) Discard() { @@ -1061,7 +1063,7 @@ func (p *parser) sliceFrom(start savepoint) []byte { return p.data[start.position.offset:p.pt.position.offset] } -func (p *parser) getMemoized(node interface{}) (resultTuple, bool) { +func (p *parser) getMemoized(node any) (resultTuple, bool) { if len(p.memo) == 0 { return resultTuple{}, false } @@ -1073,13 +1075,13 @@ func (p *parser) getMemoized(node interface{}) (resultTuple, bool) { return res, ok } -func (p *parser) setMemoized(pt savepoint, node interface{}, tuple resultTuple) { +func (p *parser) setMemoized(pt savepoint, node any, tuple resultTuple) { if p.memo == nil { - p.memo = make(map[int]map[interface{}]resultTuple) + p.memo = make(map[int]map[any]resultTuple) } m := p.memo[pt.offset] if m == nil { - m = make(map[interface{}]resultTuple) + m = make(map[any]resultTuple) p.memo[pt.offset] = m } m[node] = tuple @@ -1093,7 +1095,7 @@ func (p *parser) buildRulesTable(g *grammar) { } // nolint: gocyclo -func (p *parser) parse(g *grammar) (val interface{}, err error) { +func (p *parser) parse(g *grammar) (val any, err error) { if len(g.rules) == 0 { p.addErr(errNoRule) return nil, p.errs.err() @@ -1170,7 +1172,7 @@ func listJoin(list []string, sep string, lastSep string) string { } } -func (p *parser) parseRule(rule *rule) (interface{}, bool) { +func (p *parser) parseRule(rule *rule) (any, bool) { if p.debug { defer p.out(p.in("parseRule " + rule.name)) } @@ -1200,7 +1202,7 @@ func (p *parser) parseRule(rule *rule) (interface{}, bool) { } // nolint: gocyclo -func (p *parser) parseExpr(expr interface{}) (interface{}, bool) { +func (p *parser) parseExpr(expr any) (any, bool) { var pt savepoint if p.memoize { @@ -1217,7 +1219,7 @@ func (p *parser) parseExpr(expr interface{}) (interface{}, bool) { panic(errMaxExprCnt) } - var val interface{} + var val any var ok bool switch expr := expr.(type) { case *actionExpr: @@ -1265,7 +1267,7 @@ func (p *parser) parseExpr(expr interface{}) (interface{}, bool) { return val, ok } -func (p *parser) parseActionExpr(act *actionExpr) (interface{}, bool) { +func (p *parser) parseActionExpr(act *actionExpr) (any, bool) { if p.debug { defer p.out(p.in("parseActionExpr")) } @@ -1290,7 +1292,7 @@ func (p *parser) parseActionExpr(act *actionExpr) (interface{}, bool) { return val, ok } -func (p *parser) parseAndCodeExpr(and *andCodeExpr) (interface{}, bool) { +func (p *parser) parseAndCodeExpr(and *andCodeExpr) (any, bool) { if p.debug { defer p.out(p.in("parseAndCodeExpr")) } @@ -1306,7 +1308,7 @@ func (p *parser) parseAndCodeExpr(and *andCodeExpr) (interface{}, bool) { return nil, ok } -func (p *parser) parseAndExpr(and *andExpr) (interface{}, bool) { +func (p *parser) parseAndExpr(and *andExpr) (any, bool) { if p.debug { defer p.out(p.in("parseAndExpr")) } @@ -1322,7 +1324,7 @@ func (p *parser) parseAndExpr(and *andExpr) (interface{}, bool) { return nil, ok } -func (p *parser) parseAnyMatcher(any *anyMatcher) (interface{}, bool) { +func (p *parser) parseAnyMatcher(any *anyMatcher) (any, bool) { if p.debug { defer p.out(p.in("parseAnyMatcher")) } @@ -1339,7 +1341,7 @@ func (p *parser) parseAnyMatcher(any *anyMatcher) (interface{}, bool) { } // nolint: gocyclo -func (p *parser) parseCharClassMatcher(chr *charClassMatcher) (interface{}, bool) { +func (p *parser) parseCharClassMatcher(chr *charClassMatcher) (any, bool) { if p.debug { defer p.out(p.in("parseCharClassMatcher")) } @@ -1420,7 +1422,7 @@ func (p *parser) incChoiceAltCnt(ch *choiceExpr, altI int) { m[alt]++ } -func (p *parser) parseChoiceExpr(ch *choiceExpr) (interface{}, bool) { +func (p *parser) parseChoiceExpr(ch *choiceExpr) (any, bool) { if p.debug { defer p.out(p.in("parseChoiceExpr")) } @@ -1444,7 +1446,7 @@ func (p *parser) parseChoiceExpr(ch *choiceExpr) (interface{}, bool) { return nil, false } -func (p *parser) parseLabeledExpr(lab *labeledExpr) (interface{}, bool) { +func (p *parser) parseLabeledExpr(lab *labeledExpr) (any, bool) { if p.debug { defer p.out(p.in("parseLabeledExpr")) } @@ -1459,7 +1461,7 @@ func (p *parser) parseLabeledExpr(lab *labeledExpr) (interface{}, bool) { return val, ok } -func (p *parser) parseLitMatcher(lit *litMatcher) (interface{}, bool) { +func (p *parser) parseLitMatcher(lit *litMatcher) (any, bool) { if p.debug { defer p.out(p.in("parseLitMatcher")) } @@ -1481,7 +1483,7 @@ func (p *parser) parseLitMatcher(lit *litMatcher) (interface{}, bool) { return p.sliceFrom(start), true } -func (p *parser) parseNotCodeExpr(not *notCodeExpr) (interface{}, bool) { +func (p *parser) parseNotCodeExpr(not *notCodeExpr) (any, bool) { if p.debug { defer p.out(p.in("parseNotCodeExpr")) } @@ -1497,7 +1499,7 @@ func (p *parser) parseNotCodeExpr(not *notCodeExpr) (interface{}, bool) { return nil, !ok } -func (p *parser) parseNotExpr(not *notExpr) (interface{}, bool) { +func (p *parser) parseNotExpr(not *notExpr) (any, bool) { if p.debug { defer p.out(p.in("parseNotExpr")) } @@ -1515,12 +1517,12 @@ func (p *parser) parseNotExpr(not *notExpr) (interface{}, bool) { return nil, !ok } -func (p *parser) parseOneOrMoreExpr(expr *oneOrMoreExpr) (interface{}, bool) { +func (p *parser) parseOneOrMoreExpr(expr *oneOrMoreExpr) (any, bool) { if p.debug { defer p.out(p.in("parseOneOrMoreExpr")) } - var vals []interface{} + var vals []any for { p.pushV() @@ -1537,7 +1539,7 @@ func (p *parser) parseOneOrMoreExpr(expr *oneOrMoreExpr) (interface{}, bool) { } } -func (p *parser) parseRecoveryExpr(recover *recoveryExpr) (interface{}, bool) { +func (p *parser) parseRecoveryExpr(recover *recoveryExpr) (any, bool) { if p.debug { defer p.out(p.in("parseRecoveryExpr (" + strings.Join(recover.failureLabel, ",") + ")")) } @@ -1549,7 +1551,7 @@ func (p *parser) parseRecoveryExpr(recover *recoveryExpr) (interface{}, bool) { return val, ok } -func (p *parser) parseRuleRefExpr(ref *ruleRefExpr) (interface{}, bool) { +func (p *parser) parseRuleRefExpr(ref *ruleRefExpr) (any, bool) { if p.debug { defer p.out(p.in("parseRuleRefExpr " + ref.name)) } @@ -1566,12 +1568,12 @@ func (p *parser) parseRuleRefExpr(ref *ruleRefExpr) (interface{}, bool) { return p.parseRule(rule) } -func (p *parser) parseSeqExpr(seq *seqExpr) (interface{}, bool) { +func (p *parser) parseSeqExpr(seq *seqExpr) (any, bool) { if p.debug { defer p.out(p.in("parseSeqExpr")) } - vals := make([]interface{}, 0, len(seq.exprs)) + vals := make([]any, 0, len(seq.exprs)) pt := p.pt state := p.cloneState() @@ -1587,7 +1589,7 @@ func (p *parser) parseSeqExpr(seq *seqExpr) (interface{}, bool) { return vals, true } -func (p *parser) parseStateCodeExpr(state *stateCodeExpr) (interface{}, bool) { +func (p *parser) parseStateCodeExpr(state *stateCodeExpr) (any, bool) { if p.debug { defer p.out(p.in("parseStateCodeExpr")) } @@ -1599,7 +1601,7 @@ func (p *parser) parseStateCodeExpr(state *stateCodeExpr) (interface{}, bool) { return nil, true } -func (p *parser) parseThrowExpr(expr *throwExpr) (interface{}, bool) { +func (p *parser) parseThrowExpr(expr *throwExpr) (any, bool) { if p.debug { defer p.out(p.in("parseThrowExpr")) } @@ -1615,12 +1617,12 @@ func (p *parser) parseThrowExpr(expr *throwExpr) (interface{}, bool) { return nil, false } -func (p *parser) parseZeroOrMoreExpr(expr *zeroOrMoreExpr) (interface{}, bool) { +func (p *parser) parseZeroOrMoreExpr(expr *zeroOrMoreExpr) (any, bool) { if p.debug { defer p.out(p.in("parseZeroOrMoreExpr")) } - var vals []interface{} + var vals []any for { p.pushV() @@ -1633,7 +1635,7 @@ func (p *parser) parseZeroOrMoreExpr(expr *zeroOrMoreExpr) (interface{}, bool) { } } -func (p *parser) parseZeroOrOneExpr(expr *zeroOrOneExpr) (interface{}, bool) { +func (p *parser) parseZeroOrOneExpr(expr *zeroOrOneExpr) (any, bool) { if p.debug { defer p.out(p.in("parseZeroOrOneExpr")) } diff --git a/test/labeled_failures/labeled_failures.peg b/test/labeled_failures/labeled_failures.peg index 1a861d30..089a0be8 100644 --- a/test/labeled_failures/labeled_failures.peg +++ b/test/labeled_failures/labeled_failures.peg @@ -1,13 +1,13 @@ { package labeledfailures -func ids(id, list interface{}) (interface{}, error) { +func ids(id, list any) (any, error) { l := toStringSlice(list) l = append([]string{id.(string)}, l...) return l, nil } -func toStringSlice(v interface{}) []string { +func toStringSlice(v any) []string { if v == nil { return nil } diff --git a/test/linear/linear.go b/test/linear/linear.go index f672ecdd..db6940e6 100644 --- a/test/linear/linear.go +++ b/test/linear/linear.go @@ -24,13 +24,13 @@ var g = &grammar{ pos: position{line: 7, col: 1, offset: 75}, expr: &seqExpr{ pos: position{line: 7, col: 8, offset: 84}, - exprs: []interface{}{ + exprs: []any{ &choiceExpr{ pos: position{line: 7, col: 10, offset: 86}, - alternatives: []interface{}{ + alternatives: []any{ &seqExpr{ pos: position{line: 7, col: 10, offset: 86}, - exprs: []interface{}{ + exprs: []any{ &ruleRefExpr{ pos: position{line: 7, col: 10, offset: 86}, name: "L", @@ -46,7 +46,7 @@ var g = &grammar{ }, &seqExpr{ pos: position{line: 7, col: 17, offset: 93}, - exprs: []interface{}{ + exprs: []any{ &ruleRefExpr{ pos: position{line: 7, col: 17, offset: 93}, name: "L", @@ -62,7 +62,7 @@ var g = &grammar{ }, &seqExpr{ pos: position{line: 7, col: 24, offset: 100}, - exprs: []interface{}{ + exprs: []any{ &ruleRefExpr{ pos: position{line: 7, col: 24, offset: 100}, name: "N", @@ -78,7 +78,7 @@ var g = &grammar{ }, &seqExpr{ pos: position{line: 7, col: 31, offset: 107}, - exprs: []interface{}{ + exprs: []any{ &ruleRefExpr{ pos: position{line: 7, col: 31, offset: 107}, name: "N", @@ -94,7 +94,7 @@ var g = &grammar{ }, &seqExpr{ pos: position{line: 7, col: 38, offset: 114}, - exprs: []interface{}{ + exprs: []any{ &ruleRefExpr{ pos: position{line: 7, col: 38, offset: 114}, name: "S", @@ -110,7 +110,7 @@ var g = &grammar{ }, &seqExpr{ pos: position{line: 7, col: 45, offset: 121}, - exprs: []interface{}{ + exprs: []any{ &ruleRefExpr{ pos: position{line: 7, col: 45, offset: 121}, name: "S", @@ -333,7 +333,7 @@ func Recover(b bool) Option { // GlobalStore creates an Option to set a key to a certain value in // the globalStore. -func GlobalStore(key string, value interface{}) Option { +func GlobalStore(key string, value any) Option { return func(p *parser) Option { old := p.cur.globalStore[key] p.cur.globalStore[key] = value @@ -343,7 +343,7 @@ func GlobalStore(key string, value interface{}) Option { // InitState creates an Option to set a key to a certain value in // the global "state" store. -func InitState(key string, value interface{}) Option { +func InitState(key string, value any) Option { return func(p *parser) Option { old := p.cur.state[key] p.cur.state[key] = value @@ -352,7 +352,7 @@ func InitState(key string, value interface{}) Option { } // ParseFile parses the file identified by filename. -func ParseFile(filename string, opts ...Option) (i interface{}, err error) { // nolint: deadcode +func ParseFile(filename string, opts ...Option) (i any, err error) { // nolint: deadcode f, err := os.Open(filename) if err != nil { return nil, err @@ -367,7 +367,7 @@ func ParseFile(filename string, opts ...Option) (i interface{}, err error) { // // ParseReader parses the data from r using filename as information in the // error messages. -func ParseReader(filename string, r io.Reader, opts ...Option) (interface{}, error) { // nolint: deadcode +func ParseReader(filename string, r io.Reader, opts ...Option) (any, error) { // nolint: deadcode b, err := io.ReadAll(r) if err != nil { return nil, err @@ -378,7 +378,7 @@ func ParseReader(filename string, r io.Reader, opts ...Option) (interface{}, err // Parse parses the data from b using filename as information in the // error messages. -func Parse(filename string, b []byte, opts ...Option) (interface{}, error) { +func Parse(filename string, b []byte, opts ...Option) (any, error) { return newParser(filename, b, opts...).parse(g) } @@ -416,7 +416,7 @@ type current struct { globalStore storeDict } -type storeDict map[string]interface{} +type storeDict map[string]any // the AST types... @@ -431,34 +431,34 @@ type rule struct { pos position name string displayName string - expr interface{} + expr any } // nolint: structcheck type choiceExpr struct { pos position - alternatives []interface{} + alternatives []any } // nolint: structcheck type actionExpr struct { pos position - expr interface{} - run func(*parser) (interface{}, error) + expr any + run func(*parser) (any, error) } // nolint: structcheck type recoveryExpr struct { pos position - expr interface{} - recoverExpr interface{} + expr any + recoverExpr any failureLabel []string } // nolint: structcheck type seqExpr struct { pos position - exprs []interface{} + exprs []any } // nolint: structcheck @@ -471,20 +471,22 @@ type throwExpr struct { type labeledExpr struct { pos position label string - expr interface{} + expr any } // nolint: structcheck type expr struct { pos position - expr interface{} + expr any } -type andExpr expr // nolint: structcheck -type notExpr expr // nolint: structcheck -type zeroOrOneExpr expr // nolint: structcheck -type zeroOrMoreExpr expr // nolint: structcheck -type oneOrMoreExpr expr // nolint: structcheck +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 { @@ -632,7 +634,7 @@ func (p *parser) setOptions(opts []Option) { // nolint: structcheck,deadcode type resultTuple struct { - v interface{} + v any b bool end savepoint } @@ -678,12 +680,12 @@ type parser struct { memoize bool // memoization table for the packrat algorithm: // map[offset in source] map[expression or rule] {value, match} - memo map[int]map[interface{}]resultTuple + 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]interface{} + vstack []map[string]any // rule stack, allows identification of the current rule in errors rstack []*rule @@ -703,7 +705,7 @@ type parser struct { choiceNoMatch string // recovery expression stack, keeps track of the currently available recovery expression, these are traversed in reverse - recoveryStack []map[string]interface{} + recoveryStack []map[string]any } // push a variable set on the vstack. @@ -723,7 +725,7 @@ func (p *parser) pushV() { return } - m = make(map[string]interface{}) + m = make(map[string]any) p.vstack[len(p.vstack)-1] = m } @@ -739,7 +741,7 @@ func (p *parser) popV() { } // push a recovery expression with its labels to the recoveryStack -func (p *parser) pushRecovery(labels []string, expr interface{}) { +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) @@ -748,7 +750,7 @@ func (p *parser) pushRecovery(labels []string, expr interface{}) { p.recoveryStack = p.recoveryStack[:len(p.recoveryStack)+1] } - m := make(map[string]interface{}, len(labels)) + m := make(map[string]any, len(labels)) for _, fl := range labels { m[fl] = expr } @@ -868,11 +870,11 @@ func (p *parser) restore(pt savepoint) { // copies of the state to allow the parser to properly restore the state in // the case of backtracking. type Cloner interface { - Clone() interface{} + Clone() any } var statePool = &sync.Pool{ - New: func() interface{} { return make(storeDict) }, + New: func() any { return make(storeDict) }, } func (sd storeDict) Discard() { @@ -914,7 +916,7 @@ func (p *parser) sliceFrom(start savepoint) []byte { return p.data[start.position.offset:p.pt.position.offset] } -func (p *parser) getMemoized(node interface{}) (resultTuple, bool) { +func (p *parser) getMemoized(node any) (resultTuple, bool) { if len(p.memo) == 0 { return resultTuple{}, false } @@ -926,13 +928,13 @@ func (p *parser) getMemoized(node interface{}) (resultTuple, bool) { return res, ok } -func (p *parser) setMemoized(pt savepoint, node interface{}, tuple resultTuple) { +func (p *parser) setMemoized(pt savepoint, node any, tuple resultTuple) { if p.memo == nil { - p.memo = make(map[int]map[interface{}]resultTuple) + p.memo = make(map[int]map[any]resultTuple) } m := p.memo[pt.offset] if m == nil { - m = make(map[interface{}]resultTuple) + m = make(map[any]resultTuple) p.memo[pt.offset] = m } m[node] = tuple @@ -946,7 +948,7 @@ func (p *parser) buildRulesTable(g *grammar) { } // nolint: gocyclo -func (p *parser) parse(g *grammar) (val interface{}, err error) { +func (p *parser) parse(g *grammar) (val any, err error) { if len(g.rules) == 0 { p.addErr(errNoRule) return nil, p.errs.err() @@ -1023,7 +1025,7 @@ func listJoin(list []string, sep string, lastSep string) string { } } -func (p *parser) parseRule(rule *rule) (interface{}, bool) { +func (p *parser) parseRule(rule *rule) (any, bool) { if p.debug { defer p.out(p.in("parseRule " + rule.name)) } @@ -1053,7 +1055,7 @@ func (p *parser) parseRule(rule *rule) (interface{}, bool) { } // nolint: gocyclo -func (p *parser) parseExpr(expr interface{}) (interface{}, bool) { +func (p *parser) parseExpr(expr any) (any, bool) { var pt savepoint if p.memoize { @@ -1070,7 +1072,7 @@ func (p *parser) parseExpr(expr interface{}) (interface{}, bool) { panic(errMaxExprCnt) } - var val interface{} + var val any var ok bool switch expr := expr.(type) { case *actionExpr: @@ -1118,7 +1120,7 @@ func (p *parser) parseExpr(expr interface{}) (interface{}, bool) { return val, ok } -func (p *parser) parseActionExpr(act *actionExpr) (interface{}, bool) { +func (p *parser) parseActionExpr(act *actionExpr) (any, bool) { if p.debug { defer p.out(p.in("parseActionExpr")) } @@ -1143,7 +1145,7 @@ func (p *parser) parseActionExpr(act *actionExpr) (interface{}, bool) { return val, ok } -func (p *parser) parseAndCodeExpr(and *andCodeExpr) (interface{}, bool) { +func (p *parser) parseAndCodeExpr(and *andCodeExpr) (any, bool) { if p.debug { defer p.out(p.in("parseAndCodeExpr")) } @@ -1159,7 +1161,7 @@ func (p *parser) parseAndCodeExpr(and *andCodeExpr) (interface{}, bool) { return nil, ok } -func (p *parser) parseAndExpr(and *andExpr) (interface{}, bool) { +func (p *parser) parseAndExpr(and *andExpr) (any, bool) { if p.debug { defer p.out(p.in("parseAndExpr")) } @@ -1175,7 +1177,7 @@ func (p *parser) parseAndExpr(and *andExpr) (interface{}, bool) { return nil, ok } -func (p *parser) parseAnyMatcher(any *anyMatcher) (interface{}, bool) { +func (p *parser) parseAnyMatcher(any *anyMatcher) (any, bool) { if p.debug { defer p.out(p.in("parseAnyMatcher")) } @@ -1192,7 +1194,7 @@ func (p *parser) parseAnyMatcher(any *anyMatcher) (interface{}, bool) { } // nolint: gocyclo -func (p *parser) parseCharClassMatcher(chr *charClassMatcher) (interface{}, bool) { +func (p *parser) parseCharClassMatcher(chr *charClassMatcher) (any, bool) { if p.debug { defer p.out(p.in("parseCharClassMatcher")) } @@ -1273,7 +1275,7 @@ func (p *parser) incChoiceAltCnt(ch *choiceExpr, altI int) { m[alt]++ } -func (p *parser) parseChoiceExpr(ch *choiceExpr) (interface{}, bool) { +func (p *parser) parseChoiceExpr(ch *choiceExpr) (any, bool) { if p.debug { defer p.out(p.in("parseChoiceExpr")) } @@ -1297,7 +1299,7 @@ func (p *parser) parseChoiceExpr(ch *choiceExpr) (interface{}, bool) { return nil, false } -func (p *parser) parseLabeledExpr(lab *labeledExpr) (interface{}, bool) { +func (p *parser) parseLabeledExpr(lab *labeledExpr) (any, bool) { if p.debug { defer p.out(p.in("parseLabeledExpr")) } @@ -1312,7 +1314,7 @@ func (p *parser) parseLabeledExpr(lab *labeledExpr) (interface{}, bool) { return val, ok } -func (p *parser) parseLitMatcher(lit *litMatcher) (interface{}, bool) { +func (p *parser) parseLitMatcher(lit *litMatcher) (any, bool) { if p.debug { defer p.out(p.in("parseLitMatcher")) } @@ -1334,7 +1336,7 @@ func (p *parser) parseLitMatcher(lit *litMatcher) (interface{}, bool) { return p.sliceFrom(start), true } -func (p *parser) parseNotCodeExpr(not *notCodeExpr) (interface{}, bool) { +func (p *parser) parseNotCodeExpr(not *notCodeExpr) (any, bool) { if p.debug { defer p.out(p.in("parseNotCodeExpr")) } @@ -1350,7 +1352,7 @@ func (p *parser) parseNotCodeExpr(not *notCodeExpr) (interface{}, bool) { return nil, !ok } -func (p *parser) parseNotExpr(not *notExpr) (interface{}, bool) { +func (p *parser) parseNotExpr(not *notExpr) (any, bool) { if p.debug { defer p.out(p.in("parseNotExpr")) } @@ -1368,12 +1370,12 @@ func (p *parser) parseNotExpr(not *notExpr) (interface{}, bool) { return nil, !ok } -func (p *parser) parseOneOrMoreExpr(expr *oneOrMoreExpr) (interface{}, bool) { +func (p *parser) parseOneOrMoreExpr(expr *oneOrMoreExpr) (any, bool) { if p.debug { defer p.out(p.in("parseOneOrMoreExpr")) } - var vals []interface{} + var vals []any for { p.pushV() @@ -1390,7 +1392,7 @@ func (p *parser) parseOneOrMoreExpr(expr *oneOrMoreExpr) (interface{}, bool) { } } -func (p *parser) parseRecoveryExpr(recover *recoveryExpr) (interface{}, bool) { +func (p *parser) parseRecoveryExpr(recover *recoveryExpr) (any, bool) { if p.debug { defer p.out(p.in("parseRecoveryExpr (" + strings.Join(recover.failureLabel, ",") + ")")) } @@ -1402,7 +1404,7 @@ func (p *parser) parseRecoveryExpr(recover *recoveryExpr) (interface{}, bool) { return val, ok } -func (p *parser) parseRuleRefExpr(ref *ruleRefExpr) (interface{}, bool) { +func (p *parser) parseRuleRefExpr(ref *ruleRefExpr) (any, bool) { if p.debug { defer p.out(p.in("parseRuleRefExpr " + ref.name)) } @@ -1419,12 +1421,12 @@ func (p *parser) parseRuleRefExpr(ref *ruleRefExpr) (interface{}, bool) { return p.parseRule(rule) } -func (p *parser) parseSeqExpr(seq *seqExpr) (interface{}, bool) { +func (p *parser) parseSeqExpr(seq *seqExpr) (any, bool) { if p.debug { defer p.out(p.in("parseSeqExpr")) } - vals := make([]interface{}, 0, len(seq.exprs)) + vals := make([]any, 0, len(seq.exprs)) pt := p.pt state := p.cloneState() @@ -1440,7 +1442,7 @@ func (p *parser) parseSeqExpr(seq *seqExpr) (interface{}, bool) { return vals, true } -func (p *parser) parseStateCodeExpr(state *stateCodeExpr) (interface{}, bool) { +func (p *parser) parseStateCodeExpr(state *stateCodeExpr) (any, bool) { if p.debug { defer p.out(p.in("parseStateCodeExpr")) } @@ -1452,7 +1454,7 @@ func (p *parser) parseStateCodeExpr(state *stateCodeExpr) (interface{}, bool) { return nil, true } -func (p *parser) parseThrowExpr(expr *throwExpr) (interface{}, bool) { +func (p *parser) parseThrowExpr(expr *throwExpr) (any, bool) { if p.debug { defer p.out(p.in("parseThrowExpr")) } @@ -1468,12 +1470,12 @@ func (p *parser) parseThrowExpr(expr *throwExpr) (interface{}, bool) { return nil, false } -func (p *parser) parseZeroOrMoreExpr(expr *zeroOrMoreExpr) (interface{}, bool) { +func (p *parser) parseZeroOrMoreExpr(expr *zeroOrMoreExpr) (any, bool) { if p.debug { defer p.out(p.in("parseZeroOrMoreExpr")) } - var vals []interface{} + var vals []any for { p.pushV() @@ -1486,7 +1488,7 @@ func (p *parser) parseZeroOrMoreExpr(expr *zeroOrMoreExpr) (interface{}, bool) { } } -func (p *parser) parseZeroOrOneExpr(expr *zeroOrOneExpr) (interface{}, bool) { +func (p *parser) parseZeroOrOneExpr(expr *zeroOrOneExpr) (any, bool) { if p.debug { defer p.out(p.in("parseZeroOrOneExpr")) } diff --git a/test/max_expr_cnt/maxexpr.go b/test/max_expr_cnt/maxexpr.go index 543e642d..5f337e4c 100644 --- a/test/max_expr_cnt/maxexpr.go +++ b/test/max_expr_cnt/maxexpr.go @@ -168,7 +168,7 @@ func Recover(b bool) Option { // GlobalStore creates an Option to set a key to a certain value in // the globalStore. -func GlobalStore(key string, value interface{}) Option { +func GlobalStore(key string, value any) Option { return func(p *parser) Option { old := p.cur.globalStore[key] p.cur.globalStore[key] = value @@ -178,7 +178,7 @@ func GlobalStore(key string, value interface{}) Option { // InitState creates an Option to set a key to a certain value in // the global "state" store. -func InitState(key string, value interface{}) Option { +func InitState(key string, value any) Option { return func(p *parser) Option { old := p.cur.state[key] p.cur.state[key] = value @@ -187,7 +187,7 @@ func InitState(key string, value interface{}) Option { } // ParseFile parses the file identified by filename. -func ParseFile(filename string, opts ...Option) (i interface{}, err error) { // nolint: deadcode +func ParseFile(filename string, opts ...Option) (i any, err error) { // nolint: deadcode f, err := os.Open(filename) if err != nil { return nil, err @@ -202,7 +202,7 @@ func ParseFile(filename string, opts ...Option) (i interface{}, err error) { // // ParseReader parses the data from r using filename as information in the // error messages. -func ParseReader(filename string, r io.Reader, opts ...Option) (interface{}, error) { // nolint: deadcode +func ParseReader(filename string, r io.Reader, opts ...Option) (any, error) { // nolint: deadcode b, err := io.ReadAll(r) if err != nil { return nil, err @@ -213,7 +213,7 @@ func ParseReader(filename string, r io.Reader, opts ...Option) (interface{}, err // Parse parses the data from b using filename as information in the // error messages. -func Parse(filename string, b []byte, opts ...Option) (interface{}, error) { +func Parse(filename string, b []byte, opts ...Option) (any, error) { return newParser(filename, b, opts...).parse(g) } @@ -251,7 +251,7 @@ type current struct { globalStore storeDict } -type storeDict map[string]interface{} +type storeDict map[string]any // the AST types... @@ -266,34 +266,34 @@ type rule struct { pos position name string displayName string - expr interface{} + expr any } // nolint: structcheck type choiceExpr struct { pos position - alternatives []interface{} + alternatives []any } // nolint: structcheck type actionExpr struct { pos position - expr interface{} - run func(*parser) (interface{}, error) + expr any + run func(*parser) (any, error) } // nolint: structcheck type recoveryExpr struct { pos position - expr interface{} - recoverExpr interface{} + expr any + recoverExpr any failureLabel []string } // nolint: structcheck type seqExpr struct { pos position - exprs []interface{} + exprs []any } // nolint: structcheck @@ -306,20 +306,22 @@ type throwExpr struct { type labeledExpr struct { pos position label string - expr interface{} + expr any } // nolint: structcheck type expr struct { pos position - expr interface{} + expr any } -type andExpr expr // nolint: structcheck -type notExpr expr // nolint: structcheck -type zeroOrOneExpr expr // nolint: structcheck -type zeroOrMoreExpr expr // nolint: structcheck -type oneOrMoreExpr expr // nolint: structcheck +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 { @@ -467,7 +469,7 @@ func (p *parser) setOptions(opts []Option) { // nolint: structcheck,deadcode type resultTuple struct { - v interface{} + v any b bool end savepoint } @@ -513,12 +515,12 @@ type parser struct { memoize bool // memoization table for the packrat algorithm: // map[offset in source] map[expression or rule] {value, match} - memo map[int]map[interface{}]resultTuple + 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]interface{} + vstack []map[string]any // rule stack, allows identification of the current rule in errors rstack []*rule @@ -538,7 +540,7 @@ type parser struct { choiceNoMatch string // recovery expression stack, keeps track of the currently available recovery expression, these are traversed in reverse - recoveryStack []map[string]interface{} + recoveryStack []map[string]any } // push a variable set on the vstack. @@ -558,7 +560,7 @@ func (p *parser) pushV() { return } - m = make(map[string]interface{}) + m = make(map[string]any) p.vstack[len(p.vstack)-1] = m } @@ -574,7 +576,7 @@ func (p *parser) popV() { } // push a recovery expression with its labels to the recoveryStack -func (p *parser) pushRecovery(labels []string, expr interface{}) { +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) @@ -583,7 +585,7 @@ func (p *parser) pushRecovery(labels []string, expr interface{}) { p.recoveryStack = p.recoveryStack[:len(p.recoveryStack)+1] } - m := make(map[string]interface{}, len(labels)) + m := make(map[string]any, len(labels)) for _, fl := range labels { m[fl] = expr } @@ -703,11 +705,11 @@ func (p *parser) restore(pt savepoint) { // copies of the state to allow the parser to properly restore the state in // the case of backtracking. type Cloner interface { - Clone() interface{} + Clone() any } var statePool = &sync.Pool{ - New: func() interface{} { return make(storeDict) }, + New: func() any { return make(storeDict) }, } func (sd storeDict) Discard() { @@ -749,7 +751,7 @@ func (p *parser) sliceFrom(start savepoint) []byte { return p.data[start.position.offset:p.pt.position.offset] } -func (p *parser) getMemoized(node interface{}) (resultTuple, bool) { +func (p *parser) getMemoized(node any) (resultTuple, bool) { if len(p.memo) == 0 { return resultTuple{}, false } @@ -761,13 +763,13 @@ func (p *parser) getMemoized(node interface{}) (resultTuple, bool) { return res, ok } -func (p *parser) setMemoized(pt savepoint, node interface{}, tuple resultTuple) { +func (p *parser) setMemoized(pt savepoint, node any, tuple resultTuple) { if p.memo == nil { - p.memo = make(map[int]map[interface{}]resultTuple) + p.memo = make(map[int]map[any]resultTuple) } m := p.memo[pt.offset] if m == nil { - m = make(map[interface{}]resultTuple) + m = make(map[any]resultTuple) p.memo[pt.offset] = m } m[node] = tuple @@ -781,7 +783,7 @@ func (p *parser) buildRulesTable(g *grammar) { } // nolint: gocyclo -func (p *parser) parse(g *grammar) (val interface{}, err error) { +func (p *parser) parse(g *grammar) (val any, err error) { if len(g.rules) == 0 { p.addErr(errNoRule) return nil, p.errs.err() @@ -858,7 +860,7 @@ func listJoin(list []string, sep string, lastSep string) string { } } -func (p *parser) parseRule(rule *rule) (interface{}, bool) { +func (p *parser) parseRule(rule *rule) (any, bool) { if p.debug { defer p.out(p.in("parseRule " + rule.name)) } @@ -888,7 +890,7 @@ func (p *parser) parseRule(rule *rule) (interface{}, bool) { } // nolint: gocyclo -func (p *parser) parseExpr(expr interface{}) (interface{}, bool) { +func (p *parser) parseExpr(expr any) (any, bool) { var pt savepoint if p.memoize { @@ -905,7 +907,7 @@ func (p *parser) parseExpr(expr interface{}) (interface{}, bool) { panic(errMaxExprCnt) } - var val interface{} + var val any var ok bool switch expr := expr.(type) { case *actionExpr: @@ -953,7 +955,7 @@ func (p *parser) parseExpr(expr interface{}) (interface{}, bool) { return val, ok } -func (p *parser) parseActionExpr(act *actionExpr) (interface{}, bool) { +func (p *parser) parseActionExpr(act *actionExpr) (any, bool) { if p.debug { defer p.out(p.in("parseActionExpr")) } @@ -978,7 +980,7 @@ func (p *parser) parseActionExpr(act *actionExpr) (interface{}, bool) { return val, ok } -func (p *parser) parseAndCodeExpr(and *andCodeExpr) (interface{}, bool) { +func (p *parser) parseAndCodeExpr(and *andCodeExpr) (any, bool) { if p.debug { defer p.out(p.in("parseAndCodeExpr")) } @@ -994,7 +996,7 @@ func (p *parser) parseAndCodeExpr(and *andCodeExpr) (interface{}, bool) { return nil, ok } -func (p *parser) parseAndExpr(and *andExpr) (interface{}, bool) { +func (p *parser) parseAndExpr(and *andExpr) (any, bool) { if p.debug { defer p.out(p.in("parseAndExpr")) } @@ -1010,7 +1012,7 @@ func (p *parser) parseAndExpr(and *andExpr) (interface{}, bool) { return nil, ok } -func (p *parser) parseAnyMatcher(any *anyMatcher) (interface{}, bool) { +func (p *parser) parseAnyMatcher(any *anyMatcher) (any, bool) { if p.debug { defer p.out(p.in("parseAnyMatcher")) } @@ -1027,7 +1029,7 @@ func (p *parser) parseAnyMatcher(any *anyMatcher) (interface{}, bool) { } // nolint: gocyclo -func (p *parser) parseCharClassMatcher(chr *charClassMatcher) (interface{}, bool) { +func (p *parser) parseCharClassMatcher(chr *charClassMatcher) (any, bool) { if p.debug { defer p.out(p.in("parseCharClassMatcher")) } @@ -1108,7 +1110,7 @@ func (p *parser) incChoiceAltCnt(ch *choiceExpr, altI int) { m[alt]++ } -func (p *parser) parseChoiceExpr(ch *choiceExpr) (interface{}, bool) { +func (p *parser) parseChoiceExpr(ch *choiceExpr) (any, bool) { if p.debug { defer p.out(p.in("parseChoiceExpr")) } @@ -1132,7 +1134,7 @@ func (p *parser) parseChoiceExpr(ch *choiceExpr) (interface{}, bool) { return nil, false } -func (p *parser) parseLabeledExpr(lab *labeledExpr) (interface{}, bool) { +func (p *parser) parseLabeledExpr(lab *labeledExpr) (any, bool) { if p.debug { defer p.out(p.in("parseLabeledExpr")) } @@ -1147,7 +1149,7 @@ func (p *parser) parseLabeledExpr(lab *labeledExpr) (interface{}, bool) { return val, ok } -func (p *parser) parseLitMatcher(lit *litMatcher) (interface{}, bool) { +func (p *parser) parseLitMatcher(lit *litMatcher) (any, bool) { if p.debug { defer p.out(p.in("parseLitMatcher")) } @@ -1169,7 +1171,7 @@ func (p *parser) parseLitMatcher(lit *litMatcher) (interface{}, bool) { return p.sliceFrom(start), true } -func (p *parser) parseNotCodeExpr(not *notCodeExpr) (interface{}, bool) { +func (p *parser) parseNotCodeExpr(not *notCodeExpr) (any, bool) { if p.debug { defer p.out(p.in("parseNotCodeExpr")) } @@ -1185,7 +1187,7 @@ func (p *parser) parseNotCodeExpr(not *notCodeExpr) (interface{}, bool) { return nil, !ok } -func (p *parser) parseNotExpr(not *notExpr) (interface{}, bool) { +func (p *parser) parseNotExpr(not *notExpr) (any, bool) { if p.debug { defer p.out(p.in("parseNotExpr")) } @@ -1203,12 +1205,12 @@ func (p *parser) parseNotExpr(not *notExpr) (interface{}, bool) { return nil, !ok } -func (p *parser) parseOneOrMoreExpr(expr *oneOrMoreExpr) (interface{}, bool) { +func (p *parser) parseOneOrMoreExpr(expr *oneOrMoreExpr) (any, bool) { if p.debug { defer p.out(p.in("parseOneOrMoreExpr")) } - var vals []interface{} + var vals []any for { p.pushV() @@ -1225,7 +1227,7 @@ func (p *parser) parseOneOrMoreExpr(expr *oneOrMoreExpr) (interface{}, bool) { } } -func (p *parser) parseRecoveryExpr(recover *recoveryExpr) (interface{}, bool) { +func (p *parser) parseRecoveryExpr(recover *recoveryExpr) (any, bool) { if p.debug { defer p.out(p.in("parseRecoveryExpr (" + strings.Join(recover.failureLabel, ",") + ")")) } @@ -1237,7 +1239,7 @@ func (p *parser) parseRecoveryExpr(recover *recoveryExpr) (interface{}, bool) { return val, ok } -func (p *parser) parseRuleRefExpr(ref *ruleRefExpr) (interface{}, bool) { +func (p *parser) parseRuleRefExpr(ref *ruleRefExpr) (any, bool) { if p.debug { defer p.out(p.in("parseRuleRefExpr " + ref.name)) } @@ -1254,12 +1256,12 @@ func (p *parser) parseRuleRefExpr(ref *ruleRefExpr) (interface{}, bool) { return p.parseRule(rule) } -func (p *parser) parseSeqExpr(seq *seqExpr) (interface{}, bool) { +func (p *parser) parseSeqExpr(seq *seqExpr) (any, bool) { if p.debug { defer p.out(p.in("parseSeqExpr")) } - vals := make([]interface{}, 0, len(seq.exprs)) + vals := make([]any, 0, len(seq.exprs)) pt := p.pt state := p.cloneState() @@ -1275,7 +1277,7 @@ func (p *parser) parseSeqExpr(seq *seqExpr) (interface{}, bool) { return vals, true } -func (p *parser) parseStateCodeExpr(state *stateCodeExpr) (interface{}, bool) { +func (p *parser) parseStateCodeExpr(state *stateCodeExpr) (any, bool) { if p.debug { defer p.out(p.in("parseStateCodeExpr")) } @@ -1287,7 +1289,7 @@ func (p *parser) parseStateCodeExpr(state *stateCodeExpr) (interface{}, bool) { return nil, true } -func (p *parser) parseThrowExpr(expr *throwExpr) (interface{}, bool) { +func (p *parser) parseThrowExpr(expr *throwExpr) (any, bool) { if p.debug { defer p.out(p.in("parseThrowExpr")) } @@ -1303,12 +1305,12 @@ func (p *parser) parseThrowExpr(expr *throwExpr) (interface{}, bool) { return nil, false } -func (p *parser) parseZeroOrMoreExpr(expr *zeroOrMoreExpr) (interface{}, bool) { +func (p *parser) parseZeroOrMoreExpr(expr *zeroOrMoreExpr) (any, bool) { if p.debug { defer p.out(p.in("parseZeroOrMoreExpr")) } - var vals []interface{} + var vals []any for { p.pushV() @@ -1321,7 +1323,7 @@ func (p *parser) parseZeroOrMoreExpr(expr *zeroOrMoreExpr) (interface{}, bool) { } } -func (p *parser) parseZeroOrOneExpr(expr *zeroOrOneExpr) (interface{}, bool) { +func (p *parser) parseZeroOrOneExpr(expr *zeroOrOneExpr) (any, bool) { if p.debug { defer p.out(p.in("parseZeroOrOneExpr")) } diff --git a/test/predicates/predicates.go b/test/predicates/predicates.go index 075dc3e2..02e18ccb 100644 --- a/test/predicates/predicates.go +++ b/test/predicates/predicates.go @@ -24,10 +24,10 @@ var g = &grammar{ pos: position{line: 5, col: 1, offset: 24}, expr: &choiceExpr{ pos: position{line: 5, col: 5, offset: 30}, - alternatives: []interface{}{ + alternatives: []any{ &seqExpr{ pos: position{line: 5, col: 5, offset: 30}, - exprs: []interface{}{ + exprs: []any{ &labeledExpr{ pos: position{line: 5, col: 5, offset: 30}, label: "a", @@ -46,7 +46,7 @@ var g = &grammar{ }, &seqExpr{ pos: position{line: 10, col: 3, offset: 98}, - exprs: []interface{}{ + exprs: []any{ &labeledExpr{ pos: position{line: 10, col: 3, offset: 98}, label: "b", @@ -65,7 +65,7 @@ var g = &grammar{ }, &seqExpr{ pos: position{line: 15, col: 3, offset: 165}, - exprs: []interface{}{ + exprs: []any{ &labeledExpr{ pos: position{line: 15, col: 3, offset: 165}, label: "d", @@ -90,19 +90,19 @@ var g = &grammar{ pos: position{line: 20, col: 1, offset: 230}, expr: &seqExpr{ pos: position{line: 20, col: 5, offset: 236}, - exprs: []interface{}{ + exprs: []any{ &labeledExpr{ pos: position{line: 20, col: 5, offset: 236}, label: "out", expr: &seqExpr{ pos: position{line: 20, col: 11, offset: 242}, - exprs: []interface{}{ + exprs: []any{ &labeledExpr{ pos: position{line: 20, col: 11, offset: 242}, label: "inner", expr: &seqExpr{ pos: position{line: 20, col: 19, offset: 250}, - exprs: []interface{}{ + exprs: []any{ &charClassMatcher{ pos: position{line: 20, col: 19, offset: 250}, val: "[^abd]", @@ -146,7 +146,7 @@ var g = &grammar{ run: (*parser).callonC1, expr: &seqExpr{ pos: position{line: 22, col: 5, offset: 340}, - exprs: []interface{}{ + exprs: []any{ &andExpr{ pos: position{line: 22, col: 5, offset: 340}, expr: &labeledExpr{ @@ -176,7 +176,7 @@ var g = &grammar{ }, } -func (c *current) onA5(a interface{}) (bool, error) { +func (c *current) onA5(a any) (bool, error) { fmt.Println(string(c.text)) return true, nil } @@ -187,7 +187,7 @@ func (p *parser) callonA5() (bool, error) { return p.cur.onA5(stack["a"]) } -func (c *current) onA9(b interface{}) (bool, error) { +func (c *current) onA9(b any) (bool, error) { fmt.Println(string(c.text)) return true, nil } @@ -198,7 +198,7 @@ func (p *parser) callonA9() (bool, error) { return p.cur.onA9(stack["b"]) } -func (c *current) onA13(d interface{}) (bool, error) { +func (c *current) onA13(d any) (bool, error) { fmt.Println(string(c.text)) return true, nil } @@ -209,7 +209,7 @@ func (p *parser) callonA13() (bool, error) { return p.cur.onA13(stack["d"]) } -func (c *current) onB9(innermost interface{}) (bool, error) { +func (c *current) onB9(innermost any) (bool, error) { return true, nil } @@ -219,7 +219,7 @@ func (p *parser) callonB9() (bool, error) { return p.cur.onB9(stack["innermost"]) } -func (c *current) onB10(inner interface{}) (bool, error) { +func (c *current) onB10(inner any) (bool, error) { return true, nil } @@ -229,7 +229,7 @@ func (p *parser) callonB10() (bool, error) { return p.cur.onB10(stack["inner"]) } -func (c *current) onB11(out interface{}) (bool, error) { +func (c *current) onB11(out any) (bool, error) { return true, nil } @@ -239,11 +239,11 @@ func (p *parser) callonB11() (bool, error) { return p.cur.onB11(stack["out"]) } -func (c *current) onC1(rest interface{}) (interface{}, error) { +func (c *current) onC1(rest any) (any, error) { return nil, nil } -func (p *parser) callonC1() (interface{}, error) { +func (p *parser) callonC1() (any, error) { stack := p.vstack[len(p.vstack)-1] _ = stack return p.cur.onC1(stack["rest"]) @@ -387,7 +387,7 @@ func Recover(b bool) Option { // GlobalStore creates an Option to set a key to a certain value in // the globalStore. -func GlobalStore(key string, value interface{}) Option { +func GlobalStore(key string, value any) Option { return func(p *parser) Option { old := p.cur.globalStore[key] p.cur.globalStore[key] = value @@ -397,7 +397,7 @@ func GlobalStore(key string, value interface{}) Option { // InitState creates an Option to set a key to a certain value in // the global "state" store. -func InitState(key string, value interface{}) Option { +func InitState(key string, value any) Option { return func(p *parser) Option { old := p.cur.state[key] p.cur.state[key] = value @@ -406,7 +406,7 @@ func InitState(key string, value interface{}) Option { } // ParseFile parses the file identified by filename. -func ParseFile(filename string, opts ...Option) (i interface{}, err error) { // nolint: deadcode +func ParseFile(filename string, opts ...Option) (i any, err error) { // nolint: deadcode f, err := os.Open(filename) if err != nil { return nil, err @@ -421,7 +421,7 @@ func ParseFile(filename string, opts ...Option) (i interface{}, err error) { // // ParseReader parses the data from r using filename as information in the // error messages. -func ParseReader(filename string, r io.Reader, opts ...Option) (interface{}, error) { // nolint: deadcode +func ParseReader(filename string, r io.Reader, opts ...Option) (any, error) { // nolint: deadcode b, err := io.ReadAll(r) if err != nil { return nil, err @@ -432,7 +432,7 @@ func ParseReader(filename string, r io.Reader, opts ...Option) (interface{}, err // Parse parses the data from b using filename as information in the // error messages. -func Parse(filename string, b []byte, opts ...Option) (interface{}, error) { +func Parse(filename string, b []byte, opts ...Option) (any, error) { return newParser(filename, b, opts...).parse(g) } @@ -470,7 +470,7 @@ type current struct { globalStore storeDict } -type storeDict map[string]interface{} +type storeDict map[string]any // the AST types... @@ -485,34 +485,34 @@ type rule struct { pos position name string displayName string - expr interface{} + expr any } // nolint: structcheck type choiceExpr struct { pos position - alternatives []interface{} + alternatives []any } // nolint: structcheck type actionExpr struct { pos position - expr interface{} - run func(*parser) (interface{}, error) + expr any + run func(*parser) (any, error) } // nolint: structcheck type recoveryExpr struct { pos position - expr interface{} - recoverExpr interface{} + expr any + recoverExpr any failureLabel []string } // nolint: structcheck type seqExpr struct { pos position - exprs []interface{} + exprs []any } // nolint: structcheck @@ -525,20 +525,22 @@ type throwExpr struct { type labeledExpr struct { pos position label string - expr interface{} + expr any } // nolint: structcheck type expr struct { pos position - expr interface{} + expr any } -type andExpr expr // nolint: structcheck -type notExpr expr // nolint: structcheck -type zeroOrOneExpr expr // nolint: structcheck -type zeroOrMoreExpr expr // nolint: structcheck -type oneOrMoreExpr expr // nolint: structcheck +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 { @@ -686,7 +688,7 @@ func (p *parser) setOptions(opts []Option) { // nolint: structcheck,deadcode type resultTuple struct { - v interface{} + v any b bool end savepoint } @@ -732,12 +734,12 @@ type parser struct { memoize bool // memoization table for the packrat algorithm: // map[offset in source] map[expression or rule] {value, match} - memo map[int]map[interface{}]resultTuple + 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]interface{} + vstack []map[string]any // rule stack, allows identification of the current rule in errors rstack []*rule @@ -757,7 +759,7 @@ type parser struct { choiceNoMatch string // recovery expression stack, keeps track of the currently available recovery expression, these are traversed in reverse - recoveryStack []map[string]interface{} + recoveryStack []map[string]any } // push a variable set on the vstack. @@ -777,7 +779,7 @@ func (p *parser) pushV() { return } - m = make(map[string]interface{}) + m = make(map[string]any) p.vstack[len(p.vstack)-1] = m } @@ -793,7 +795,7 @@ func (p *parser) popV() { } // push a recovery expression with its labels to the recoveryStack -func (p *parser) pushRecovery(labels []string, expr interface{}) { +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) @@ -802,7 +804,7 @@ func (p *parser) pushRecovery(labels []string, expr interface{}) { p.recoveryStack = p.recoveryStack[:len(p.recoveryStack)+1] } - m := make(map[string]interface{}, len(labels)) + m := make(map[string]any, len(labels)) for _, fl := range labels { m[fl] = expr } @@ -922,11 +924,11 @@ func (p *parser) restore(pt savepoint) { // copies of the state to allow the parser to properly restore the state in // the case of backtracking. type Cloner interface { - Clone() interface{} + Clone() any } var statePool = &sync.Pool{ - New: func() interface{} { return make(storeDict) }, + New: func() any { return make(storeDict) }, } func (sd storeDict) Discard() { @@ -968,7 +970,7 @@ func (p *parser) sliceFrom(start savepoint) []byte { return p.data[start.position.offset:p.pt.position.offset] } -func (p *parser) getMemoized(node interface{}) (resultTuple, bool) { +func (p *parser) getMemoized(node any) (resultTuple, bool) { if len(p.memo) == 0 { return resultTuple{}, false } @@ -980,13 +982,13 @@ func (p *parser) getMemoized(node interface{}) (resultTuple, bool) { return res, ok } -func (p *parser) setMemoized(pt savepoint, node interface{}, tuple resultTuple) { +func (p *parser) setMemoized(pt savepoint, node any, tuple resultTuple) { if p.memo == nil { - p.memo = make(map[int]map[interface{}]resultTuple) + p.memo = make(map[int]map[any]resultTuple) } m := p.memo[pt.offset] if m == nil { - m = make(map[interface{}]resultTuple) + m = make(map[any]resultTuple) p.memo[pt.offset] = m } m[node] = tuple @@ -1000,7 +1002,7 @@ func (p *parser) buildRulesTable(g *grammar) { } // nolint: gocyclo -func (p *parser) parse(g *grammar) (val interface{}, err error) { +func (p *parser) parse(g *grammar) (val any, err error) { if len(g.rules) == 0 { p.addErr(errNoRule) return nil, p.errs.err() @@ -1077,7 +1079,7 @@ func listJoin(list []string, sep string, lastSep string) string { } } -func (p *parser) parseRule(rule *rule) (interface{}, bool) { +func (p *parser) parseRule(rule *rule) (any, bool) { if p.debug { defer p.out(p.in("parseRule " + rule.name)) } @@ -1107,7 +1109,7 @@ func (p *parser) parseRule(rule *rule) (interface{}, bool) { } // nolint: gocyclo -func (p *parser) parseExpr(expr interface{}) (interface{}, bool) { +func (p *parser) parseExpr(expr any) (any, bool) { var pt savepoint if p.memoize { @@ -1124,7 +1126,7 @@ func (p *parser) parseExpr(expr interface{}) (interface{}, bool) { panic(errMaxExprCnt) } - var val interface{} + var val any var ok bool switch expr := expr.(type) { case *actionExpr: @@ -1172,7 +1174,7 @@ func (p *parser) parseExpr(expr interface{}) (interface{}, bool) { return val, ok } -func (p *parser) parseActionExpr(act *actionExpr) (interface{}, bool) { +func (p *parser) parseActionExpr(act *actionExpr) (any, bool) { if p.debug { defer p.out(p.in("parseActionExpr")) } @@ -1197,7 +1199,7 @@ func (p *parser) parseActionExpr(act *actionExpr) (interface{}, bool) { return val, ok } -func (p *parser) parseAndCodeExpr(and *andCodeExpr) (interface{}, bool) { +func (p *parser) parseAndCodeExpr(and *andCodeExpr) (any, bool) { if p.debug { defer p.out(p.in("parseAndCodeExpr")) } @@ -1213,7 +1215,7 @@ func (p *parser) parseAndCodeExpr(and *andCodeExpr) (interface{}, bool) { return nil, ok } -func (p *parser) parseAndExpr(and *andExpr) (interface{}, bool) { +func (p *parser) parseAndExpr(and *andExpr) (any, bool) { if p.debug { defer p.out(p.in("parseAndExpr")) } @@ -1229,7 +1231,7 @@ func (p *parser) parseAndExpr(and *andExpr) (interface{}, bool) { return nil, ok } -func (p *parser) parseAnyMatcher(any *anyMatcher) (interface{}, bool) { +func (p *parser) parseAnyMatcher(any *anyMatcher) (any, bool) { if p.debug { defer p.out(p.in("parseAnyMatcher")) } @@ -1246,7 +1248,7 @@ func (p *parser) parseAnyMatcher(any *anyMatcher) (interface{}, bool) { } // nolint: gocyclo -func (p *parser) parseCharClassMatcher(chr *charClassMatcher) (interface{}, bool) { +func (p *parser) parseCharClassMatcher(chr *charClassMatcher) (any, bool) { if p.debug { defer p.out(p.in("parseCharClassMatcher")) } @@ -1327,7 +1329,7 @@ func (p *parser) incChoiceAltCnt(ch *choiceExpr, altI int) { m[alt]++ } -func (p *parser) parseChoiceExpr(ch *choiceExpr) (interface{}, bool) { +func (p *parser) parseChoiceExpr(ch *choiceExpr) (any, bool) { if p.debug { defer p.out(p.in("parseChoiceExpr")) } @@ -1351,7 +1353,7 @@ func (p *parser) parseChoiceExpr(ch *choiceExpr) (interface{}, bool) { return nil, false } -func (p *parser) parseLabeledExpr(lab *labeledExpr) (interface{}, bool) { +func (p *parser) parseLabeledExpr(lab *labeledExpr) (any, bool) { if p.debug { defer p.out(p.in("parseLabeledExpr")) } @@ -1366,7 +1368,7 @@ func (p *parser) parseLabeledExpr(lab *labeledExpr) (interface{}, bool) { return val, ok } -func (p *parser) parseLitMatcher(lit *litMatcher) (interface{}, bool) { +func (p *parser) parseLitMatcher(lit *litMatcher) (any, bool) { if p.debug { defer p.out(p.in("parseLitMatcher")) } @@ -1388,7 +1390,7 @@ func (p *parser) parseLitMatcher(lit *litMatcher) (interface{}, bool) { return p.sliceFrom(start), true } -func (p *parser) parseNotCodeExpr(not *notCodeExpr) (interface{}, bool) { +func (p *parser) parseNotCodeExpr(not *notCodeExpr) (any, bool) { if p.debug { defer p.out(p.in("parseNotCodeExpr")) } @@ -1404,7 +1406,7 @@ func (p *parser) parseNotCodeExpr(not *notCodeExpr) (interface{}, bool) { return nil, !ok } -func (p *parser) parseNotExpr(not *notExpr) (interface{}, bool) { +func (p *parser) parseNotExpr(not *notExpr) (any, bool) { if p.debug { defer p.out(p.in("parseNotExpr")) } @@ -1422,12 +1424,12 @@ func (p *parser) parseNotExpr(not *notExpr) (interface{}, bool) { return nil, !ok } -func (p *parser) parseOneOrMoreExpr(expr *oneOrMoreExpr) (interface{}, bool) { +func (p *parser) parseOneOrMoreExpr(expr *oneOrMoreExpr) (any, bool) { if p.debug { defer p.out(p.in("parseOneOrMoreExpr")) } - var vals []interface{} + var vals []any for { p.pushV() @@ -1444,7 +1446,7 @@ func (p *parser) parseOneOrMoreExpr(expr *oneOrMoreExpr) (interface{}, bool) { } } -func (p *parser) parseRecoveryExpr(recover *recoveryExpr) (interface{}, bool) { +func (p *parser) parseRecoveryExpr(recover *recoveryExpr) (any, bool) { if p.debug { defer p.out(p.in("parseRecoveryExpr (" + strings.Join(recover.failureLabel, ",") + ")")) } @@ -1456,7 +1458,7 @@ func (p *parser) parseRecoveryExpr(recover *recoveryExpr) (interface{}, bool) { return val, ok } -func (p *parser) parseRuleRefExpr(ref *ruleRefExpr) (interface{}, bool) { +func (p *parser) parseRuleRefExpr(ref *ruleRefExpr) (any, bool) { if p.debug { defer p.out(p.in("parseRuleRefExpr " + ref.name)) } @@ -1473,12 +1475,12 @@ func (p *parser) parseRuleRefExpr(ref *ruleRefExpr) (interface{}, bool) { return p.parseRule(rule) } -func (p *parser) parseSeqExpr(seq *seqExpr) (interface{}, bool) { +func (p *parser) parseSeqExpr(seq *seqExpr) (any, bool) { if p.debug { defer p.out(p.in("parseSeqExpr")) } - vals := make([]interface{}, 0, len(seq.exprs)) + vals := make([]any, 0, len(seq.exprs)) pt := p.pt state := p.cloneState() @@ -1494,7 +1496,7 @@ func (p *parser) parseSeqExpr(seq *seqExpr) (interface{}, bool) { return vals, true } -func (p *parser) parseStateCodeExpr(state *stateCodeExpr) (interface{}, bool) { +func (p *parser) parseStateCodeExpr(state *stateCodeExpr) (any, bool) { if p.debug { defer p.out(p.in("parseStateCodeExpr")) } @@ -1506,7 +1508,7 @@ func (p *parser) parseStateCodeExpr(state *stateCodeExpr) (interface{}, bool) { return nil, true } -func (p *parser) parseThrowExpr(expr *throwExpr) (interface{}, bool) { +func (p *parser) parseThrowExpr(expr *throwExpr) (any, bool) { if p.debug { defer p.out(p.in("parseThrowExpr")) } @@ -1522,12 +1524,12 @@ func (p *parser) parseThrowExpr(expr *throwExpr) (interface{}, bool) { return nil, false } -func (p *parser) parseZeroOrMoreExpr(expr *zeroOrMoreExpr) (interface{}, bool) { +func (p *parser) parseZeroOrMoreExpr(expr *zeroOrMoreExpr) (any, bool) { if p.debug { defer p.out(p.in("parseZeroOrMoreExpr")) } - var vals []interface{} + var vals []any for { p.pushV() @@ -1540,7 +1542,7 @@ func (p *parser) parseZeroOrMoreExpr(expr *zeroOrMoreExpr) (interface{}, bool) { } } -func (p *parser) parseZeroOrOneExpr(expr *zeroOrOneExpr) (interface{}, bool) { +func (p *parser) parseZeroOrOneExpr(expr *zeroOrOneExpr) (any, bool) { if p.debug { defer p.out(p.in("parseZeroOrOneExpr")) } diff --git a/test/predicates/predicates_test.go b/test/predicates/predicates_test.go index 32567efc..392fce3c 100644 --- a/test/predicates/predicates_test.go +++ b/test/predicates/predicates_test.go @@ -5,15 +5,15 @@ import "testing" // Go1.7: The Method and NumMethod methods of Type and Value no longer return or count unexported methods. // So cannot use reflect.TypeOf and MethodByName to test the implemented methods. func TestPredicatesArgs(t *testing.T) { - var cur interface{} = ¤t{} + var cur any = ¤t{} _, ok := cur.(interface { - onA5(interface{}) (bool, error) - onA9(interface{}) (bool, error) - onA13(interface{}) (bool, error) - onB9(interface{}) (bool, error) - onB10(interface{}) (bool, error) - onB11(interface{}) (bool, error) - onC1(interface{}) (interface{}, error) + onA5(any) (bool, error) + onA9(any) (bool, error) + onA13(any) (bool, error) + onB9(any) (bool, error) + onB10(any) (bool, error) + onB11(any) (bool, error) + onC1(any) (any, error) }) if !ok { t.Errorf("want *current to have the expected methods") diff --git a/test/runeerror/runeerror.go b/test/runeerror/runeerror.go index df39279c..90182613 100644 --- a/test/runeerror/runeerror.go +++ b/test/runeerror/runeerror.go @@ -17,9 +17,9 @@ import ( "unicode/utf8" ) -func joinBytes(a interface{}) []byte { +func joinBytes(a any) []byte { var A []byte - for _, x := range a.([]interface{}) { + for _, x := range a.([]any) { A = append(A, x.([]uint8)...) } return A @@ -29,26 +29,26 @@ var g = &grammar{ rules: []*rule{ { name: "Program", - pos: position{line: 13, col: 1, offset: 213}, + pos: position{line: 13, col: 1, offset: 197}, expr: &actionExpr{ - pos: position{line: 13, col: 12, offset: 224}, + pos: position{line: 13, col: 12, offset: 208}, run: (*parser).callonProgram1, expr: &seqExpr{ - pos: position{line: 13, col: 12, offset: 224}, - exprs: []interface{}{ + pos: position{line: 13, col: 12, offset: 208}, + exprs: []any{ &litMatcher{ - pos: position{line: 13, col: 12, offset: 224}, + pos: position{line: 13, col: 12, offset: 208}, val: "\n", ignoreCase: false, want: "\"\\n\"", }, &labeledExpr{ - pos: position{line: 13, col: 17, offset: 229}, + pos: position{line: 13, col: 17, offset: 213}, label: "a", expr: &oneOrMoreExpr{ - pos: position{line: 13, col: 19, offset: 231}, + pos: position{line: 13, col: 19, offset: 215}, expr: &charClassMatcher{ - pos: position{line: 13, col: 19, offset: 231}, + pos: position{line: 13, col: 19, offset: 215}, val: "[^\\n]", chars: []rune{'\n'}, ignoreCase: false, @@ -57,22 +57,22 @@ var g = &grammar{ }, }, &litMatcher{ - pos: position{line: 13, col: 26, offset: 238}, + pos: position{line: 13, col: 26, offset: 222}, val: "\n", ignoreCase: false, want: "\"\\n\"", }, &labeledExpr{ - pos: position{line: 13, col: 31, offset: 243}, + pos: position{line: 13, col: 31, offset: 227}, label: "b", expr: &anyMatcher{ - line: 13, col: 33, offset: 245, + line: 13, col: 33, offset: 229, }, }, ¬Expr{ - pos: position{line: 13, col: 35, offset: 247}, + pos: position{line: 13, col: 35, offset: 231}, expr: &anyMatcher{ - line: 13, col: 36, offset: 248, + line: 13, col: 36, offset: 232, }, }, }, @@ -82,13 +82,13 @@ var g = &grammar{ }, } -func (c *current) onProgram1(a, b interface{}) (interface{}, error) { +func (c *current) onProgram1(a, b any) (any, error) { return [][]byte{ c.text, joinBytes(a), b.([]uint8), }, nil } -func (p *parser) callonProgram1() (interface{}, error) { +func (p *parser) callonProgram1() (any, error) { stack := p.vstack[len(p.vstack)-1] _ = stack return p.cur.onProgram1(stack["a"], stack["b"]) @@ -232,7 +232,7 @@ func Recover(b bool) Option { // GlobalStore creates an Option to set a key to a certain value in // the globalStore. -func GlobalStore(key string, value interface{}) Option { +func GlobalStore(key string, value any) Option { return func(p *parser) Option { old := p.cur.globalStore[key] p.cur.globalStore[key] = value @@ -242,7 +242,7 @@ func GlobalStore(key string, value interface{}) Option { // InitState creates an Option to set a key to a certain value in // the global "state" store. -func InitState(key string, value interface{}) Option { +func InitState(key string, value any) Option { return func(p *parser) Option { old := p.cur.state[key] p.cur.state[key] = value @@ -251,7 +251,7 @@ func InitState(key string, value interface{}) Option { } // ParseFile parses the file identified by filename. -func ParseFile(filename string, opts ...Option) (i interface{}, err error) { // nolint: deadcode +func ParseFile(filename string, opts ...Option) (i any, err error) { // nolint: deadcode f, err := os.Open(filename) if err != nil { return nil, err @@ -266,7 +266,7 @@ func ParseFile(filename string, opts ...Option) (i interface{}, err error) { // // ParseReader parses the data from r using filename as information in the // error messages. -func ParseReader(filename string, r io.Reader, opts ...Option) (interface{}, error) { // nolint: deadcode +func ParseReader(filename string, r io.Reader, opts ...Option) (any, error) { // nolint: deadcode b, err := io.ReadAll(r) if err != nil { return nil, err @@ -277,7 +277,7 @@ func ParseReader(filename string, r io.Reader, opts ...Option) (interface{}, err // Parse parses the data from b using filename as information in the // error messages. -func Parse(filename string, b []byte, opts ...Option) (interface{}, error) { +func Parse(filename string, b []byte, opts ...Option) (any, error) { return newParser(filename, b, opts...).parse(g) } @@ -315,7 +315,7 @@ type current struct { globalStore storeDict } -type storeDict map[string]interface{} +type storeDict map[string]any // the AST types... @@ -330,34 +330,34 @@ type rule struct { pos position name string displayName string - expr interface{} + expr any } // nolint: structcheck type choiceExpr struct { pos position - alternatives []interface{} + alternatives []any } // nolint: structcheck type actionExpr struct { pos position - expr interface{} - run func(*parser) (interface{}, error) + expr any + run func(*parser) (any, error) } // nolint: structcheck type recoveryExpr struct { pos position - expr interface{} - recoverExpr interface{} + expr any + recoverExpr any failureLabel []string } // nolint: structcheck type seqExpr struct { pos position - exprs []interface{} + exprs []any } // nolint: structcheck @@ -370,20 +370,22 @@ type throwExpr struct { type labeledExpr struct { pos position label string - expr interface{} + expr any } // nolint: structcheck type expr struct { pos position - expr interface{} + expr any } -type andExpr expr // nolint: structcheck -type notExpr expr // nolint: structcheck -type zeroOrOneExpr expr // nolint: structcheck -type zeroOrMoreExpr expr // nolint: structcheck -type oneOrMoreExpr expr // nolint: structcheck +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 { @@ -531,7 +533,7 @@ func (p *parser) setOptions(opts []Option) { // nolint: structcheck,deadcode type resultTuple struct { - v interface{} + v any b bool end savepoint } @@ -577,12 +579,12 @@ type parser struct { memoize bool // memoization table for the packrat algorithm: // map[offset in source] map[expression or rule] {value, match} - memo map[int]map[interface{}]resultTuple + 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]interface{} + vstack []map[string]any // rule stack, allows identification of the current rule in errors rstack []*rule @@ -602,7 +604,7 @@ type parser struct { choiceNoMatch string // recovery expression stack, keeps track of the currently available recovery expression, these are traversed in reverse - recoveryStack []map[string]interface{} + recoveryStack []map[string]any } // push a variable set on the vstack. @@ -622,7 +624,7 @@ func (p *parser) pushV() { return } - m = make(map[string]interface{}) + m = make(map[string]any) p.vstack[len(p.vstack)-1] = m } @@ -638,7 +640,7 @@ func (p *parser) popV() { } // push a recovery expression with its labels to the recoveryStack -func (p *parser) pushRecovery(labels []string, expr interface{}) { +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) @@ -647,7 +649,7 @@ func (p *parser) pushRecovery(labels []string, expr interface{}) { p.recoveryStack = p.recoveryStack[:len(p.recoveryStack)+1] } - m := make(map[string]interface{}, len(labels)) + m := make(map[string]any, len(labels)) for _, fl := range labels { m[fl] = expr } @@ -767,11 +769,11 @@ func (p *parser) restore(pt savepoint) { // copies of the state to allow the parser to properly restore the state in // the case of backtracking. type Cloner interface { - Clone() interface{} + Clone() any } var statePool = &sync.Pool{ - New: func() interface{} { return make(storeDict) }, + New: func() any { return make(storeDict) }, } func (sd storeDict) Discard() { @@ -813,7 +815,7 @@ func (p *parser) sliceFrom(start savepoint) []byte { return p.data[start.position.offset:p.pt.position.offset] } -func (p *parser) getMemoized(node interface{}) (resultTuple, bool) { +func (p *parser) getMemoized(node any) (resultTuple, bool) { if len(p.memo) == 0 { return resultTuple{}, false } @@ -825,13 +827,13 @@ func (p *parser) getMemoized(node interface{}) (resultTuple, bool) { return res, ok } -func (p *parser) setMemoized(pt savepoint, node interface{}, tuple resultTuple) { +func (p *parser) setMemoized(pt savepoint, node any, tuple resultTuple) { if p.memo == nil { - p.memo = make(map[int]map[interface{}]resultTuple) + p.memo = make(map[int]map[any]resultTuple) } m := p.memo[pt.offset] if m == nil { - m = make(map[interface{}]resultTuple) + m = make(map[any]resultTuple) p.memo[pt.offset] = m } m[node] = tuple @@ -845,7 +847,7 @@ func (p *parser) buildRulesTable(g *grammar) { } // nolint: gocyclo -func (p *parser) parse(g *grammar) (val interface{}, err error) { +func (p *parser) parse(g *grammar) (val any, err error) { if len(g.rules) == 0 { p.addErr(errNoRule) return nil, p.errs.err() @@ -922,7 +924,7 @@ func listJoin(list []string, sep string, lastSep string) string { } } -func (p *parser) parseRule(rule *rule) (interface{}, bool) { +func (p *parser) parseRule(rule *rule) (any, bool) { if p.debug { defer p.out(p.in("parseRule " + rule.name)) } @@ -952,7 +954,7 @@ func (p *parser) parseRule(rule *rule) (interface{}, bool) { } // nolint: gocyclo -func (p *parser) parseExpr(expr interface{}) (interface{}, bool) { +func (p *parser) parseExpr(expr any) (any, bool) { var pt savepoint if p.memoize { @@ -969,7 +971,7 @@ func (p *parser) parseExpr(expr interface{}) (interface{}, bool) { panic(errMaxExprCnt) } - var val interface{} + var val any var ok bool switch expr := expr.(type) { case *actionExpr: @@ -1017,7 +1019,7 @@ func (p *parser) parseExpr(expr interface{}) (interface{}, bool) { return val, ok } -func (p *parser) parseActionExpr(act *actionExpr) (interface{}, bool) { +func (p *parser) parseActionExpr(act *actionExpr) (any, bool) { if p.debug { defer p.out(p.in("parseActionExpr")) } @@ -1042,7 +1044,7 @@ func (p *parser) parseActionExpr(act *actionExpr) (interface{}, bool) { return val, ok } -func (p *parser) parseAndCodeExpr(and *andCodeExpr) (interface{}, bool) { +func (p *parser) parseAndCodeExpr(and *andCodeExpr) (any, bool) { if p.debug { defer p.out(p.in("parseAndCodeExpr")) } @@ -1058,7 +1060,7 @@ func (p *parser) parseAndCodeExpr(and *andCodeExpr) (interface{}, bool) { return nil, ok } -func (p *parser) parseAndExpr(and *andExpr) (interface{}, bool) { +func (p *parser) parseAndExpr(and *andExpr) (any, bool) { if p.debug { defer p.out(p.in("parseAndExpr")) } @@ -1074,7 +1076,7 @@ func (p *parser) parseAndExpr(and *andExpr) (interface{}, bool) { return nil, ok } -func (p *parser) parseAnyMatcher(any *anyMatcher) (interface{}, bool) { +func (p *parser) parseAnyMatcher(any *anyMatcher) (any, bool) { if p.debug { defer p.out(p.in("parseAnyMatcher")) } @@ -1091,7 +1093,7 @@ func (p *parser) parseAnyMatcher(any *anyMatcher) (interface{}, bool) { } // nolint: gocyclo -func (p *parser) parseCharClassMatcher(chr *charClassMatcher) (interface{}, bool) { +func (p *parser) parseCharClassMatcher(chr *charClassMatcher) (any, bool) { if p.debug { defer p.out(p.in("parseCharClassMatcher")) } @@ -1172,7 +1174,7 @@ func (p *parser) incChoiceAltCnt(ch *choiceExpr, altI int) { m[alt]++ } -func (p *parser) parseChoiceExpr(ch *choiceExpr) (interface{}, bool) { +func (p *parser) parseChoiceExpr(ch *choiceExpr) (any, bool) { if p.debug { defer p.out(p.in("parseChoiceExpr")) } @@ -1196,7 +1198,7 @@ func (p *parser) parseChoiceExpr(ch *choiceExpr) (interface{}, bool) { return nil, false } -func (p *parser) parseLabeledExpr(lab *labeledExpr) (interface{}, bool) { +func (p *parser) parseLabeledExpr(lab *labeledExpr) (any, bool) { if p.debug { defer p.out(p.in("parseLabeledExpr")) } @@ -1211,7 +1213,7 @@ func (p *parser) parseLabeledExpr(lab *labeledExpr) (interface{}, bool) { return val, ok } -func (p *parser) parseLitMatcher(lit *litMatcher) (interface{}, bool) { +func (p *parser) parseLitMatcher(lit *litMatcher) (any, bool) { if p.debug { defer p.out(p.in("parseLitMatcher")) } @@ -1233,7 +1235,7 @@ func (p *parser) parseLitMatcher(lit *litMatcher) (interface{}, bool) { return p.sliceFrom(start), true } -func (p *parser) parseNotCodeExpr(not *notCodeExpr) (interface{}, bool) { +func (p *parser) parseNotCodeExpr(not *notCodeExpr) (any, bool) { if p.debug { defer p.out(p.in("parseNotCodeExpr")) } @@ -1249,7 +1251,7 @@ func (p *parser) parseNotCodeExpr(not *notCodeExpr) (interface{}, bool) { return nil, !ok } -func (p *parser) parseNotExpr(not *notExpr) (interface{}, bool) { +func (p *parser) parseNotExpr(not *notExpr) (any, bool) { if p.debug { defer p.out(p.in("parseNotExpr")) } @@ -1267,12 +1269,12 @@ func (p *parser) parseNotExpr(not *notExpr) (interface{}, bool) { return nil, !ok } -func (p *parser) parseOneOrMoreExpr(expr *oneOrMoreExpr) (interface{}, bool) { +func (p *parser) parseOneOrMoreExpr(expr *oneOrMoreExpr) (any, bool) { if p.debug { defer p.out(p.in("parseOneOrMoreExpr")) } - var vals []interface{} + var vals []any for { p.pushV() @@ -1289,7 +1291,7 @@ func (p *parser) parseOneOrMoreExpr(expr *oneOrMoreExpr) (interface{}, bool) { } } -func (p *parser) parseRecoveryExpr(recover *recoveryExpr) (interface{}, bool) { +func (p *parser) parseRecoveryExpr(recover *recoveryExpr) (any, bool) { if p.debug { defer p.out(p.in("parseRecoveryExpr (" + strings.Join(recover.failureLabel, ",") + ")")) } @@ -1301,7 +1303,7 @@ func (p *parser) parseRecoveryExpr(recover *recoveryExpr) (interface{}, bool) { return val, ok } -func (p *parser) parseRuleRefExpr(ref *ruleRefExpr) (interface{}, bool) { +func (p *parser) parseRuleRefExpr(ref *ruleRefExpr) (any, bool) { if p.debug { defer p.out(p.in("parseRuleRefExpr " + ref.name)) } @@ -1318,12 +1320,12 @@ func (p *parser) parseRuleRefExpr(ref *ruleRefExpr) (interface{}, bool) { return p.parseRule(rule) } -func (p *parser) parseSeqExpr(seq *seqExpr) (interface{}, bool) { +func (p *parser) parseSeqExpr(seq *seqExpr) (any, bool) { if p.debug { defer p.out(p.in("parseSeqExpr")) } - vals := make([]interface{}, 0, len(seq.exprs)) + vals := make([]any, 0, len(seq.exprs)) pt := p.pt state := p.cloneState() @@ -1339,7 +1341,7 @@ func (p *parser) parseSeqExpr(seq *seqExpr) (interface{}, bool) { return vals, true } -func (p *parser) parseStateCodeExpr(state *stateCodeExpr) (interface{}, bool) { +func (p *parser) parseStateCodeExpr(state *stateCodeExpr) (any, bool) { if p.debug { defer p.out(p.in("parseStateCodeExpr")) } @@ -1351,7 +1353,7 @@ func (p *parser) parseStateCodeExpr(state *stateCodeExpr) (interface{}, bool) { return nil, true } -func (p *parser) parseThrowExpr(expr *throwExpr) (interface{}, bool) { +func (p *parser) parseThrowExpr(expr *throwExpr) (any, bool) { if p.debug { defer p.out(p.in("parseThrowExpr")) } @@ -1367,12 +1369,12 @@ func (p *parser) parseThrowExpr(expr *throwExpr) (interface{}, bool) { return nil, false } -func (p *parser) parseZeroOrMoreExpr(expr *zeroOrMoreExpr) (interface{}, bool) { +func (p *parser) parseZeroOrMoreExpr(expr *zeroOrMoreExpr) (any, bool) { if p.debug { defer p.out(p.in("parseZeroOrMoreExpr")) } - var vals []interface{} + var vals []any for { p.pushV() @@ -1385,7 +1387,7 @@ func (p *parser) parseZeroOrMoreExpr(expr *zeroOrMoreExpr) (interface{}, bool) { } } -func (p *parser) parseZeroOrOneExpr(expr *zeroOrOneExpr) (interface{}, bool) { +func (p *parser) parseZeroOrOneExpr(expr *zeroOrOneExpr) (any, bool) { if p.debug { defer p.out(p.in("parseZeroOrOneExpr")) } diff --git a/test/runeerror/runeerror.peg b/test/runeerror/runeerror.peg index 2efb9954..33815fba 100644 --- a/test/runeerror/runeerror.peg +++ b/test/runeerror/runeerror.peg @@ -1,9 +1,9 @@ { package runeerror - func joinBytes(a interface{}) []byte { + func joinBytes(a any) []byte { var A []byte - for _, x := range a.([]interface{}) { + for _, x := range a.([]any) { A = append(A, x.([]uint8)...) } return A diff --git a/test/state/state.go b/test/state/state.go index 21e94192..99e860ed 100644 --- a/test/state/state.go +++ b/test/state/state.go @@ -27,7 +27,7 @@ var g = &grammar{ run: (*parser).callonstart1, expr: &seqExpr{ pos: position{line: 5, col: 9, offset: 27}, - exprs: []interface{}{ + exprs: []any{ &stateCodeExpr{ pos: position{line: 5, col: 9, offset: 27}, run: (*parser).callonstart3, @@ -36,13 +36,13 @@ var g = &grammar{ pos: position{line: 10, col: 3, offset: 115}, expr: &seqExpr{ pos: position{line: 10, col: 4, offset: 116}, - exprs: []interface{}{ + exprs: []any{ &choiceExpr{ pos: position{line: 10, col: 5, offset: 117}, - alternatives: []interface{}{ + alternatives: []any{ &seqExpr{ pos: position{line: 14, col: 5, offset: 173}, - exprs: []interface{}{ + exprs: []any{ &litMatcher{ pos: position{line: 14, col: 5, offset: 173}, val: "abc", @@ -63,7 +63,7 @@ var g = &grammar{ }, &seqExpr{ pos: position{line: 15, col: 5, offset: 188}, - exprs: []interface{}{ + exprs: []any{ &litMatcher{ pos: position{line: 15, col: 5, offset: 188}, val: "abc", @@ -84,7 +84,7 @@ var g = &grammar{ }, &seqExpr{ pos: position{line: 16, col: 5, offset: 203}, - exprs: []interface{}{ + exprs: []any{ &litMatcher{ pos: position{line: 16, col: 5, offset: 203}, val: "abcf", @@ -166,12 +166,12 @@ func (p *parser) callonstart17() error { return p.cur.onstart17() } -func (c *current) onstart1() (interface{}, error) { +func (c *current) onstart1() (any, error) { return c.state["countCs"], nil } -func (p *parser) callonstart1() (interface{}, error) { +func (p *parser) callonstart1() (any, error) { stack := p.vstack[len(p.vstack)-1] _ = stack return p.cur.onstart1() @@ -315,7 +315,7 @@ func Recover(b bool) Option { // GlobalStore creates an Option to set a key to a certain value in // the globalStore. -func GlobalStore(key string, value interface{}) Option { +func GlobalStore(key string, value any) Option { return func(p *parser) Option { old := p.cur.globalStore[key] p.cur.globalStore[key] = value @@ -325,7 +325,7 @@ func GlobalStore(key string, value interface{}) Option { // InitState creates an Option to set a key to a certain value in // the global "state" store. -func InitState(key string, value interface{}) Option { +func InitState(key string, value any) Option { return func(p *parser) Option { old := p.cur.state[key] p.cur.state[key] = value @@ -334,7 +334,7 @@ func InitState(key string, value interface{}) Option { } // ParseFile parses the file identified by filename. -func ParseFile(filename string, opts ...Option) (i interface{}, err error) { // nolint: deadcode +func ParseFile(filename string, opts ...Option) (i any, err error) { // nolint: deadcode f, err := os.Open(filename) if err != nil { return nil, err @@ -349,7 +349,7 @@ func ParseFile(filename string, opts ...Option) (i interface{}, err error) { // // ParseReader parses the data from r using filename as information in the // error messages. -func ParseReader(filename string, r io.Reader, opts ...Option) (interface{}, error) { // nolint: deadcode +func ParseReader(filename string, r io.Reader, opts ...Option) (any, error) { // nolint: deadcode b, err := io.ReadAll(r) if err != nil { return nil, err @@ -360,7 +360,7 @@ func ParseReader(filename string, r io.Reader, opts ...Option) (interface{}, err // Parse parses the data from b using filename as information in the // error messages. -func Parse(filename string, b []byte, opts ...Option) (interface{}, error) { +func Parse(filename string, b []byte, opts ...Option) (any, error) { return newParser(filename, b, opts...).parse(g) } @@ -398,7 +398,7 @@ type current struct { globalStore storeDict } -type storeDict map[string]interface{} +type storeDict map[string]any // the AST types... @@ -413,34 +413,34 @@ type rule struct { pos position name string displayName string - expr interface{} + expr any } // nolint: structcheck type choiceExpr struct { pos position - alternatives []interface{} + alternatives []any } // nolint: structcheck type actionExpr struct { pos position - expr interface{} - run func(*parser) (interface{}, error) + expr any + run func(*parser) (any, error) } // nolint: structcheck type recoveryExpr struct { pos position - expr interface{} - recoverExpr interface{} + expr any + recoverExpr any failureLabel []string } // nolint: structcheck type seqExpr struct { pos position - exprs []interface{} + exprs []any } // nolint: structcheck @@ -453,20 +453,22 @@ type throwExpr struct { type labeledExpr struct { pos position label string - expr interface{} + expr any } // nolint: structcheck type expr struct { pos position - expr interface{} + expr any } -type andExpr expr // nolint: structcheck -type notExpr expr // nolint: structcheck -type zeroOrOneExpr expr // nolint: structcheck -type zeroOrMoreExpr expr // nolint: structcheck -type oneOrMoreExpr expr // nolint: structcheck +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 { @@ -614,7 +616,7 @@ func (p *parser) setOptions(opts []Option) { // nolint: structcheck,deadcode type resultTuple struct { - v interface{} + v any b bool end savepoint } @@ -660,12 +662,12 @@ type parser struct { memoize bool // memoization table for the packrat algorithm: // map[offset in source] map[expression or rule] {value, match} - memo map[int]map[interface{}]resultTuple + 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]interface{} + vstack []map[string]any // rule stack, allows identification of the current rule in errors rstack []*rule @@ -685,7 +687,7 @@ type parser struct { choiceNoMatch string // recovery expression stack, keeps track of the currently available recovery expression, these are traversed in reverse - recoveryStack []map[string]interface{} + recoveryStack []map[string]any } // push a variable set on the vstack. @@ -705,7 +707,7 @@ func (p *parser) pushV() { return } - m = make(map[string]interface{}) + m = make(map[string]any) p.vstack[len(p.vstack)-1] = m } @@ -721,7 +723,7 @@ func (p *parser) popV() { } // push a recovery expression with its labels to the recoveryStack -func (p *parser) pushRecovery(labels []string, expr interface{}) { +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) @@ -730,7 +732,7 @@ func (p *parser) pushRecovery(labels []string, expr interface{}) { p.recoveryStack = p.recoveryStack[:len(p.recoveryStack)+1] } - m := make(map[string]interface{}, len(labels)) + m := make(map[string]any, len(labels)) for _, fl := range labels { m[fl] = expr } @@ -850,11 +852,11 @@ func (p *parser) restore(pt savepoint) { // copies of the state to allow the parser to properly restore the state in // the case of backtracking. type Cloner interface { - Clone() interface{} + Clone() any } var statePool = &sync.Pool{ - New: func() interface{} { return make(storeDict) }, + New: func() any { return make(storeDict) }, } func (sd storeDict) Discard() { @@ -896,7 +898,7 @@ func (p *parser) sliceFrom(start savepoint) []byte { return p.data[start.position.offset:p.pt.position.offset] } -func (p *parser) getMemoized(node interface{}) (resultTuple, bool) { +func (p *parser) getMemoized(node any) (resultTuple, bool) { if len(p.memo) == 0 { return resultTuple{}, false } @@ -908,13 +910,13 @@ func (p *parser) getMemoized(node interface{}) (resultTuple, bool) { return res, ok } -func (p *parser) setMemoized(pt savepoint, node interface{}, tuple resultTuple) { +func (p *parser) setMemoized(pt savepoint, node any, tuple resultTuple) { if p.memo == nil { - p.memo = make(map[int]map[interface{}]resultTuple) + p.memo = make(map[int]map[any]resultTuple) } m := p.memo[pt.offset] if m == nil { - m = make(map[interface{}]resultTuple) + m = make(map[any]resultTuple) p.memo[pt.offset] = m } m[node] = tuple @@ -928,7 +930,7 @@ func (p *parser) buildRulesTable(g *grammar) { } // nolint: gocyclo -func (p *parser) parse(g *grammar) (val interface{}, err error) { +func (p *parser) parse(g *grammar) (val any, err error) { if len(g.rules) == 0 { p.addErr(errNoRule) return nil, p.errs.err() @@ -1005,7 +1007,7 @@ func listJoin(list []string, sep string, lastSep string) string { } } -func (p *parser) parseRule(rule *rule) (interface{}, bool) { +func (p *parser) parseRule(rule *rule) (any, bool) { if p.debug { defer p.out(p.in("parseRule " + rule.name)) } @@ -1035,7 +1037,7 @@ func (p *parser) parseRule(rule *rule) (interface{}, bool) { } // nolint: gocyclo -func (p *parser) parseExpr(expr interface{}) (interface{}, bool) { +func (p *parser) parseExpr(expr any) (any, bool) { var pt savepoint if p.memoize { @@ -1052,7 +1054,7 @@ func (p *parser) parseExpr(expr interface{}) (interface{}, bool) { panic(errMaxExprCnt) } - var val interface{} + var val any var ok bool switch expr := expr.(type) { case *actionExpr: @@ -1100,7 +1102,7 @@ func (p *parser) parseExpr(expr interface{}) (interface{}, bool) { return val, ok } -func (p *parser) parseActionExpr(act *actionExpr) (interface{}, bool) { +func (p *parser) parseActionExpr(act *actionExpr) (any, bool) { if p.debug { defer p.out(p.in("parseActionExpr")) } @@ -1125,7 +1127,7 @@ func (p *parser) parseActionExpr(act *actionExpr) (interface{}, bool) { return val, ok } -func (p *parser) parseAndCodeExpr(and *andCodeExpr) (interface{}, bool) { +func (p *parser) parseAndCodeExpr(and *andCodeExpr) (any, bool) { if p.debug { defer p.out(p.in("parseAndCodeExpr")) } @@ -1141,7 +1143,7 @@ func (p *parser) parseAndCodeExpr(and *andCodeExpr) (interface{}, bool) { return nil, ok } -func (p *parser) parseAndExpr(and *andExpr) (interface{}, bool) { +func (p *parser) parseAndExpr(and *andExpr) (any, bool) { if p.debug { defer p.out(p.in("parseAndExpr")) } @@ -1157,7 +1159,7 @@ func (p *parser) parseAndExpr(and *andExpr) (interface{}, bool) { return nil, ok } -func (p *parser) parseAnyMatcher(any *anyMatcher) (interface{}, bool) { +func (p *parser) parseAnyMatcher(any *anyMatcher) (any, bool) { if p.debug { defer p.out(p.in("parseAnyMatcher")) } @@ -1174,7 +1176,7 @@ func (p *parser) parseAnyMatcher(any *anyMatcher) (interface{}, bool) { } // nolint: gocyclo -func (p *parser) parseCharClassMatcher(chr *charClassMatcher) (interface{}, bool) { +func (p *parser) parseCharClassMatcher(chr *charClassMatcher) (any, bool) { if p.debug { defer p.out(p.in("parseCharClassMatcher")) } @@ -1255,7 +1257,7 @@ func (p *parser) incChoiceAltCnt(ch *choiceExpr, altI int) { m[alt]++ } -func (p *parser) parseChoiceExpr(ch *choiceExpr) (interface{}, bool) { +func (p *parser) parseChoiceExpr(ch *choiceExpr) (any, bool) { if p.debug { defer p.out(p.in("parseChoiceExpr")) } @@ -1279,7 +1281,7 @@ func (p *parser) parseChoiceExpr(ch *choiceExpr) (interface{}, bool) { return nil, false } -func (p *parser) parseLabeledExpr(lab *labeledExpr) (interface{}, bool) { +func (p *parser) parseLabeledExpr(lab *labeledExpr) (any, bool) { if p.debug { defer p.out(p.in("parseLabeledExpr")) } @@ -1294,7 +1296,7 @@ func (p *parser) parseLabeledExpr(lab *labeledExpr) (interface{}, bool) { return val, ok } -func (p *parser) parseLitMatcher(lit *litMatcher) (interface{}, bool) { +func (p *parser) parseLitMatcher(lit *litMatcher) (any, bool) { if p.debug { defer p.out(p.in("parseLitMatcher")) } @@ -1316,7 +1318,7 @@ func (p *parser) parseLitMatcher(lit *litMatcher) (interface{}, bool) { return p.sliceFrom(start), true } -func (p *parser) parseNotCodeExpr(not *notCodeExpr) (interface{}, bool) { +func (p *parser) parseNotCodeExpr(not *notCodeExpr) (any, bool) { if p.debug { defer p.out(p.in("parseNotCodeExpr")) } @@ -1332,7 +1334,7 @@ func (p *parser) parseNotCodeExpr(not *notCodeExpr) (interface{}, bool) { return nil, !ok } -func (p *parser) parseNotExpr(not *notExpr) (interface{}, bool) { +func (p *parser) parseNotExpr(not *notExpr) (any, bool) { if p.debug { defer p.out(p.in("parseNotExpr")) } @@ -1350,12 +1352,12 @@ func (p *parser) parseNotExpr(not *notExpr) (interface{}, bool) { return nil, !ok } -func (p *parser) parseOneOrMoreExpr(expr *oneOrMoreExpr) (interface{}, bool) { +func (p *parser) parseOneOrMoreExpr(expr *oneOrMoreExpr) (any, bool) { if p.debug { defer p.out(p.in("parseOneOrMoreExpr")) } - var vals []interface{} + var vals []any for { p.pushV() @@ -1372,7 +1374,7 @@ func (p *parser) parseOneOrMoreExpr(expr *oneOrMoreExpr) (interface{}, bool) { } } -func (p *parser) parseRecoveryExpr(recover *recoveryExpr) (interface{}, bool) { +func (p *parser) parseRecoveryExpr(recover *recoveryExpr) (any, bool) { if p.debug { defer p.out(p.in("parseRecoveryExpr (" + strings.Join(recover.failureLabel, ",") + ")")) } @@ -1384,7 +1386,7 @@ func (p *parser) parseRecoveryExpr(recover *recoveryExpr) (interface{}, bool) { return val, ok } -func (p *parser) parseRuleRefExpr(ref *ruleRefExpr) (interface{}, bool) { +func (p *parser) parseRuleRefExpr(ref *ruleRefExpr) (any, bool) { if p.debug { defer p.out(p.in("parseRuleRefExpr " + ref.name)) } @@ -1401,12 +1403,12 @@ func (p *parser) parseRuleRefExpr(ref *ruleRefExpr) (interface{}, bool) { return p.parseRule(rule) } -func (p *parser) parseSeqExpr(seq *seqExpr) (interface{}, bool) { +func (p *parser) parseSeqExpr(seq *seqExpr) (any, bool) { if p.debug { defer p.out(p.in("parseSeqExpr")) } - vals := make([]interface{}, 0, len(seq.exprs)) + vals := make([]any, 0, len(seq.exprs)) pt := p.pt state := p.cloneState() @@ -1422,7 +1424,7 @@ func (p *parser) parseSeqExpr(seq *seqExpr) (interface{}, bool) { return vals, true } -func (p *parser) parseStateCodeExpr(state *stateCodeExpr) (interface{}, bool) { +func (p *parser) parseStateCodeExpr(state *stateCodeExpr) (any, bool) { if p.debug { defer p.out(p.in("parseStateCodeExpr")) } @@ -1434,7 +1436,7 @@ func (p *parser) parseStateCodeExpr(state *stateCodeExpr) (interface{}, bool) { return nil, true } -func (p *parser) parseThrowExpr(expr *throwExpr) (interface{}, bool) { +func (p *parser) parseThrowExpr(expr *throwExpr) (any, bool) { if p.debug { defer p.out(p.in("parseThrowExpr")) } @@ -1450,12 +1452,12 @@ func (p *parser) parseThrowExpr(expr *throwExpr) (interface{}, bool) { return nil, false } -func (p *parser) parseZeroOrMoreExpr(expr *zeroOrMoreExpr) (interface{}, bool) { +func (p *parser) parseZeroOrMoreExpr(expr *zeroOrMoreExpr) (any, bool) { if p.debug { defer p.out(p.in("parseZeroOrMoreExpr")) } - var vals []interface{} + var vals []any for { p.pushV() @@ -1468,7 +1470,7 @@ func (p *parser) parseZeroOrMoreExpr(expr *zeroOrMoreExpr) (interface{}, bool) { } } -func (p *parser) parseZeroOrOneExpr(expr *zeroOrOneExpr) (interface{}, bool) { +func (p *parser) parseZeroOrOneExpr(expr *zeroOrOneExpr) (any, bool) { if p.debug { defer p.out(p.in("parseZeroOrOneExpr")) } diff --git a/test/stateclone/stateclone.go b/test/stateclone/stateclone.go index bec6481d..23310b29 100644 --- a/test/stateclone/stateclone.go +++ b/test/stateclone/stateclone.go @@ -19,7 +19,7 @@ import ( type values []int -func (vals values) Clone() interface{} { +func (vals values) Clone() any { clone := make(values, 0, len(vals)) clone = append(clone, vals...) return clone @@ -29,43 +29,43 @@ var g = &grammar{ rules: []*rule{ { name: "start", - pos: position{line: 14, col: 1, offset: 171}, + pos: position{line: 14, col: 1, offset: 163}, expr: &actionExpr{ - pos: position{line: 14, col: 9, offset: 179}, + pos: position{line: 14, col: 9, offset: 171}, run: (*parser).callonstart1, expr: &seqExpr{ - pos: position{line: 14, col: 9, offset: 179}, - exprs: []interface{}{ + pos: position{line: 14, col: 9, offset: 171}, + exprs: []any{ &stateCodeExpr{ - pos: position{line: 14, col: 9, offset: 179}, + pos: position{line: 14, col: 9, offset: 171}, run: (*parser).callonstart3, }, &zeroOrMoreExpr{ - pos: position{line: 21, col: 3, offset: 304}, + pos: position{line: 21, col: 3, offset: 296}, expr: &seqExpr{ - pos: position{line: 21, col: 4, offset: 305}, - exprs: []interface{}{ + pos: position{line: 21, col: 4, offset: 297}, + exprs: []any{ &choiceExpr{ - pos: position{line: 21, col: 5, offset: 306}, - alternatives: []interface{}{ + pos: position{line: 21, col: 5, offset: 298}, + alternatives: []any{ &ruleRefExpr{ - pos: position{line: 21, col: 5, offset: 306}, + pos: position{line: 21, col: 5, offset: 298}, name: "x", }, &ruleRefExpr{ - pos: position{line: 21, col: 7, offset: 308}, + pos: position{line: 21, col: 7, offset: 300}, name: "y", }, &ruleRefExpr{ - pos: position{line: 21, col: 9, offset: 310}, + pos: position{line: 21, col: 9, offset: 302}, name: "z", }, }, }, &zeroOrMoreExpr{ - pos: position{line: 21, col: 12, offset: 313}, + pos: position{line: 21, col: 12, offset: 305}, expr: &ruleRefExpr{ - pos: position{line: 21, col: 12, offset: 313}, + pos: position{line: 21, col: 12, offset: 305}, name: "ws", }, }, @@ -78,22 +78,22 @@ var g = &grammar{ }, { name: "x", - pos: position{line: 25, col: 1, offset: 355}, + pos: position{line: 25, col: 1, offset: 347}, expr: &seqExpr{ - pos: position{line: 25, col: 5, offset: 359}, - exprs: []interface{}{ + pos: position{line: 25, col: 5, offset: 351}, + exprs: []any{ &litMatcher{ - pos: position{line: 25, col: 5, offset: 359}, + pos: position{line: 25, col: 5, offset: 351}, val: "ab", ignoreCase: false, want: "\"ab\"", }, &ruleRefExpr{ - pos: position{line: 25, col: 10, offset: 364}, + pos: position{line: 25, col: 10, offset: 356}, name: "c", }, &litMatcher{ - pos: position{line: 25, col: 12, offset: 366}, + pos: position{line: 25, col: 12, offset: 358}, val: "d", ignoreCase: false, want: "\"d\"", @@ -103,22 +103,22 @@ var g = &grammar{ }, { name: "y", - pos: position{line: 26, col: 1, offset: 370}, + pos: position{line: 26, col: 1, offset: 362}, expr: &seqExpr{ - pos: position{line: 26, col: 5, offset: 374}, - exprs: []interface{}{ + pos: position{line: 26, col: 5, offset: 366}, + exprs: []any{ &litMatcher{ - pos: position{line: 26, col: 5, offset: 374}, + pos: position{line: 26, col: 5, offset: 366}, val: "a", ignoreCase: false, want: "\"a\"", }, &ruleRefExpr{ - pos: position{line: 26, col: 9, offset: 378}, + pos: position{line: 26, col: 9, offset: 370}, name: "bc", }, &litMatcher{ - pos: position{line: 26, col: 12, offset: 381}, + pos: position{line: 26, col: 12, offset: 373}, val: "e", ignoreCase: false, want: "\"e\"", @@ -128,18 +128,18 @@ var g = &grammar{ }, { name: "z", - pos: position{line: 27, col: 1, offset: 385}, + pos: position{line: 27, col: 1, offset: 377}, expr: &seqExpr{ - pos: position{line: 27, col: 5, offset: 389}, - exprs: []interface{}{ + pos: position{line: 27, col: 5, offset: 381}, + exprs: []any{ &litMatcher{ - pos: position{line: 27, col: 5, offset: 389}, + pos: position{line: 27, col: 5, offset: 381}, val: "abcf", ignoreCase: false, want: "\"abcf\"", }, &stateCodeExpr{ - pos: position{line: 27, col: 12, offset: 396}, + pos: position{line: 27, col: 12, offset: 388}, run: (*parser).callonz3, }, }, @@ -147,18 +147,18 @@ var g = &grammar{ }, { name: "c", - pos: position{line: 29, col: 1, offset: 467}, + pos: position{line: 29, col: 1, offset: 459}, expr: &seqExpr{ - pos: position{line: 29, col: 5, offset: 471}, - exprs: []interface{}{ + pos: position{line: 29, col: 5, offset: 463}, + exprs: []any{ &litMatcher{ - pos: position{line: 29, col: 5, offset: 471}, + pos: position{line: 29, col: 5, offset: 463}, val: "c", ignoreCase: false, want: "\"c\"", }, &stateCodeExpr{ - pos: position{line: 29, col: 9, offset: 475}, + pos: position{line: 29, col: 9, offset: 467}, run: (*parser).callonc3, }, }, @@ -166,18 +166,18 @@ var g = &grammar{ }, { name: "bc", - pos: position{line: 30, col: 1, offset: 546}, + pos: position{line: 30, col: 1, offset: 538}, expr: &seqExpr{ - pos: position{line: 30, col: 6, offset: 551}, - exprs: []interface{}{ + pos: position{line: 30, col: 6, offset: 543}, + exprs: []any{ &litMatcher{ - pos: position{line: 30, col: 6, offset: 551}, + pos: position{line: 30, col: 6, offset: 543}, val: "bc", ignoreCase: false, want: "\"bc\"", }, &stateCodeExpr{ - pos: position{line: 30, col: 11, offset: 556}, + pos: position{line: 30, col: 11, offset: 548}, run: (*parser).callonbc3, }, }, @@ -185,18 +185,18 @@ var g = &grammar{ }, { name: "ws", - pos: position{line: 32, col: 1, offset: 627}, + pos: position{line: 32, col: 1, offset: 619}, expr: &choiceExpr{ - pos: position{line: 32, col: 6, offset: 632}, - alternatives: []interface{}{ + pos: position{line: 32, col: 6, offset: 624}, + alternatives: []any{ &litMatcher{ - pos: position{line: 32, col: 6, offset: 632}, + pos: position{line: 32, col: 6, offset: 624}, val: " ", ignoreCase: false, want: "\" \"", }, &litMatcher{ - pos: position{line: 32, col: 12, offset: 638}, + pos: position{line: 32, col: 12, offset: 630}, val: "\n", ignoreCase: false, want: "\"\\n\"", @@ -223,12 +223,12 @@ func (p *parser) callonstart3() error { return p.cur.onstart3() } -func (c *current) onstart1() (interface{}, error) { +func (c *current) onstart1() (any, error) { return c.state["vals"], nil } -func (p *parser) callonstart1() (interface{}, error) { +func (p *parser) callonstart1() (any, error) { stack := p.vstack[len(p.vstack)-1] _ = stack return p.cur.onstart1() @@ -405,7 +405,7 @@ func Recover(b bool) Option { // GlobalStore creates an Option to set a key to a certain value in // the globalStore. -func GlobalStore(key string, value interface{}) Option { +func GlobalStore(key string, value any) Option { return func(p *parser) Option { old := p.cur.globalStore[key] p.cur.globalStore[key] = value @@ -415,7 +415,7 @@ func GlobalStore(key string, value interface{}) Option { // InitState creates an Option to set a key to a certain value in // the global "state" store. -func InitState(key string, value interface{}) Option { +func InitState(key string, value any) Option { return func(p *parser) Option { old := p.cur.state[key] p.cur.state[key] = value @@ -424,7 +424,7 @@ func InitState(key string, value interface{}) Option { } // ParseFile parses the file identified by filename. -func ParseFile(filename string, opts ...Option) (i interface{}, err error) { // nolint: deadcode +func ParseFile(filename string, opts ...Option) (i any, err error) { // nolint: deadcode f, err := os.Open(filename) if err != nil { return nil, err @@ -439,7 +439,7 @@ func ParseFile(filename string, opts ...Option) (i interface{}, err error) { // // ParseReader parses the data from r using filename as information in the // error messages. -func ParseReader(filename string, r io.Reader, opts ...Option) (interface{}, error) { // nolint: deadcode +func ParseReader(filename string, r io.Reader, opts ...Option) (any, error) { // nolint: deadcode b, err := io.ReadAll(r) if err != nil { return nil, err @@ -450,7 +450,7 @@ func ParseReader(filename string, r io.Reader, opts ...Option) (interface{}, err // Parse parses the data from b using filename as information in the // error messages. -func Parse(filename string, b []byte, opts ...Option) (interface{}, error) { +func Parse(filename string, b []byte, opts ...Option) (any, error) { return newParser(filename, b, opts...).parse(g) } @@ -488,7 +488,7 @@ type current struct { globalStore storeDict } -type storeDict map[string]interface{} +type storeDict map[string]any // the AST types... @@ -503,34 +503,34 @@ type rule struct { pos position name string displayName string - expr interface{} + expr any } // nolint: structcheck type choiceExpr struct { pos position - alternatives []interface{} + alternatives []any } // nolint: structcheck type actionExpr struct { pos position - expr interface{} - run func(*parser) (interface{}, error) + expr any + run func(*parser) (any, error) } // nolint: structcheck type recoveryExpr struct { pos position - expr interface{} - recoverExpr interface{} + expr any + recoverExpr any failureLabel []string } // nolint: structcheck type seqExpr struct { pos position - exprs []interface{} + exprs []any } // nolint: structcheck @@ -543,20 +543,22 @@ type throwExpr struct { type labeledExpr struct { pos position label string - expr interface{} + expr any } // nolint: structcheck type expr struct { pos position - expr interface{} + expr any } -type andExpr expr // nolint: structcheck -type notExpr expr // nolint: structcheck -type zeroOrOneExpr expr // nolint: structcheck -type zeroOrMoreExpr expr // nolint: structcheck -type oneOrMoreExpr expr // nolint: structcheck +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 { @@ -704,7 +706,7 @@ func (p *parser) setOptions(opts []Option) { // nolint: structcheck,deadcode type resultTuple struct { - v interface{} + v any b bool end savepoint } @@ -750,12 +752,12 @@ type parser struct { memoize bool // memoization table for the packrat algorithm: // map[offset in source] map[expression or rule] {value, match} - memo map[int]map[interface{}]resultTuple + 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]interface{} + vstack []map[string]any // rule stack, allows identification of the current rule in errors rstack []*rule @@ -775,7 +777,7 @@ type parser struct { choiceNoMatch string // recovery expression stack, keeps track of the currently available recovery expression, these are traversed in reverse - recoveryStack []map[string]interface{} + recoveryStack []map[string]any } // push a variable set on the vstack. @@ -795,7 +797,7 @@ func (p *parser) pushV() { return } - m = make(map[string]interface{}) + m = make(map[string]any) p.vstack[len(p.vstack)-1] = m } @@ -811,7 +813,7 @@ func (p *parser) popV() { } // push a recovery expression with its labels to the recoveryStack -func (p *parser) pushRecovery(labels []string, expr interface{}) { +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) @@ -820,7 +822,7 @@ func (p *parser) pushRecovery(labels []string, expr interface{}) { p.recoveryStack = p.recoveryStack[:len(p.recoveryStack)+1] } - m := make(map[string]interface{}, len(labels)) + m := make(map[string]any, len(labels)) for _, fl := range labels { m[fl] = expr } @@ -940,11 +942,11 @@ func (p *parser) restore(pt savepoint) { // copies of the state to allow the parser to properly restore the state in // the case of backtracking. type Cloner interface { - Clone() interface{} + Clone() any } var statePool = &sync.Pool{ - New: func() interface{} { return make(storeDict) }, + New: func() any { return make(storeDict) }, } func (sd storeDict) Discard() { @@ -986,7 +988,7 @@ func (p *parser) sliceFrom(start savepoint) []byte { return p.data[start.position.offset:p.pt.position.offset] } -func (p *parser) getMemoized(node interface{}) (resultTuple, bool) { +func (p *parser) getMemoized(node any) (resultTuple, bool) { if len(p.memo) == 0 { return resultTuple{}, false } @@ -998,13 +1000,13 @@ func (p *parser) getMemoized(node interface{}) (resultTuple, bool) { return res, ok } -func (p *parser) setMemoized(pt savepoint, node interface{}, tuple resultTuple) { +func (p *parser) setMemoized(pt savepoint, node any, tuple resultTuple) { if p.memo == nil { - p.memo = make(map[int]map[interface{}]resultTuple) + p.memo = make(map[int]map[any]resultTuple) } m := p.memo[pt.offset] if m == nil { - m = make(map[interface{}]resultTuple) + m = make(map[any]resultTuple) p.memo[pt.offset] = m } m[node] = tuple @@ -1018,7 +1020,7 @@ func (p *parser) buildRulesTable(g *grammar) { } // nolint: gocyclo -func (p *parser) parse(g *grammar) (val interface{}, err error) { +func (p *parser) parse(g *grammar) (val any, err error) { if len(g.rules) == 0 { p.addErr(errNoRule) return nil, p.errs.err() @@ -1095,7 +1097,7 @@ func listJoin(list []string, sep string, lastSep string) string { } } -func (p *parser) parseRule(rule *rule) (interface{}, bool) { +func (p *parser) parseRule(rule *rule) (any, bool) { if p.debug { defer p.out(p.in("parseRule " + rule.name)) } @@ -1125,7 +1127,7 @@ func (p *parser) parseRule(rule *rule) (interface{}, bool) { } // nolint: gocyclo -func (p *parser) parseExpr(expr interface{}) (interface{}, bool) { +func (p *parser) parseExpr(expr any) (any, bool) { var pt savepoint if p.memoize { @@ -1142,7 +1144,7 @@ func (p *parser) parseExpr(expr interface{}) (interface{}, bool) { panic(errMaxExprCnt) } - var val interface{} + var val any var ok bool switch expr := expr.(type) { case *actionExpr: @@ -1190,7 +1192,7 @@ func (p *parser) parseExpr(expr interface{}) (interface{}, bool) { return val, ok } -func (p *parser) parseActionExpr(act *actionExpr) (interface{}, bool) { +func (p *parser) parseActionExpr(act *actionExpr) (any, bool) { if p.debug { defer p.out(p.in("parseActionExpr")) } @@ -1215,7 +1217,7 @@ func (p *parser) parseActionExpr(act *actionExpr) (interface{}, bool) { return val, ok } -func (p *parser) parseAndCodeExpr(and *andCodeExpr) (interface{}, bool) { +func (p *parser) parseAndCodeExpr(and *andCodeExpr) (any, bool) { if p.debug { defer p.out(p.in("parseAndCodeExpr")) } @@ -1231,7 +1233,7 @@ func (p *parser) parseAndCodeExpr(and *andCodeExpr) (interface{}, bool) { return nil, ok } -func (p *parser) parseAndExpr(and *andExpr) (interface{}, bool) { +func (p *parser) parseAndExpr(and *andExpr) (any, bool) { if p.debug { defer p.out(p.in("parseAndExpr")) } @@ -1247,7 +1249,7 @@ func (p *parser) parseAndExpr(and *andExpr) (interface{}, bool) { return nil, ok } -func (p *parser) parseAnyMatcher(any *anyMatcher) (interface{}, bool) { +func (p *parser) parseAnyMatcher(any *anyMatcher) (any, bool) { if p.debug { defer p.out(p.in("parseAnyMatcher")) } @@ -1264,7 +1266,7 @@ func (p *parser) parseAnyMatcher(any *anyMatcher) (interface{}, bool) { } // nolint: gocyclo -func (p *parser) parseCharClassMatcher(chr *charClassMatcher) (interface{}, bool) { +func (p *parser) parseCharClassMatcher(chr *charClassMatcher) (any, bool) { if p.debug { defer p.out(p.in("parseCharClassMatcher")) } @@ -1345,7 +1347,7 @@ func (p *parser) incChoiceAltCnt(ch *choiceExpr, altI int) { m[alt]++ } -func (p *parser) parseChoiceExpr(ch *choiceExpr) (interface{}, bool) { +func (p *parser) parseChoiceExpr(ch *choiceExpr) (any, bool) { if p.debug { defer p.out(p.in("parseChoiceExpr")) } @@ -1369,7 +1371,7 @@ func (p *parser) parseChoiceExpr(ch *choiceExpr) (interface{}, bool) { return nil, false } -func (p *parser) parseLabeledExpr(lab *labeledExpr) (interface{}, bool) { +func (p *parser) parseLabeledExpr(lab *labeledExpr) (any, bool) { if p.debug { defer p.out(p.in("parseLabeledExpr")) } @@ -1384,7 +1386,7 @@ func (p *parser) parseLabeledExpr(lab *labeledExpr) (interface{}, bool) { return val, ok } -func (p *parser) parseLitMatcher(lit *litMatcher) (interface{}, bool) { +func (p *parser) parseLitMatcher(lit *litMatcher) (any, bool) { if p.debug { defer p.out(p.in("parseLitMatcher")) } @@ -1406,7 +1408,7 @@ func (p *parser) parseLitMatcher(lit *litMatcher) (interface{}, bool) { return p.sliceFrom(start), true } -func (p *parser) parseNotCodeExpr(not *notCodeExpr) (interface{}, bool) { +func (p *parser) parseNotCodeExpr(not *notCodeExpr) (any, bool) { if p.debug { defer p.out(p.in("parseNotCodeExpr")) } @@ -1422,7 +1424,7 @@ func (p *parser) parseNotCodeExpr(not *notCodeExpr) (interface{}, bool) { return nil, !ok } -func (p *parser) parseNotExpr(not *notExpr) (interface{}, bool) { +func (p *parser) parseNotExpr(not *notExpr) (any, bool) { if p.debug { defer p.out(p.in("parseNotExpr")) } @@ -1440,12 +1442,12 @@ func (p *parser) parseNotExpr(not *notExpr) (interface{}, bool) { return nil, !ok } -func (p *parser) parseOneOrMoreExpr(expr *oneOrMoreExpr) (interface{}, bool) { +func (p *parser) parseOneOrMoreExpr(expr *oneOrMoreExpr) (any, bool) { if p.debug { defer p.out(p.in("parseOneOrMoreExpr")) } - var vals []interface{} + var vals []any for { p.pushV() @@ -1462,7 +1464,7 @@ func (p *parser) parseOneOrMoreExpr(expr *oneOrMoreExpr) (interface{}, bool) { } } -func (p *parser) parseRecoveryExpr(recover *recoveryExpr) (interface{}, bool) { +func (p *parser) parseRecoveryExpr(recover *recoveryExpr) (any, bool) { if p.debug { defer p.out(p.in("parseRecoveryExpr (" + strings.Join(recover.failureLabel, ",") + ")")) } @@ -1474,7 +1476,7 @@ func (p *parser) parseRecoveryExpr(recover *recoveryExpr) (interface{}, bool) { return val, ok } -func (p *parser) parseRuleRefExpr(ref *ruleRefExpr) (interface{}, bool) { +func (p *parser) parseRuleRefExpr(ref *ruleRefExpr) (any, bool) { if p.debug { defer p.out(p.in("parseRuleRefExpr " + ref.name)) } @@ -1491,12 +1493,12 @@ func (p *parser) parseRuleRefExpr(ref *ruleRefExpr) (interface{}, bool) { return p.parseRule(rule) } -func (p *parser) parseSeqExpr(seq *seqExpr) (interface{}, bool) { +func (p *parser) parseSeqExpr(seq *seqExpr) (any, bool) { if p.debug { defer p.out(p.in("parseSeqExpr")) } - vals := make([]interface{}, 0, len(seq.exprs)) + vals := make([]any, 0, len(seq.exprs)) pt := p.pt state := p.cloneState() @@ -1512,7 +1514,7 @@ func (p *parser) parseSeqExpr(seq *seqExpr) (interface{}, bool) { return vals, true } -func (p *parser) parseStateCodeExpr(state *stateCodeExpr) (interface{}, bool) { +func (p *parser) parseStateCodeExpr(state *stateCodeExpr) (any, bool) { if p.debug { defer p.out(p.in("parseStateCodeExpr")) } @@ -1524,7 +1526,7 @@ func (p *parser) parseStateCodeExpr(state *stateCodeExpr) (interface{}, bool) { return nil, true } -func (p *parser) parseThrowExpr(expr *throwExpr) (interface{}, bool) { +func (p *parser) parseThrowExpr(expr *throwExpr) (any, bool) { if p.debug { defer p.out(p.in("parseThrowExpr")) } @@ -1540,12 +1542,12 @@ func (p *parser) parseThrowExpr(expr *throwExpr) (interface{}, bool) { return nil, false } -func (p *parser) parseZeroOrMoreExpr(expr *zeroOrMoreExpr) (interface{}, bool) { +func (p *parser) parseZeroOrMoreExpr(expr *zeroOrMoreExpr) (any, bool) { if p.debug { defer p.out(p.in("parseZeroOrMoreExpr")) } - var vals []interface{} + var vals []any for { p.pushV() @@ -1558,7 +1560,7 @@ func (p *parser) parseZeroOrMoreExpr(expr *zeroOrMoreExpr) (interface{}, bool) { } } -func (p *parser) parseZeroOrOneExpr(expr *zeroOrOneExpr) (interface{}, bool) { +func (p *parser) parseZeroOrOneExpr(expr *zeroOrOneExpr) (any, bool) { if p.debug { defer p.out(p.in("parseZeroOrOneExpr")) } diff --git a/test/stateclone/stateclone.peg b/test/stateclone/stateclone.peg index 9dcc7a10..01b3bc05 100644 --- a/test/stateclone/stateclone.peg +++ b/test/stateclone/stateclone.peg @@ -3,7 +3,7 @@ package stateclone type values []int -func (vals values) Clone() interface{} { +func (vals values) Clone() any { clone := make(values, 0, len(vals)) clone = append(clone, vals...) return clone diff --git a/test/statereadonly/statereadonly.go b/test/statereadonly/statereadonly.go index 35110954..07074289 100644 --- a/test/statereadonly/statereadonly.go +++ b/test/statereadonly/statereadonly.go @@ -27,7 +27,7 @@ var g = &grammar{ run: (*parser).callonstart1, expr: &seqExpr{ pos: position{line: 5, col: 9, offset: 35}, - exprs: []interface{}{ + exprs: []any{ &stateCodeExpr{ pos: position{line: 5, col: 9, offset: 35}, run: (*parser).callonstart3, @@ -36,10 +36,10 @@ var g = &grammar{ pos: position{line: 5, col: 49, offset: 75}, expr: &seqExpr{ pos: position{line: 5, col: 50, offset: 76}, - exprs: []interface{}{ + exprs: []any{ &choiceExpr{ pos: position{line: 5, col: 51, offset: 77}, - alternatives: []interface{}{ + alternatives: []any{ &ruleRefExpr{ pos: position{line: 5, col: 51, offset: 77}, name: "x", @@ -73,7 +73,7 @@ var g = &grammar{ pos: position{line: 7, col: 1, offset: 126}, expr: &seqExpr{ pos: position{line: 7, col: 5, offset: 130}, - exprs: []interface{}{ + exprs: []any{ &litMatcher{ pos: position{line: 7, col: 5, offset: 130}, val: "ab", @@ -98,7 +98,7 @@ var g = &grammar{ pos: position{line: 8, col: 1, offset: 141}, expr: &seqExpr{ pos: position{line: 8, col: 5, offset: 145}, - exprs: []interface{}{ + exprs: []any{ &litMatcher{ pos: position{line: 8, col: 5, offset: 145}, val: "a", @@ -137,7 +137,7 @@ var g = &grammar{ pos: position{line: 11, col: 1, offset: 238}, expr: &seqExpr{ pos: position{line: 11, col: 5, offset: 242}, - exprs: []interface{}{ + exprs: []any{ &litMatcher{ pos: position{line: 11, col: 5, offset: 242}, val: "c", @@ -156,7 +156,7 @@ var g = &grammar{ pos: position{line: 12, col: 1, offset: 319}, expr: &seqExpr{ pos: position{line: 12, col: 6, offset: 324}, - exprs: []interface{}{ + exprs: []any{ &litMatcher{ pos: position{line: 12, col: 6, offset: 324}, val: "bc", @@ -175,7 +175,7 @@ var g = &grammar{ pos: position{line: 14, col: 1, offset: 403}, expr: &choiceExpr{ pos: position{line: 14, col: 6, offset: 408}, - alternatives: []interface{}{ + alternatives: []any{ &litMatcher{ pos: position{line: 14, col: 6, offset: 408}, val: " ", @@ -205,22 +205,22 @@ func (p *parser) callonstart3() error { return p.cur.onstart3() } -func (c *current) onstart1() (interface{}, error) { +func (c *current) onstart1() (any, error) { return c.state["countCs"], nil } -func (p *parser) callonstart1() (interface{}, error) { +func (p *parser) callonstart1() (any, error) { stack := p.vstack[len(p.vstack)-1] _ = stack return p.cur.onstart1() } -func (c *current) onz1() (interface{}, error) { +func (c *current) onz1() (any, error) { c.state["countCs"] = c.state["countCs"].(int) + 5 return nil, nil } -func (p *parser) callonz1() (interface{}, error) { +func (p *parser) callonz1() (any, error) { stack := p.vstack[len(p.vstack)-1] _ = stack return p.cur.onz1() @@ -386,7 +386,7 @@ func Recover(b bool) Option { // GlobalStore creates an Option to set a key to a certain value in // the globalStore. -func GlobalStore(key string, value interface{}) Option { +func GlobalStore(key string, value any) Option { return func(p *parser) Option { old := p.cur.globalStore[key] p.cur.globalStore[key] = value @@ -396,7 +396,7 @@ func GlobalStore(key string, value interface{}) Option { // InitState creates an Option to set a key to a certain value in // the global "state" store. -func InitState(key string, value interface{}) Option { +func InitState(key string, value any) Option { return func(p *parser) Option { old := p.cur.state[key] p.cur.state[key] = value @@ -405,7 +405,7 @@ func InitState(key string, value interface{}) Option { } // ParseFile parses the file identified by filename. -func ParseFile(filename string, opts ...Option) (i interface{}, err error) { // nolint: deadcode +func ParseFile(filename string, opts ...Option) (i any, err error) { // nolint: deadcode f, err := os.Open(filename) if err != nil { return nil, err @@ -420,7 +420,7 @@ func ParseFile(filename string, opts ...Option) (i interface{}, err error) { // // ParseReader parses the data from r using filename as information in the // error messages. -func ParseReader(filename string, r io.Reader, opts ...Option) (interface{}, error) { // nolint: deadcode +func ParseReader(filename string, r io.Reader, opts ...Option) (any, error) { // nolint: deadcode b, err := io.ReadAll(r) if err != nil { return nil, err @@ -431,7 +431,7 @@ func ParseReader(filename string, r io.Reader, opts ...Option) (interface{}, err // Parse parses the data from b using filename as information in the // error messages. -func Parse(filename string, b []byte, opts ...Option) (interface{}, error) { +func Parse(filename string, b []byte, opts ...Option) (any, error) { return newParser(filename, b, opts...).parse(g) } @@ -469,7 +469,7 @@ type current struct { globalStore storeDict } -type storeDict map[string]interface{} +type storeDict map[string]any // the AST types... @@ -484,34 +484,34 @@ type rule struct { pos position name string displayName string - expr interface{} + expr any } // nolint: structcheck type choiceExpr struct { pos position - alternatives []interface{} + alternatives []any } // nolint: structcheck type actionExpr struct { pos position - expr interface{} - run func(*parser) (interface{}, error) + expr any + run func(*parser) (any, error) } // nolint: structcheck type recoveryExpr struct { pos position - expr interface{} - recoverExpr interface{} + expr any + recoverExpr any failureLabel []string } // nolint: structcheck type seqExpr struct { pos position - exprs []interface{} + exprs []any } // nolint: structcheck @@ -524,20 +524,22 @@ type throwExpr struct { type labeledExpr struct { pos position label string - expr interface{} + expr any } // nolint: structcheck type expr struct { pos position - expr interface{} + expr any } -type andExpr expr // nolint: structcheck -type notExpr expr // nolint: structcheck -type zeroOrOneExpr expr // nolint: structcheck -type zeroOrMoreExpr expr // nolint: structcheck -type oneOrMoreExpr expr // nolint: structcheck +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 { @@ -685,7 +687,7 @@ func (p *parser) setOptions(opts []Option) { // nolint: structcheck,deadcode type resultTuple struct { - v interface{} + v any b bool end savepoint } @@ -731,12 +733,12 @@ type parser struct { memoize bool // memoization table for the packrat algorithm: // map[offset in source] map[expression or rule] {value, match} - memo map[int]map[interface{}]resultTuple + 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]interface{} + vstack []map[string]any // rule stack, allows identification of the current rule in errors rstack []*rule @@ -756,7 +758,7 @@ type parser struct { choiceNoMatch string // recovery expression stack, keeps track of the currently available recovery expression, these are traversed in reverse - recoveryStack []map[string]interface{} + recoveryStack []map[string]any } // push a variable set on the vstack. @@ -776,7 +778,7 @@ func (p *parser) pushV() { return } - m = make(map[string]interface{}) + m = make(map[string]any) p.vstack[len(p.vstack)-1] = m } @@ -792,7 +794,7 @@ func (p *parser) popV() { } // push a recovery expression with its labels to the recoveryStack -func (p *parser) pushRecovery(labels []string, expr interface{}) { +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) @@ -801,7 +803,7 @@ func (p *parser) pushRecovery(labels []string, expr interface{}) { p.recoveryStack = p.recoveryStack[:len(p.recoveryStack)+1] } - m := make(map[string]interface{}, len(labels)) + m := make(map[string]any, len(labels)) for _, fl := range labels { m[fl] = expr } @@ -921,11 +923,11 @@ func (p *parser) restore(pt savepoint) { // copies of the state to allow the parser to properly restore the state in // the case of backtracking. type Cloner interface { - Clone() interface{} + Clone() any } var statePool = &sync.Pool{ - New: func() interface{} { return make(storeDict) }, + New: func() any { return make(storeDict) }, } func (sd storeDict) Discard() { @@ -967,7 +969,7 @@ func (p *parser) sliceFrom(start savepoint) []byte { return p.data[start.position.offset:p.pt.position.offset] } -func (p *parser) getMemoized(node interface{}) (resultTuple, bool) { +func (p *parser) getMemoized(node any) (resultTuple, bool) { if len(p.memo) == 0 { return resultTuple{}, false } @@ -979,13 +981,13 @@ func (p *parser) getMemoized(node interface{}) (resultTuple, bool) { return res, ok } -func (p *parser) setMemoized(pt savepoint, node interface{}, tuple resultTuple) { +func (p *parser) setMemoized(pt savepoint, node any, tuple resultTuple) { if p.memo == nil { - p.memo = make(map[int]map[interface{}]resultTuple) + p.memo = make(map[int]map[any]resultTuple) } m := p.memo[pt.offset] if m == nil { - m = make(map[interface{}]resultTuple) + m = make(map[any]resultTuple) p.memo[pt.offset] = m } m[node] = tuple @@ -999,7 +1001,7 @@ func (p *parser) buildRulesTable(g *grammar) { } // nolint: gocyclo -func (p *parser) parse(g *grammar) (val interface{}, err error) { +func (p *parser) parse(g *grammar) (val any, err error) { if len(g.rules) == 0 { p.addErr(errNoRule) return nil, p.errs.err() @@ -1076,7 +1078,7 @@ func listJoin(list []string, sep string, lastSep string) string { } } -func (p *parser) parseRule(rule *rule) (interface{}, bool) { +func (p *parser) parseRule(rule *rule) (any, bool) { if p.debug { defer p.out(p.in("parseRule " + rule.name)) } @@ -1106,7 +1108,7 @@ func (p *parser) parseRule(rule *rule) (interface{}, bool) { } // nolint: gocyclo -func (p *parser) parseExpr(expr interface{}) (interface{}, bool) { +func (p *parser) parseExpr(expr any) (any, bool) { var pt savepoint if p.memoize { @@ -1123,7 +1125,7 @@ func (p *parser) parseExpr(expr interface{}) (interface{}, bool) { panic(errMaxExprCnt) } - var val interface{} + var val any var ok bool switch expr := expr.(type) { case *actionExpr: @@ -1171,7 +1173,7 @@ func (p *parser) parseExpr(expr interface{}) (interface{}, bool) { return val, ok } -func (p *parser) parseActionExpr(act *actionExpr) (interface{}, bool) { +func (p *parser) parseActionExpr(act *actionExpr) (any, bool) { if p.debug { defer p.out(p.in("parseActionExpr")) } @@ -1196,7 +1198,7 @@ func (p *parser) parseActionExpr(act *actionExpr) (interface{}, bool) { return val, ok } -func (p *parser) parseAndCodeExpr(and *andCodeExpr) (interface{}, bool) { +func (p *parser) parseAndCodeExpr(and *andCodeExpr) (any, bool) { if p.debug { defer p.out(p.in("parseAndCodeExpr")) } @@ -1212,7 +1214,7 @@ func (p *parser) parseAndCodeExpr(and *andCodeExpr) (interface{}, bool) { return nil, ok } -func (p *parser) parseAndExpr(and *andExpr) (interface{}, bool) { +func (p *parser) parseAndExpr(and *andExpr) (any, bool) { if p.debug { defer p.out(p.in("parseAndExpr")) } @@ -1228,7 +1230,7 @@ func (p *parser) parseAndExpr(and *andExpr) (interface{}, bool) { return nil, ok } -func (p *parser) parseAnyMatcher(any *anyMatcher) (interface{}, bool) { +func (p *parser) parseAnyMatcher(any *anyMatcher) (any, bool) { if p.debug { defer p.out(p.in("parseAnyMatcher")) } @@ -1245,7 +1247,7 @@ func (p *parser) parseAnyMatcher(any *anyMatcher) (interface{}, bool) { } // nolint: gocyclo -func (p *parser) parseCharClassMatcher(chr *charClassMatcher) (interface{}, bool) { +func (p *parser) parseCharClassMatcher(chr *charClassMatcher) (any, bool) { if p.debug { defer p.out(p.in("parseCharClassMatcher")) } @@ -1326,7 +1328,7 @@ func (p *parser) incChoiceAltCnt(ch *choiceExpr, altI int) { m[alt]++ } -func (p *parser) parseChoiceExpr(ch *choiceExpr) (interface{}, bool) { +func (p *parser) parseChoiceExpr(ch *choiceExpr) (any, bool) { if p.debug { defer p.out(p.in("parseChoiceExpr")) } @@ -1350,7 +1352,7 @@ func (p *parser) parseChoiceExpr(ch *choiceExpr) (interface{}, bool) { return nil, false } -func (p *parser) parseLabeledExpr(lab *labeledExpr) (interface{}, bool) { +func (p *parser) parseLabeledExpr(lab *labeledExpr) (any, bool) { if p.debug { defer p.out(p.in("parseLabeledExpr")) } @@ -1365,7 +1367,7 @@ func (p *parser) parseLabeledExpr(lab *labeledExpr) (interface{}, bool) { return val, ok } -func (p *parser) parseLitMatcher(lit *litMatcher) (interface{}, bool) { +func (p *parser) parseLitMatcher(lit *litMatcher) (any, bool) { if p.debug { defer p.out(p.in("parseLitMatcher")) } @@ -1387,7 +1389,7 @@ func (p *parser) parseLitMatcher(lit *litMatcher) (interface{}, bool) { return p.sliceFrom(start), true } -func (p *parser) parseNotCodeExpr(not *notCodeExpr) (interface{}, bool) { +func (p *parser) parseNotCodeExpr(not *notCodeExpr) (any, bool) { if p.debug { defer p.out(p.in("parseNotCodeExpr")) } @@ -1403,7 +1405,7 @@ func (p *parser) parseNotCodeExpr(not *notCodeExpr) (interface{}, bool) { return nil, !ok } -func (p *parser) parseNotExpr(not *notExpr) (interface{}, bool) { +func (p *parser) parseNotExpr(not *notExpr) (any, bool) { if p.debug { defer p.out(p.in("parseNotExpr")) } @@ -1421,12 +1423,12 @@ func (p *parser) parseNotExpr(not *notExpr) (interface{}, bool) { return nil, !ok } -func (p *parser) parseOneOrMoreExpr(expr *oneOrMoreExpr) (interface{}, bool) { +func (p *parser) parseOneOrMoreExpr(expr *oneOrMoreExpr) (any, bool) { if p.debug { defer p.out(p.in("parseOneOrMoreExpr")) } - var vals []interface{} + var vals []any for { p.pushV() @@ -1443,7 +1445,7 @@ func (p *parser) parseOneOrMoreExpr(expr *oneOrMoreExpr) (interface{}, bool) { } } -func (p *parser) parseRecoveryExpr(recover *recoveryExpr) (interface{}, bool) { +func (p *parser) parseRecoveryExpr(recover *recoveryExpr) (any, bool) { if p.debug { defer p.out(p.in("parseRecoveryExpr (" + strings.Join(recover.failureLabel, ",") + ")")) } @@ -1455,7 +1457,7 @@ func (p *parser) parseRecoveryExpr(recover *recoveryExpr) (interface{}, bool) { return val, ok } -func (p *parser) parseRuleRefExpr(ref *ruleRefExpr) (interface{}, bool) { +func (p *parser) parseRuleRefExpr(ref *ruleRefExpr) (any, bool) { if p.debug { defer p.out(p.in("parseRuleRefExpr " + ref.name)) } @@ -1472,12 +1474,12 @@ func (p *parser) parseRuleRefExpr(ref *ruleRefExpr) (interface{}, bool) { return p.parseRule(rule) } -func (p *parser) parseSeqExpr(seq *seqExpr) (interface{}, bool) { +func (p *parser) parseSeqExpr(seq *seqExpr) (any, bool) { if p.debug { defer p.out(p.in("parseSeqExpr")) } - vals := make([]interface{}, 0, len(seq.exprs)) + vals := make([]any, 0, len(seq.exprs)) pt := p.pt state := p.cloneState() @@ -1493,7 +1495,7 @@ func (p *parser) parseSeqExpr(seq *seqExpr) (interface{}, bool) { return vals, true } -func (p *parser) parseStateCodeExpr(state *stateCodeExpr) (interface{}, bool) { +func (p *parser) parseStateCodeExpr(state *stateCodeExpr) (any, bool) { if p.debug { defer p.out(p.in("parseStateCodeExpr")) } @@ -1505,7 +1507,7 @@ func (p *parser) parseStateCodeExpr(state *stateCodeExpr) (interface{}, bool) { return nil, true } -func (p *parser) parseThrowExpr(expr *throwExpr) (interface{}, bool) { +func (p *parser) parseThrowExpr(expr *throwExpr) (any, bool) { if p.debug { defer p.out(p.in("parseThrowExpr")) } @@ -1521,12 +1523,12 @@ func (p *parser) parseThrowExpr(expr *throwExpr) (interface{}, bool) { return nil, false } -func (p *parser) parseZeroOrMoreExpr(expr *zeroOrMoreExpr) (interface{}, bool) { +func (p *parser) parseZeroOrMoreExpr(expr *zeroOrMoreExpr) (any, bool) { if p.debug { defer p.out(p.in("parseZeroOrMoreExpr")) } - var vals []interface{} + var vals []any for { p.pushV() @@ -1539,7 +1541,7 @@ func (p *parser) parseZeroOrMoreExpr(expr *zeroOrMoreExpr) (interface{}, bool) { } } -func (p *parser) parseZeroOrOneExpr(expr *zeroOrOneExpr) (interface{}, bool) { +func (p *parser) parseZeroOrOneExpr(expr *zeroOrOneExpr) (any, bool) { if p.debug { defer p.out(p.in("parseZeroOrOneExpr")) } diff --git a/test/staterestore/optimized/staterestore.go b/test/staterestore/optimized/staterestore.go index 87ebb83a..71e26e70 100644 --- a/test/staterestore/optimized/staterestore.go +++ b/test/staterestore/optimized/staterestore.go @@ -42,7 +42,7 @@ var g = &grammar{ run: (*parser).callonTestExpr1, expr: &seqExpr{ pos: position{line: 19, col: 13, offset: 298}, - exprs: []interface{}{ + exprs: []any{ &stateCodeExpr{ pos: position{line: 19, col: 13, offset: 298}, run: (*parser).callonTestExpr3, @@ -57,15 +57,15 @@ var g = &grammar{ pos: position{line: 35, col: 13, offset: 609}, expr: &seqExpr{ pos: position{line: 34, col: 7, offset: 591}, - exprs: []interface{}{ + exprs: []any{ &zeroOrMoreExpr{ pos: position{line: 45, col: 6, offset: 757}, expr: &choiceExpr{ pos: position{line: 45, col: 8, offset: 759}, - alternatives: []interface{}{ + alternatives: []any{ &seqExpr{ pos: position{line: 36, col: 8, offset: 628}, - exprs: []interface{}{ + exprs: []any{ &litMatcher{ pos: position{line: 36, col: 8, offset: 628}, val: "\n", @@ -80,7 +80,7 @@ var g = &grammar{ }, &seqExpr{ pos: position{line: 44, col: 12, offset: 736}, - exprs: []interface{}{ + exprs: []any{ &litMatcher{ pos: position{line: 44, col: 12, offset: 736}, val: "#", @@ -91,12 +91,12 @@ var g = &grammar{ pos: position{line: 44, col: 16, offset: 740}, expr: &seqExpr{ pos: position{line: 44, col: 18, offset: 742}, - exprs: []interface{}{ + exprs: []any{ ¬Expr{ pos: position{line: 44, col: 18, offset: 742}, expr: &seqExpr{ pos: position{line: 36, col: 8, offset: 628}, - exprs: []interface{}{ + exprs: []any{ &litMatcher{ pos: position{line: 36, col: 8, offset: 628}, val: "\n", @@ -134,15 +134,15 @@ var g = &grammar{ pos: position{line: 35, col: 17, offset: 613}, expr: &seqExpr{ pos: position{line: 34, col: 7, offset: 591}, - exprs: []interface{}{ + exprs: []any{ &zeroOrMoreExpr{ pos: position{line: 45, col: 6, offset: 757}, expr: &choiceExpr{ pos: position{line: 45, col: 8, offset: 759}, - alternatives: []interface{}{ + alternatives: []any{ &seqExpr{ pos: position{line: 36, col: 8, offset: 628}, - exprs: []interface{}{ + exprs: []any{ &litMatcher{ pos: position{line: 36, col: 8, offset: 628}, val: "\n", @@ -157,7 +157,7 @@ var g = &grammar{ }, &seqExpr{ pos: position{line: 44, col: 12, offset: 736}, - exprs: []interface{}{ + exprs: []any{ &litMatcher{ pos: position{line: 44, col: 12, offset: 736}, val: "#", @@ -168,12 +168,12 @@ var g = &grammar{ pos: position{line: 44, col: 16, offset: 740}, expr: &seqExpr{ pos: position{line: 44, col: 18, offset: 742}, - exprs: []interface{}{ + exprs: []any{ ¬Expr{ pos: position{line: 44, col: 18, offset: 742}, expr: &seqExpr{ pos: position{line: 36, col: 8, offset: 628}, - exprs: []interface{}{ + exprs: []any{ &litMatcher{ pos: position{line: 36, col: 8, offset: 628}, val: "\n", @@ -211,15 +211,15 @@ var g = &grammar{ pos: position{line: 35, col: 21, offset: 617}, expr: &seqExpr{ pos: position{line: 34, col: 7, offset: 591}, - exprs: []interface{}{ + exprs: []any{ &zeroOrMoreExpr{ pos: position{line: 45, col: 6, offset: 757}, expr: &choiceExpr{ pos: position{line: 45, col: 8, offset: 759}, - alternatives: []interface{}{ + alternatives: []any{ &seqExpr{ pos: position{line: 36, col: 8, offset: 628}, - exprs: []interface{}{ + exprs: []any{ &litMatcher{ pos: position{line: 36, col: 8, offset: 628}, val: "\n", @@ -234,7 +234,7 @@ var g = &grammar{ }, &seqExpr{ pos: position{line: 44, col: 12, offset: 736}, - exprs: []interface{}{ + exprs: []any{ &litMatcher{ pos: position{line: 44, col: 12, offset: 736}, val: "#", @@ -245,12 +245,12 @@ var g = &grammar{ pos: position{line: 44, col: 16, offset: 740}, expr: &seqExpr{ pos: position{line: 44, col: 18, offset: 742}, - exprs: []interface{}{ + exprs: []any{ ¬Expr{ pos: position{line: 44, col: 18, offset: 742}, expr: &seqExpr{ pos: position{line: 36, col: 8, offset: 628}, - exprs: []interface{}{ + exprs: []any{ &litMatcher{ pos: position{line: 36, col: 8, offset: 628}, val: "\n", @@ -288,10 +288,10 @@ var g = &grammar{ pos: position{line: 45, col: 6, offset: 757}, expr: &choiceExpr{ pos: position{line: 45, col: 8, offset: 759}, - alternatives: []interface{}{ + alternatives: []any{ &seqExpr{ pos: position{line: 36, col: 8, offset: 628}, - exprs: []interface{}{ + exprs: []any{ &litMatcher{ pos: position{line: 36, col: 8, offset: 628}, val: "\n", @@ -306,7 +306,7 @@ var g = &grammar{ }, &seqExpr{ pos: position{line: 44, col: 12, offset: 736}, - exprs: []interface{}{ + exprs: []any{ &litMatcher{ pos: position{line: 44, col: 12, offset: 736}, val: "#", @@ -317,12 +317,12 @@ var g = &grammar{ pos: position{line: 44, col: 16, offset: 740}, expr: &seqExpr{ pos: position{line: 44, col: 18, offset: 742}, - exprs: []interface{}{ + exprs: []any{ ¬Expr{ pos: position{line: 44, col: 18, offset: 742}, expr: &seqExpr{ pos: position{line: 36, col: 8, offset: 628}, - exprs: []interface{}{ + exprs: []any{ &litMatcher{ pos: position{line: 36, col: 8, offset: 628}, val: "\n", @@ -365,7 +365,7 @@ var g = &grammar{ run: (*parser).callonTestAnd1, expr: &seqExpr{ pos: position{line: 24, col: 12, offset: 396}, - exprs: []interface{}{ + exprs: []any{ &stateCodeExpr{ pos: position{line: 24, col: 12, offset: 396}, run: (*parser).callonTestAnd3, @@ -374,7 +374,7 @@ var g = &grammar{ pos: position{line: 24, col: 48, offset: 432}, expr: &seqExpr{ pos: position{line: 36, col: 8, offset: 628}, - exprs: []interface{}{ + exprs: []any{ &litMatcher{ pos: position{line: 36, col: 8, offset: 628}, val: "\n", @@ -409,19 +409,19 @@ var g = &grammar{ run: (*parser).callonTestNot1, expr: &seqExpr{ pos: position{line: 29, col: 12, offset: 494}, - exprs: []interface{}{ + exprs: []any{ &stateCodeExpr{ pos: position{line: 29, col: 12, offset: 494}, run: (*parser).callonTestNot3, }, &choiceExpr{ pos: position{line: 29, col: 50, offset: 532}, - alternatives: []interface{}{ + alternatives: []any{ ¬Expr{ pos: position{line: 29, col: 50, offset: 532}, expr: &seqExpr{ pos: position{line: 36, col: 8, offset: 628}, - exprs: []interface{}{ + exprs: []any{ &litMatcher{ pos: position{line: 36, col: 8, offset: 628}, val: "\n", @@ -437,7 +437,7 @@ var g = &grammar{ }, &seqExpr{ pos: position{line: 36, col: 8, offset: 628}, - exprs: []interface{}{ + exprs: []any{ &litMatcher{ pos: position{line: 36, col: 8, offset: 628}, val: "\n", @@ -582,12 +582,12 @@ func (p *parser) callonTestExpr68() error { return p.cur.onTestExpr68() } -func (c *current) onTestExpr1() (interface{}, error) { +func (c *current) onTestExpr1() (any, error) { return c.state["cnt"], nil } -func (p *parser) callonTestExpr1() (interface{}, error) { +func (p *parser) callonTestExpr1() (any, error) { stack := p.vstack[len(p.vstack)-1] _ = stack return p.cur.onTestExpr1() @@ -618,12 +618,12 @@ func (p *parser) callonTestAnd7() error { return p.cur.onTestAnd7() } -func (c *current) onTestAnd1() (interface{}, error) { +func (c *current) onTestAnd1() (any, error) { return c.state["cnt"], nil } -func (p *parser) callonTestAnd1() (interface{}, error) { +func (p *parser) callonTestAnd1() (any, error) { stack := p.vstack[len(p.vstack)-1] _ = stack return p.cur.onTestAnd1() @@ -668,12 +668,12 @@ func (p *parser) callonTestNot11() error { return p.cur.onTestNot11() } -func (c *current) onTestNot1() (interface{}, error) { +func (c *current) onTestNot1() (any, error) { return c.state["cnt"], nil } -func (p *parser) callonTestNot1() (interface{}, error) { +func (p *parser) callonTestNot1() (any, error) { stack := p.vstack[len(p.vstack)-1] _ = stack return p.cur.onTestNot1() @@ -761,7 +761,7 @@ func Recover(b bool) Option { // GlobalStore creates an Option to set a key to a certain value in // the globalStore. -func GlobalStore(key string, value interface{}) Option { +func GlobalStore(key string, value any) Option { return func(p *parser) Option { old := p.cur.globalStore[key] p.cur.globalStore[key] = value @@ -771,7 +771,7 @@ func GlobalStore(key string, value interface{}) Option { // InitState creates an Option to set a key to a certain value in // the global "state" store. -func InitState(key string, value interface{}) Option { +func InitState(key string, value any) Option { return func(p *parser) Option { old := p.cur.state[key] p.cur.state[key] = value @@ -780,7 +780,7 @@ func InitState(key string, value interface{}) Option { } // ParseFile parses the file identified by filename. -func ParseFile(filename string, opts ...Option) (i interface{}, err error) { // nolint: deadcode +func ParseFile(filename string, opts ...Option) (i any, err error) { // nolint: deadcode f, err := os.Open(filename) if err != nil { return nil, err @@ -795,7 +795,7 @@ func ParseFile(filename string, opts ...Option) (i interface{}, err error) { // // ParseReader parses the data from r using filename as information in the // error messages. -func ParseReader(filename string, r io.Reader, opts ...Option) (interface{}, error) { // nolint: deadcode +func ParseReader(filename string, r io.Reader, opts ...Option) (any, error) { // nolint: deadcode b, err := io.ReadAll(r) if err != nil { return nil, err @@ -806,7 +806,7 @@ func ParseReader(filename string, r io.Reader, opts ...Option) (interface{}, err // Parse parses the data from b using filename as information in the // error messages. -func Parse(filename string, b []byte, opts ...Option) (interface{}, error) { +func Parse(filename string, b []byte, opts ...Option) (any, error) { return newParser(filename, b, opts...).parse(g) } @@ -844,7 +844,7 @@ type current struct { globalStore storeDict } -type storeDict map[string]interface{} +type storeDict map[string]any // the AST types... @@ -859,34 +859,34 @@ type rule struct { pos position name string displayName string - expr interface{} + expr any } // nolint: structcheck type choiceExpr struct { pos position - alternatives []interface{} + alternatives []any } // nolint: structcheck type actionExpr struct { pos position - expr interface{} - run func(*parser) (interface{}, error) + expr any + run func(*parser) (any, error) } // nolint: structcheck type recoveryExpr struct { pos position - expr interface{} - recoverExpr interface{} + expr any + recoverExpr any failureLabel []string } // nolint: structcheck type seqExpr struct { pos position - exprs []interface{} + exprs []any } // nolint: structcheck @@ -899,20 +899,22 @@ type throwExpr struct { type labeledExpr struct { pos position label string - expr interface{} + expr any } // nolint: structcheck type expr struct { pos position - expr interface{} + expr any } -type andExpr expr // nolint: structcheck -type notExpr expr // nolint: structcheck -type zeroOrOneExpr expr // nolint: structcheck -type zeroOrMoreExpr expr // nolint: structcheck -type oneOrMoreExpr expr // nolint: structcheck +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 { @@ -1060,7 +1062,7 @@ func (p *parser) setOptions(opts []Option) { // nolint: structcheck,deadcode type resultTuple struct { - v interface{} + v any b bool end savepoint } @@ -1105,7 +1107,7 @@ type parser struct { // rules table, maps the rule identifier to the rule node rules map[string]*rule // variables stack, map of label to value - vstack []map[string]interface{} + vstack []map[string]any // rule stack, allows identification of the current rule in errors rstack []*rule @@ -1125,7 +1127,7 @@ type parser struct { choiceNoMatch string // recovery expression stack, keeps track of the currently available recovery expression, these are traversed in reverse - recoveryStack []map[string]interface{} + recoveryStack []map[string]any } // push a variable set on the vstack. @@ -1145,7 +1147,7 @@ func (p *parser) pushV() { return } - m = make(map[string]interface{}) + m = make(map[string]any) p.vstack[len(p.vstack)-1] = m } @@ -1161,7 +1163,7 @@ func (p *parser) popV() { } // push a recovery expression with its labels to the recoveryStack -func (p *parser) pushRecovery(labels []string, expr interface{}) { +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) @@ -1170,7 +1172,7 @@ func (p *parser) pushRecovery(labels []string, expr interface{}) { p.recoveryStack = p.recoveryStack[:len(p.recoveryStack)+1] } - m := make(map[string]interface{}, len(labels)) + m := make(map[string]any, len(labels)) for _, fl := range labels { m[fl] = expr } @@ -1267,11 +1269,11 @@ func (p *parser) restore(pt savepoint) { // copies of the state to allow the parser to properly restore the state in // the case of backtracking. type Cloner interface { - Clone() interface{} + Clone() any } var statePool = &sync.Pool{ - New: func() interface{} { return make(storeDict) }, + New: func() any { return make(storeDict) }, } func (sd storeDict) Discard() { @@ -1315,7 +1317,7 @@ func (p *parser) buildRulesTable(g *grammar) { } // nolint: gocyclo -func (p *parser) parse(g *grammar) (val interface{}, err error) { +func (p *parser) parse(g *grammar) (val any, err error) { if len(g.rules) == 0 { p.addErr(errNoRule) return nil, p.errs.err() @@ -1389,7 +1391,7 @@ func listJoin(list []string, sep string, lastSep string) string { } } -func (p *parser) parseRule(rule *rule) (interface{}, bool) { +func (p *parser) parseRule(rule *rule) (any, bool) { p.rstack = append(p.rstack, rule) p.pushV() val, ok := p.parseExpr(rule.expr) @@ -1399,14 +1401,14 @@ func (p *parser) parseRule(rule *rule) (interface{}, bool) { } // nolint: gocyclo -func (p *parser) parseExpr(expr interface{}) (interface{}, bool) { +func (p *parser) parseExpr(expr any) (any, bool) { p.ExprCnt++ if p.ExprCnt > p.maxExprCnt { panic(errMaxExprCnt) } - var val interface{} + var val any var ok bool switch expr := expr.(type) { case *actionExpr: @@ -1451,7 +1453,7 @@ func (p *parser) parseExpr(expr interface{}) (interface{}, bool) { return val, ok } -func (p *parser) parseActionExpr(act *actionExpr) (interface{}, bool) { +func (p *parser) parseActionExpr(act *actionExpr) (any, bool) { start := p.pt val, ok := p.parseExpr(act.expr) if ok { @@ -1469,7 +1471,7 @@ func (p *parser) parseActionExpr(act *actionExpr) (interface{}, bool) { return val, ok } -func (p *parser) parseAndCodeExpr(and *andCodeExpr) (interface{}, bool) { +func (p *parser) parseAndCodeExpr(and *andCodeExpr) (any, bool) { state := p.cloneState() ok, err := and.run(p) @@ -1481,7 +1483,7 @@ func (p *parser) parseAndCodeExpr(and *andCodeExpr) (interface{}, bool) { return nil, ok } -func (p *parser) parseAndExpr(and *andExpr) (interface{}, bool) { +func (p *parser) parseAndExpr(and *andExpr) (any, bool) { pt := p.pt state := p.cloneState() p.pushV() @@ -1493,7 +1495,7 @@ func (p *parser) parseAndExpr(and *andExpr) (interface{}, bool) { return nil, ok } -func (p *parser) parseAnyMatcher(any *anyMatcher) (interface{}, bool) { +func (p *parser) parseAnyMatcher(any *anyMatcher) (any, bool) { if p.pt.rn == utf8.RuneError && p.pt.w == 0 { // EOF - see utf8.DecodeRune p.failAt(false, p.pt.position, ".") @@ -1506,7 +1508,7 @@ func (p *parser) parseAnyMatcher(any *anyMatcher) (interface{}, bool) { } // nolint: gocyclo -func (p *parser) parseCharClassMatcher(chr *charClassMatcher) (interface{}, bool) { +func (p *parser) parseCharClassMatcher(chr *charClassMatcher) (any, bool) { cur := p.pt.rn start := p.pt @@ -1568,7 +1570,7 @@ func (p *parser) parseCharClassMatcher(chr *charClassMatcher) (interface{}, bool return nil, false } -func (p *parser) parseChoiceExpr(ch *choiceExpr) (interface{}, bool) { +func (p *parser) parseChoiceExpr(ch *choiceExpr) (any, bool) { for altI, alt := range ch.alternatives { // dummy assignment to prevent compile error if optimized _ = altI @@ -1586,7 +1588,7 @@ func (p *parser) parseChoiceExpr(ch *choiceExpr) (interface{}, bool) { return nil, false } -func (p *parser) parseLabeledExpr(lab *labeledExpr) (interface{}, bool) { +func (p *parser) parseLabeledExpr(lab *labeledExpr) (any, bool) { p.pushV() val, ok := p.parseExpr(lab.expr) p.popV() @@ -1597,7 +1599,7 @@ func (p *parser) parseLabeledExpr(lab *labeledExpr) (interface{}, bool) { return val, ok } -func (p *parser) parseLitMatcher(lit *litMatcher) (interface{}, bool) { +func (p *parser) parseLitMatcher(lit *litMatcher) (any, bool) { start := p.pt for _, want := range lit.val { cur := p.pt.rn @@ -1615,7 +1617,7 @@ func (p *parser) parseLitMatcher(lit *litMatcher) (interface{}, bool) { return p.sliceFrom(start), true } -func (p *parser) parseNotCodeExpr(not *notCodeExpr) (interface{}, bool) { +func (p *parser) parseNotCodeExpr(not *notCodeExpr) (any, bool) { state := p.cloneState() ok, err := not.run(p) @@ -1627,7 +1629,7 @@ func (p *parser) parseNotCodeExpr(not *notCodeExpr) (interface{}, bool) { return nil, !ok } -func (p *parser) parseNotExpr(not *notExpr) (interface{}, bool) { +func (p *parser) parseNotExpr(not *notExpr) (any, bool) { pt := p.pt state := p.cloneState() p.pushV() @@ -1641,8 +1643,8 @@ func (p *parser) parseNotExpr(not *notExpr) (interface{}, bool) { return nil, !ok } -func (p *parser) parseOneOrMoreExpr(expr *oneOrMoreExpr) (interface{}, bool) { - var vals []interface{} +func (p *parser) parseOneOrMoreExpr(expr *oneOrMoreExpr) (any, bool) { + var vals []any for { p.pushV() @@ -1659,7 +1661,7 @@ func (p *parser) parseOneOrMoreExpr(expr *oneOrMoreExpr) (interface{}, bool) { } } -func (p *parser) parseRecoveryExpr(recover *recoveryExpr) (interface{}, bool) { +func (p *parser) parseRecoveryExpr(recover *recoveryExpr) (any, bool) { p.pushRecovery(recover.failureLabel, recover.recoverExpr) val, ok := p.parseExpr(recover.expr) @@ -1668,7 +1670,7 @@ func (p *parser) parseRecoveryExpr(recover *recoveryExpr) (interface{}, bool) { return val, ok } -func (p *parser) parseRuleRefExpr(ref *ruleRefExpr) (interface{}, bool) { +func (p *parser) parseRuleRefExpr(ref *ruleRefExpr) (any, bool) { if ref.name == "" { panic(fmt.Sprintf("%s: invalid rule: missing name", ref.pos)) } @@ -1681,8 +1683,8 @@ func (p *parser) parseRuleRefExpr(ref *ruleRefExpr) (interface{}, bool) { return p.parseRule(rule) } -func (p *parser) parseSeqExpr(seq *seqExpr) (interface{}, bool) { - vals := make([]interface{}, 0, len(seq.exprs)) +func (p *parser) parseSeqExpr(seq *seqExpr) (any, bool) { + vals := make([]any, 0, len(seq.exprs)) pt := p.pt state := p.cloneState() @@ -1698,7 +1700,7 @@ func (p *parser) parseSeqExpr(seq *seqExpr) (interface{}, bool) { return vals, true } -func (p *parser) parseStateCodeExpr(state *stateCodeExpr) (interface{}, bool) { +func (p *parser) parseStateCodeExpr(state *stateCodeExpr) (any, bool) { err := state.run(p) if err != nil { p.addErr(err) @@ -1706,7 +1708,7 @@ func (p *parser) parseStateCodeExpr(state *stateCodeExpr) (interface{}, bool) { return nil, true } -func (p *parser) parseThrowExpr(expr *throwExpr) (interface{}, bool) { +func (p *parser) parseThrowExpr(expr *throwExpr) (any, bool) { for i := len(p.recoveryStack) - 1; i >= 0; i-- { if recoverExpr, ok := p.recoveryStack[i][expr.label]; ok { @@ -1719,8 +1721,8 @@ func (p *parser) parseThrowExpr(expr *throwExpr) (interface{}, bool) { return nil, false } -func (p *parser) parseZeroOrMoreExpr(expr *zeroOrMoreExpr) (interface{}, bool) { - var vals []interface{} +func (p *parser) parseZeroOrMoreExpr(expr *zeroOrMoreExpr) (any, bool) { + var vals []any for { p.pushV() @@ -1733,7 +1735,7 @@ func (p *parser) parseZeroOrMoreExpr(expr *zeroOrMoreExpr) (interface{}, bool) { } } -func (p *parser) parseZeroOrOneExpr(expr *zeroOrOneExpr) (interface{}, bool) { +func (p *parser) parseZeroOrOneExpr(expr *zeroOrOneExpr) (any, bool) { p.pushV() val, _ := p.parseExpr(expr.expr) p.popV() diff --git a/test/staterestore/standard/staterestore.go b/test/staterestore/standard/staterestore.go index 28239f75..b490e8be 100644 --- a/test/staterestore/standard/staterestore.go +++ b/test/staterestore/standard/staterestore.go @@ -42,7 +42,7 @@ var g = &grammar{ run: (*parser).callonTestExpr1, expr: &seqExpr{ pos: position{line: 19, col: 13, offset: 298}, - exprs: []interface{}{ + exprs: []any{ &stateCodeExpr{ pos: position{line: 19, col: 13, offset: 298}, run: (*parser).callonTestExpr3, @@ -71,7 +71,7 @@ var g = &grammar{ run: (*parser).callonTestAnd1, expr: &seqExpr{ pos: position{line: 24, col: 12, offset: 396}, - exprs: []interface{}{ + exprs: []any{ &stateCodeExpr{ pos: position{line: 24, col: 12, offset: 396}, run: (*parser).callonTestAnd3, @@ -102,14 +102,14 @@ var g = &grammar{ run: (*parser).callonTestNot1, expr: &seqExpr{ pos: position{line: 29, col: 12, offset: 494}, - exprs: []interface{}{ + exprs: []any{ &stateCodeExpr{ pos: position{line: 29, col: 12, offset: 494}, run: (*parser).callonTestNot3, }, &choiceExpr{ pos: position{line: 29, col: 50, offset: 532}, - alternatives: []interface{}{ + alternatives: []any{ ¬Expr{ pos: position{line: 29, col: 50, offset: 532}, expr: &ruleRefExpr{ @@ -132,7 +132,7 @@ var g = &grammar{ pos: position{line: 34, col: 1, offset: 585}, expr: &seqExpr{ pos: position{line: 34, col: 7, offset: 591}, - exprs: []interface{}{ + exprs: []any{ &ruleRefExpr{ pos: position{line: 34, col: 7, offset: 591}, name: "_", @@ -151,7 +151,7 @@ var g = &grammar{ pos: position{line: 35, col: 1, offset: 597}, expr: &seqExpr{ pos: position{line: 35, col: 9, offset: 605}, - exprs: []interface{}{ + exprs: []any{ &litMatcher{ pos: position{line: 35, col: 9, offset: 605}, val: "f", @@ -187,7 +187,7 @@ var g = &grammar{ pos: position{line: 36, col: 1, offset: 621}, expr: &seqExpr{ pos: position{line: 36, col: 8, offset: 628}, - exprs: []interface{}{ + exprs: []any{ &litMatcher{ pos: position{line: 36, col: 8, offset: 628}, val: "\n", @@ -206,7 +206,7 @@ var g = &grammar{ pos: position{line: 44, col: 1, offset: 725}, expr: &seqExpr{ pos: position{line: 44, col: 12, offset: 736}, - exprs: []interface{}{ + exprs: []any{ &litMatcher{ pos: position{line: 44, col: 12, offset: 736}, val: "#", @@ -217,7 +217,7 @@ var g = &grammar{ pos: position{line: 44, col: 16, offset: 740}, expr: &seqExpr{ pos: position{line: 44, col: 18, offset: 742}, - exprs: []interface{}{ + exprs: []any{ ¬Expr{ pos: position{line: 44, col: 18, offset: 742}, expr: &ruleRefExpr{ @@ -241,7 +241,7 @@ var g = &grammar{ pos: position{line: 45, col: 6, offset: 757}, expr: &choiceExpr{ pos: position{line: 45, col: 8, offset: 759}, - alternatives: []interface{}{ + alternatives: []any{ &ruleRefExpr{ pos: position{line: 45, col: 8, offset: 759}, name: "EOL", @@ -278,12 +278,12 @@ func (p *parser) callonTestExpr3() error { return p.cur.onTestExpr3() } -func (c *current) onTestExpr1() (interface{}, error) { +func (c *current) onTestExpr1() (any, error) { return c.state["cnt"], nil } -func (p *parser) callonTestExpr1() (interface{}, error) { +func (p *parser) callonTestExpr1() (any, error) { stack := p.vstack[len(p.vstack)-1] _ = stack return p.cur.onTestExpr1() @@ -300,12 +300,12 @@ func (p *parser) callonTestAnd3() error { return p.cur.onTestAnd3() } -func (c *current) onTestAnd1() (interface{}, error) { +func (c *current) onTestAnd1() (any, error) { return c.state["cnt"], nil } -func (p *parser) callonTestAnd1() (interface{}, error) { +func (p *parser) callonTestAnd1() (any, error) { stack := p.vstack[len(p.vstack)-1] _ = stack return p.cur.onTestAnd1() @@ -322,12 +322,12 @@ func (p *parser) callonTestNot3() error { return p.cur.onTestNot3() } -func (c *current) onTestNot1() (interface{}, error) { +func (c *current) onTestNot1() (any, error) { return c.state["cnt"], nil } -func (p *parser) callonTestNot1() (interface{}, error) { +func (p *parser) callonTestNot1() (any, error) { stack := p.vstack[len(p.vstack)-1] _ = stack return p.cur.onTestNot1() @@ -485,7 +485,7 @@ func Recover(b bool) Option { // GlobalStore creates an Option to set a key to a certain value in // the globalStore. -func GlobalStore(key string, value interface{}) Option { +func GlobalStore(key string, value any) Option { return func(p *parser) Option { old := p.cur.globalStore[key] p.cur.globalStore[key] = value @@ -495,7 +495,7 @@ func GlobalStore(key string, value interface{}) Option { // InitState creates an Option to set a key to a certain value in // the global "state" store. -func InitState(key string, value interface{}) Option { +func InitState(key string, value any) Option { return func(p *parser) Option { old := p.cur.state[key] p.cur.state[key] = value @@ -504,7 +504,7 @@ func InitState(key string, value interface{}) Option { } // ParseFile parses the file identified by filename. -func ParseFile(filename string, opts ...Option) (i interface{}, err error) { // nolint: deadcode +func ParseFile(filename string, opts ...Option) (i any, err error) { // nolint: deadcode f, err := os.Open(filename) if err != nil { return nil, err @@ -519,7 +519,7 @@ func ParseFile(filename string, opts ...Option) (i interface{}, err error) { // // ParseReader parses the data from r using filename as information in the // error messages. -func ParseReader(filename string, r io.Reader, opts ...Option) (interface{}, error) { // nolint: deadcode +func ParseReader(filename string, r io.Reader, opts ...Option) (any, error) { // nolint: deadcode b, err := io.ReadAll(r) if err != nil { return nil, err @@ -530,7 +530,7 @@ func ParseReader(filename string, r io.Reader, opts ...Option) (interface{}, err // Parse parses the data from b using filename as information in the // error messages. -func Parse(filename string, b []byte, opts ...Option) (interface{}, error) { +func Parse(filename string, b []byte, opts ...Option) (any, error) { return newParser(filename, b, opts...).parse(g) } @@ -568,7 +568,7 @@ type current struct { globalStore storeDict } -type storeDict map[string]interface{} +type storeDict map[string]any // the AST types... @@ -583,34 +583,34 @@ type rule struct { pos position name string displayName string - expr interface{} + expr any } // nolint: structcheck type choiceExpr struct { pos position - alternatives []interface{} + alternatives []any } // nolint: structcheck type actionExpr struct { pos position - expr interface{} - run func(*parser) (interface{}, error) + expr any + run func(*parser) (any, error) } // nolint: structcheck type recoveryExpr struct { pos position - expr interface{} - recoverExpr interface{} + expr any + recoverExpr any failureLabel []string } // nolint: structcheck type seqExpr struct { pos position - exprs []interface{} + exprs []any } // nolint: structcheck @@ -623,20 +623,22 @@ type throwExpr struct { type labeledExpr struct { pos position label string - expr interface{} + expr any } // nolint: structcheck type expr struct { pos position - expr interface{} + expr any } -type andExpr expr // nolint: structcheck -type notExpr expr // nolint: structcheck -type zeroOrOneExpr expr // nolint: structcheck -type zeroOrMoreExpr expr // nolint: structcheck -type oneOrMoreExpr expr // nolint: structcheck +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 { @@ -784,7 +786,7 @@ func (p *parser) setOptions(opts []Option) { // nolint: structcheck,deadcode type resultTuple struct { - v interface{} + v any b bool end savepoint } @@ -830,12 +832,12 @@ type parser struct { memoize bool // memoization table for the packrat algorithm: // map[offset in source] map[expression or rule] {value, match} - memo map[int]map[interface{}]resultTuple + 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]interface{} + vstack []map[string]any // rule stack, allows identification of the current rule in errors rstack []*rule @@ -855,7 +857,7 @@ type parser struct { choiceNoMatch string // recovery expression stack, keeps track of the currently available recovery expression, these are traversed in reverse - recoveryStack []map[string]interface{} + recoveryStack []map[string]any } // push a variable set on the vstack. @@ -875,7 +877,7 @@ func (p *parser) pushV() { return } - m = make(map[string]interface{}) + m = make(map[string]any) p.vstack[len(p.vstack)-1] = m } @@ -891,7 +893,7 @@ func (p *parser) popV() { } // push a recovery expression with its labels to the recoveryStack -func (p *parser) pushRecovery(labels []string, expr interface{}) { +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) @@ -900,7 +902,7 @@ func (p *parser) pushRecovery(labels []string, expr interface{}) { p.recoveryStack = p.recoveryStack[:len(p.recoveryStack)+1] } - m := make(map[string]interface{}, len(labels)) + m := make(map[string]any, len(labels)) for _, fl := range labels { m[fl] = expr } @@ -1020,11 +1022,11 @@ func (p *parser) restore(pt savepoint) { // copies of the state to allow the parser to properly restore the state in // the case of backtracking. type Cloner interface { - Clone() interface{} + Clone() any } var statePool = &sync.Pool{ - New: func() interface{} { return make(storeDict) }, + New: func() any { return make(storeDict) }, } func (sd storeDict) Discard() { @@ -1066,7 +1068,7 @@ func (p *parser) sliceFrom(start savepoint) []byte { return p.data[start.position.offset:p.pt.position.offset] } -func (p *parser) getMemoized(node interface{}) (resultTuple, bool) { +func (p *parser) getMemoized(node any) (resultTuple, bool) { if len(p.memo) == 0 { return resultTuple{}, false } @@ -1078,13 +1080,13 @@ func (p *parser) getMemoized(node interface{}) (resultTuple, bool) { return res, ok } -func (p *parser) setMemoized(pt savepoint, node interface{}, tuple resultTuple) { +func (p *parser) setMemoized(pt savepoint, node any, tuple resultTuple) { if p.memo == nil { - p.memo = make(map[int]map[interface{}]resultTuple) + p.memo = make(map[int]map[any]resultTuple) } m := p.memo[pt.offset] if m == nil { - m = make(map[interface{}]resultTuple) + m = make(map[any]resultTuple) p.memo[pt.offset] = m } m[node] = tuple @@ -1098,7 +1100,7 @@ func (p *parser) buildRulesTable(g *grammar) { } // nolint: gocyclo -func (p *parser) parse(g *grammar) (val interface{}, err error) { +func (p *parser) parse(g *grammar) (val any, err error) { if len(g.rules) == 0 { p.addErr(errNoRule) return nil, p.errs.err() @@ -1175,7 +1177,7 @@ func listJoin(list []string, sep string, lastSep string) string { } } -func (p *parser) parseRule(rule *rule) (interface{}, bool) { +func (p *parser) parseRule(rule *rule) (any, bool) { if p.debug { defer p.out(p.in("parseRule " + rule.name)) } @@ -1205,7 +1207,7 @@ func (p *parser) parseRule(rule *rule) (interface{}, bool) { } // nolint: gocyclo -func (p *parser) parseExpr(expr interface{}) (interface{}, bool) { +func (p *parser) parseExpr(expr any) (any, bool) { var pt savepoint if p.memoize { @@ -1222,7 +1224,7 @@ func (p *parser) parseExpr(expr interface{}) (interface{}, bool) { panic(errMaxExprCnt) } - var val interface{} + var val any var ok bool switch expr := expr.(type) { case *actionExpr: @@ -1270,7 +1272,7 @@ func (p *parser) parseExpr(expr interface{}) (interface{}, bool) { return val, ok } -func (p *parser) parseActionExpr(act *actionExpr) (interface{}, bool) { +func (p *parser) parseActionExpr(act *actionExpr) (any, bool) { if p.debug { defer p.out(p.in("parseActionExpr")) } @@ -1295,7 +1297,7 @@ func (p *parser) parseActionExpr(act *actionExpr) (interface{}, bool) { return val, ok } -func (p *parser) parseAndCodeExpr(and *andCodeExpr) (interface{}, bool) { +func (p *parser) parseAndCodeExpr(and *andCodeExpr) (any, bool) { if p.debug { defer p.out(p.in("parseAndCodeExpr")) } @@ -1311,7 +1313,7 @@ func (p *parser) parseAndCodeExpr(and *andCodeExpr) (interface{}, bool) { return nil, ok } -func (p *parser) parseAndExpr(and *andExpr) (interface{}, bool) { +func (p *parser) parseAndExpr(and *andExpr) (any, bool) { if p.debug { defer p.out(p.in("parseAndExpr")) } @@ -1327,7 +1329,7 @@ func (p *parser) parseAndExpr(and *andExpr) (interface{}, bool) { return nil, ok } -func (p *parser) parseAnyMatcher(any *anyMatcher) (interface{}, bool) { +func (p *parser) parseAnyMatcher(any *anyMatcher) (any, bool) { if p.debug { defer p.out(p.in("parseAnyMatcher")) } @@ -1344,7 +1346,7 @@ func (p *parser) parseAnyMatcher(any *anyMatcher) (interface{}, bool) { } // nolint: gocyclo -func (p *parser) parseCharClassMatcher(chr *charClassMatcher) (interface{}, bool) { +func (p *parser) parseCharClassMatcher(chr *charClassMatcher) (any, bool) { if p.debug { defer p.out(p.in("parseCharClassMatcher")) } @@ -1425,7 +1427,7 @@ func (p *parser) incChoiceAltCnt(ch *choiceExpr, altI int) { m[alt]++ } -func (p *parser) parseChoiceExpr(ch *choiceExpr) (interface{}, bool) { +func (p *parser) parseChoiceExpr(ch *choiceExpr) (any, bool) { if p.debug { defer p.out(p.in("parseChoiceExpr")) } @@ -1449,7 +1451,7 @@ func (p *parser) parseChoiceExpr(ch *choiceExpr) (interface{}, bool) { return nil, false } -func (p *parser) parseLabeledExpr(lab *labeledExpr) (interface{}, bool) { +func (p *parser) parseLabeledExpr(lab *labeledExpr) (any, bool) { if p.debug { defer p.out(p.in("parseLabeledExpr")) } @@ -1464,7 +1466,7 @@ func (p *parser) parseLabeledExpr(lab *labeledExpr) (interface{}, bool) { return val, ok } -func (p *parser) parseLitMatcher(lit *litMatcher) (interface{}, bool) { +func (p *parser) parseLitMatcher(lit *litMatcher) (any, bool) { if p.debug { defer p.out(p.in("parseLitMatcher")) } @@ -1486,7 +1488,7 @@ func (p *parser) parseLitMatcher(lit *litMatcher) (interface{}, bool) { return p.sliceFrom(start), true } -func (p *parser) parseNotCodeExpr(not *notCodeExpr) (interface{}, bool) { +func (p *parser) parseNotCodeExpr(not *notCodeExpr) (any, bool) { if p.debug { defer p.out(p.in("parseNotCodeExpr")) } @@ -1502,7 +1504,7 @@ func (p *parser) parseNotCodeExpr(not *notCodeExpr) (interface{}, bool) { return nil, !ok } -func (p *parser) parseNotExpr(not *notExpr) (interface{}, bool) { +func (p *parser) parseNotExpr(not *notExpr) (any, bool) { if p.debug { defer p.out(p.in("parseNotExpr")) } @@ -1520,12 +1522,12 @@ func (p *parser) parseNotExpr(not *notExpr) (interface{}, bool) { return nil, !ok } -func (p *parser) parseOneOrMoreExpr(expr *oneOrMoreExpr) (interface{}, bool) { +func (p *parser) parseOneOrMoreExpr(expr *oneOrMoreExpr) (any, bool) { if p.debug { defer p.out(p.in("parseOneOrMoreExpr")) } - var vals []interface{} + var vals []any for { p.pushV() @@ -1542,7 +1544,7 @@ func (p *parser) parseOneOrMoreExpr(expr *oneOrMoreExpr) (interface{}, bool) { } } -func (p *parser) parseRecoveryExpr(recover *recoveryExpr) (interface{}, bool) { +func (p *parser) parseRecoveryExpr(recover *recoveryExpr) (any, bool) { if p.debug { defer p.out(p.in("parseRecoveryExpr (" + strings.Join(recover.failureLabel, ",") + ")")) } @@ -1554,7 +1556,7 @@ func (p *parser) parseRecoveryExpr(recover *recoveryExpr) (interface{}, bool) { return val, ok } -func (p *parser) parseRuleRefExpr(ref *ruleRefExpr) (interface{}, bool) { +func (p *parser) parseRuleRefExpr(ref *ruleRefExpr) (any, bool) { if p.debug { defer p.out(p.in("parseRuleRefExpr " + ref.name)) } @@ -1571,12 +1573,12 @@ func (p *parser) parseRuleRefExpr(ref *ruleRefExpr) (interface{}, bool) { return p.parseRule(rule) } -func (p *parser) parseSeqExpr(seq *seqExpr) (interface{}, bool) { +func (p *parser) parseSeqExpr(seq *seqExpr) (any, bool) { if p.debug { defer p.out(p.in("parseSeqExpr")) } - vals := make([]interface{}, 0, len(seq.exprs)) + vals := make([]any, 0, len(seq.exprs)) pt := p.pt state := p.cloneState() @@ -1592,7 +1594,7 @@ func (p *parser) parseSeqExpr(seq *seqExpr) (interface{}, bool) { return vals, true } -func (p *parser) parseStateCodeExpr(state *stateCodeExpr) (interface{}, bool) { +func (p *parser) parseStateCodeExpr(state *stateCodeExpr) (any, bool) { if p.debug { defer p.out(p.in("parseStateCodeExpr")) } @@ -1604,7 +1606,7 @@ func (p *parser) parseStateCodeExpr(state *stateCodeExpr) (interface{}, bool) { return nil, true } -func (p *parser) parseThrowExpr(expr *throwExpr) (interface{}, bool) { +func (p *parser) parseThrowExpr(expr *throwExpr) (any, bool) { if p.debug { defer p.out(p.in("parseThrowExpr")) } @@ -1620,12 +1622,12 @@ func (p *parser) parseThrowExpr(expr *throwExpr) (interface{}, bool) { return nil, false } -func (p *parser) parseZeroOrMoreExpr(expr *zeroOrMoreExpr) (interface{}, bool) { +func (p *parser) parseZeroOrMoreExpr(expr *zeroOrMoreExpr) (any, bool) { if p.debug { defer p.out(p.in("parseZeroOrMoreExpr")) } - var vals []interface{} + var vals []any for { p.pushV() @@ -1638,7 +1640,7 @@ func (p *parser) parseZeroOrMoreExpr(expr *zeroOrMoreExpr) (interface{}, bool) { } } -func (p *parser) parseZeroOrOneExpr(expr *zeroOrOneExpr) (interface{}, bool) { +func (p *parser) parseZeroOrOneExpr(expr *zeroOrOneExpr) (any, bool) { if p.debug { defer p.out(p.in("parseZeroOrOneExpr")) } diff --git a/test/staterestore/staterestore.go b/test/staterestore/staterestore.go index 28239f75..b490e8be 100644 --- a/test/staterestore/staterestore.go +++ b/test/staterestore/staterestore.go @@ -42,7 +42,7 @@ var g = &grammar{ run: (*parser).callonTestExpr1, expr: &seqExpr{ pos: position{line: 19, col: 13, offset: 298}, - exprs: []interface{}{ + exprs: []any{ &stateCodeExpr{ pos: position{line: 19, col: 13, offset: 298}, run: (*parser).callonTestExpr3, @@ -71,7 +71,7 @@ var g = &grammar{ run: (*parser).callonTestAnd1, expr: &seqExpr{ pos: position{line: 24, col: 12, offset: 396}, - exprs: []interface{}{ + exprs: []any{ &stateCodeExpr{ pos: position{line: 24, col: 12, offset: 396}, run: (*parser).callonTestAnd3, @@ -102,14 +102,14 @@ var g = &grammar{ run: (*parser).callonTestNot1, expr: &seqExpr{ pos: position{line: 29, col: 12, offset: 494}, - exprs: []interface{}{ + exprs: []any{ &stateCodeExpr{ pos: position{line: 29, col: 12, offset: 494}, run: (*parser).callonTestNot3, }, &choiceExpr{ pos: position{line: 29, col: 50, offset: 532}, - alternatives: []interface{}{ + alternatives: []any{ ¬Expr{ pos: position{line: 29, col: 50, offset: 532}, expr: &ruleRefExpr{ @@ -132,7 +132,7 @@ var g = &grammar{ pos: position{line: 34, col: 1, offset: 585}, expr: &seqExpr{ pos: position{line: 34, col: 7, offset: 591}, - exprs: []interface{}{ + exprs: []any{ &ruleRefExpr{ pos: position{line: 34, col: 7, offset: 591}, name: "_", @@ -151,7 +151,7 @@ var g = &grammar{ pos: position{line: 35, col: 1, offset: 597}, expr: &seqExpr{ pos: position{line: 35, col: 9, offset: 605}, - exprs: []interface{}{ + exprs: []any{ &litMatcher{ pos: position{line: 35, col: 9, offset: 605}, val: "f", @@ -187,7 +187,7 @@ var g = &grammar{ pos: position{line: 36, col: 1, offset: 621}, expr: &seqExpr{ pos: position{line: 36, col: 8, offset: 628}, - exprs: []interface{}{ + exprs: []any{ &litMatcher{ pos: position{line: 36, col: 8, offset: 628}, val: "\n", @@ -206,7 +206,7 @@ var g = &grammar{ pos: position{line: 44, col: 1, offset: 725}, expr: &seqExpr{ pos: position{line: 44, col: 12, offset: 736}, - exprs: []interface{}{ + exprs: []any{ &litMatcher{ pos: position{line: 44, col: 12, offset: 736}, val: "#", @@ -217,7 +217,7 @@ var g = &grammar{ pos: position{line: 44, col: 16, offset: 740}, expr: &seqExpr{ pos: position{line: 44, col: 18, offset: 742}, - exprs: []interface{}{ + exprs: []any{ ¬Expr{ pos: position{line: 44, col: 18, offset: 742}, expr: &ruleRefExpr{ @@ -241,7 +241,7 @@ var g = &grammar{ pos: position{line: 45, col: 6, offset: 757}, expr: &choiceExpr{ pos: position{line: 45, col: 8, offset: 759}, - alternatives: []interface{}{ + alternatives: []any{ &ruleRefExpr{ pos: position{line: 45, col: 8, offset: 759}, name: "EOL", @@ -278,12 +278,12 @@ func (p *parser) callonTestExpr3() error { return p.cur.onTestExpr3() } -func (c *current) onTestExpr1() (interface{}, error) { +func (c *current) onTestExpr1() (any, error) { return c.state["cnt"], nil } -func (p *parser) callonTestExpr1() (interface{}, error) { +func (p *parser) callonTestExpr1() (any, error) { stack := p.vstack[len(p.vstack)-1] _ = stack return p.cur.onTestExpr1() @@ -300,12 +300,12 @@ func (p *parser) callonTestAnd3() error { return p.cur.onTestAnd3() } -func (c *current) onTestAnd1() (interface{}, error) { +func (c *current) onTestAnd1() (any, error) { return c.state["cnt"], nil } -func (p *parser) callonTestAnd1() (interface{}, error) { +func (p *parser) callonTestAnd1() (any, error) { stack := p.vstack[len(p.vstack)-1] _ = stack return p.cur.onTestAnd1() @@ -322,12 +322,12 @@ func (p *parser) callonTestNot3() error { return p.cur.onTestNot3() } -func (c *current) onTestNot1() (interface{}, error) { +func (c *current) onTestNot1() (any, error) { return c.state["cnt"], nil } -func (p *parser) callonTestNot1() (interface{}, error) { +func (p *parser) callonTestNot1() (any, error) { stack := p.vstack[len(p.vstack)-1] _ = stack return p.cur.onTestNot1() @@ -485,7 +485,7 @@ func Recover(b bool) Option { // GlobalStore creates an Option to set a key to a certain value in // the globalStore. -func GlobalStore(key string, value interface{}) Option { +func GlobalStore(key string, value any) Option { return func(p *parser) Option { old := p.cur.globalStore[key] p.cur.globalStore[key] = value @@ -495,7 +495,7 @@ func GlobalStore(key string, value interface{}) Option { // InitState creates an Option to set a key to a certain value in // the global "state" store. -func InitState(key string, value interface{}) Option { +func InitState(key string, value any) Option { return func(p *parser) Option { old := p.cur.state[key] p.cur.state[key] = value @@ -504,7 +504,7 @@ func InitState(key string, value interface{}) Option { } // ParseFile parses the file identified by filename. -func ParseFile(filename string, opts ...Option) (i interface{}, err error) { // nolint: deadcode +func ParseFile(filename string, opts ...Option) (i any, err error) { // nolint: deadcode f, err := os.Open(filename) if err != nil { return nil, err @@ -519,7 +519,7 @@ func ParseFile(filename string, opts ...Option) (i interface{}, err error) { // // ParseReader parses the data from r using filename as information in the // error messages. -func ParseReader(filename string, r io.Reader, opts ...Option) (interface{}, error) { // nolint: deadcode +func ParseReader(filename string, r io.Reader, opts ...Option) (any, error) { // nolint: deadcode b, err := io.ReadAll(r) if err != nil { return nil, err @@ -530,7 +530,7 @@ func ParseReader(filename string, r io.Reader, opts ...Option) (interface{}, err // Parse parses the data from b using filename as information in the // error messages. -func Parse(filename string, b []byte, opts ...Option) (interface{}, error) { +func Parse(filename string, b []byte, opts ...Option) (any, error) { return newParser(filename, b, opts...).parse(g) } @@ -568,7 +568,7 @@ type current struct { globalStore storeDict } -type storeDict map[string]interface{} +type storeDict map[string]any // the AST types... @@ -583,34 +583,34 @@ type rule struct { pos position name string displayName string - expr interface{} + expr any } // nolint: structcheck type choiceExpr struct { pos position - alternatives []interface{} + alternatives []any } // nolint: structcheck type actionExpr struct { pos position - expr interface{} - run func(*parser) (interface{}, error) + expr any + run func(*parser) (any, error) } // nolint: structcheck type recoveryExpr struct { pos position - expr interface{} - recoverExpr interface{} + expr any + recoverExpr any failureLabel []string } // nolint: structcheck type seqExpr struct { pos position - exprs []interface{} + exprs []any } // nolint: structcheck @@ -623,20 +623,22 @@ type throwExpr struct { type labeledExpr struct { pos position label string - expr interface{} + expr any } // nolint: structcheck type expr struct { pos position - expr interface{} + expr any } -type andExpr expr // nolint: structcheck -type notExpr expr // nolint: structcheck -type zeroOrOneExpr expr // nolint: structcheck -type zeroOrMoreExpr expr // nolint: structcheck -type oneOrMoreExpr expr // nolint: structcheck +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 { @@ -784,7 +786,7 @@ func (p *parser) setOptions(opts []Option) { // nolint: structcheck,deadcode type resultTuple struct { - v interface{} + v any b bool end savepoint } @@ -830,12 +832,12 @@ type parser struct { memoize bool // memoization table for the packrat algorithm: // map[offset in source] map[expression or rule] {value, match} - memo map[int]map[interface{}]resultTuple + 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]interface{} + vstack []map[string]any // rule stack, allows identification of the current rule in errors rstack []*rule @@ -855,7 +857,7 @@ type parser struct { choiceNoMatch string // recovery expression stack, keeps track of the currently available recovery expression, these are traversed in reverse - recoveryStack []map[string]interface{} + recoveryStack []map[string]any } // push a variable set on the vstack. @@ -875,7 +877,7 @@ func (p *parser) pushV() { return } - m = make(map[string]interface{}) + m = make(map[string]any) p.vstack[len(p.vstack)-1] = m } @@ -891,7 +893,7 @@ func (p *parser) popV() { } // push a recovery expression with its labels to the recoveryStack -func (p *parser) pushRecovery(labels []string, expr interface{}) { +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) @@ -900,7 +902,7 @@ func (p *parser) pushRecovery(labels []string, expr interface{}) { p.recoveryStack = p.recoveryStack[:len(p.recoveryStack)+1] } - m := make(map[string]interface{}, len(labels)) + m := make(map[string]any, len(labels)) for _, fl := range labels { m[fl] = expr } @@ -1020,11 +1022,11 @@ func (p *parser) restore(pt savepoint) { // copies of the state to allow the parser to properly restore the state in // the case of backtracking. type Cloner interface { - Clone() interface{} + Clone() any } var statePool = &sync.Pool{ - New: func() interface{} { return make(storeDict) }, + New: func() any { return make(storeDict) }, } func (sd storeDict) Discard() { @@ -1066,7 +1068,7 @@ func (p *parser) sliceFrom(start savepoint) []byte { return p.data[start.position.offset:p.pt.position.offset] } -func (p *parser) getMemoized(node interface{}) (resultTuple, bool) { +func (p *parser) getMemoized(node any) (resultTuple, bool) { if len(p.memo) == 0 { return resultTuple{}, false } @@ -1078,13 +1080,13 @@ func (p *parser) getMemoized(node interface{}) (resultTuple, bool) { return res, ok } -func (p *parser) setMemoized(pt savepoint, node interface{}, tuple resultTuple) { +func (p *parser) setMemoized(pt savepoint, node any, tuple resultTuple) { if p.memo == nil { - p.memo = make(map[int]map[interface{}]resultTuple) + p.memo = make(map[int]map[any]resultTuple) } m := p.memo[pt.offset] if m == nil { - m = make(map[interface{}]resultTuple) + m = make(map[any]resultTuple) p.memo[pt.offset] = m } m[node] = tuple @@ -1098,7 +1100,7 @@ func (p *parser) buildRulesTable(g *grammar) { } // nolint: gocyclo -func (p *parser) parse(g *grammar) (val interface{}, err error) { +func (p *parser) parse(g *grammar) (val any, err error) { if len(g.rules) == 0 { p.addErr(errNoRule) return nil, p.errs.err() @@ -1175,7 +1177,7 @@ func listJoin(list []string, sep string, lastSep string) string { } } -func (p *parser) parseRule(rule *rule) (interface{}, bool) { +func (p *parser) parseRule(rule *rule) (any, bool) { if p.debug { defer p.out(p.in("parseRule " + rule.name)) } @@ -1205,7 +1207,7 @@ func (p *parser) parseRule(rule *rule) (interface{}, bool) { } // nolint: gocyclo -func (p *parser) parseExpr(expr interface{}) (interface{}, bool) { +func (p *parser) parseExpr(expr any) (any, bool) { var pt savepoint if p.memoize { @@ -1222,7 +1224,7 @@ func (p *parser) parseExpr(expr interface{}) (interface{}, bool) { panic(errMaxExprCnt) } - var val interface{} + var val any var ok bool switch expr := expr.(type) { case *actionExpr: @@ -1270,7 +1272,7 @@ func (p *parser) parseExpr(expr interface{}) (interface{}, bool) { return val, ok } -func (p *parser) parseActionExpr(act *actionExpr) (interface{}, bool) { +func (p *parser) parseActionExpr(act *actionExpr) (any, bool) { if p.debug { defer p.out(p.in("parseActionExpr")) } @@ -1295,7 +1297,7 @@ func (p *parser) parseActionExpr(act *actionExpr) (interface{}, bool) { return val, ok } -func (p *parser) parseAndCodeExpr(and *andCodeExpr) (interface{}, bool) { +func (p *parser) parseAndCodeExpr(and *andCodeExpr) (any, bool) { if p.debug { defer p.out(p.in("parseAndCodeExpr")) } @@ -1311,7 +1313,7 @@ func (p *parser) parseAndCodeExpr(and *andCodeExpr) (interface{}, bool) { return nil, ok } -func (p *parser) parseAndExpr(and *andExpr) (interface{}, bool) { +func (p *parser) parseAndExpr(and *andExpr) (any, bool) { if p.debug { defer p.out(p.in("parseAndExpr")) } @@ -1327,7 +1329,7 @@ func (p *parser) parseAndExpr(and *andExpr) (interface{}, bool) { return nil, ok } -func (p *parser) parseAnyMatcher(any *anyMatcher) (interface{}, bool) { +func (p *parser) parseAnyMatcher(any *anyMatcher) (any, bool) { if p.debug { defer p.out(p.in("parseAnyMatcher")) } @@ -1344,7 +1346,7 @@ func (p *parser) parseAnyMatcher(any *anyMatcher) (interface{}, bool) { } // nolint: gocyclo -func (p *parser) parseCharClassMatcher(chr *charClassMatcher) (interface{}, bool) { +func (p *parser) parseCharClassMatcher(chr *charClassMatcher) (any, bool) { if p.debug { defer p.out(p.in("parseCharClassMatcher")) } @@ -1425,7 +1427,7 @@ func (p *parser) incChoiceAltCnt(ch *choiceExpr, altI int) { m[alt]++ } -func (p *parser) parseChoiceExpr(ch *choiceExpr) (interface{}, bool) { +func (p *parser) parseChoiceExpr(ch *choiceExpr) (any, bool) { if p.debug { defer p.out(p.in("parseChoiceExpr")) } @@ -1449,7 +1451,7 @@ func (p *parser) parseChoiceExpr(ch *choiceExpr) (interface{}, bool) { return nil, false } -func (p *parser) parseLabeledExpr(lab *labeledExpr) (interface{}, bool) { +func (p *parser) parseLabeledExpr(lab *labeledExpr) (any, bool) { if p.debug { defer p.out(p.in("parseLabeledExpr")) } @@ -1464,7 +1466,7 @@ func (p *parser) parseLabeledExpr(lab *labeledExpr) (interface{}, bool) { return val, ok } -func (p *parser) parseLitMatcher(lit *litMatcher) (interface{}, bool) { +func (p *parser) parseLitMatcher(lit *litMatcher) (any, bool) { if p.debug { defer p.out(p.in("parseLitMatcher")) } @@ -1486,7 +1488,7 @@ func (p *parser) parseLitMatcher(lit *litMatcher) (interface{}, bool) { return p.sliceFrom(start), true } -func (p *parser) parseNotCodeExpr(not *notCodeExpr) (interface{}, bool) { +func (p *parser) parseNotCodeExpr(not *notCodeExpr) (any, bool) { if p.debug { defer p.out(p.in("parseNotCodeExpr")) } @@ -1502,7 +1504,7 @@ func (p *parser) parseNotCodeExpr(not *notCodeExpr) (interface{}, bool) { return nil, !ok } -func (p *parser) parseNotExpr(not *notExpr) (interface{}, bool) { +func (p *parser) parseNotExpr(not *notExpr) (any, bool) { if p.debug { defer p.out(p.in("parseNotExpr")) } @@ -1520,12 +1522,12 @@ func (p *parser) parseNotExpr(not *notExpr) (interface{}, bool) { return nil, !ok } -func (p *parser) parseOneOrMoreExpr(expr *oneOrMoreExpr) (interface{}, bool) { +func (p *parser) parseOneOrMoreExpr(expr *oneOrMoreExpr) (any, bool) { if p.debug { defer p.out(p.in("parseOneOrMoreExpr")) } - var vals []interface{} + var vals []any for { p.pushV() @@ -1542,7 +1544,7 @@ func (p *parser) parseOneOrMoreExpr(expr *oneOrMoreExpr) (interface{}, bool) { } } -func (p *parser) parseRecoveryExpr(recover *recoveryExpr) (interface{}, bool) { +func (p *parser) parseRecoveryExpr(recover *recoveryExpr) (any, bool) { if p.debug { defer p.out(p.in("parseRecoveryExpr (" + strings.Join(recover.failureLabel, ",") + ")")) } @@ -1554,7 +1556,7 @@ func (p *parser) parseRecoveryExpr(recover *recoveryExpr) (interface{}, bool) { return val, ok } -func (p *parser) parseRuleRefExpr(ref *ruleRefExpr) (interface{}, bool) { +func (p *parser) parseRuleRefExpr(ref *ruleRefExpr) (any, bool) { if p.debug { defer p.out(p.in("parseRuleRefExpr " + ref.name)) } @@ -1571,12 +1573,12 @@ func (p *parser) parseRuleRefExpr(ref *ruleRefExpr) (interface{}, bool) { return p.parseRule(rule) } -func (p *parser) parseSeqExpr(seq *seqExpr) (interface{}, bool) { +func (p *parser) parseSeqExpr(seq *seqExpr) (any, bool) { if p.debug { defer p.out(p.in("parseSeqExpr")) } - vals := make([]interface{}, 0, len(seq.exprs)) + vals := make([]any, 0, len(seq.exprs)) pt := p.pt state := p.cloneState() @@ -1592,7 +1594,7 @@ func (p *parser) parseSeqExpr(seq *seqExpr) (interface{}, bool) { return vals, true } -func (p *parser) parseStateCodeExpr(state *stateCodeExpr) (interface{}, bool) { +func (p *parser) parseStateCodeExpr(state *stateCodeExpr) (any, bool) { if p.debug { defer p.out(p.in("parseStateCodeExpr")) } @@ -1604,7 +1606,7 @@ func (p *parser) parseStateCodeExpr(state *stateCodeExpr) (interface{}, bool) { return nil, true } -func (p *parser) parseThrowExpr(expr *throwExpr) (interface{}, bool) { +func (p *parser) parseThrowExpr(expr *throwExpr) (any, bool) { if p.debug { defer p.out(p.in("parseThrowExpr")) } @@ -1620,12 +1622,12 @@ func (p *parser) parseThrowExpr(expr *throwExpr) (interface{}, bool) { return nil, false } -func (p *parser) parseZeroOrMoreExpr(expr *zeroOrMoreExpr) (interface{}, bool) { +func (p *parser) parseZeroOrMoreExpr(expr *zeroOrMoreExpr) (any, bool) { if p.debug { defer p.out(p.in("parseZeroOrMoreExpr")) } - var vals []interface{} + var vals []any for { p.pushV() @@ -1638,7 +1640,7 @@ func (p *parser) parseZeroOrMoreExpr(expr *zeroOrMoreExpr) (interface{}, bool) { } } -func (p *parser) parseZeroOrOneExpr(expr *zeroOrOneExpr) (interface{}, bool) { +func (p *parser) parseZeroOrOneExpr(expr *zeroOrOneExpr) (any, bool) { if p.debug { defer p.out(p.in("parseZeroOrOneExpr")) } diff --git a/test/thrownrecover/thrownrecover.go b/test/thrownrecover/thrownrecover.go index 9f43fe06..eb593986 100644 --- a/test/thrownrecover/thrownrecover.go +++ b/test/thrownrecover/thrownrecover.go @@ -24,7 +24,7 @@ var g = &grammar{ pos: position{line: 6, col: 1, offset: 28}, expr: &choiceExpr{ pos: position{line: 6, col: 9, offset: 36}, - alternatives: []interface{}{ + alternatives: []any{ &ruleRefExpr{ pos: position{line: 6, col: 9, offset: 36}, name: "case01", @@ -52,7 +52,7 @@ var g = &grammar{ run: (*parser).calloncase011, expr: &seqExpr{ pos: position{line: 11, col: 10, offset: 117}, - exprs: []interface{}{ + exprs: []any{ &litMatcher{ pos: position{line: 11, col: 10, offset: 117}, val: "case01:", @@ -95,7 +95,7 @@ var g = &grammar{ pos: position{line: 15, col: 1, offset: 241}, expr: &choiceExpr{ pos: position{line: 15, col: 10, offset: 250}, - alternatives: []interface{}{ + alternatives: []any{ ¬Expr{ pos: position{line: 15, col: 10, offset: 250}, expr: &anyMatcher{ @@ -107,7 +107,7 @@ var g = &grammar{ run: (*parser).callonnumber4, expr: &seqExpr{ pos: position{line: 15, col: 15, offset: 255}, - exprs: []interface{}{ + exprs: []any{ &labeledExpr{ pos: position{line: 15, col: 15, offset: 255}, label: "d", @@ -135,7 +135,7 @@ var g = &grammar{ pos: position{line: 22, col: 1, offset: 372}, expr: &choiceExpr{ pos: position{line: 22, col: 9, offset: 380}, - alternatives: []interface{}{ + alternatives: []any{ &actionExpr{ pos: position{line: 22, col: 9, offset: 380}, run: (*parser).callondigit2, @@ -155,7 +155,7 @@ var g = &grammar{ label: "x", expr: &seqExpr{ pos: position{line: 22, col: 52, offset: 423}, - exprs: []interface{}{ + exprs: []any{ &andExpr{ pos: position{line: 22, col: 52, offset: 423}, expr: &charClassMatcher{ @@ -175,7 +175,7 @@ var g = &grammar{ }, }, &throwExpr{ - pos: position{line: 22, col: 112, offset: 483}, + pos: position{line: 22, col: 104, offset: 475}, label: "errOther", }, }, @@ -183,26 +183,26 @@ var g = &grammar{ }, { name: "ErrNonNumber", - pos: position{line: 24, col: 1, offset: 496}, + pos: position{line: 24, col: 1, offset: 488}, expr: &actionExpr{ - pos: position{line: 24, col: 16, offset: 511}, + pos: position{line: 24, col: 16, offset: 503}, run: (*parser).callonErrNonNumber1, expr: &seqExpr{ - pos: position{line: 24, col: 16, offset: 511}, - exprs: []interface{}{ + pos: position{line: 24, col: 16, offset: 503}, + exprs: []any{ &andCodeExpr{ - pos: position{line: 24, col: 16, offset: 511}, + pos: position{line: 24, col: 16, offset: 503}, run: (*parser).callonErrNonNumber3, }, &zeroOrMoreExpr{ - pos: position{line: 26, col: 3, offset: 566}, + pos: position{line: 26, col: 3, offset: 558}, expr: &seqExpr{ - pos: position{line: 26, col: 5, offset: 568}, - exprs: []interface{}{ + pos: position{line: 26, col: 5, offset: 560}, + exprs: []any{ ¬Expr{ - pos: position{line: 26, col: 5, offset: 568}, + pos: position{line: 26, col: 5, offset: 560}, expr: &charClassMatcher{ - pos: position{line: 26, col: 6, offset: 569}, + pos: position{line: 26, col: 6, offset: 561}, val: "[0-9]", ranges: []rune{'0', '9'}, ignoreCase: false, @@ -210,7 +210,7 @@ var g = &grammar{ }, }, &anyMatcher{ - line: 26, col: 12, offset: 575, + line: 26, col: 12, offset: 567, }, }, }, @@ -221,25 +221,25 @@ var g = &grammar{ }, { name: "case02", - pos: position{line: 31, col: 1, offset: 637}, + pos: position{line: 31, col: 1, offset: 629}, expr: &seqExpr{ - pos: position{line: 31, col: 10, offset: 646}, - exprs: []interface{}{ + pos: position{line: 31, col: 10, offset: 638}, + exprs: []any{ &litMatcher{ - pos: position{line: 31, col: 10, offset: 646}, + pos: position{line: 31, col: 10, offset: 638}, val: "case02:", ignoreCase: false, want: "\"case02:\"", }, &choiceExpr{ - pos: position{line: 31, col: 21, offset: 657}, - alternatives: []interface{}{ + pos: position{line: 31, col: 21, offset: 649}, + alternatives: []any{ &ruleRefExpr{ - pos: position{line: 31, col: 21, offset: 657}, + pos: position{line: 31, col: 21, offset: 649}, name: "ThrowUndefLabel", }, &andCodeExpr{ - pos: position{line: 31, col: 39, offset: 675}, + pos: position{line: 31, col: 39, offset: 667}, run: (*parser).calloncase025, }, }, @@ -249,32 +249,32 @@ var g = &grammar{ }, { name: "ThrowUndefLabel", - pos: position{line: 33, col: 1, offset: 734}, + pos: position{line: 33, col: 1, offset: 726}, expr: &throwExpr{ - pos: position{line: 33, col: 19, offset: 752}, + pos: position{line: 33, col: 19, offset: 744}, label: "undeflabel", }, }, { name: "case03", - pos: position{line: 38, col: 1, offset: 796}, + pos: position{line: 38, col: 1, offset: 788}, expr: &actionExpr{ - pos: position{line: 38, col: 10, offset: 805}, + pos: position{line: 38, col: 10, offset: 797}, run: (*parser).calloncase031, expr: &seqExpr{ - pos: position{line: 38, col: 10, offset: 805}, - exprs: []interface{}{ + pos: position{line: 38, col: 10, offset: 797}, + exprs: []any{ &litMatcher{ - pos: position{line: 38, col: 10, offset: 805}, + pos: position{line: 38, col: 10, offset: 797}, val: "case03:", ignoreCase: false, want: "\"case03:\"", }, &labeledExpr{ - pos: position{line: 38, col: 20, offset: 815}, + pos: position{line: 38, col: 20, offset: 807}, label: "case03", expr: &ruleRefExpr{ - pos: position{line: 38, col: 27, offset: 822}, + pos: position{line: 38, col: 27, offset: 814}, name: "OuterRecover03", }, }, @@ -284,17 +284,17 @@ var g = &grammar{ }, { name: "OuterRecover03", - pos: position{line: 40, col: 1, offset: 861}, + pos: position{line: 40, col: 1, offset: 853}, expr: &recoveryExpr{ - pos: position{line: 40, col: 18, offset: 878}, + pos: position{line: 40, col: 18, offset: 870}, expr: &recoveryExpr{ - pos: position{line: 40, col: 18, offset: 878}, + pos: position{line: 40, col: 18, offset: 870}, expr: &ruleRefExpr{ - pos: position{line: 40, col: 18, offset: 878}, + pos: position{line: 40, col: 18, offset: 870}, name: "InnerRecover03", }, recoverExpr: &ruleRefExpr{ - pos: position{line: 40, col: 66, offset: 926}, + pos: position{line: 40, col: 66, offset: 918}, name: "ErrAlphaOuter03", }, failureLabel: []string{ @@ -303,7 +303,7 @@ var g = &grammar{ }, }, recoverExpr: &ruleRefExpr{ - pos: position{line: 40, col: 95, offset: 955}, + pos: position{line: 40, col: 95, offset: 947}, name: "ErrOtherOuter03", }, failureLabel: []string{ @@ -313,15 +313,15 @@ var g = &grammar{ }, { name: "InnerRecover03", - pos: position{line: 42, col: 1, offset: 972}, + pos: position{line: 42, col: 1, offset: 964}, expr: &recoveryExpr{ - pos: position{line: 42, col: 18, offset: 989}, + pos: position{line: 42, col: 18, offset: 981}, expr: &ruleRefExpr{ - pos: position{line: 42, col: 18, offset: 989}, + pos: position{line: 42, col: 18, offset: 981}, name: "number03", }, recoverExpr: &ruleRefExpr{ - pos: position{line: 42, col: 45, offset: 1016}, + pos: position{line: 42, col: 45, offset: 1008}, name: "ErrAlphaInner03", }, failureLabel: []string{ @@ -331,35 +331,35 @@ var g = &grammar{ }, { name: "number03", - pos: position{line: 44, col: 1, offset: 1033}, + pos: position{line: 44, col: 1, offset: 1025}, expr: &choiceExpr{ - pos: position{line: 44, col: 12, offset: 1044}, - alternatives: []interface{}{ + pos: position{line: 44, col: 12, offset: 1036}, + alternatives: []any{ ¬Expr{ - pos: position{line: 44, col: 12, offset: 1044}, + pos: position{line: 44, col: 12, offset: 1036}, expr: &anyMatcher{ - line: 44, col: 13, offset: 1045, + line: 44, col: 13, offset: 1037, }, }, &actionExpr{ - pos: position{line: 44, col: 17, offset: 1049}, + pos: position{line: 44, col: 17, offset: 1041}, run: (*parser).callonnumber034, expr: &seqExpr{ - pos: position{line: 44, col: 17, offset: 1049}, - exprs: []interface{}{ + pos: position{line: 44, col: 17, offset: 1041}, + exprs: []any{ &labeledExpr{ - pos: position{line: 44, col: 17, offset: 1049}, + pos: position{line: 44, col: 17, offset: 1041}, label: "d", expr: &ruleRefExpr{ - pos: position{line: 44, col: 19, offset: 1051}, + pos: position{line: 44, col: 19, offset: 1043}, name: "digit03", }, }, &labeledExpr{ - pos: position{line: 44, col: 27, offset: 1059}, + pos: position{line: 44, col: 27, offset: 1051}, label: "n", expr: &ruleRefExpr{ - pos: position{line: 44, col: 29, offset: 1061}, + pos: position{line: 44, col: 29, offset: 1053}, name: "number03", }, }, @@ -371,15 +371,15 @@ var g = &grammar{ }, { name: "digit03", - pos: position{line: 51, col: 1, offset: 1170}, + pos: position{line: 51, col: 1, offset: 1162}, expr: &choiceExpr{ - pos: position{line: 51, col: 11, offset: 1180}, - alternatives: []interface{}{ + pos: position{line: 51, col: 11, offset: 1172}, + alternatives: []any{ &actionExpr{ - pos: position{line: 51, col: 11, offset: 1180}, + pos: position{line: 51, col: 11, offset: 1172}, run: (*parser).callondigit032, expr: &charClassMatcher{ - pos: position{line: 51, col: 11, offset: 1180}, + pos: position{line: 51, col: 11, offset: 1172}, val: "[0-9]", ranges: []rune{'0', '9'}, ignoreCase: false, @@ -387,18 +387,18 @@ var g = &grammar{ }, }, &actionExpr{ - pos: position{line: 51, col: 50, offset: 1219}, + pos: position{line: 51, col: 50, offset: 1211}, run: (*parser).callondigit034, expr: &labeledExpr{ - pos: position{line: 51, col: 50, offset: 1219}, + pos: position{line: 51, col: 50, offset: 1211}, label: "x", expr: &seqExpr{ - pos: position{line: 51, col: 54, offset: 1223}, - exprs: []interface{}{ + pos: position{line: 51, col: 54, offset: 1215}, + exprs: []any{ &andExpr{ - pos: position{line: 51, col: 54, offset: 1223}, + pos: position{line: 51, col: 54, offset: 1215}, expr: &charClassMatcher{ - pos: position{line: 51, col: 55, offset: 1224}, + pos: position{line: 51, col: 55, offset: 1216}, val: "[a-z]", ranges: []rune{'a', 'z'}, ignoreCase: false, @@ -406,7 +406,7 @@ var g = &grammar{ }, }, &throwExpr{ - pos: position{line: 51, col: 61, offset: 1230}, + pos: position{line: 51, col: 61, offset: 1222}, label: "errAlphaLower", }, }, @@ -414,18 +414,18 @@ var g = &grammar{ }, }, &actionExpr{ - pos: position{line: 51, col: 119, offset: 1288}, + pos: position{line: 51, col: 111, offset: 1272}, run: (*parser).callondigit0310, expr: &labeledExpr{ - pos: position{line: 51, col: 119, offset: 1288}, + pos: position{line: 51, col: 111, offset: 1272}, label: "x", expr: &seqExpr{ - pos: position{line: 51, col: 123, offset: 1292}, - exprs: []interface{}{ + pos: position{line: 51, col: 115, offset: 1276}, + exprs: []any{ &andExpr{ - pos: position{line: 51, col: 123, offset: 1292}, + pos: position{line: 51, col: 115, offset: 1276}, expr: &charClassMatcher{ - pos: position{line: 51, col: 124, offset: 1293}, + pos: position{line: 51, col: 116, offset: 1277}, val: "[A-Z]", ranges: []rune{'A', 'Z'}, ignoreCase: false, @@ -433,7 +433,7 @@ var g = &grammar{ }, }, &throwExpr{ - pos: position{line: 51, col: 130, offset: 1299}, + pos: position{line: 51, col: 122, offset: 1283}, label: "errAlphaUpper", }, }, @@ -441,7 +441,7 @@ var g = &grammar{ }, }, &throwExpr{ - pos: position{line: 51, col: 188, offset: 1357}, + pos: position{line: 51, col: 172, offset: 1333}, label: "errOther", }, }, @@ -449,26 +449,26 @@ var g = &grammar{ }, { name: "ErrAlphaInner03", - pos: position{line: 53, col: 1, offset: 1370}, + pos: position{line: 53, col: 1, offset: 1346}, expr: &actionExpr{ - pos: position{line: 53, col: 19, offset: 1388}, + pos: position{line: 53, col: 19, offset: 1364}, run: (*parser).callonErrAlphaInner031, expr: &seqExpr{ - pos: position{line: 53, col: 19, offset: 1388}, - exprs: []interface{}{ + pos: position{line: 53, col: 19, offset: 1364}, + exprs: []any{ &andCodeExpr{ - pos: position{line: 53, col: 19, offset: 1388}, + pos: position{line: 53, col: 19, offset: 1364}, run: (*parser).callonErrAlphaInner033, }, &zeroOrMoreExpr{ - pos: position{line: 55, col: 3, offset: 1464}, + pos: position{line: 55, col: 3, offset: 1440}, expr: &seqExpr{ - pos: position{line: 55, col: 5, offset: 1466}, - exprs: []interface{}{ + pos: position{line: 55, col: 5, offset: 1442}, + exprs: []any{ ¬Expr{ - pos: position{line: 55, col: 5, offset: 1466}, + pos: position{line: 55, col: 5, offset: 1442}, expr: &charClassMatcher{ - pos: position{line: 55, col: 6, offset: 1467}, + pos: position{line: 55, col: 6, offset: 1443}, val: "[0-9]", ranges: []rune{'0', '9'}, ignoreCase: false, @@ -476,7 +476,7 @@ var g = &grammar{ }, }, &anyMatcher{ - line: 55, col: 12, offset: 1473, + line: 55, col: 12, offset: 1449, }, }, }, @@ -487,26 +487,26 @@ var g = &grammar{ }, { name: "ErrAlphaOuter03", - pos: position{line: 57, col: 1, offset: 1499}, + pos: position{line: 57, col: 1, offset: 1475}, expr: &actionExpr{ - pos: position{line: 57, col: 19, offset: 1517}, + pos: position{line: 57, col: 19, offset: 1493}, run: (*parser).callonErrAlphaOuter031, expr: &seqExpr{ - pos: position{line: 57, col: 19, offset: 1517}, - exprs: []interface{}{ + pos: position{line: 57, col: 19, offset: 1493}, + exprs: []any{ &andCodeExpr{ - pos: position{line: 57, col: 19, offset: 1517}, + pos: position{line: 57, col: 19, offset: 1493}, run: (*parser).callonErrAlphaOuter033, }, &zeroOrMoreExpr{ - pos: position{line: 59, col: 3, offset: 1593}, + pos: position{line: 59, col: 3, offset: 1569}, expr: &seqExpr{ - pos: position{line: 59, col: 5, offset: 1595}, - exprs: []interface{}{ + pos: position{line: 59, col: 5, offset: 1571}, + exprs: []any{ ¬Expr{ - pos: position{line: 59, col: 5, offset: 1595}, + pos: position{line: 59, col: 5, offset: 1571}, expr: &charClassMatcher{ - pos: position{line: 59, col: 6, offset: 1596}, + pos: position{line: 59, col: 6, offset: 1572}, val: "[0-9]", ranges: []rune{'0', '9'}, ignoreCase: false, @@ -514,7 +514,7 @@ var g = &grammar{ }, }, &anyMatcher{ - line: 59, col: 12, offset: 1602, + line: 59, col: 12, offset: 1578, }, }, }, @@ -525,26 +525,26 @@ var g = &grammar{ }, { name: "ErrOtherOuter03", - pos: position{line: 61, col: 1, offset: 1628}, + pos: position{line: 61, col: 1, offset: 1604}, expr: &actionExpr{ - pos: position{line: 61, col: 19, offset: 1646}, + pos: position{line: 61, col: 19, offset: 1622}, run: (*parser).callonErrOtherOuter031, expr: &seqExpr{ - pos: position{line: 61, col: 19, offset: 1646}, - exprs: []interface{}{ + pos: position{line: 61, col: 19, offset: 1622}, + exprs: []any{ &andCodeExpr{ - pos: position{line: 61, col: 19, offset: 1646}, + pos: position{line: 61, col: 19, offset: 1622}, run: (*parser).callonErrOtherOuter033, }, &zeroOrMoreExpr{ - pos: position{line: 63, col: 3, offset: 1717}, + pos: position{line: 63, col: 3, offset: 1693}, expr: &seqExpr{ - pos: position{line: 63, col: 5, offset: 1719}, - exprs: []interface{}{ + pos: position{line: 63, col: 5, offset: 1695}, + exprs: []any{ ¬Expr{ - pos: position{line: 63, col: 5, offset: 1719}, + pos: position{line: 63, col: 5, offset: 1695}, expr: &charClassMatcher{ - pos: position{line: 63, col: 6, offset: 1720}, + pos: position{line: 63, col: 6, offset: 1696}, val: "[0-9]", ranges: []rune{'0', '9'}, ignoreCase: false, @@ -552,7 +552,7 @@ var g = &grammar{ }, }, &anyMatcher{ - line: 63, col: 12, offset: 1726, + line: 63, col: 12, offset: 1702, }, }, }, @@ -563,24 +563,24 @@ var g = &grammar{ }, { name: "case04", - pos: position{line: 68, col: 1, offset: 1811}, + pos: position{line: 68, col: 1, offset: 1787}, expr: &actionExpr{ - pos: position{line: 68, col: 10, offset: 1820}, + pos: position{line: 68, col: 10, offset: 1796}, run: (*parser).calloncase041, expr: &seqExpr{ - pos: position{line: 68, col: 10, offset: 1820}, - exprs: []interface{}{ + pos: position{line: 68, col: 10, offset: 1796}, + exprs: []any{ &litMatcher{ - pos: position{line: 68, col: 10, offset: 1820}, + pos: position{line: 68, col: 10, offset: 1796}, val: "case04:", ignoreCase: false, want: "\"case04:\"", }, &labeledExpr{ - pos: position{line: 68, col: 20, offset: 1830}, + pos: position{line: 68, col: 20, offset: 1806}, label: "case04", expr: &ruleRefExpr{ - pos: position{line: 68, col: 27, offset: 1837}, + pos: position{line: 68, col: 27, offset: 1813}, name: "OuterRecover04", }, }, @@ -590,17 +590,17 @@ var g = &grammar{ }, { name: "OuterRecover04", - pos: position{line: 70, col: 1, offset: 1876}, + pos: position{line: 70, col: 1, offset: 1852}, expr: &recoveryExpr{ - pos: position{line: 70, col: 18, offset: 1893}, + pos: position{line: 70, col: 18, offset: 1869}, expr: &recoveryExpr{ - pos: position{line: 70, col: 18, offset: 1893}, + pos: position{line: 70, col: 18, offset: 1869}, expr: &ruleRefExpr{ - pos: position{line: 70, col: 18, offset: 1893}, + pos: position{line: 70, col: 18, offset: 1869}, name: "InnerRecover04", }, recoverExpr: &ruleRefExpr{ - pos: position{line: 70, col: 66, offset: 1941}, + pos: position{line: 70, col: 66, offset: 1917}, name: "ErrAlphaOuter04", }, failureLabel: []string{ @@ -609,7 +609,7 @@ var g = &grammar{ }, }, recoverExpr: &ruleRefExpr{ - pos: position{line: 70, col: 95, offset: 1970}, + pos: position{line: 70, col: 95, offset: 1946}, name: "ErrOtherOuter04", }, failureLabel: []string{ @@ -619,15 +619,15 @@ var g = &grammar{ }, { name: "InnerRecover04", - pos: position{line: 72, col: 1, offset: 1987}, + pos: position{line: 72, col: 1, offset: 1963}, expr: &recoveryExpr{ - pos: position{line: 72, col: 18, offset: 2004}, + pos: position{line: 72, col: 18, offset: 1980}, expr: &ruleRefExpr{ - pos: position{line: 72, col: 18, offset: 2004}, + pos: position{line: 72, col: 18, offset: 1980}, name: "number04", }, recoverExpr: &ruleRefExpr{ - pos: position{line: 72, col: 45, offset: 2031}, + pos: position{line: 72, col: 45, offset: 2007}, name: "ErrAlphaInner04", }, failureLabel: []string{ @@ -637,35 +637,35 @@ var g = &grammar{ }, { name: "number04", - pos: position{line: 74, col: 1, offset: 2048}, + pos: position{line: 74, col: 1, offset: 2024}, expr: &choiceExpr{ - pos: position{line: 74, col: 12, offset: 2059}, - alternatives: []interface{}{ + pos: position{line: 74, col: 12, offset: 2035}, + alternatives: []any{ ¬Expr{ - pos: position{line: 74, col: 12, offset: 2059}, + pos: position{line: 74, col: 12, offset: 2035}, expr: &anyMatcher{ - line: 74, col: 13, offset: 2060, + line: 74, col: 13, offset: 2036, }, }, &actionExpr{ - pos: position{line: 74, col: 17, offset: 2064}, + pos: position{line: 74, col: 17, offset: 2040}, run: (*parser).callonnumber044, expr: &seqExpr{ - pos: position{line: 74, col: 17, offset: 2064}, - exprs: []interface{}{ + pos: position{line: 74, col: 17, offset: 2040}, + exprs: []any{ &labeledExpr{ - pos: position{line: 74, col: 17, offset: 2064}, + pos: position{line: 74, col: 17, offset: 2040}, label: "d", expr: &ruleRefExpr{ - pos: position{line: 74, col: 19, offset: 2066}, + pos: position{line: 74, col: 19, offset: 2042}, name: "digit04", }, }, &labeledExpr{ - pos: position{line: 74, col: 27, offset: 2074}, + pos: position{line: 74, col: 27, offset: 2050}, label: "n", expr: &ruleRefExpr{ - pos: position{line: 74, col: 29, offset: 2076}, + pos: position{line: 74, col: 29, offset: 2052}, name: "number04", }, }, @@ -677,15 +677,15 @@ var g = &grammar{ }, { name: "digit04", - pos: position{line: 81, col: 1, offset: 2185}, + pos: position{line: 81, col: 1, offset: 2161}, expr: &choiceExpr{ - pos: position{line: 81, col: 11, offset: 2195}, - alternatives: []interface{}{ + pos: position{line: 81, col: 11, offset: 2171}, + alternatives: []any{ &actionExpr{ - pos: position{line: 81, col: 11, offset: 2195}, + pos: position{line: 81, col: 11, offset: 2171}, run: (*parser).callondigit042, expr: &charClassMatcher{ - pos: position{line: 81, col: 11, offset: 2195}, + pos: position{line: 81, col: 11, offset: 2171}, val: "[0-9]", ranges: []rune{'0', '9'}, ignoreCase: false, @@ -693,18 +693,18 @@ var g = &grammar{ }, }, &actionExpr{ - pos: position{line: 81, col: 50, offset: 2234}, + pos: position{line: 81, col: 50, offset: 2210}, run: (*parser).callondigit044, expr: &labeledExpr{ - pos: position{line: 81, col: 50, offset: 2234}, + pos: position{line: 81, col: 50, offset: 2210}, label: "x", expr: &seqExpr{ - pos: position{line: 81, col: 54, offset: 2238}, - exprs: []interface{}{ + pos: position{line: 81, col: 54, offset: 2214}, + exprs: []any{ &andExpr{ - pos: position{line: 81, col: 54, offset: 2238}, + pos: position{line: 81, col: 54, offset: 2214}, expr: &charClassMatcher{ - pos: position{line: 81, col: 55, offset: 2239}, + pos: position{line: 81, col: 55, offset: 2215}, val: "[a-z]", ranges: []rune{'a', 'z'}, ignoreCase: false, @@ -712,7 +712,7 @@ var g = &grammar{ }, }, &throwExpr{ - pos: position{line: 81, col: 61, offset: 2245}, + pos: position{line: 81, col: 61, offset: 2221}, label: "errAlphaLower", }, }, @@ -720,18 +720,18 @@ var g = &grammar{ }, }, &actionExpr{ - pos: position{line: 81, col: 119, offset: 2303}, + pos: position{line: 81, col: 111, offset: 2271}, run: (*parser).callondigit0410, expr: &labeledExpr{ - pos: position{line: 81, col: 119, offset: 2303}, + pos: position{line: 81, col: 111, offset: 2271}, label: "x", expr: &seqExpr{ - pos: position{line: 81, col: 123, offset: 2307}, - exprs: []interface{}{ + pos: position{line: 81, col: 115, offset: 2275}, + exprs: []any{ &andExpr{ - pos: position{line: 81, col: 123, offset: 2307}, + pos: position{line: 81, col: 115, offset: 2275}, expr: &charClassMatcher{ - pos: position{line: 81, col: 124, offset: 2308}, + pos: position{line: 81, col: 116, offset: 2276}, val: "[A-Z]", ranges: []rune{'A', 'Z'}, ignoreCase: false, @@ -739,7 +739,7 @@ var g = &grammar{ }, }, &throwExpr{ - pos: position{line: 81, col: 130, offset: 2314}, + pos: position{line: 81, col: 122, offset: 2282}, label: "errAlphaUpper", }, }, @@ -747,7 +747,7 @@ var g = &grammar{ }, }, &throwExpr{ - pos: position{line: 81, col: 188, offset: 2372}, + pos: position{line: 81, col: 172, offset: 2332}, label: "errOther", }, }, @@ -755,34 +755,34 @@ var g = &grammar{ }, { name: "ErrAlphaInner04", - pos: position{line: 83, col: 1, offset: 2385}, + pos: position{line: 83, col: 1, offset: 2345}, expr: &andCodeExpr{ - pos: position{line: 83, col: 19, offset: 2403}, + pos: position{line: 83, col: 19, offset: 2363}, run: (*parser).callonErrAlphaInner041, }, }, { name: "ErrAlphaOuter04", - pos: position{line: 87, col: 1, offset: 2431}, + pos: position{line: 87, col: 1, offset: 2391}, expr: &actionExpr{ - pos: position{line: 87, col: 19, offset: 2449}, + pos: position{line: 87, col: 19, offset: 2409}, run: (*parser).callonErrAlphaOuter041, expr: &seqExpr{ - pos: position{line: 87, col: 19, offset: 2449}, - exprs: []interface{}{ + pos: position{line: 87, col: 19, offset: 2409}, + exprs: []any{ &andCodeExpr{ - pos: position{line: 87, col: 19, offset: 2449}, + pos: position{line: 87, col: 19, offset: 2409}, run: (*parser).callonErrAlphaOuter043, }, &zeroOrMoreExpr{ - pos: position{line: 89, col: 3, offset: 2516}, + pos: position{line: 89, col: 3, offset: 2476}, expr: &seqExpr{ - pos: position{line: 89, col: 5, offset: 2518}, - exprs: []interface{}{ + pos: position{line: 89, col: 5, offset: 2478}, + exprs: []any{ ¬Expr{ - pos: position{line: 89, col: 5, offset: 2518}, + pos: position{line: 89, col: 5, offset: 2478}, expr: &charClassMatcher{ - pos: position{line: 89, col: 6, offset: 2519}, + pos: position{line: 89, col: 6, offset: 2479}, val: "[0-9]", ranges: []rune{'0', '9'}, ignoreCase: false, @@ -790,7 +790,7 @@ var g = &grammar{ }, }, &anyMatcher{ - line: 89, col: 12, offset: 2525, + line: 89, col: 12, offset: 2485, }, }, }, @@ -801,26 +801,26 @@ var g = &grammar{ }, { name: "ErrOtherOuter04", - pos: position{line: 91, col: 1, offset: 2551}, + pos: position{line: 91, col: 1, offset: 2511}, expr: &actionExpr{ - pos: position{line: 91, col: 19, offset: 2569}, + pos: position{line: 91, col: 19, offset: 2529}, run: (*parser).callonErrOtherOuter041, expr: &seqExpr{ - pos: position{line: 91, col: 19, offset: 2569}, - exprs: []interface{}{ + pos: position{line: 91, col: 19, offset: 2529}, + exprs: []any{ &andCodeExpr{ - pos: position{line: 91, col: 19, offset: 2569}, + pos: position{line: 91, col: 19, offset: 2529}, run: (*parser).callonErrOtherOuter043, }, &zeroOrMoreExpr{ - pos: position{line: 93, col: 3, offset: 2640}, + pos: position{line: 93, col: 3, offset: 2600}, expr: &seqExpr{ - pos: position{line: 93, col: 5, offset: 2642}, - exprs: []interface{}{ + pos: position{line: 93, col: 5, offset: 2602}, + exprs: []any{ ¬Expr{ - pos: position{line: 93, col: 5, offset: 2642}, + pos: position{line: 93, col: 5, offset: 2602}, expr: &charClassMatcher{ - pos: position{line: 93, col: 6, offset: 2643}, + pos: position{line: 93, col: 6, offset: 2603}, val: "[0-9]", ranges: []rune{'0', '9'}, ignoreCase: false, @@ -828,7 +828,7 @@ var g = &grammar{ }, }, &anyMatcher{ - line: 93, col: 12, offset: 2649, + line: 93, col: 12, offset: 2609, }, }, }, @@ -840,44 +840,44 @@ var g = &grammar{ }, } -func (c *current) oncase011(case01 interface{}) (interface{}, error) { +func (c *current) oncase011(case01 any) (any, error) { return case01, nil } -func (p *parser) calloncase011() (interface{}, error) { +func (p *parser) calloncase011() (any, error) { stack := p.vstack[len(p.vstack)-1] _ = stack return p.cur.oncase011(stack["case01"]) } -func (c *current) onnumber4(d, n interface{}) (interface{}, error) { +func (c *current) onnumber4(d, n any) (any, error) { if n == nil { return d.(string), nil } return d.(string) + n.(string), nil } -func (p *parser) callonnumber4() (interface{}, error) { +func (p *parser) callonnumber4() (any, error) { stack := p.vstack[len(p.vstack)-1] _ = stack return p.cur.onnumber4(stack["d"], stack["n"]) } -func (c *current) ondigit2() (interface{}, error) { +func (c *current) ondigit2() (any, error) { return string(c.text), nil } -func (p *parser) callondigit2() (interface{}, error) { +func (p *parser) callondigit2() (any, error) { stack := p.vstack[len(p.vstack)-1] _ = stack return p.cur.ondigit2() } -func (c *current) ondigit4(x interface{}) (interface{}, error) { - return x.([]interface{})[1], nil +func (c *current) ondigit4(x any) (any, error) { + return x.([]any)[1], nil } -func (p *parser) callondigit4() (interface{}, error) { +func (p *parser) callondigit4() (any, error) { stack := p.vstack[len(p.vstack)-1] _ = stack return p.cur.ondigit4(stack["x"]) @@ -893,11 +893,11 @@ func (p *parser) callonErrNonNumber3() (bool, error) { return p.cur.onErrNonNumber3() } -func (c *current) onErrNonNumber1() (interface{}, error) { +func (c *current) onErrNonNumber1() (any, error) { return "?", nil } -func (p *parser) callonErrNonNumber1() (interface{}, error) { +func (p *parser) callonErrNonNumber1() (any, error) { stack := p.vstack[len(p.vstack)-1] _ = stack return p.cur.onErrNonNumber1() @@ -913,54 +913,54 @@ func (p *parser) calloncase025() (bool, error) { return p.cur.oncase025() } -func (c *current) oncase031(case03 interface{}) (interface{}, error) { +func (c *current) oncase031(case03 any) (any, error) { return case03, nil } -func (p *parser) calloncase031() (interface{}, error) { +func (p *parser) calloncase031() (any, error) { stack := p.vstack[len(p.vstack)-1] _ = stack return p.cur.oncase031(stack["case03"]) } -func (c *current) onnumber034(d, n interface{}) (interface{}, error) { +func (c *current) onnumber034(d, n any) (any, error) { if n == nil { return d.(string), nil } return d.(string) + n.(string), nil } -func (p *parser) callonnumber034() (interface{}, error) { +func (p *parser) callonnumber034() (any, error) { stack := p.vstack[len(p.vstack)-1] _ = stack return p.cur.onnumber034(stack["d"], stack["n"]) } -func (c *current) ondigit032() (interface{}, error) { +func (c *current) ondigit032() (any, error) { return string(c.text), nil } -func (p *parser) callondigit032() (interface{}, error) { +func (p *parser) callondigit032() (any, error) { stack := p.vstack[len(p.vstack)-1] _ = stack return p.cur.ondigit032() } -func (c *current) ondigit034(x interface{}) (interface{}, error) { - return x.([]interface{})[1], nil +func (c *current) ondigit034(x any) (any, error) { + return x.([]any)[1], nil } -func (p *parser) callondigit034() (interface{}, error) { +func (p *parser) callondigit034() (any, error) { stack := p.vstack[len(p.vstack)-1] _ = stack return p.cur.ondigit034(stack["x"]) } -func (c *current) ondigit0310(x interface{}) (interface{}, error) { - return x.([]interface{})[1], nil +func (c *current) ondigit0310(x any) (any, error) { + return x.([]any)[1], nil } -func (p *parser) callondigit0310() (interface{}, error) { +func (p *parser) callondigit0310() (any, error) { stack := p.vstack[len(p.vstack)-1] _ = stack return p.cur.ondigit0310(stack["x"]) @@ -976,11 +976,11 @@ func (p *parser) callonErrAlphaInner033() (bool, error) { return p.cur.onErrAlphaInner033() } -func (c *current) onErrAlphaInner031() (interface{}, error) { +func (c *current) onErrAlphaInner031() (any, error) { return "<", nil } -func (p *parser) callonErrAlphaInner031() (interface{}, error) { +func (p *parser) callonErrAlphaInner031() (any, error) { stack := p.vstack[len(p.vstack)-1] _ = stack return p.cur.onErrAlphaInner031() @@ -996,11 +996,11 @@ func (p *parser) callonErrAlphaOuter033() (bool, error) { return p.cur.onErrAlphaOuter033() } -func (c *current) onErrAlphaOuter031() (interface{}, error) { +func (c *current) onErrAlphaOuter031() (any, error) { return ">", nil } -func (p *parser) callonErrAlphaOuter031() (interface{}, error) { +func (p *parser) callonErrAlphaOuter031() (any, error) { stack := p.vstack[len(p.vstack)-1] _ = stack return p.cur.onErrAlphaOuter031() @@ -1016,64 +1016,64 @@ func (p *parser) callonErrOtherOuter033() (bool, error) { return p.cur.onErrOtherOuter033() } -func (c *current) onErrOtherOuter031() (interface{}, error) { +func (c *current) onErrOtherOuter031() (any, error) { return "?", nil } -func (p *parser) callonErrOtherOuter031() (interface{}, error) { +func (p *parser) callonErrOtherOuter031() (any, error) { stack := p.vstack[len(p.vstack)-1] _ = stack return p.cur.onErrOtherOuter031() } -func (c *current) oncase041(case04 interface{}) (interface{}, error) { +func (c *current) oncase041(case04 any) (any, error) { return case04, nil } -func (p *parser) calloncase041() (interface{}, error) { +func (p *parser) calloncase041() (any, error) { stack := p.vstack[len(p.vstack)-1] _ = stack return p.cur.oncase041(stack["case04"]) } -func (c *current) onnumber044(d, n interface{}) (interface{}, error) { +func (c *current) onnumber044(d, n any) (any, error) { if n == nil { return d.(string), nil } return d.(string) + n.(string), nil } -func (p *parser) callonnumber044() (interface{}, error) { +func (p *parser) callonnumber044() (any, error) { stack := p.vstack[len(p.vstack)-1] _ = stack return p.cur.onnumber044(stack["d"], stack["n"]) } -func (c *current) ondigit042() (interface{}, error) { +func (c *current) ondigit042() (any, error) { return string(c.text), nil } -func (p *parser) callondigit042() (interface{}, error) { +func (p *parser) callondigit042() (any, error) { stack := p.vstack[len(p.vstack)-1] _ = stack return p.cur.ondigit042() } -func (c *current) ondigit044(x interface{}) (interface{}, error) { - return x.([]interface{})[1], nil +func (c *current) ondigit044(x any) (any, error) { + return x.([]any)[1], nil } -func (p *parser) callondigit044() (interface{}, error) { +func (p *parser) callondigit044() (any, error) { stack := p.vstack[len(p.vstack)-1] _ = stack return p.cur.ondigit044(stack["x"]) } -func (c *current) ondigit0410(x interface{}) (interface{}, error) { - return x.([]interface{})[1], nil +func (c *current) ondigit0410(x any) (any, error) { + return x.([]any)[1], nil } -func (p *parser) callondigit0410() (interface{}, error) { +func (p *parser) callondigit0410() (any, error) { stack := p.vstack[len(p.vstack)-1] _ = stack return p.cur.ondigit0410(stack["x"]) @@ -1099,11 +1099,11 @@ func (p *parser) callonErrAlphaOuter043() (bool, error) { return p.cur.onErrAlphaOuter043() } -func (c *current) onErrAlphaOuter041() (interface{}, error) { +func (c *current) onErrAlphaOuter041() (any, error) { return "x", nil } -func (p *parser) callonErrAlphaOuter041() (interface{}, error) { +func (p *parser) callonErrAlphaOuter041() (any, error) { stack := p.vstack[len(p.vstack)-1] _ = stack return p.cur.onErrAlphaOuter041() @@ -1119,11 +1119,11 @@ func (p *parser) callonErrOtherOuter043() (bool, error) { return p.cur.onErrOtherOuter043() } -func (c *current) onErrOtherOuter041() (interface{}, error) { +func (c *current) onErrOtherOuter041() (any, error) { return "?", nil } -func (p *parser) callonErrOtherOuter041() (interface{}, error) { +func (p *parser) callonErrOtherOuter041() (any, error) { stack := p.vstack[len(p.vstack)-1] _ = stack return p.cur.onErrOtherOuter041() @@ -1267,7 +1267,7 @@ func Recover(b bool) Option { // GlobalStore creates an Option to set a key to a certain value in // the globalStore. -func GlobalStore(key string, value interface{}) Option { +func GlobalStore(key string, value any) Option { return func(p *parser) Option { old := p.cur.globalStore[key] p.cur.globalStore[key] = value @@ -1277,7 +1277,7 @@ func GlobalStore(key string, value interface{}) Option { // InitState creates an Option to set a key to a certain value in // the global "state" store. -func InitState(key string, value interface{}) Option { +func InitState(key string, value any) Option { return func(p *parser) Option { old := p.cur.state[key] p.cur.state[key] = value @@ -1286,7 +1286,7 @@ func InitState(key string, value interface{}) Option { } // ParseFile parses the file identified by filename. -func ParseFile(filename string, opts ...Option) (i interface{}, err error) { // nolint: deadcode +func ParseFile(filename string, opts ...Option) (i any, err error) { // nolint: deadcode f, err := os.Open(filename) if err != nil { return nil, err @@ -1301,7 +1301,7 @@ func ParseFile(filename string, opts ...Option) (i interface{}, err error) { // // ParseReader parses the data from r using filename as information in the // error messages. -func ParseReader(filename string, r io.Reader, opts ...Option) (interface{}, error) { // nolint: deadcode +func ParseReader(filename string, r io.Reader, opts ...Option) (any, error) { // nolint: deadcode b, err := io.ReadAll(r) if err != nil { return nil, err @@ -1312,7 +1312,7 @@ func ParseReader(filename string, r io.Reader, opts ...Option) (interface{}, err // Parse parses the data from b using filename as information in the // error messages. -func Parse(filename string, b []byte, opts ...Option) (interface{}, error) { +func Parse(filename string, b []byte, opts ...Option) (any, error) { return newParser(filename, b, opts...).parse(g) } @@ -1350,7 +1350,7 @@ type current struct { globalStore storeDict } -type storeDict map[string]interface{} +type storeDict map[string]any // the AST types... @@ -1365,34 +1365,34 @@ type rule struct { pos position name string displayName string - expr interface{} + expr any } // nolint: structcheck type choiceExpr struct { pos position - alternatives []interface{} + alternatives []any } // nolint: structcheck type actionExpr struct { pos position - expr interface{} - run func(*parser) (interface{}, error) + expr any + run func(*parser) (any, error) } // nolint: structcheck type recoveryExpr struct { pos position - expr interface{} - recoverExpr interface{} + expr any + recoverExpr any failureLabel []string } // nolint: structcheck type seqExpr struct { pos position - exprs []interface{} + exprs []any } // nolint: structcheck @@ -1405,20 +1405,22 @@ type throwExpr struct { type labeledExpr struct { pos position label string - expr interface{} + expr any } // nolint: structcheck type expr struct { pos position - expr interface{} + expr any } -type andExpr expr // nolint: structcheck -type notExpr expr // nolint: structcheck -type zeroOrOneExpr expr // nolint: structcheck -type zeroOrMoreExpr expr // nolint: structcheck -type oneOrMoreExpr expr // nolint: structcheck +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 { @@ -1566,7 +1568,7 @@ func (p *parser) setOptions(opts []Option) { // nolint: structcheck,deadcode type resultTuple struct { - v interface{} + v any b bool end savepoint } @@ -1612,12 +1614,12 @@ type parser struct { memoize bool // memoization table for the packrat algorithm: // map[offset in source] map[expression or rule] {value, match} - memo map[int]map[interface{}]resultTuple + 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]interface{} + vstack []map[string]any // rule stack, allows identification of the current rule in errors rstack []*rule @@ -1637,7 +1639,7 @@ type parser struct { choiceNoMatch string // recovery expression stack, keeps track of the currently available recovery expression, these are traversed in reverse - recoveryStack []map[string]interface{} + recoveryStack []map[string]any } // push a variable set on the vstack. @@ -1657,7 +1659,7 @@ func (p *parser) pushV() { return } - m = make(map[string]interface{}) + m = make(map[string]any) p.vstack[len(p.vstack)-1] = m } @@ -1673,7 +1675,7 @@ func (p *parser) popV() { } // push a recovery expression with its labels to the recoveryStack -func (p *parser) pushRecovery(labels []string, expr interface{}) { +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) @@ -1682,7 +1684,7 @@ func (p *parser) pushRecovery(labels []string, expr interface{}) { p.recoveryStack = p.recoveryStack[:len(p.recoveryStack)+1] } - m := make(map[string]interface{}, len(labels)) + m := make(map[string]any, len(labels)) for _, fl := range labels { m[fl] = expr } @@ -1802,11 +1804,11 @@ func (p *parser) restore(pt savepoint) { // copies of the state to allow the parser to properly restore the state in // the case of backtracking. type Cloner interface { - Clone() interface{} + Clone() any } var statePool = &sync.Pool{ - New: func() interface{} { return make(storeDict) }, + New: func() any { return make(storeDict) }, } func (sd storeDict) Discard() { @@ -1848,7 +1850,7 @@ func (p *parser) sliceFrom(start savepoint) []byte { return p.data[start.position.offset:p.pt.position.offset] } -func (p *parser) getMemoized(node interface{}) (resultTuple, bool) { +func (p *parser) getMemoized(node any) (resultTuple, bool) { if len(p.memo) == 0 { return resultTuple{}, false } @@ -1860,13 +1862,13 @@ func (p *parser) getMemoized(node interface{}) (resultTuple, bool) { return res, ok } -func (p *parser) setMemoized(pt savepoint, node interface{}, tuple resultTuple) { +func (p *parser) setMemoized(pt savepoint, node any, tuple resultTuple) { if p.memo == nil { - p.memo = make(map[int]map[interface{}]resultTuple) + p.memo = make(map[int]map[any]resultTuple) } m := p.memo[pt.offset] if m == nil { - m = make(map[interface{}]resultTuple) + m = make(map[any]resultTuple) p.memo[pt.offset] = m } m[node] = tuple @@ -1880,7 +1882,7 @@ func (p *parser) buildRulesTable(g *grammar) { } // nolint: gocyclo -func (p *parser) parse(g *grammar) (val interface{}, err error) { +func (p *parser) parse(g *grammar) (val any, err error) { if len(g.rules) == 0 { p.addErr(errNoRule) return nil, p.errs.err() @@ -1957,7 +1959,7 @@ func listJoin(list []string, sep string, lastSep string) string { } } -func (p *parser) parseRule(rule *rule) (interface{}, bool) { +func (p *parser) parseRule(rule *rule) (any, bool) { if p.debug { defer p.out(p.in("parseRule " + rule.name)) } @@ -1987,7 +1989,7 @@ func (p *parser) parseRule(rule *rule) (interface{}, bool) { } // nolint: gocyclo -func (p *parser) parseExpr(expr interface{}) (interface{}, bool) { +func (p *parser) parseExpr(expr any) (any, bool) { var pt savepoint if p.memoize { @@ -2004,7 +2006,7 @@ func (p *parser) parseExpr(expr interface{}) (interface{}, bool) { panic(errMaxExprCnt) } - var val interface{} + var val any var ok bool switch expr := expr.(type) { case *actionExpr: @@ -2052,7 +2054,7 @@ func (p *parser) parseExpr(expr interface{}) (interface{}, bool) { return val, ok } -func (p *parser) parseActionExpr(act *actionExpr) (interface{}, bool) { +func (p *parser) parseActionExpr(act *actionExpr) (any, bool) { if p.debug { defer p.out(p.in("parseActionExpr")) } @@ -2077,7 +2079,7 @@ func (p *parser) parseActionExpr(act *actionExpr) (interface{}, bool) { return val, ok } -func (p *parser) parseAndCodeExpr(and *andCodeExpr) (interface{}, bool) { +func (p *parser) parseAndCodeExpr(and *andCodeExpr) (any, bool) { if p.debug { defer p.out(p.in("parseAndCodeExpr")) } @@ -2093,7 +2095,7 @@ func (p *parser) parseAndCodeExpr(and *andCodeExpr) (interface{}, bool) { return nil, ok } -func (p *parser) parseAndExpr(and *andExpr) (interface{}, bool) { +func (p *parser) parseAndExpr(and *andExpr) (any, bool) { if p.debug { defer p.out(p.in("parseAndExpr")) } @@ -2109,7 +2111,7 @@ func (p *parser) parseAndExpr(and *andExpr) (interface{}, bool) { return nil, ok } -func (p *parser) parseAnyMatcher(any *anyMatcher) (interface{}, bool) { +func (p *parser) parseAnyMatcher(any *anyMatcher) (any, bool) { if p.debug { defer p.out(p.in("parseAnyMatcher")) } @@ -2126,7 +2128,7 @@ func (p *parser) parseAnyMatcher(any *anyMatcher) (interface{}, bool) { } // nolint: gocyclo -func (p *parser) parseCharClassMatcher(chr *charClassMatcher) (interface{}, bool) { +func (p *parser) parseCharClassMatcher(chr *charClassMatcher) (any, bool) { if p.debug { defer p.out(p.in("parseCharClassMatcher")) } @@ -2207,7 +2209,7 @@ func (p *parser) incChoiceAltCnt(ch *choiceExpr, altI int) { m[alt]++ } -func (p *parser) parseChoiceExpr(ch *choiceExpr) (interface{}, bool) { +func (p *parser) parseChoiceExpr(ch *choiceExpr) (any, bool) { if p.debug { defer p.out(p.in("parseChoiceExpr")) } @@ -2231,7 +2233,7 @@ func (p *parser) parseChoiceExpr(ch *choiceExpr) (interface{}, bool) { return nil, false } -func (p *parser) parseLabeledExpr(lab *labeledExpr) (interface{}, bool) { +func (p *parser) parseLabeledExpr(lab *labeledExpr) (any, bool) { if p.debug { defer p.out(p.in("parseLabeledExpr")) } @@ -2246,7 +2248,7 @@ func (p *parser) parseLabeledExpr(lab *labeledExpr) (interface{}, bool) { return val, ok } -func (p *parser) parseLitMatcher(lit *litMatcher) (interface{}, bool) { +func (p *parser) parseLitMatcher(lit *litMatcher) (any, bool) { if p.debug { defer p.out(p.in("parseLitMatcher")) } @@ -2268,7 +2270,7 @@ func (p *parser) parseLitMatcher(lit *litMatcher) (interface{}, bool) { return p.sliceFrom(start), true } -func (p *parser) parseNotCodeExpr(not *notCodeExpr) (interface{}, bool) { +func (p *parser) parseNotCodeExpr(not *notCodeExpr) (any, bool) { if p.debug { defer p.out(p.in("parseNotCodeExpr")) } @@ -2284,7 +2286,7 @@ func (p *parser) parseNotCodeExpr(not *notCodeExpr) (interface{}, bool) { return nil, !ok } -func (p *parser) parseNotExpr(not *notExpr) (interface{}, bool) { +func (p *parser) parseNotExpr(not *notExpr) (any, bool) { if p.debug { defer p.out(p.in("parseNotExpr")) } @@ -2302,12 +2304,12 @@ func (p *parser) parseNotExpr(not *notExpr) (interface{}, bool) { return nil, !ok } -func (p *parser) parseOneOrMoreExpr(expr *oneOrMoreExpr) (interface{}, bool) { +func (p *parser) parseOneOrMoreExpr(expr *oneOrMoreExpr) (any, bool) { if p.debug { defer p.out(p.in("parseOneOrMoreExpr")) } - var vals []interface{} + var vals []any for { p.pushV() @@ -2324,7 +2326,7 @@ func (p *parser) parseOneOrMoreExpr(expr *oneOrMoreExpr) (interface{}, bool) { } } -func (p *parser) parseRecoveryExpr(recover *recoveryExpr) (interface{}, bool) { +func (p *parser) parseRecoveryExpr(recover *recoveryExpr) (any, bool) { if p.debug { defer p.out(p.in("parseRecoveryExpr (" + strings.Join(recover.failureLabel, ",") + ")")) } @@ -2336,7 +2338,7 @@ func (p *parser) parseRecoveryExpr(recover *recoveryExpr) (interface{}, bool) { return val, ok } -func (p *parser) parseRuleRefExpr(ref *ruleRefExpr) (interface{}, bool) { +func (p *parser) parseRuleRefExpr(ref *ruleRefExpr) (any, bool) { if p.debug { defer p.out(p.in("parseRuleRefExpr " + ref.name)) } @@ -2353,12 +2355,12 @@ func (p *parser) parseRuleRefExpr(ref *ruleRefExpr) (interface{}, bool) { return p.parseRule(rule) } -func (p *parser) parseSeqExpr(seq *seqExpr) (interface{}, bool) { +func (p *parser) parseSeqExpr(seq *seqExpr) (any, bool) { if p.debug { defer p.out(p.in("parseSeqExpr")) } - vals := make([]interface{}, 0, len(seq.exprs)) + vals := make([]any, 0, len(seq.exprs)) pt := p.pt state := p.cloneState() @@ -2374,7 +2376,7 @@ func (p *parser) parseSeqExpr(seq *seqExpr) (interface{}, bool) { return vals, true } -func (p *parser) parseStateCodeExpr(state *stateCodeExpr) (interface{}, bool) { +func (p *parser) parseStateCodeExpr(state *stateCodeExpr) (any, bool) { if p.debug { defer p.out(p.in("parseStateCodeExpr")) } @@ -2386,7 +2388,7 @@ func (p *parser) parseStateCodeExpr(state *stateCodeExpr) (interface{}, bool) { return nil, true } -func (p *parser) parseThrowExpr(expr *throwExpr) (interface{}, bool) { +func (p *parser) parseThrowExpr(expr *throwExpr) (any, bool) { if p.debug { defer p.out(p.in("parseThrowExpr")) } @@ -2402,12 +2404,12 @@ func (p *parser) parseThrowExpr(expr *throwExpr) (interface{}, bool) { return nil, false } -func (p *parser) parseZeroOrMoreExpr(expr *zeroOrMoreExpr) (interface{}, bool) { +func (p *parser) parseZeroOrMoreExpr(expr *zeroOrMoreExpr) (any, bool) { if p.debug { defer p.out(p.in("parseZeroOrMoreExpr")) } - var vals []interface{} + var vals []any for { p.pushV() @@ -2420,7 +2422,7 @@ func (p *parser) parseZeroOrMoreExpr(expr *zeroOrMoreExpr) (interface{}, bool) { } } -func (p *parser) parseZeroOrOneExpr(expr *zeroOrOneExpr) (interface{}, bool) { +func (p *parser) parseZeroOrOneExpr(expr *zeroOrOneExpr) (any, bool) { if p.debug { defer p.out(p.in("parseZeroOrOneExpr")) } diff --git a/test/thrownrecover/thrownrecover.peg b/test/thrownrecover/thrownrecover.peg index 77d5b14d..37292519 100644 --- a/test/thrownrecover/thrownrecover.peg +++ b/test/thrownrecover/thrownrecover.peg @@ -19,7 +19,7 @@ number = !. / d:digit n:number { return d.(string) + n.(string), nil } -digit = [0-9] { return string(c.text), nil } / x:( &[a-z] %{errAlpha} ) { return x.([]interface{})[1], nil } / %{errOther} +digit = [0-9] { return string(c.text), nil } / x:( &[a-z] %{errAlpha} ) { return x.([]any)[1], nil } / %{errOther} ErrNonNumber = &{ return true, errors.New("expecting a number") @@ -48,7 +48,7 @@ number03 = !. / d:digit03 n:number03 { return d.(string) + n.(string), nil } -digit03 = [0-9] { return string(c.text), nil } / x:( &[a-z] %{errAlphaLower} ) { return x.([]interface{})[1], nil } / x:( &[A-Z] %{errAlphaUpper} ) { return x.([]interface{})[1], nil } / %{errOther} +digit03 = [0-9] { return string(c.text), nil } / x:( &[a-z] %{errAlphaLower} ) { return x.([]any)[1], nil } / x:( &[A-Z] %{errAlphaUpper} ) { return x.([]any)[1], nil } / %{errOther} ErrAlphaInner03 = &{ return true, errors.New("expecting a number, got lower case char") @@ -78,7 +78,7 @@ number04 = !. / d:digit04 n:number04 { return d.(string) + n.(string), nil } -digit04 = [0-9] { return string(c.text), nil } / x:( &[a-z] %{errAlphaLower} ) { return x.([]interface{})[1], nil } / x:( &[A-Z] %{errAlphaUpper} ) { return x.([]interface{})[1], nil } / %{errOther} +digit04 = [0-9] { return string(c.text), nil } / x:( &[a-z] %{errAlphaLower} ) { return x.([]any)[1], nil } / x:( &[A-Z] %{errAlphaUpper} ) { return x.([]any)[1], nil } / %{errOther} ErrAlphaInner04 = &{ return false, nil diff --git a/test/thrownrecover/thrownrecover_test.go b/test/thrownrecover/thrownrecover_test.go index 3b4d8fde..2833df4e 100644 --- a/test/thrownrecover/thrownrecover_test.go +++ b/test/thrownrecover/thrownrecover_test.go @@ -8,7 +8,7 @@ import ( func TestThrowAndRecover(t *testing.T) { cases := []struct { input string - captures interface{} + captures any errors []string }{ // Case 01: Recover multiple labels diff --git a/unicode_classes.go b/unicode_classes.go index 36001562..868f9c3a 100644 --- a/unicode_classes.go +++ b/unicode_classes.go @@ -4,118 +4,118 @@ package main var unicodeClasses = map[string]bool{ - "ASCII_Hex_Digit": true, - "Arabic": true, - "Armenian": true, - "Avestan": true, - "Balinese": true, - "Bamum": true, - "Bassa_Vah": true, - "Batak": true, - "Bengali": true, - "Bidi_Control": true, - "Bopomofo": true, - "Brahmi": true, - "Braille": true, - "Buginese": true, - "Buhid": true, - "C": true, - "Canadian_Aboriginal": true, - "Carian": true, - "Caucasian_Albanian": true, - "Cc": true, - "Cf": true, - "Chakma": true, - "Cham": true, - "Cherokee": true, - "Co": true, - "Common": true, - "Coptic": true, - "Cs": true, - "Cuneiform": true, - "Cypriot": true, - "Cyrillic": true, - "Dash": true, - "Deprecated": true, - "Deseret": true, - "Devanagari": true, - "Diacritic": true, - "Duployan": true, - "Egyptian_Hieroglyphs": true, - "Elbasan": true, - "Ethiopic": true, - "Extender": true, - "Georgian": true, - "Glagolitic": true, - "Gothic": true, - "Grantha": true, - "Greek": true, - "Gujarati": true, - "Gurmukhi": true, - "Han": true, - "Hangul": true, - "Hanunoo": true, - "Hebrew": true, - "Hex_Digit": true, - "Hiragana": true, - "Hyphen": true, - "IDS_Binary_Operator": true, - "IDS_Trinary_Operator": true, - "Ideographic": true, - "Imperial_Aramaic": true, - "Inherited": true, - "Inscriptional_Pahlavi": true, - "Inscriptional_Parthian": true, - "Javanese": true, - "Join_Control": true, - "Kaithi": true, - "Kannada": true, - "Katakana": true, - "Kayah_Li": true, - "Kharoshthi": true, - "Khmer": true, - "Khojki": true, - "Khudawadi": true, - "L": true, - "Lao": true, - "Latin": true, - "Lepcha": true, - "Limbu": true, - "Linear_A": true, - "Linear_B": true, - "Lisu": true, - "Ll": true, - "Lm": true, - "Lo": true, - "Logical_Order_Exception": true, - "Lt": true, - "Lu": true, - "Lycian": true, - "Lydian": true, - "M": true, - "Mahajani": true, - "Malayalam": true, - "Mandaic": true, - "Manichaean": true, - "Mc": true, - "Me": true, - "Meetei_Mayek": true, - "Mende_Kikakui": true, - "Meroitic_Cursive": true, - "Meroitic_Hieroglyphs": true, - "Miao": true, - "Mn": true, - "Modi": true, - "Mongolian": true, - "Mro": true, - "Myanmar": true, - "N": true, - "Nabataean": true, - "Nd": true, - "New_Tai_Lue": true, - "Nko": true, - "Nl": true, - "No": true, + "ASCII_Hex_Digit": true, + "Arabic": true, + "Armenian": true, + "Avestan": true, + "Balinese": true, + "Bamum": true, + "Bassa_Vah": true, + "Batak": true, + "Bengali": true, + "Bidi_Control": true, + "Bopomofo": true, + "Brahmi": true, + "Braille": true, + "Buginese": true, + "Buhid": true, + "C": true, + "Canadian_Aboriginal": true, + "Carian": true, + "Caucasian_Albanian": true, + "Cc": true, + "Cf": true, + "Chakma": true, + "Cham": true, + "Cherokee": true, + "Co": true, + "Common": true, + "Coptic": true, + "Cs": true, + "Cuneiform": true, + "Cypriot": true, + "Cyrillic": true, + "Dash": true, + "Deprecated": true, + "Deseret": true, + "Devanagari": true, + "Diacritic": true, + "Duployan": true, + "Egyptian_Hieroglyphs": true, + "Elbasan": true, + "Ethiopic": true, + "Extender": true, + "Georgian": true, + "Glagolitic": true, + "Gothic": true, + "Grantha": true, + "Greek": true, + "Gujarati": true, + "Gurmukhi": true, + "Han": true, + "Hangul": true, + "Hanunoo": true, + "Hebrew": true, + "Hex_Digit": true, + "Hiragana": true, + "Hyphen": true, + "IDS_Binary_Operator": true, + "IDS_Trinary_Operator": true, + "Ideographic": true, + "Imperial_Aramaic": true, + "Inherited": true, + "Inscriptional_Pahlavi": true, + "Inscriptional_Parthian": true, + "Javanese": true, + "Join_Control": true, + "Kaithi": true, + "Kannada": true, + "Katakana": true, + "Kayah_Li": true, + "Kharoshthi": true, + "Khmer": true, + "Khojki": true, + "Khudawadi": true, + "L": true, + "Lao": true, + "Latin": true, + "Lepcha": true, + "Limbu": true, + "Linear_A": true, + "Linear_B": true, + "Lisu": true, + "Ll": true, + "Lm": true, + "Lo": true, + "Logical_Order_Exception": true, + "Lt": true, + "Lu": true, + "Lycian": true, + "Lydian": true, + "M": true, + "Mahajani": true, + "Malayalam": true, + "Mandaic": true, + "Manichaean": true, + "Mc": true, + "Me": true, + "Meetei_Mayek": true, + "Mende_Kikakui": true, + "Meroitic_Cursive": true, + "Meroitic_Hieroglyphs": true, + "Miao": true, + "Mn": true, + "Modi": true, + "Mongolian": true, + "Mro": true, + "Myanmar": true, + "N": true, + "Nabataean": true, + "Nd": true, + "New_Tai_Lue": true, + "Nko": true, + "Nl": true, + "No": true, "Noncharacter_Code_Point": true, "Ogham": true, "Ol_Chiki": true,