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

Function NewSourceInfo

common/ast/ast.go:201–225  ·  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

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

Callers 15

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 11

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