Debian Codegraph @

parser/options.go

raw symbols SCIP
1 // Copyright 2021 Google LLC
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14
15 package parserscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/parser`/
16
17 import "fmtscip-go gomod github.com/golang/go/src go1.23.0 fmt/"
18
19 type optionsscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/parser`/options# struct {
20 maxRecursionDepthscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/parser`/options#maxRecursionDepth. int
21 errorReportingLimitscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/parser`/options#errorReportingLimit. int
22 errorRecoveryTokenLookaheadLimitscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/parser`/options#errorRecoveryTokenLookaheadLimit. int
23 errorRecoveryLimitscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/parser`/options#errorRecoveryLimit. int
24 expressionSizeCodePointLimitscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/parser`/options#expressionSizeCodePointLimit. int
25 macrosscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/parser`/options#macros. map[string]Macroscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/parser`/Macro#
26 populateMacroCallsscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/parser`/options#populateMacroCalls. bool
27 enableOptionalSyntaxscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/parser`/options#enableOptionalSyntax. bool
28 enableVariadicOperatorASTsscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/parser`/options#enableVariadicOperatorASTs. bool
29 enableIdentEscapeSyntaxscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/parser`/options#enableIdentEscapeSyntax. bool
30 enableHiddenAccumulatorNamescip-go gomod github.com/google/cel-go . `github.com/google/cel-go/parser`/options#enableHiddenAccumulatorName. bool
31 }
32
33 // Option configures the behavior of the parser.
34 type Optionscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/parser`/Option# func(*optionsscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/parser`/options#) error
35
36 // MaxRecursionDepth limits the maximum depth the parser will attempt to parse the expression before giving up.
37 func MaxRecursionDepthscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/parser`/MaxRecursionDepth().(limit int) Optionscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/parser`/Option# {
38 return func(opts *optionsscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/parser`/options#) error {
39 if limit < -1 {
40 return fmtscip-go gomod github.com/golang/go/src go1.23.0 fmt/.Errorfscip-go gomod github.com/golang/go/src go1.23.0 fmt/Errorf().("max recursion depth must be greater than or equal to -1: %d", limit)
41 }
42 opts.maxRecursionDepthscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/parser`/options#maxRecursionDepth. = limit
43 return nil
44 }
45 }
46
47 // ErrorRecoveryLookaheadTokenLimit limits the number of lexer tokens that may be considered during error recovery.
48 //
49 // Error recovery often involves looking ahead in the input to determine if there's a point at which parsing may
50 // successfully resume. In some pathological cases, the parser can look through quite a large set of input which
51 // in turn generates a lot of back-tracking and performance degredation.
52 //
53 // The limit must be >= 1, and is recommended to be less than the default of 256.
54 func ErrorRecoveryLookaheadTokenLimitscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/parser`/ErrorRecoveryLookaheadTokenLimit().(limit int) Optionscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/parser`/Option# {
55 return func(opts *optionsscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/parser`/options#) error {
56 if limit < 1 {
57 return fmtscip-go gomod github.com/golang/go/src go1.23.0 fmt/.Errorfscip-go gomod github.com/golang/go/src go1.23.0 fmt/Errorf().("error recovery lookahead token limit must be at least 1: %d", limit)
58 }
59 opts.errorRecoveryTokenLookaheadLimitscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/parser`/options#errorRecoveryTokenLookaheadLimit. = limit
60 return nil
61 }
62 }
63
64 // ErrorRecoveryLimit limits the number of attempts the parser will perform to recover from an error.
65 func ErrorRecoveryLimitscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/parser`/ErrorRecoveryLimit().(limit int) Optionscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/parser`/Option# {
66 return func(opts *optionsscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/parser`/options#) error {
67 if limit < -1 {
68 return fmtscip-go gomod github.com/golang/go/src go1.23.0 fmt/.Errorfscip-go gomod github.com/golang/go/src go1.23.0 fmt/Errorf().("error recovery limit must be greater than or equal to -1: %d", limit)
69 }
70 opts.errorRecoveryLimitscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/parser`/options#errorRecoveryLimit. = limit
71 return nil
72 }
73 }
74
75 // ErrorReportingLimit limits the number of syntax error reports before terminating parsing.
76 //
77 // The limit must be at least 1. If unset, the limit will be 100.
78 func ErrorReportingLimitscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/parser`/ErrorReportingLimit().(limit int) Optionscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/parser`/Option# {
79 return func(opts *optionsscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/parser`/options#) error {
80 if limit < 1 {
81 return fmtscip-go gomod github.com/golang/go/src go1.23.0 fmt/.Errorfscip-go gomod github.com/golang/go/src go1.23.0 fmt/Errorf().("error reporting limit must be at least 1: %d", limit)
82 }
83 opts.errorReportingLimitscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/parser`/options#errorReportingLimit. = limit
84 return nil
85 }
86 }
87
88 // ExpressionSizeCodePointLimit is an option which limits the maximum code point count of an
89 // expression.
90 func ExpressionSizeCodePointLimitscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/parser`/ExpressionSizeCodePointLimit().(expressionSizeCodePointLimit int) Optionscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/parser`/Option# {
91 return func(opts *optionsscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/parser`/options#) error {
92 if expressionSizeCodePointLimit < -1 {
93 return fmtscip-go gomod github.com/golang/go/src go1.23.0 fmt/.Errorfscip-go gomod github.com/golang/go/src go1.23.0 fmt/Errorf().("expression size code point limit must be greater than or equal to -1: %d", expressionSizeCodePointLimit)
94 }
95 opts.expressionSizeCodePointLimitscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/parser`/options#expressionSizeCodePointLimit. = expressionSizeCodePointLimit
96 return nil
97 }
98 }
99
100 // Macros adds the given macros to the parser.
101 func Macrosscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/parser`/Macros().(macros ...Macroscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/parser`/Macro#) Optionscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/parser`/Option# {
102 return func(opts *optionsscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/parser`/options#) error {
103 for _, m := range macros {
104 if m != nil {
105 if opts.macrosscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/parser`/options#macros. == nil {
106 opts.macrosscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/parser`/options#macros. = make(map[string]Macroscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/parser`/Macro#)
107 }
108 opts.macrosscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/parser`/options#macros.[m.MacroKeyscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/parser`/Macro#MacroKey.()] = m
109 }
110 }
111 return nil
112 }
113 }
114
115 // PopulateMacroCalls ensures that the original call signatures replaced by expanded macros
116 // are preserved in the `SourceInfo` of parse result.
117 func PopulateMacroCallsscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/parser`/PopulateMacroCalls().(populateMacroCalls bool) Optionscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/parser`/Option# {
118 return func(opts *optionsscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/parser`/options#) error {
119 opts.populateMacroCallsscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/parser`/options#populateMacroCalls. = populateMacroCalls
120 return nil
121 }
122 }
123
124 // EnableOptionalSyntax enables syntax for optional field and index selection.
125 func EnableOptionalSyntaxscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/parser`/EnableOptionalSyntax().(optionalSyntax bool) Optionscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/parser`/Option# {
126 return func(opts *optionsscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/parser`/options#) error {
127 opts.enableOptionalSyntaxscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/parser`/options#enableOptionalSyntax. = optionalSyntax
128 return nil
129 }
130 }
131
132 // EnableIdentEscapeSyntax enables backtick (`) escaped field identifiers. This
133 // supports extended types of characters in identifiers, e.g. foo.`baz-bar`.
134 func EnableIdentEscapeSyntaxscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/parser`/EnableIdentEscapeSyntax().(enableIdentEscapeSyntax bool) Optionscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/parser`/Option# {
135 return func(opts *optionsscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/parser`/options#) error {
136 opts.enableIdentEscapeSyntaxscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/parser`/options#enableIdentEscapeSyntax. = enableIdentEscapeSyntax
137 return nil
138 }
139 }
140
141 // EnableHiddenAccumulatorName uses an accumulator variable name that is not a
142 // normally accessible identifier in source for comprehension macros. Compatibility notes:
143 // with this option enabled, a parsed AST would be semantically the same as if disabled, but would
144 // have different internal identifiers in any of the built-in comprehension sub-expressions. When
145 // disabled, it is possible but almost certainly a logic error to access the accumulator variable.
146 func EnableHiddenAccumulatorNamescip-go gomod github.com/google/cel-go . `github.com/google/cel-go/parser`/EnableHiddenAccumulatorName().(enabled bool) Optionscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/parser`/Option# {
147 return func(opts *optionsscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/parser`/options#) error {
148 opts.enableHiddenAccumulatorNamescip-go gomod github.com/google/cel-go . `github.com/google/cel-go/parser`/options#enableHiddenAccumulatorName. = enabled
149 return nil
150 }
151 }
152
153 // EnableVariadicOperatorASTs enables a compact representation of chained like-kind commutative
154 // operators. e.g. `a || b || c || d` -> `call(op='||', args=[a, b, c, d])`
155 //
156 // The benefit of enabling variadic operators ASTs is a more compact representation deeply nested
157 // logic graphs.
158 func EnableVariadicOperatorASTsscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/parser`/EnableVariadicOperatorASTs().(varArgASTs bool) Optionscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/parser`/Option# {
159 return func(opts *optionsscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/parser`/options#) error {
160 opts.enableVariadicOperatorASTsscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/parser`/options#enableVariadicOperatorASTs. = varArgASTs
161 return nil
162 }
163 }