NewParser builds and returns a new Parser using the provided options.
(opts ...Option)
| 30 | |
| 31 | // NewParser builds and returns a new Parser using the provided options. |
| 32 | func NewParser(opts ...Option) (*Parser, error) { |
| 33 | p := &Parser{} |
| 34 | p.enableHiddenAccumulatorName = true |
| 35 | p.enableIdentEscapeSyntax = true |
| 36 | for _, opt := range opts { |
| 37 | if err := opt(&p.options); err != nil { |
| 38 | return nil, err |
| 39 | } |
| 40 | } |
| 41 | if p.errorReportingLimit == 0 { |
| 42 | p.errorReportingLimit = 100 |
| 43 | } |
| 44 | if p.maxRecursionDepth == 0 { |
| 45 | p.maxRecursionDepth = 250 |
| 46 | } |
| 47 | if p.maxRecursionDepth == -1 { |
| 48 | p.maxRecursionDepth = math.MaxInt |
| 49 | } |
| 50 | if p.errorRecoveryTokenLookaheadLimit == 0 { |
| 51 | p.errorRecoveryTokenLookaheadLimit = 256 |
| 52 | } |
| 53 | if p.errorRecoveryLimit == 0 { |
| 54 | p.errorRecoveryLimit = 30 |
| 55 | } |
| 56 | if p.errorRecoveryLimit == -1 { |
| 57 | p.errorRecoveryLimit = math.MaxInt |
| 58 | } |
| 59 | if p.expressionSizeCodePointLimit == 0 { |
| 60 | p.expressionSizeCodePointLimit = 100_000 |
| 61 | } |
| 62 | if p.expressionSizeCodePointLimit == -1 { |
| 63 | p.expressionSizeCodePointLimit = math.MaxInt |
| 64 | } |
| 65 | if p.maxExpressionNodeCount == 0 { |
| 66 | p.maxExpressionNodeCount = 100_000 |
| 67 | } |
| 68 | if p.maxExpressionNodeCount == -1 { |
| 69 | p.maxExpressionNodeCount = math.MaxInt |
| 70 | } |
| 71 | // Bool is false by default, so populateMacroCalls will be false by default |
| 72 | return p, nil |
| 73 | } |
| 74 | |
| 75 | // mustNewParser does the work of NewParser and panics if an error occurs. |
| 76 | // |
no outgoing calls