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