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

Function NewSourceInfo

common/ast/ast.go:193–217  ·  view source on GitHub ↗

NewSourceInfo creates a simple SourceInfo object from an input common.Source value.

(src common.Source)

Source from the content-addressed store, hash-verified

191
192// NewSourceInfo creates a simple SourceInfo object from an input common.Source value.
193func NewSourceInfo(src common.Source) *SourceInfo {
194 var lineOffsets []int32
195 var desc string
196 baseLine := int32(0)
197 baseCol := int32(0)
198 if src != nil {
199 desc = src.Description()
200 lineOffsets = src.LineOffsets()
201 // Determine whether the source metadata should be computed relative
202 // to a base line and column value. This can be determined by requesting
203 // the location for offset 0 from the source object.
204 if loc, found := src.OffsetLocation(0); found {
205 baseLine = int32(loc.Line()) - 1
206 baseCol = int32(loc.Column())
207 }
208 }
209 return &SourceInfo{
210 desc: desc,
211 lines: lineOffsets,
212 baseLine: baseLine,
213 baseCol: baseCol,
214 offsetRanges: make(map[int64]OffsetRange),
215 macroCalls: make(map[int64]Expr),
216 }
217}
218
219// CopySourceInfo creates a deep copy of the MacroCalls within the input SourceInfo.
220//

Callers 14

ParseMethod · 0.92
PruneAstFunction · 0.92
TestCheckInvalidLiteralFunction · 0.92
newParserHelperFunction · 0.92
TestUnparseErrorsFunction · 0.92
OptimizeMethod · 0.92
TestSourceInfoFunction · 0.92
TestSourceInfoNilSafetyFunction · 0.92
TestHasExtensionFunction · 0.92

Calls 5

DescriptionMethod · 0.65
LineOffsetsMethod · 0.65
OffsetLocationMethod · 0.65
LineMethod · 0.65
ColumnMethod · 0.65

Tested by 10

TestCheckInvalidLiteralFunction · 0.74
TestUnparseErrorsFunction · 0.74
TestSourceInfoFunction · 0.74
TestSourceInfoNilSafetyFunction · 0.74
TestHasExtensionFunction · 0.74
TestConvertASTFunction · 0.74