From 93550b0420710791a315a668dd8990622db556a5 Mon Sep 17 00:00:00 2001 From: Elara6331 Date: Wed, 7 Feb 2024 18:27:08 -0800 Subject: [PATCH] Add the ability to ignore errors in ExprTags --- README.md | 14 + ast/ast.go | 5 +- examples/readme/readme.salix.html | 2 +- parser/parser.go | 647 ++++++++++++++++-------------- parser/salix.peg | 9 +- salix.go | 6 +- 6 files changed, 365 insertions(+), 318 deletions(-) diff --git a/README.md b/README.md index fdca171..e6f8041 100644 --- a/README.md +++ b/README.md @@ -26,6 +26,7 @@ Salix's syntax is similar to Leaf and (in my opinion at least), it's much more f - [Global Functions](#global-functions) - [Adding Custom Functions](#adding-custom-functions) - [Expressions](#expressions) + - [Ignoring errors](#ignoring-errors) - [Ternary Expressions](#ternary-expressions) - [Coalescing operator](#coalescing-operator) - [The `in` operator](#the-in-operator) @@ -189,6 +190,19 @@ You can include custom functions as variables using the WithVarMap method on tem Salix's expressions mostly work like Go's, but there are some extra features worth mentioning. +### Ignoring errors + +If you'd like to ignore errors in an expression tag, you can do that by adding a question mark at the end. + + +```html + +#(example.Example()) + + +#(example.Example())? +``` + ### Ternary Expressions Salix supports ternary expressions, which allow you to choose a value based on whether a condition is true. For example: diff --git a/ast/ast.go b/ast/ast.go index 293a801..70aafa7 100644 --- a/ast/ast.go +++ b/ast/ast.go @@ -32,8 +32,9 @@ func (t Tag) Pos() Position { } type ExprTag struct { - Value Node - Position Position + Value Node + IgnoreError bool + Position Position } func (et ExprTag) Pos() Position { diff --git a/examples/readme/readme.salix.html b/examples/readme/readme.salix.html index f9b313b..131e122 100644 --- a/examples/readme/readme.salix.html +++ b/examples/readme/readme.salix.html @@ -13,4 +13,4 @@ #!for - \ No newline at end of file + diff --git a/parser/parser.go b/parser/parser.go index f881757..411f4ab 100644 --- a/parser/parser.go +++ b/parser/parser.go @@ -63,58 +63,58 @@ var g = &grammar{ rules: []*rule{ { name: "Root", - pos: position{line: 71, col: 1, offset: 1729}, + pos: position{line: 53, col: 1, offset: 1001}, expr: &actionExpr{ - pos: position{line: 71, col: 8, offset: 1736}, + pos: position{line: 53, col: 8, offset: 1008}, run: (*parser).callonRoot1, expr: &labeledExpr{ - pos: position{line: 71, col: 8, offset: 1736}, + pos: position{line: 53, col: 8, offset: 1008}, label: "items", expr: &zeroOrMoreExpr{ - pos: position{line: 71, col: 14, offset: 1742}, + pos: position{line: 53, col: 14, offset: 1014}, expr: &choiceExpr{ - pos: position{line: 71, col: 15, offset: 1743}, + pos: position{line: 53, col: 15, offset: 1015}, alternatives: []any{ &ruleRefExpr{ - pos: position{line: 71, col: 15, offset: 1743}, + pos: position{line: 53, col: 15, offset: 1015}, name: "Tag", }, &ruleRefExpr{ - pos: position{line: 71, col: 21, offset: 1749}, + pos: position{line: 53, col: 21, offset: 1021}, name: "ExprTag", }, &actionExpr{ - pos: position{line: 89, col: 10, offset: 2183}, + pos: position{line: 71, col: 10, offset: 1482}, run: (*parser).callonRoot7, expr: &seqExpr{ - pos: position{line: 89, col: 10, offset: 2183}, + pos: position{line: 71, col: 10, offset: 1482}, exprs: []any{ &litMatcher{ - pos: position{line: 89, col: 10, offset: 2183}, + pos: position{line: 71, col: 10, offset: 1482}, val: "#!", ignoreCase: false, want: "\"#!\"", }, &labeledExpr{ - pos: position{line: 89, col: 15, offset: 2188}, + pos: position{line: 71, col: 15, offset: 1487}, label: "name", expr: &actionExpr{ - pos: position{line: 191, col: 9, offset: 4770}, + pos: position{line: 174, col: 9, offset: 4129}, run: (*parser).callonRoot11, expr: &seqExpr{ - pos: position{line: 191, col: 9, offset: 4770}, + pos: position{line: 174, col: 9, offset: 4129}, exprs: []any{ &charClassMatcher{ - pos: position{line: 191, col: 9, offset: 4770}, + pos: position{line: 174, col: 9, offset: 4129}, val: "[a-z]i", ranges: []rune{'a', 'z'}, ignoreCase: true, inverted: false, }, &zeroOrMoreExpr{ - pos: position{line: 191, col: 16, offset: 4777}, + pos: position{line: 174, col: 16, offset: 4136}, expr: &charClassMatcher{ - pos: position{line: 191, col: 16, offset: 4777}, + pos: position{line: 174, col: 16, offset: 4136}, val: "[_a-z0-9]i", chars: []rune{'_'}, ranges: []rune{'a', 'z', '0', '9'}, @@ -130,18 +130,18 @@ var g = &grammar{ }, }, &actionExpr{ - pos: position{line: 267, col: 8, offset: 6415}, + pos: position{line: 250, col: 8, offset: 5774}, run: (*parser).callonRoot16, expr: &seqExpr{ - pos: position{line: 267, col: 8, offset: 6415}, + pos: position{line: 250, col: 8, offset: 5774}, exprs: []any{ &anyMatcher{ - line: 267, col: 8, offset: 6415, + line: 250, col: 8, offset: 5774, }, &zeroOrMoreExpr{ - pos: position{line: 267, col: 10, offset: 6417}, + pos: position{line: 250, col: 10, offset: 5776}, expr: &charClassMatcher{ - pos: position{line: 267, col: 10, offset: 6417}, + pos: position{line: 250, col: 10, offset: 5776}, val: "[^#]", chars: []rune{'#'}, ignoreCase: false, @@ -161,39 +161,39 @@ var g = &grammar{ }, { name: "Tag", - pos: position{line: 80, col: 1, offset: 1954}, + pos: position{line: 62, col: 1, offset: 1226}, expr: &actionExpr{ - pos: position{line: 80, col: 7, offset: 1960}, + pos: position{line: 62, col: 7, offset: 1232}, run: (*parser).callonTag1, expr: &seqExpr{ - pos: position{line: 80, col: 7, offset: 1960}, + pos: position{line: 62, col: 7, offset: 1232}, exprs: []any{ &litMatcher{ - pos: position{line: 80, col: 7, offset: 1960}, + pos: position{line: 62, col: 7, offset: 1232}, val: "#", ignoreCase: false, want: "\"#\"", }, &labeledExpr{ - pos: position{line: 80, col: 11, offset: 1964}, + pos: position{line: 62, col: 11, offset: 1236}, label: "name", expr: &actionExpr{ - pos: position{line: 191, col: 9, offset: 4770}, + pos: position{line: 174, col: 9, offset: 4129}, run: (*parser).callonTag5, expr: &seqExpr{ - pos: position{line: 191, col: 9, offset: 4770}, + pos: position{line: 174, col: 9, offset: 4129}, exprs: []any{ &charClassMatcher{ - pos: position{line: 191, col: 9, offset: 4770}, + pos: position{line: 174, col: 9, offset: 4129}, val: "[a-z]i", ranges: []rune{'a', 'z'}, ignoreCase: true, inverted: false, }, &zeroOrMoreExpr{ - pos: position{line: 191, col: 16, offset: 4777}, + pos: position{line: 174, col: 16, offset: 4136}, expr: &charClassMatcher{ - pos: position{line: 191, col: 16, offset: 4777}, + pos: position{line: 174, col: 16, offset: 4136}, val: "[_a-z0-9]i", chars: []rune{'_'}, ranges: []rune{'a', 'z', '0', '9'}, @@ -206,23 +206,36 @@ var g = &grammar{ }, }, &labeledExpr{ - pos: position{line: 80, col: 22, offset: 1975}, + pos: position{line: 62, col: 22, offset: 1247}, label: "params", expr: &zeroOrOneExpr{ - pos: position{line: 80, col: 29, offset: 1982}, + pos: position{line: 62, col: 29, offset: 1254}, expr: &ruleRefExpr{ - pos: position{line: 80, col: 29, offset: 1982}, + pos: position{line: 62, col: 29, offset: 1254}, name: "ParamList", }, }, }, &labeledExpr{ - pos: position{line: 80, col: 40, offset: 1993}, + pos: position{line: 62, col: 40, offset: 1265}, + label: "ignoreErr", + expr: &zeroOrOneExpr{ + pos: position{line: 62, col: 50, offset: 1275}, + expr: &litMatcher{ + pos: position{line: 62, col: 50, offset: 1275}, + val: "?", + ignoreCase: false, + want: "\"?\"", + }, + }, + }, + &labeledExpr{ + pos: position{line: 62, col: 55, offset: 1280}, label: "body", expr: &zeroOrOneExpr{ - pos: position{line: 80, col: 45, offset: 1998}, + pos: position{line: 62, col: 60, offset: 1285}, expr: &litMatcher{ - pos: position{line: 80, col: 45, offset: 1998}, + pos: position{line: 62, col: 60, offset: 1285}, val: ":", ignoreCase: false, want: "\":\"", @@ -237,33 +250,46 @@ var g = &grammar{ }, { name: "ExprTag", - pos: position{line: 96, col: 1, offset: 2303}, + pos: position{line: 78, col: 1, offset: 1602}, expr: &actionExpr{ - pos: position{line: 96, col: 11, offset: 2313}, + pos: position{line: 78, col: 11, offset: 1612}, run: (*parser).callonExprTag1, expr: &seqExpr{ - pos: position{line: 96, col: 11, offset: 2313}, + pos: position{line: 78, col: 11, offset: 1612}, exprs: []any{ &litMatcher{ - pos: position{line: 96, col: 11, offset: 2313}, + pos: position{line: 78, col: 11, offset: 1612}, val: "#(", ignoreCase: false, want: "\"#(\"", }, &labeledExpr{ - pos: position{line: 96, col: 16, offset: 2318}, + pos: position{line: 78, col: 16, offset: 1617}, label: "item", expr: &ruleRefExpr{ - pos: position{line: 96, col: 21, offset: 2323}, + pos: position{line: 78, col: 21, offset: 1622}, name: "Expr", }, }, &litMatcher{ - pos: position{line: 96, col: 26, offset: 2328}, + pos: position{line: 78, col: 26, offset: 1627}, val: ")", ignoreCase: false, want: "\")\"", }, + &labeledExpr{ + pos: position{line: 78, col: 30, offset: 1631}, + label: "ignoreErr", + expr: &zeroOrOneExpr{ + pos: position{line: 78, col: 40, offset: 1641}, + expr: &litMatcher{ + pos: position{line: 78, col: 40, offset: 1641}, + val: "?", + ignoreCase: false, + want: "\"?\"", + }, + }, + }, }, }, }, @@ -272,20 +298,20 @@ var g = &grammar{ }, { name: "Expr", - pos: position{line: 103, col: 1, offset: 2436}, + pos: position{line: 86, col: 1, offset: 1795}, expr: &choiceExpr{ - pos: position{line: 103, col: 8, offset: 2443}, + pos: position{line: 86, col: 8, offset: 1802}, alternatives: []any{ &ruleRefExpr{ - pos: position{line: 103, col: 8, offset: 2443}, + pos: position{line: 86, col: 8, offset: 1802}, name: "Ternary", }, &ruleRefExpr{ - pos: position{line: 103, col: 18, offset: 2453}, + pos: position{line: 86, col: 18, offset: 1812}, name: "Assignment", }, &ruleRefExpr{ - pos: position{line: 103, col: 31, offset: 2466}, + pos: position{line: 86, col: 31, offset: 1825}, name: "LogicalExpr", }, }, @@ -295,16 +321,16 @@ var g = &grammar{ }, { name: "Assignable", - pos: position{line: 104, col: 1, offset: 2478}, + pos: position{line: 87, col: 1, offset: 1837}, expr: &choiceExpr{ - pos: position{line: 104, col: 14, offset: 2491}, + pos: position{line: 87, col: 14, offset: 1850}, alternatives: []any{ &ruleRefExpr{ - pos: position{line: 104, col: 14, offset: 2491}, + pos: position{line: 87, col: 14, offset: 1850}, name: "Ternary", }, &ruleRefExpr{ - pos: position{line: 104, col: 24, offset: 2501}, + pos: position{line: 87, col: 24, offset: 1860}, name: "LogicalExpr", }, }, @@ -314,17 +340,17 @@ var g = &grammar{ }, { name: "LogicalExpr", - pos: position{line: 106, col: 1, offset: 2514}, + pos: position{line: 89, col: 1, offset: 1873}, expr: &actionExpr{ - pos: position{line: 106, col: 15, offset: 2528}, + pos: position{line: 89, col: 15, offset: 1887}, run: (*parser).callonLogicalExpr1, expr: &seqExpr{ - pos: position{line: 106, col: 15, offset: 2528}, + pos: position{line: 89, col: 15, offset: 1887}, exprs: []any{ &zeroOrMoreExpr{ - pos: position{line: 269, col: 18, offset: 6503}, + pos: position{line: 252, col: 18, offset: 5862}, expr: &charClassMatcher{ - pos: position{line: 269, col: 18, offset: 6503}, + pos: position{line: 252, col: 18, offset: 5862}, val: "[ \\t\\r\\n]", chars: []rune{' ', '\t', '\r', '\n'}, ignoreCase: false, @@ -332,25 +358,25 @@ var g = &grammar{ }, }, &labeledExpr{ - pos: position{line: 106, col: 17, offset: 2530}, + pos: position{line: 89, col: 17, offset: 1889}, label: "first", expr: &ruleRefExpr{ - pos: position{line: 106, col: 23, offset: 2536}, + pos: position{line: 89, col: 23, offset: 1895}, name: "ComparisonExpr", }, }, &labeledExpr{ - pos: position{line: 106, col: 38, offset: 2551}, + pos: position{line: 89, col: 38, offset: 1910}, label: "rest", expr: &zeroOrMoreExpr{ - pos: position{line: 106, col: 43, offset: 2556}, + pos: position{line: 89, col: 43, offset: 1915}, expr: &seqExpr{ - pos: position{line: 106, col: 44, offset: 2557}, + pos: position{line: 89, col: 44, offset: 1916}, exprs: []any{ &zeroOrMoreExpr{ - pos: position{line: 269, col: 18, offset: 6503}, + pos: position{line: 252, col: 18, offset: 5862}, expr: &charClassMatcher{ - pos: position{line: 269, col: 18, offset: 6503}, + pos: position{line: 252, col: 18, offset: 5862}, val: "[ \\t\\r\\n]", chars: []rune{' ', '\t', '\r', '\n'}, ignoreCase: false, @@ -358,19 +384,19 @@ var g = &grammar{ }, }, &actionExpr{ - pos: position{line: 246, col: 13, offset: 5974}, + pos: position{line: 229, col: 13, offset: 5333}, run: (*parser).callonLogicalExpr12, expr: &choiceExpr{ - pos: position{line: 246, col: 14, offset: 5975}, + pos: position{line: 229, col: 14, offset: 5334}, alternatives: []any{ &litMatcher{ - pos: position{line: 246, col: 14, offset: 5975}, + pos: position{line: 229, col: 14, offset: 5334}, val: "||", ignoreCase: false, want: "\"||\"", }, &litMatcher{ - pos: position{line: 246, col: 21, offset: 5982}, + pos: position{line: 229, col: 21, offset: 5341}, val: "&&", ignoreCase: false, want: "\"&&\"", @@ -379,9 +405,9 @@ var g = &grammar{ }, }, &zeroOrMoreExpr{ - pos: position{line: 269, col: 18, offset: 6503}, + pos: position{line: 252, col: 18, offset: 5862}, expr: &charClassMatcher{ - pos: position{line: 269, col: 18, offset: 6503}, + pos: position{line: 252, col: 18, offset: 5862}, val: "[ \\t\\r\\n]", chars: []rune{' ', '\t', '\r', '\n'}, ignoreCase: false, @@ -389,7 +415,7 @@ var g = &grammar{ }, }, &ruleRefExpr{ - pos: position{line: 106, col: 58, offset: 2571}, + pos: position{line: 89, col: 58, offset: 1930}, name: "ComparisonExpr", }, }, @@ -397,9 +423,9 @@ var g = &grammar{ }, }, &zeroOrMoreExpr{ - pos: position{line: 269, col: 18, offset: 6503}, + pos: position{line: 252, col: 18, offset: 5862}, expr: &charClassMatcher{ - pos: position{line: 269, col: 18, offset: 6503}, + pos: position{line: 252, col: 18, offset: 5862}, val: "[ \\t\\r\\n]", chars: []rune{' ', '\t', '\r', '\n'}, ignoreCase: false, @@ -414,17 +440,17 @@ var g = &grammar{ }, { name: "ComparisonExpr", - pos: position{line: 110, col: 1, offset: 2634}, + pos: position{line: 93, col: 1, offset: 1993}, expr: &actionExpr{ - pos: position{line: 110, col: 18, offset: 2651}, + pos: position{line: 93, col: 18, offset: 2010}, run: (*parser).callonComparisonExpr1, expr: &seqExpr{ - pos: position{line: 110, col: 18, offset: 2651}, + pos: position{line: 93, col: 18, offset: 2010}, exprs: []any{ &zeroOrMoreExpr{ - pos: position{line: 269, col: 18, offset: 6503}, + pos: position{line: 252, col: 18, offset: 5862}, expr: &charClassMatcher{ - pos: position{line: 269, col: 18, offset: 6503}, + pos: position{line: 252, col: 18, offset: 5862}, val: "[ \\t\\r\\n]", chars: []rune{' ', '\t', '\r', '\n'}, ignoreCase: false, @@ -432,25 +458,25 @@ var g = &grammar{ }, }, &labeledExpr{ - pos: position{line: 110, col: 20, offset: 2653}, + pos: position{line: 93, col: 20, offset: 2012}, label: "first", expr: &ruleRefExpr{ - pos: position{line: 110, col: 26, offset: 2659}, + pos: position{line: 93, col: 26, offset: 2018}, name: "ArithmeticExpr", }, }, &labeledExpr{ - pos: position{line: 110, col: 41, offset: 2674}, + pos: position{line: 93, col: 41, offset: 2033}, label: "rest", expr: &zeroOrMoreExpr{ - pos: position{line: 110, col: 46, offset: 2679}, + pos: position{line: 93, col: 46, offset: 2038}, expr: &seqExpr{ - pos: position{line: 110, col: 47, offset: 2680}, + pos: position{line: 93, col: 47, offset: 2039}, exprs: []any{ &zeroOrMoreExpr{ - pos: position{line: 269, col: 18, offset: 6503}, + pos: position{line: 252, col: 18, offset: 5862}, expr: &charClassMatcher{ - pos: position{line: 269, col: 18, offset: 6503}, + pos: position{line: 252, col: 18, offset: 5862}, val: "[ \\t\\r\\n]", chars: []rune{' ', '\t', '\r', '\n'}, ignoreCase: false, @@ -458,44 +484,44 @@ var g = &grammar{ }, }, &actionExpr{ - pos: position{line: 253, col: 16, offset: 6107}, + pos: position{line: 236, col: 16, offset: 5466}, run: (*parser).callonComparisonExpr12, expr: &choiceExpr{ - pos: position{line: 253, col: 17, offset: 6108}, + pos: position{line: 236, col: 17, offset: 5467}, alternatives: []any{ &litMatcher{ - pos: position{line: 253, col: 17, offset: 6108}, + pos: position{line: 236, col: 17, offset: 5467}, val: "==", ignoreCase: false, want: "\"==\"", }, &litMatcher{ - pos: position{line: 253, col: 24, offset: 6115}, + pos: position{line: 236, col: 24, offset: 5474}, val: "!=", ignoreCase: false, want: "\"!=\"", }, &litMatcher{ - pos: position{line: 253, col: 31, offset: 6122}, + pos: position{line: 236, col: 31, offset: 5481}, val: "<=", ignoreCase: false, want: "\"<=\"", }, &litMatcher{ - pos: position{line: 253, col: 38, offset: 6129}, + pos: position{line: 236, col: 38, offset: 5488}, val: ">=", ignoreCase: false, want: "\">=\"", }, &charClassMatcher{ - pos: position{line: 253, col: 45, offset: 6136}, + pos: position{line: 236, col: 45, offset: 5495}, val: "[<>]", chars: []rune{'<', '>'}, ignoreCase: false, inverted: false, }, &litMatcher{ - pos: position{line: 253, col: 57, offset: 6148}, + pos: position{line: 236, col: 57, offset: 5507}, val: "in", ignoreCase: true, want: "\"in\"i", @@ -504,9 +530,9 @@ var g = &grammar{ }, }, &zeroOrMoreExpr{ - pos: position{line: 269, col: 18, offset: 6503}, + pos: position{line: 252, col: 18, offset: 5862}, expr: &charClassMatcher{ - pos: position{line: 269, col: 18, offset: 6503}, + pos: position{line: 252, col: 18, offset: 5862}, val: "[ \\t\\r\\n]", chars: []rune{' ', '\t', '\r', '\n'}, ignoreCase: false, @@ -514,7 +540,7 @@ var g = &grammar{ }, }, &ruleRefExpr{ - pos: position{line: 110, col: 64, offset: 2697}, + pos: position{line: 93, col: 64, offset: 2056}, name: "ArithmeticExpr", }, }, @@ -522,9 +548,9 @@ var g = &grammar{ }, }, &zeroOrMoreExpr{ - pos: position{line: 269, col: 18, offset: 6503}, + pos: position{line: 252, col: 18, offset: 5862}, expr: &charClassMatcher{ - pos: position{line: 269, col: 18, offset: 6503}, + pos: position{line: 252, col: 18, offset: 5862}, val: "[ \\t\\r\\n]", chars: []rune{' ', '\t', '\r', '\n'}, ignoreCase: false, @@ -539,17 +565,17 @@ var g = &grammar{ }, { name: "ArithmeticExpr", - pos: position{line: 114, col: 1, offset: 2760}, + pos: position{line: 97, col: 1, offset: 2119}, expr: &actionExpr{ - pos: position{line: 114, col: 18, offset: 2777}, + pos: position{line: 97, col: 18, offset: 2136}, run: (*parser).callonArithmeticExpr1, expr: &seqExpr{ - pos: position{line: 114, col: 18, offset: 2777}, + pos: position{line: 97, col: 18, offset: 2136}, exprs: []any{ &zeroOrMoreExpr{ - pos: position{line: 269, col: 18, offset: 6503}, + pos: position{line: 252, col: 18, offset: 5862}, expr: &charClassMatcher{ - pos: position{line: 269, col: 18, offset: 6503}, + pos: position{line: 252, col: 18, offset: 5862}, val: "[ \\t\\r\\n]", chars: []rune{' ', '\t', '\r', '\n'}, ignoreCase: false, @@ -557,25 +583,25 @@ var g = &grammar{ }, }, &labeledExpr{ - pos: position{line: 114, col: 20, offset: 2779}, + pos: position{line: 97, col: 20, offset: 2138}, label: "first", expr: &ruleRefExpr{ - pos: position{line: 114, col: 26, offset: 2785}, + pos: position{line: 97, col: 26, offset: 2144}, name: "Value", }, }, &labeledExpr{ - pos: position{line: 114, col: 32, offset: 2791}, + pos: position{line: 97, col: 32, offset: 2150}, label: "rest", expr: &zeroOrMoreExpr{ - pos: position{line: 114, col: 37, offset: 2796}, + pos: position{line: 97, col: 37, offset: 2155}, expr: &seqExpr{ - pos: position{line: 114, col: 38, offset: 2797}, + pos: position{line: 97, col: 38, offset: 2156}, exprs: []any{ &zeroOrMoreExpr{ - pos: position{line: 269, col: 18, offset: 6503}, + pos: position{line: 252, col: 18, offset: 5862}, expr: &charClassMatcher{ - pos: position{line: 269, col: 18, offset: 6503}, + pos: position{line: 252, col: 18, offset: 5862}, val: "[ \\t\\r\\n]", chars: []rune{' ', '\t', '\r', '\n'}, ignoreCase: false, @@ -583,10 +609,10 @@ var g = &grammar{ }, }, &actionExpr{ - pos: position{line: 260, col: 16, offset: 6274}, + pos: position{line: 243, col: 16, offset: 5633}, run: (*parser).callonArithmeticExpr12, expr: &charClassMatcher{ - pos: position{line: 260, col: 17, offset: 6275}, + pos: position{line: 243, col: 17, offset: 5634}, val: "[+-/*%]", chars: []rune{'+', '-', '/', '*', '%'}, ignoreCase: false, @@ -594,9 +620,9 @@ var g = &grammar{ }, }, &zeroOrMoreExpr{ - pos: position{line: 269, col: 18, offset: 6503}, + pos: position{line: 252, col: 18, offset: 5862}, expr: &charClassMatcher{ - pos: position{line: 269, col: 18, offset: 6503}, + pos: position{line: 252, col: 18, offset: 5862}, val: "[ \\t\\r\\n]", chars: []rune{' ', '\t', '\r', '\n'}, ignoreCase: false, @@ -604,7 +630,7 @@ var g = &grammar{ }, }, &ruleRefExpr{ - pos: position{line: 114, col: 55, offset: 2814}, + pos: position{line: 97, col: 55, offset: 2173}, name: "Value", }, }, @@ -612,9 +638,9 @@ var g = &grammar{ }, }, &zeroOrMoreExpr{ - pos: position{line: 269, col: 18, offset: 6503}, + pos: position{line: 252, col: 18, offset: 5862}, expr: &charClassMatcher{ - pos: position{line: 269, col: 18, offset: 6503}, + pos: position{line: 252, col: 18, offset: 5862}, val: "[ \\t\\r\\n]", chars: []rune{' ', '\t', '\r', '\n'}, ignoreCase: false, @@ -629,29 +655,29 @@ var g = &grammar{ }, { name: "ParenExpr", - pos: position{line: 118, col: 1, offset: 2868}, + pos: position{line: 101, col: 1, offset: 2227}, expr: &actionExpr{ - pos: position{line: 118, col: 13, offset: 2880}, + pos: position{line: 101, col: 13, offset: 2239}, run: (*parser).callonParenExpr1, expr: &seqExpr{ - pos: position{line: 118, col: 13, offset: 2880}, + pos: position{line: 101, col: 13, offset: 2239}, exprs: []any{ &litMatcher{ - pos: position{line: 118, col: 13, offset: 2880}, + pos: position{line: 101, col: 13, offset: 2239}, val: "(", ignoreCase: false, want: "\"(\"", }, &labeledExpr{ - pos: position{line: 118, col: 17, offset: 2884}, + pos: position{line: 101, col: 17, offset: 2243}, label: "expr", expr: &ruleRefExpr{ - pos: position{line: 118, col: 22, offset: 2889}, + pos: position{line: 101, col: 22, offset: 2248}, name: "Expr", }, }, &litMatcher{ - pos: position{line: 118, col: 27, offset: 2894}, + pos: position{line: 101, col: 27, offset: 2253}, val: ")", ignoreCase: false, want: "\")\"", @@ -664,46 +690,46 @@ var g = &grammar{ }, { name: "ParamList", - pos: position{line: 122, col: 1, offset: 2924}, + pos: position{line: 105, col: 1, offset: 2283}, expr: &actionExpr{ - pos: position{line: 122, col: 13, offset: 2936}, + pos: position{line: 105, col: 13, offset: 2295}, run: (*parser).callonParamList1, expr: &seqExpr{ - pos: position{line: 122, col: 13, offset: 2936}, + pos: position{line: 105, col: 13, offset: 2295}, exprs: []any{ &litMatcher{ - pos: position{line: 122, col: 13, offset: 2936}, + pos: position{line: 105, col: 13, offset: 2295}, val: "(", ignoreCase: false, want: "\"(\"", }, &labeledExpr{ - pos: position{line: 122, col: 17, offset: 2940}, + pos: position{line: 105, col: 17, offset: 2299}, label: "params", expr: &zeroOrOneExpr{ - pos: position{line: 122, col: 24, offset: 2947}, + pos: position{line: 105, col: 24, offset: 2306}, expr: &seqExpr{ - pos: position{line: 122, col: 25, offset: 2948}, + pos: position{line: 105, col: 25, offset: 2307}, exprs: []any{ &ruleRefExpr{ - pos: position{line: 122, col: 25, offset: 2948}, + pos: position{line: 105, col: 25, offset: 2307}, name: "Expr", }, &zeroOrMoreExpr{ - pos: position{line: 122, col: 30, offset: 2953}, + pos: position{line: 105, col: 30, offset: 2312}, expr: &seqExpr{ - pos: position{line: 122, col: 32, offset: 2955}, + pos: position{line: 105, col: 32, offset: 2314}, exprs: []any{ &litMatcher{ - pos: position{line: 122, col: 32, offset: 2955}, + pos: position{line: 105, col: 32, offset: 2314}, val: ",", ignoreCase: false, want: "\",\"", }, &zeroOrMoreExpr{ - pos: position{line: 269, col: 18, offset: 6503}, + pos: position{line: 252, col: 18, offset: 5862}, expr: &charClassMatcher{ - pos: position{line: 269, col: 18, offset: 6503}, + pos: position{line: 252, col: 18, offset: 5862}, val: "[ \\t\\r\\n]", chars: []rune{' ', '\t', '\r', '\n'}, ignoreCase: false, @@ -711,7 +737,7 @@ var g = &grammar{ }, }, &ruleRefExpr{ - pos: position{line: 122, col: 38, offset: 2961}, + pos: position{line: 105, col: 38, offset: 2320}, name: "Expr", }, }, @@ -722,7 +748,7 @@ var g = &grammar{ }, }, &litMatcher{ - pos: position{line: 122, col: 49, offset: 2972}, + pos: position{line: 105, col: 49, offset: 2331}, val: ")", ignoreCase: false, want: "\")\"", @@ -735,20 +761,20 @@ var g = &grammar{ }, { name: "Value", - pos: position{line: 136, col: 1, offset: 3334}, + pos: position{line: 119, col: 1, offset: 2693}, expr: &actionExpr{ - pos: position{line: 136, col: 9, offset: 3342}, + pos: position{line: 119, col: 9, offset: 2701}, run: (*parser).callonValue1, expr: &seqExpr{ - pos: position{line: 136, col: 9, offset: 3342}, + pos: position{line: 119, col: 9, offset: 2701}, exprs: []any{ &labeledExpr{ - pos: position{line: 136, col: 9, offset: 3342}, + pos: position{line: 119, col: 9, offset: 2701}, label: "not", expr: &zeroOrOneExpr{ - pos: position{line: 136, col: 13, offset: 3346}, + pos: position{line: 119, col: 13, offset: 2705}, expr: &litMatcher{ - pos: position{line: 136, col: 13, offset: 3346}, + pos: position{line: 119, col: 13, offset: 2705}, val: "!", ignoreCase: false, want: "\"!\"", @@ -756,42 +782,42 @@ var g = &grammar{ }, }, &labeledExpr{ - pos: position{line: 136, col: 18, offset: 3351}, + pos: position{line: 119, col: 18, offset: 2710}, label: "node", expr: &choiceExpr{ - pos: position{line: 136, col: 24, offset: 3357}, + pos: position{line: 119, col: 24, offset: 2716}, alternatives: []any{ &ruleRefExpr{ - pos: position{line: 136, col: 24, offset: 3357}, + pos: position{line: 119, col: 24, offset: 2716}, name: "MethodCall", }, &ruleRefExpr{ - pos: position{line: 136, col: 37, offset: 3370}, + pos: position{line: 119, col: 37, offset: 2729}, name: "FieldAccess", }, &ruleRefExpr{ - pos: position{line: 136, col: 51, offset: 3384}, + pos: position{line: 119, col: 51, offset: 2743}, name: "Index", }, &actionExpr{ - pos: position{line: 222, col: 10, offset: 5477}, + pos: position{line: 205, col: 10, offset: 4836}, run: (*parser).callonValue11, expr: &seqExpr{ - pos: position{line: 222, col: 10, offset: 5477}, + pos: position{line: 205, col: 10, offset: 4836}, exprs: []any{ &litMatcher{ - pos: position{line: 222, col: 10, offset: 5477}, + pos: position{line: 205, col: 10, offset: 4836}, val: "\"", ignoreCase: false, want: "\"\\\"\"", }, &labeledExpr{ - pos: position{line: 222, col: 14, offset: 5481}, + pos: position{line: 205, col: 14, offset: 4840}, label: "value", expr: &zeroOrMoreExpr{ - pos: position{line: 222, col: 20, offset: 5487}, + pos: position{line: 205, col: 20, offset: 4846}, expr: &charClassMatcher{ - pos: position{line: 222, col: 20, offset: 5487}, + pos: position{line: 205, col: 20, offset: 4846}, val: "[^\"]", chars: []rune{'"'}, ignoreCase: false, @@ -800,7 +826,7 @@ var g = &grammar{ }, }, &litMatcher{ - pos: position{line: 222, col: 26, offset: 5493}, + pos: position{line: 205, col: 26, offset: 4852}, val: "\"", ignoreCase: false, want: "\"\\\"\"", @@ -809,24 +835,24 @@ var g = &grammar{ }, }, &actionExpr{ - pos: position{line: 230, col: 13, offset: 5644}, + pos: position{line: 213, col: 13, offset: 5003}, run: (*parser).callonValue18, expr: &seqExpr{ - pos: position{line: 230, col: 13, offset: 5644}, + pos: position{line: 213, col: 13, offset: 5003}, exprs: []any{ &litMatcher{ - pos: position{line: 230, col: 13, offset: 5644}, + pos: position{line: 213, col: 13, offset: 5003}, val: "`", ignoreCase: false, want: "\"`\"", }, &labeledExpr{ - pos: position{line: 230, col: 17, offset: 5648}, + pos: position{line: 213, col: 17, offset: 5007}, label: "value", expr: &zeroOrMoreExpr{ - pos: position{line: 230, col: 23, offset: 5654}, + pos: position{line: 213, col: 23, offset: 5013}, expr: &charClassMatcher{ - pos: position{line: 230, col: 23, offset: 5654}, + pos: position{line: 213, col: 23, offset: 5013}, val: "[^`]", chars: []rune{'`'}, ignoreCase: false, @@ -835,7 +861,7 @@ var g = &grammar{ }, }, &litMatcher{ - pos: position{line: 230, col: 29, offset: 5660}, + pos: position{line: 213, col: 29, offset: 5019}, val: "`", ignoreCase: false, want: "\"`\"", @@ -844,30 +870,30 @@ var g = &grammar{ }, }, &actionExpr{ - pos: position{line: 214, col: 9, offset: 5296}, + pos: position{line: 197, col: 9, offset: 4655}, run: (*parser).callonValue25, expr: &seqExpr{ - pos: position{line: 214, col: 9, offset: 5296}, + pos: position{line: 197, col: 9, offset: 4655}, exprs: []any{ &zeroOrOneExpr{ - pos: position{line: 214, col: 9, offset: 5296}, + pos: position{line: 197, col: 9, offset: 4655}, expr: &litMatcher{ - pos: position{line: 214, col: 9, offset: 5296}, + pos: position{line: 197, col: 9, offset: 4655}, val: "-", ignoreCase: false, want: "\"-\"", }, }, &labeledExpr{ - pos: position{line: 214, col: 14, offset: 5301}, + pos: position{line: 197, col: 14, offset: 4660}, label: "value", expr: &seqExpr{ - pos: position{line: 214, col: 21, offset: 5308}, + pos: position{line: 197, col: 21, offset: 4667}, exprs: []any{ &oneOrMoreExpr{ - pos: position{line: 214, col: 21, offset: 5308}, + pos: position{line: 197, col: 21, offset: 4667}, expr: &charClassMatcher{ - pos: position{line: 214, col: 21, offset: 5308}, + pos: position{line: 197, col: 21, offset: 4667}, val: "[0-9]", ranges: []rune{'0', '9'}, ignoreCase: false, @@ -875,15 +901,15 @@ var g = &grammar{ }, }, &litMatcher{ - pos: position{line: 214, col: 28, offset: 5315}, + pos: position{line: 197, col: 28, offset: 4674}, val: ".", ignoreCase: false, want: "\".\"", }, &oneOrMoreExpr{ - pos: position{line: 214, col: 32, offset: 5319}, + pos: position{line: 197, col: 32, offset: 4678}, expr: &charClassMatcher{ - pos: position{line: 214, col: 32, offset: 5319}, + pos: position{line: 197, col: 32, offset: 4678}, val: "[0-9]", ranges: []rune{'0', '9'}, ignoreCase: false, @@ -897,36 +923,36 @@ var g = &grammar{ }, }, &actionExpr{ - pos: position{line: 206, col: 11, offset: 5085}, + pos: position{line: 189, col: 11, offset: 4444}, run: (*parser).callonValue36, expr: &seqExpr{ - pos: position{line: 206, col: 11, offset: 5085}, + pos: position{line: 189, col: 11, offset: 4444}, exprs: []any{ &zeroOrOneExpr{ - pos: position{line: 206, col: 11, offset: 5085}, + pos: position{line: 189, col: 11, offset: 4444}, expr: &litMatcher{ - pos: position{line: 206, col: 11, offset: 5085}, + pos: position{line: 189, col: 11, offset: 4444}, val: "-", ignoreCase: false, want: "\"-\"", }, }, &choiceExpr{ - pos: position{line: 206, col: 17, offset: 5091}, + pos: position{line: 189, col: 17, offset: 4450}, alternatives: []any{ &seqExpr{ - pos: position{line: 206, col: 17, offset: 5091}, + pos: position{line: 189, col: 17, offset: 4450}, exprs: []any{ &litMatcher{ - pos: position{line: 206, col: 17, offset: 5091}, + pos: position{line: 189, col: 17, offset: 4450}, val: "0x", ignoreCase: false, want: "\"0x\"", }, &oneOrMoreExpr{ - pos: position{line: 206, col: 22, offset: 5096}, + pos: position{line: 189, col: 22, offset: 4455}, expr: &charClassMatcher{ - pos: position{line: 206, col: 22, offset: 5096}, + pos: position{line: 189, col: 22, offset: 4455}, val: "[0-9a-f]i", ranges: []rune{'0', '9', 'a', 'f'}, ignoreCase: true, @@ -936,18 +962,18 @@ var g = &grammar{ }, }, &seqExpr{ - pos: position{line: 206, col: 35, offset: 5109}, + pos: position{line: 189, col: 35, offset: 4468}, exprs: []any{ &litMatcher{ - pos: position{line: 206, col: 35, offset: 5109}, + pos: position{line: 189, col: 35, offset: 4468}, val: "0o", ignoreCase: false, want: "\"0o\"", }, &oneOrMoreExpr{ - pos: position{line: 206, col: 40, offset: 5114}, + pos: position{line: 189, col: 40, offset: 4473}, expr: &charClassMatcher{ - pos: position{line: 206, col: 40, offset: 5114}, + pos: position{line: 189, col: 40, offset: 4473}, val: "[0-7]", ranges: []rune{'0', '7'}, ignoreCase: false, @@ -957,18 +983,18 @@ var g = &grammar{ }, }, &seqExpr{ - pos: position{line: 206, col: 49, offset: 5123}, + pos: position{line: 189, col: 49, offset: 4482}, exprs: []any{ &litMatcher{ - pos: position{line: 206, col: 49, offset: 5123}, + pos: position{line: 189, col: 49, offset: 4482}, val: "0b", ignoreCase: false, want: "\"0b\"", }, &oneOrMoreExpr{ - pos: position{line: 206, col: 54, offset: 5128}, + pos: position{line: 189, col: 54, offset: 4487}, expr: &charClassMatcher{ - pos: position{line: 206, col: 54, offset: 5128}, + pos: position{line: 189, col: 54, offset: 4487}, val: "[01]", chars: []rune{'0', '1'}, ignoreCase: false, @@ -978,9 +1004,9 @@ var g = &grammar{ }, }, &oneOrMoreExpr{ - pos: position{line: 206, col: 62, offset: 5136}, + pos: position{line: 189, col: 62, offset: 4495}, expr: &charClassMatcher{ - pos: position{line: 206, col: 62, offset: 5136}, + pos: position{line: 189, col: 62, offset: 4495}, val: "[0-9]", ranges: []rune{'0', '9'}, ignoreCase: false, @@ -993,19 +1019,19 @@ var g = &grammar{ }, }, &actionExpr{ - pos: position{line: 238, col: 8, offset: 5806}, + pos: position{line: 221, col: 8, offset: 5165}, run: (*parser).callonValue55, expr: &choiceExpr{ - pos: position{line: 238, col: 9, offset: 5807}, + pos: position{line: 221, col: 9, offset: 5166}, alternatives: []any{ &litMatcher{ - pos: position{line: 238, col: 9, offset: 5807}, + pos: position{line: 221, col: 9, offset: 5166}, val: "true", ignoreCase: true, want: "\"true\"i", }, &litMatcher{ - pos: position{line: 238, col: 19, offset: 5817}, + pos: position{line: 221, col: 19, offset: 5176}, val: "false", ignoreCase: true, want: "\"false\"i", @@ -1014,30 +1040,30 @@ var g = &grammar{ }, }, &ruleRefExpr{ - pos: position{line: 136, col: 105, offset: 3438}, + pos: position{line: 119, col: 105, offset: 2797}, name: "FuncCall", }, &ruleRefExpr{ - pos: position{line: 136, col: 116, offset: 3449}, + pos: position{line: 119, col: 116, offset: 2808}, name: "VariableOr", }, &actionExpr{ - pos: position{line: 191, col: 9, offset: 4770}, + pos: position{line: 174, col: 9, offset: 4129}, run: (*parser).callonValue61, expr: &seqExpr{ - pos: position{line: 191, col: 9, offset: 4770}, + pos: position{line: 174, col: 9, offset: 4129}, exprs: []any{ &charClassMatcher{ - pos: position{line: 191, col: 9, offset: 4770}, + pos: position{line: 174, col: 9, offset: 4129}, val: "[a-z]i", ranges: []rune{'a', 'z'}, ignoreCase: true, inverted: false, }, &zeroOrMoreExpr{ - pos: position{line: 191, col: 16, offset: 4777}, + pos: position{line: 174, col: 16, offset: 4136}, expr: &charClassMatcher{ - pos: position{line: 191, col: 16, offset: 4777}, + pos: position{line: 174, col: 16, offset: 4136}, val: "[_a-z0-9]i", chars: []rune{'_'}, ranges: []rune{'a', 'z', '0', '9'}, @@ -1049,7 +1075,7 @@ var g = &grammar{ }, }, &ruleRefExpr{ - pos: position{line: 136, col: 137, offset: 3470}, + pos: position{line: 119, col: 137, offset: 2829}, name: "ParenExpr", }, }, @@ -1063,33 +1089,33 @@ var g = &grammar{ }, { name: "VariableOr", - pos: position{line: 143, col: 1, offset: 3576}, + pos: position{line: 126, col: 1, offset: 2935}, expr: &actionExpr{ - pos: position{line: 143, col: 14, offset: 3589}, + pos: position{line: 126, col: 14, offset: 2948}, run: (*parser).callonVariableOr1, expr: &seqExpr{ - pos: position{line: 143, col: 14, offset: 3589}, + pos: position{line: 126, col: 14, offset: 2948}, exprs: []any{ &labeledExpr{ - pos: position{line: 143, col: 14, offset: 3589}, + pos: position{line: 126, col: 14, offset: 2948}, label: "variable", expr: &actionExpr{ - pos: position{line: 191, col: 9, offset: 4770}, + pos: position{line: 174, col: 9, offset: 4129}, run: (*parser).callonVariableOr4, expr: &seqExpr{ - pos: position{line: 191, col: 9, offset: 4770}, + pos: position{line: 174, col: 9, offset: 4129}, exprs: []any{ &charClassMatcher{ - pos: position{line: 191, col: 9, offset: 4770}, + pos: position{line: 174, col: 9, offset: 4129}, val: "[a-z]i", ranges: []rune{'a', 'z'}, ignoreCase: true, inverted: false, }, &zeroOrMoreExpr{ - pos: position{line: 191, col: 16, offset: 4777}, + pos: position{line: 174, col: 16, offset: 4136}, expr: &charClassMatcher{ - pos: position{line: 191, col: 16, offset: 4777}, + pos: position{line: 174, col: 16, offset: 4136}, val: "[_a-z0-9]i", chars: []rune{'_'}, ranges: []rune{'a', 'z', '0', '9'}, @@ -1102,9 +1128,9 @@ var g = &grammar{ }, }, &zeroOrMoreExpr{ - pos: position{line: 269, col: 18, offset: 6503}, + pos: position{line: 252, col: 18, offset: 5862}, expr: &charClassMatcher{ - pos: position{line: 269, col: 18, offset: 6503}, + pos: position{line: 252, col: 18, offset: 5862}, val: "[ \\t\\r\\n]", chars: []rune{' ', '\t', '\r', '\n'}, ignoreCase: false, @@ -1112,15 +1138,15 @@ var g = &grammar{ }, }, &litMatcher{ - pos: position{line: 143, col: 31, offset: 3606}, + pos: position{line: 126, col: 31, offset: 2965}, val: "|", ignoreCase: false, want: "\"|\"", }, &zeroOrMoreExpr{ - pos: position{line: 269, col: 18, offset: 6503}, + pos: position{line: 252, col: 18, offset: 5862}, expr: &charClassMatcher{ - pos: position{line: 269, col: 18, offset: 6503}, + pos: position{line: 252, col: 18, offset: 5862}, val: "[ \\t\\r\\n]", chars: []rune{' ', '\t', '\r', '\n'}, ignoreCase: false, @@ -1128,10 +1154,10 @@ var g = &grammar{ }, }, &labeledExpr{ - pos: position{line: 143, col: 37, offset: 3612}, + pos: position{line: 126, col: 37, offset: 2971}, label: "or", expr: &ruleRefExpr{ - pos: position{line: 143, col: 40, offset: 3615}, + pos: position{line: 126, col: 40, offset: 2974}, name: "Assignable", }, }, @@ -1143,33 +1169,33 @@ var g = &grammar{ }, { name: "Assignment", - pos: position{line: 150, col: 1, offset: 3742}, + pos: position{line: 133, col: 1, offset: 3101}, expr: &actionExpr{ - pos: position{line: 150, col: 14, offset: 3755}, + pos: position{line: 133, col: 14, offset: 3114}, run: (*parser).callonAssignment1, expr: &seqExpr{ - pos: position{line: 150, col: 14, offset: 3755}, + pos: position{line: 133, col: 14, offset: 3114}, exprs: []any{ &labeledExpr{ - pos: position{line: 150, col: 14, offset: 3755}, + pos: position{line: 133, col: 14, offset: 3114}, label: "name", expr: &actionExpr{ - pos: position{line: 191, col: 9, offset: 4770}, + pos: position{line: 174, col: 9, offset: 4129}, run: (*parser).callonAssignment4, expr: &seqExpr{ - pos: position{line: 191, col: 9, offset: 4770}, + pos: position{line: 174, col: 9, offset: 4129}, exprs: []any{ &charClassMatcher{ - pos: position{line: 191, col: 9, offset: 4770}, + pos: position{line: 174, col: 9, offset: 4129}, val: "[a-z]i", ranges: []rune{'a', 'z'}, ignoreCase: true, inverted: false, }, &zeroOrMoreExpr{ - pos: position{line: 191, col: 16, offset: 4777}, + pos: position{line: 174, col: 16, offset: 4136}, expr: &charClassMatcher{ - pos: position{line: 191, col: 16, offset: 4777}, + pos: position{line: 174, col: 16, offset: 4136}, val: "[_a-z0-9]i", chars: []rune{'_'}, ranges: []rune{'a', 'z', '0', '9'}, @@ -1182,9 +1208,9 @@ var g = &grammar{ }, }, &zeroOrMoreExpr{ - pos: position{line: 269, col: 18, offset: 6503}, + pos: position{line: 252, col: 18, offset: 5862}, expr: &charClassMatcher{ - pos: position{line: 269, col: 18, offset: 6503}, + pos: position{line: 252, col: 18, offset: 5862}, val: "[ \\t\\r\\n]", chars: []rune{' ', '\t', '\r', '\n'}, ignoreCase: false, @@ -1192,15 +1218,15 @@ var g = &grammar{ }, }, &litMatcher{ - pos: position{line: 150, col: 27, offset: 3768}, + pos: position{line: 133, col: 27, offset: 3127}, val: "=", ignoreCase: false, want: "\"=\"", }, &zeroOrMoreExpr{ - pos: position{line: 269, col: 18, offset: 6503}, + pos: position{line: 252, col: 18, offset: 5862}, expr: &charClassMatcher{ - pos: position{line: 269, col: 18, offset: 6503}, + pos: position{line: 252, col: 18, offset: 5862}, val: "[ \\t\\r\\n]", chars: []rune{' ', '\t', '\r', '\n'}, ignoreCase: false, @@ -1208,10 +1234,10 @@ var g = &grammar{ }, }, &labeledExpr{ - pos: position{line: 150, col: 33, offset: 3774}, + pos: position{line: 133, col: 33, offset: 3133}, label: "value", expr: &ruleRefExpr{ - pos: position{line: 150, col: 39, offset: 3780}, + pos: position{line: 133, col: 39, offset: 3139}, name: "Assignable", }, }, @@ -1223,25 +1249,25 @@ var g = &grammar{ }, { name: "Ternary", - pos: position{line: 158, col: 1, offset: 3935}, + pos: position{line: 141, col: 1, offset: 3294}, expr: &actionExpr{ - pos: position{line: 158, col: 11, offset: 3945}, + pos: position{line: 141, col: 11, offset: 3304}, run: (*parser).callonTernary1, expr: &seqExpr{ - pos: position{line: 158, col: 11, offset: 3945}, + pos: position{line: 141, col: 11, offset: 3304}, exprs: []any{ &labeledExpr{ - pos: position{line: 158, col: 11, offset: 3945}, + pos: position{line: 141, col: 11, offset: 3304}, label: "cond", expr: &ruleRefExpr{ - pos: position{line: 158, col: 16, offset: 3950}, + pos: position{line: 141, col: 16, offset: 3309}, name: "Assignable", }, }, &zeroOrMoreExpr{ - pos: position{line: 269, col: 18, offset: 6503}, + pos: position{line: 252, col: 18, offset: 5862}, expr: &charClassMatcher{ - pos: position{line: 269, col: 18, offset: 6503}, + pos: position{line: 252, col: 18, offset: 5862}, val: "[ \\t\\r\\n]", chars: []rune{' ', '\t', '\r', '\n'}, ignoreCase: false, @@ -1249,15 +1275,15 @@ var g = &grammar{ }, }, &litMatcher{ - pos: position{line: 158, col: 29, offset: 3963}, + pos: position{line: 141, col: 29, offset: 3322}, val: "?", ignoreCase: false, want: "\"?\"", }, &zeroOrMoreExpr{ - pos: position{line: 269, col: 18, offset: 6503}, + pos: position{line: 252, col: 18, offset: 5862}, expr: &charClassMatcher{ - pos: position{line: 269, col: 18, offset: 6503}, + pos: position{line: 252, col: 18, offset: 5862}, val: "[ \\t\\r\\n]", chars: []rune{' ', '\t', '\r', '\n'}, ignoreCase: false, @@ -1265,17 +1291,17 @@ var g = &grammar{ }, }, &labeledExpr{ - pos: position{line: 158, col: 35, offset: 3969}, + pos: position{line: 141, col: 35, offset: 3328}, label: "ifTrue", expr: &ruleRefExpr{ - pos: position{line: 158, col: 42, offset: 3976}, + pos: position{line: 141, col: 42, offset: 3335}, name: "Value", }, }, &zeroOrMoreExpr{ - pos: position{line: 269, col: 18, offset: 6503}, + pos: position{line: 252, col: 18, offset: 5862}, expr: &charClassMatcher{ - pos: position{line: 269, col: 18, offset: 6503}, + pos: position{line: 252, col: 18, offset: 5862}, val: "[ \\t\\r\\n]", chars: []rune{' ', '\t', '\r', '\n'}, ignoreCase: false, @@ -1283,15 +1309,15 @@ var g = &grammar{ }, }, &litMatcher{ - pos: position{line: 158, col: 50, offset: 3984}, + pos: position{line: 141, col: 50, offset: 3343}, val: ":", ignoreCase: false, want: "\":\"", }, &zeroOrMoreExpr{ - pos: position{line: 269, col: 18, offset: 6503}, + pos: position{line: 252, col: 18, offset: 5862}, expr: &charClassMatcher{ - pos: position{line: 269, col: 18, offset: 6503}, + pos: position{line: 252, col: 18, offset: 5862}, val: "[ \\t\\r\\n]", chars: []rune{' ', '\t', '\r', '\n'}, ignoreCase: false, @@ -1299,10 +1325,10 @@ var g = &grammar{ }, }, &labeledExpr{ - pos: position{line: 158, col: 56, offset: 3990}, + pos: position{line: 141, col: 56, offset: 3349}, label: "elseVal", expr: &ruleRefExpr{ - pos: position{line: 158, col: 64, offset: 3998}, + pos: position{line: 141, col: 64, offset: 3357}, name: "Value", }, }, @@ -1314,47 +1340,47 @@ var g = &grammar{ }, { name: "MethodCall", - pos: position{line: 166, col: 1, offset: 4157}, + pos: position{line: 149, col: 1, offset: 3516}, expr: &actionExpr{ - pos: position{line: 166, col: 14, offset: 4170}, + pos: position{line: 149, col: 14, offset: 3529}, run: (*parser).callonMethodCall1, expr: &seqExpr{ - pos: position{line: 166, col: 14, offset: 4170}, + pos: position{line: 149, col: 14, offset: 3529}, exprs: []any{ &labeledExpr{ - pos: position{line: 166, col: 14, offset: 4170}, + pos: position{line: 149, col: 14, offset: 3529}, label: "value", expr: &ruleRefExpr{ - pos: position{line: 166, col: 20, offset: 4176}, + pos: position{line: 149, col: 20, offset: 3535}, name: "Value", }, }, &litMatcher{ - pos: position{line: 166, col: 26, offset: 4182}, + pos: position{line: 149, col: 26, offset: 3541}, val: ".", ignoreCase: false, want: "\".\"", }, &labeledExpr{ - pos: position{line: 166, col: 30, offset: 4186}, + pos: position{line: 149, col: 30, offset: 3545}, label: "name", expr: &actionExpr{ - pos: position{line: 191, col: 9, offset: 4770}, + pos: position{line: 174, col: 9, offset: 4129}, run: (*parser).callonMethodCall7, expr: &seqExpr{ - pos: position{line: 191, col: 9, offset: 4770}, + pos: position{line: 174, col: 9, offset: 4129}, exprs: []any{ &charClassMatcher{ - pos: position{line: 191, col: 9, offset: 4770}, + pos: position{line: 174, col: 9, offset: 4129}, val: "[a-z]i", ranges: []rune{'a', 'z'}, ignoreCase: true, inverted: false, }, &zeroOrMoreExpr{ - pos: position{line: 191, col: 16, offset: 4777}, + pos: position{line: 174, col: 16, offset: 4136}, expr: &charClassMatcher{ - pos: position{line: 191, col: 16, offset: 4777}, + pos: position{line: 174, col: 16, offset: 4136}, val: "[_a-z0-9]i", chars: []rune{'_'}, ranges: []rune{'a', 'z', '0', '9'}, @@ -1367,10 +1393,10 @@ var g = &grammar{ }, }, &labeledExpr{ - pos: position{line: 166, col: 41, offset: 4197}, + pos: position{line: 149, col: 41, offset: 3556}, label: "params", expr: &ruleRefExpr{ - pos: position{line: 166, col: 48, offset: 4204}, + pos: position{line: 149, col: 48, offset: 3563}, name: "ParamList", }, }, @@ -1382,37 +1408,37 @@ var g = &grammar{ }, { name: "Index", - pos: position{line: 175, col: 1, offset: 4397}, + pos: position{line: 158, col: 1, offset: 3756}, expr: &actionExpr{ - pos: position{line: 175, col: 9, offset: 4405}, + pos: position{line: 158, col: 9, offset: 3764}, run: (*parser).callonIndex1, expr: &seqExpr{ - pos: position{line: 175, col: 9, offset: 4405}, + pos: position{line: 158, col: 9, offset: 3764}, exprs: []any{ &labeledExpr{ - pos: position{line: 175, col: 9, offset: 4405}, + pos: position{line: 158, col: 9, offset: 3764}, label: "value", expr: &ruleRefExpr{ - pos: position{line: 175, col: 15, offset: 4411}, + pos: position{line: 158, col: 15, offset: 3770}, name: "Value", }, }, &litMatcher{ - pos: position{line: 175, col: 21, offset: 4417}, + pos: position{line: 158, col: 21, offset: 3776}, val: "[", ignoreCase: false, want: "\"[\"", }, &labeledExpr{ - pos: position{line: 175, col: 25, offset: 4421}, + pos: position{line: 158, col: 25, offset: 3780}, label: "index", expr: &ruleRefExpr{ - pos: position{line: 175, col: 31, offset: 4427}, + pos: position{line: 158, col: 31, offset: 3786}, name: "Value", }, }, &litMatcher{ - pos: position{line: 175, col: 37, offset: 4433}, + pos: position{line: 158, col: 37, offset: 3792}, val: "]", ignoreCase: false, want: "\"]\"", @@ -1425,47 +1451,47 @@ var g = &grammar{ }, { name: "FieldAccess", - pos: position{line: 183, col: 1, offset: 4576}, + pos: position{line: 166, col: 1, offset: 3935}, expr: &actionExpr{ - pos: position{line: 183, col: 15, offset: 4590}, + pos: position{line: 166, col: 15, offset: 3949}, run: (*parser).callonFieldAccess1, expr: &seqExpr{ - pos: position{line: 183, col: 15, offset: 4590}, + pos: position{line: 166, col: 15, offset: 3949}, exprs: []any{ &labeledExpr{ - pos: position{line: 183, col: 15, offset: 4590}, + pos: position{line: 166, col: 15, offset: 3949}, label: "value", expr: &ruleRefExpr{ - pos: position{line: 183, col: 21, offset: 4596}, + pos: position{line: 166, col: 21, offset: 3955}, name: "Value", }, }, &litMatcher{ - pos: position{line: 183, col: 27, offset: 4602}, + pos: position{line: 166, col: 27, offset: 3961}, val: ".", ignoreCase: false, want: "\".\"", }, &labeledExpr{ - pos: position{line: 183, col: 31, offset: 4606}, + pos: position{line: 166, col: 31, offset: 3965}, label: "name", expr: &actionExpr{ - pos: position{line: 191, col: 9, offset: 4770}, + pos: position{line: 174, col: 9, offset: 4129}, run: (*parser).callonFieldAccess7, expr: &seqExpr{ - pos: position{line: 191, col: 9, offset: 4770}, + pos: position{line: 174, col: 9, offset: 4129}, exprs: []any{ &charClassMatcher{ - pos: position{line: 191, col: 9, offset: 4770}, + pos: position{line: 174, col: 9, offset: 4129}, val: "[a-z]i", ranges: []rune{'a', 'z'}, ignoreCase: true, inverted: false, }, &zeroOrMoreExpr{ - pos: position{line: 191, col: 16, offset: 4777}, + pos: position{line: 174, col: 16, offset: 4136}, expr: &charClassMatcher{ - pos: position{line: 191, col: 16, offset: 4777}, + pos: position{line: 174, col: 16, offset: 4136}, val: "[_a-z0-9]i", chars: []rune{'_'}, ranges: []rune{'a', 'z', '0', '9'}, @@ -1485,33 +1511,33 @@ var g = &grammar{ }, { name: "FuncCall", - pos: position{line: 198, col: 1, offset: 4891}, + pos: position{line: 181, col: 1, offset: 4250}, expr: &actionExpr{ - pos: position{line: 198, col: 12, offset: 4902}, + pos: position{line: 181, col: 12, offset: 4261}, run: (*parser).callonFuncCall1, expr: &seqExpr{ - pos: position{line: 198, col: 12, offset: 4902}, + pos: position{line: 181, col: 12, offset: 4261}, exprs: []any{ &labeledExpr{ - pos: position{line: 198, col: 12, offset: 4902}, + pos: position{line: 181, col: 12, offset: 4261}, label: "name", expr: &actionExpr{ - pos: position{line: 191, col: 9, offset: 4770}, + pos: position{line: 174, col: 9, offset: 4129}, run: (*parser).callonFuncCall4, expr: &seqExpr{ - pos: position{line: 191, col: 9, offset: 4770}, + pos: position{line: 174, col: 9, offset: 4129}, exprs: []any{ &charClassMatcher{ - pos: position{line: 191, col: 9, offset: 4770}, + pos: position{line: 174, col: 9, offset: 4129}, val: "[a-z]i", ranges: []rune{'a', 'z'}, ignoreCase: true, inverted: false, }, &zeroOrMoreExpr{ - pos: position{line: 191, col: 16, offset: 4777}, + pos: position{line: 174, col: 16, offset: 4136}, expr: &charClassMatcher{ - pos: position{line: 191, col: 16, offset: 4777}, + pos: position{line: 174, col: 16, offset: 4136}, val: "[_a-z0-9]i", chars: []rune{'_'}, ranges: []rune{'a', 'z', '0', '9'}, @@ -1524,10 +1550,10 @@ var g = &grammar{ }, }, &labeledExpr{ - pos: position{line: 198, col: 23, offset: 4913}, + pos: position{line: 181, col: 23, offset: 4272}, label: "params", expr: &ruleRefExpr{ - pos: position{line: 198, col: 30, offset: 4920}, + pos: position{line: 181, col: 30, offset: 4279}, name: "ParamList", }, }, @@ -1606,7 +1632,7 @@ func (p *parser) callonTag5() (any, error) { return p.cur.onTag5() } -func (c *current) onTag1(name, params, body any) (any, error) { +func (c *current) onTag1(name, params, ignoreErr, body any) (any, error) { return ast.Tag{ Name: name.(ast.Ident), Params: toNodeSlice(params), @@ -1618,20 +1644,21 @@ func (c *current) onTag1(name, params, body any) (any, error) { func (p *parser) callonTag1() (any, error) { stack := p.vstack[len(p.vstack)-1] _ = stack - return p.cur.onTag1(stack["name"], stack["params"], stack["body"]) + return p.cur.onTag1(stack["name"], stack["params"], stack["ignoreErr"], stack["body"]) } -func (c *current) onExprTag1(item any) (any, error) { +func (c *current) onExprTag1(item, ignoreErr any) (any, error) { return ast.ExprTag{ - Value: item.(ast.Node), - Position: getPos(c), + Value: item.(ast.Node), + IgnoreError: ignoreErr != nil, + Position: getPos(c), }, nil } func (p *parser) callonExprTag1() (any, error) { stack := p.vstack[len(p.vstack)-1] _ = stack - return p.cur.onExprTag1(stack["item"]) + return p.cur.onExprTag1(stack["item"], stack["ignoreErr"]) } func (c *current) onLogicalExpr12() (any, error) { diff --git a/parser/salix.peg b/parser/salix.peg index 0f6e179..1dc3eb6 100644 --- a/parser/salix.peg +++ b/parser/salix.peg @@ -75,10 +75,11 @@ EndTag = "#!" name:Ident { }, nil } -ExprTag = "#(" item:Expr ')' { +ExprTag = "#(" item:Expr ')' ignoreErr:'?'? { return ast.ExprTag{ - Value: item.(ast.Node), - Position: getPos(c), + Value: item.(ast.Node), + IgnoreError: ignoreErr != nil, + Position: getPos(c), }, nil } @@ -248,4 +249,4 @@ ArithmeticOp = ('+' / '-' / '/' / '*' / '%') { Text = . [^#]* { return ast.Text{Data: c.text, Position: getPos(c)}, nil } -_ "whitespace" ← [ \t\r\n]* \ No newline at end of file +_ "whitespace" ← [ \t\r\n]* diff --git a/salix.go b/salix.go index 5b79c8a..e6bfd8e 100644 --- a/salix.go +++ b/salix.go @@ -112,7 +112,11 @@ func (t *Template) execute(w io.Writer, nodes []ast.Node, local map[string]any) case ast.ExprTag: v, err := t.getValue(node.Value, local) if err != nil { - return err + if node.IgnoreError { + continue + } else { + return err + } } if _, ok := v.(ast.Assignment); ok { continue