MCPcopy Create free account
hub / github.com/cel-expr/cel-go / Parse

Method Parse

parser/pratt_parser.go:108–149  ·  view source on GitHub ↗

Parse parses the expression represented by source using the Pratt parser and returns the result.

(source common.Source)

Source from the content-addressed store, hash-verified

106
107// Parse parses the expression represented by source using the Pratt parser and returns the result.
108func (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
151func (p *prattParserWorker) initTokenStream() {
152 p.currTok = token{kind: tokError, start: 0, end: 0}

Callers

nothing calls this directly

Calls 13

ReportErrorMethod · 0.95
initTokenStreamMethod · 0.95
parseMethod · 0.95
GetErrorsMethod · 0.95
NewErrorsFunction · 0.92
NewBufferFunction · 0.92
NewASTFunction · 0.92
newParserHelperFunction · 0.85
newLexerFunction · 0.85
getSourceInfoMethod · 0.80
ContentMethod · 0.65

Tested by

no test coverage detected