Parse parses the expression represented by source and returns the result.
(source common.Source)
| 90 | |
| 91 | // Parse parses the expression represented by source and returns the result. |
| 92 | func (p *Parser) Parse(source common.Source) (*ast.AST, *common.Errors) { |
| 93 | errs := common.NewErrors(source) |
| 94 | accu := AccumulatorName |
| 95 | if p.enableHiddenAccumulatorName { |
| 96 | accu = HiddenAccumulatorName |
| 97 | } |
| 98 | fac := ast.NewExprFactoryWithAccumulator(accu) |
| 99 | impl := parser{ |
| 100 | errors: &parseErrors{errs}, |
| 101 | exprFactory: fac, |
| 102 | helper: newParserHelper(source, fac), |
| 103 | macros: p.macros, |
| 104 | maxRecursionDepth: p.maxRecursionDepth, |
| 105 | errorReportingLimit: p.errorReportingLimit, |
| 106 | errorRecoveryLimit: p.errorRecoveryLimit, |
| 107 | errorRecoveryLookaheadTokenLimit: p.errorRecoveryTokenLookaheadLimit, |
| 108 | populateMacroCalls: p.populateMacroCalls, |
| 109 | enableOptionalSyntax: p.enableOptionalSyntax, |
| 110 | enableVariadicOperatorASTs: p.enableVariadicOperatorASTs, |
| 111 | enableIdentEscapeSyntax: p.enableIdentEscapeSyntax, |
| 112 | } |
| 113 | buf, ok := source.(runes.Buffer) |
| 114 | if !ok { |
| 115 | buf = runes.NewBuffer(source.Content()) |
| 116 | } |
| 117 | var out ast.Expr |
| 118 | if buf.Len() > p.expressionSizeCodePointLimit { |
| 119 | out = impl.reportError(common.NoLocation, |
| 120 | "expression code point size exceeds limit: size: %d, limit %d", |
| 121 | buf.Len(), p.expressionSizeCodePointLimit) |
| 122 | } else { |
| 123 | out = impl.parse(buf, source.Description()) |
| 124 | } |
| 125 | return ast.NewAST(out, impl.helper.getSourceInfo()), errs |
| 126 | } |
| 127 | |
| 128 | // reservedIds are not legal to use as variables. We exclude them post-parse, as they *are* valid |
| 129 | // field names for protos, and it would complicate the grammar to distinguish the cases. |