MCPcopy
hub / github.com/hashicorp/hcl / scanTokens

Function scanTokens

hclsyntax/scan_tokens.go:4222–5273  ·  view source on GitHub ↗

line scan_tokens.rl:18

(data []byte, filename string, start hcl.Pos, mode scanMode)

Source from the content-addressed store, hash-verified

4220//line scan_tokens.rl:18
4221
4222func scanTokens(data []byte, filename string, start hcl.Pos, mode scanMode) []Token {
4223 stripData := stripUTF8BOM(data)
4224 start.Byte += len(data) - len(stripData)
4225 data = stripData
4226
4227 f := &tokenAccum{
4228 Filename: filename,
4229 Bytes: data,
4230 Pos: start,
4231 StartByte: start.Byte,
4232 }
4233
4234//line scan_tokens.rl:317
4235
4236 // Ragel state
4237 p := 0 // "Pointer" into data
4238 pe := len(data) // End-of-data "pointer"
4239 ts := 0
4240 te := 0
4241 act := 0
4242 eof := pe
4243 var stack []int
4244 var top int
4245
4246 var cs int // current state
4247 switch mode {
4248 case scanNormal:
4249 cs = hcltok_en_main
4250 case scanTemplate:
4251 cs = hcltok_en_bareTemplate
4252 case scanIdentOnly:
4253 cs = hcltok_en_identOnly
4254 default:
4255 panic("invalid scanMode")
4256 }
4257
4258 braces := 0
4259 var retBraces []int // stack of brace levels that cause us to use fret
4260 var heredocs []heredocInProgress // stack of heredocs we're currently processing
4261
4262//line scan_tokens.rl:352
4263
4264 // Make Go compiler happy
4265 _ = ts
4266 _ = te
4267 _ = act
4268 _ = eof
4269
4270 token := func(ty TokenType) {
4271 f.emitToken(ty, ts, te)
4272 }
4273 selfToken := func() {
4274 b := data[ts:te]
4275 if len(b) != 1 {
4276 // should never happen
4277 panic("selfToken only works for single-character tokens")
4278 }
4279 f.emitToken(TokenType(b[0]), ts, te)

Callers 6

LexConfigFunction · 0.85
LexExpressionFunction · 0.85
LexTemplateFunction · 0.85
ValidIdentifierFunction · 0.85
TestScanTokens_normalFunction · 0.85
TestScanTokens_templateFunction · 0.85

Calls 5

emitTokenMethod · 0.95
stripUTF8BOMFunction · 0.85
TokenTypeTypeAlias · 0.85
tokenStruct · 0.85
EqualMethod · 0.80

Tested by 2

TestScanTokens_normalFunction · 0.68
TestScanTokens_templateFunction · 0.68