MCPcopy Create free account
hub / github.com/KhronosGroup/SPIRV-Tools / lex

Function lex

utils/vscode/src/parser/parser.go:354–392  ·  view source on GitHub ↗

lex returns all the tokens and diagnostics after lexing source.

(source string)

Source from the content-addressed store, hash-verified

352
353// lex returns all the tokens and diagnostics after lexing source.
354func lex(source string) ([]*Token, []Diagnostic, error) {
355 l := lexer{source: source, lexerState: lexerState{pos: Position{1, 1}}}
356
357 lastPos := Position{}
358 for l.e == nil {
359 // Integrity check that the parser is making progress
360 if l.pos == lastPos {
361 log.Panicf("Parsing stuck at %v", l.pos)
362 }
363 lastPos = l.pos
364
365 s := l.save()
366 r := l.next()
367 switch {
368 case r == '%':
369 l.restore(s)
370 l.pident()
371 case r == '+' || r == '-' || r == '_' || isAlphaNumeric(r):
372 l.restore(s)
373 l.numberOrIdent()
374 case r == '"':
375 l.restore(s)
376 l.string()
377 case r == '=', r == '|':
378 l.restore(s)
379 l.operator()
380 case r == ';':
381 l.restore(s)
382 l.lineComment()
383 case r == '\n':
384 l.restore(s)
385 l.newline()
386 }
387 }
388 if l.e != nil && l.e != io.EOF {
389 return nil, nil, l.e
390 }
391 return l.toks, l.diags, nil
392}
393
394func isNumeric(r rune) bool { return unicode.IsDigit(r) }
395func isAlpha(r rune) bool { return unicode.IsLetter(r) }

Callers 1

ParseFunction · 0.85

Calls 10

saveMethod · 0.95
nextMethod · 0.95
restoreMethod · 0.95
pidentMethod · 0.95
numberOrIdentMethod · 0.95
stringMethod · 0.95
operatorMethod · 0.95
lineCommentMethod · 0.95
newlineMethod · 0.95
isAlphaNumericFunction · 0.85

Tested by

no test coverage detected