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, )
| 442 | // unless there is an error. If the given terminators are not found, the |
| 443 | // function returns 0. |
| 444 | func (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 | |
| 462 | func (l *lexer) readSQLConstruct( |
| 463 | isExpr, allowEmpty bool, terminator1 int, terminators ...int, |
no test coverage detected