(line, col int)
| 554 | } |
| 555 | |
| 556 | func (t *Tokenizer) readMultiLineString(line, col int) (Token, error) { |
| 557 | var sb strings.Builder |
| 558 | for { |
| 559 | if t.pos >= len(t.input) { |
| 560 | return Token{}, t.error("unterminated multi-line string") |
| 561 | } |
| 562 | ch := t.peek() |
| 563 | if ch == '"' && t.peekAt(1) == '"' && t.peekAt(2) == '"' { |
| 564 | t.advance() |
| 565 | t.advance() |
| 566 | t.advance() |
| 567 | content := dedentMultiLineString(sb.String()) |
| 568 | return Token{Type: TokenMultiLineString, Value: content, Line: line, Col: col}, nil |
| 569 | } |
| 570 | ch = t.advance() |
| 571 | if ch == '\\' { |
| 572 | escaped, err := t.readEscape() |
| 573 | if err != nil { |
| 574 | return Token{}, err |
| 575 | } |
| 576 | sb.WriteString(escaped) |
| 577 | } else { |
| 578 | sb.WriteRune(ch) |
| 579 | } |
| 580 | } |
| 581 | } |
| 582 | |
| 583 | // dedentMultiLineString removes common leading whitespace from multi-line strings. |
| 584 | // The last line's whitespace determines the indentation to strip. |
no test coverage detected