MCPcopy Create free account
hub / github.com/cockroachdb/cockroachdb-parser / findFirstOccurrence

Method findFirstOccurrence

pkg/sql/plpgsql/parser/lexer.go:444–460  ·  view source on GitHub ↗

findFirstOccurrence searches from the current position for occurrences of the supplied tokens, returning the first one found. The cursor is not advanced unless there is an error. If the given terminators are not found, the function returns 0.

(
	terminator1 int, terminators ...int,
)

Source from the content-addressed store, hash-verified

442// unless there is an error. If the given terminators are not found, the
443// function returns 0.
444func (l *lexer) findFirstOccurrence(
445 terminator1 int, terminators ...int,
446) (foundToken int, err error) {
447 if l.parser.Lookahead() != -1 {
448 // Push back the lookahead token so that it can be included.
449 l.PushBack(1)
450 }
451 originalPos := l.lastPos
452 _, _, terminatorMet, err := l.readSQLConstruct(
453 true /* isExpr */, true /* allowEmpty */, terminator1, terminators...,
454 )
455 if err == nil {
456 // Restore the original position.
457 l.lastPos = originalPos
458 }
459 return terminatorMet, err
460}
461
462func (l *lexer) readSQLConstruct(
463 isExpr, allowEmpty bool, terminator1 int, terminators ...int,

Callers 1

ParseMethod · 0.80

Calls 3

PushBackMethod · 0.95
readSQLConstructMethod · 0.95
LookaheadMethod · 0.65

Tested by

no test coverage detected