Parse parses the expression represented by source using the Pratt parser and returns the result.
(source common.Source)
| 106 | |
| 107 | // Parse parses the expression represented by source using the Pratt parser and returns the result. |
| 108 | func (p *prattParser) Parse(source common.Source) (*ast.AST, *common.Errors) { |
| 109 | errs := common.NewErrors(source) |
| 110 | buf, ok := source.(runes.Buffer) |
| 111 | if !ok { |
| 112 | buf = runes.NewBuffer(source.Content()) |
| 113 | } |
| 114 | if buf.Len() > p.expressionSizeCodePointLimit { |
| 115 | errs.ReportError(common.NoLocation, |
| 116 | "expression code point size exceeds limit: size: %d, limit %d", |
| 117 | buf.Len(), p.expressionSizeCodePointLimit) |
| 118 | return nil, errs |
| 119 | } |
| 120 | accu := AccumulatorName |
| 121 | if p.enableHiddenAccumulatorName { |
| 122 | accu = HiddenAccumulatorName |
| 123 | } |
| 124 | fac := ast.NewExprFactoryWithAccumulator(accu) |
| 125 | pratt := &prattParserWorker{ |
| 126 | content: buf, |
| 127 | length: int32(buf.Len()), |
| 128 | helper: newParserHelper(source, fac), |
| 129 | errors: &parseErrors{errs}, |
| 130 | exprFactory: fac, |
| 131 | lexer: newLexer(buf), |
| 132 | macros: p.macros, |
| 133 | maxRecursionDepth: p.maxRecursionDepth, |
| 134 | maxExpressionNodeCount: p.maxExpressionNodeCount, |
| 135 | errorReportingLimit: p.errorReportingLimit, |
| 136 | errorRecoveryLimit: p.errorRecoveryLimit, |
| 137 | populateMacroCalls: p.populateMacroCalls, |
| 138 | enableOptionalSyntax: p.enableOptionalSyntax, |
| 139 | enableVariadicOperatorASTs: p.enableVariadicOperatorASTs, |
| 140 | enableIdentEscapeSyntax: p.enableIdentEscapeSyntax, |
| 141 | enableCallEscapeSyntax: p.enableCallEscapeSyntax, |
| 142 | } |
| 143 | pratt.initTokenStream() |
| 144 | out := pratt.parse() |
| 145 | if len(errs.GetErrors()) > 0 { |
| 146 | return nil, errs |
| 147 | } |
| 148 | return ast.NewAST(out, pratt.helper.getSourceInfo()), errs |
| 149 | } |
| 150 | |
| 151 | func (p *prattParserWorker) initTokenStream() { |
| 152 | p.currTok = token{kind: tokError, start: 0, end: 0} |
nothing calls this directly
no test coverage detected