toSQLPosition converts an internal Position => a models.Location
(pos Position)
| 1740 | |
| 1741 | // toSQLPosition converts an internal Position => a models.Location |
| 1742 | func (t *Tokenizer) toSQLPosition(pos Position) models.Location { |
| 1743 | // Find the line containing pos |
| 1744 | line := 1 |
| 1745 | lineStart := 0 |
| 1746 | |
| 1747 | // Find the line number using lineStarts |
| 1748 | for i := 0; i < len(t.lineStarts); i++ { |
| 1749 | if t.lineStarts[i] > pos.Index { |
| 1750 | break |
| 1751 | } |
| 1752 | line = i + 1 |
| 1753 | lineStart = t.lineStarts[i] |
| 1754 | } |
| 1755 | |
| 1756 | // Calculate column by counting characters from line start |
| 1757 | // Column is 1-based, so we start at 1 |
| 1758 | column := 1 |
| 1759 | for i := lineStart; i < pos.Index && i < len(t.input); i++ { |
| 1760 | if t.input[i] == '\t' { |
| 1761 | column += 4 // Treat tab as 4 spaces |
| 1762 | } else { |
| 1763 | column++ |
| 1764 | } |
| 1765 | } |
| 1766 | |
| 1767 | // Ensure column is never less than 1 |
| 1768 | if column < 1 { |
| 1769 | column = 1 |
| 1770 | } |
| 1771 | |
| 1772 | return models.Location{ |
| 1773 | Line: line, |
| 1774 | Column: column, |
| 1775 | } |
| 1776 | } |
| 1777 | |
| 1778 | // getCurrentPosition returns the Location of the tokenizer's current byte index |
| 1779 | func (t *Tokenizer) getCurrentPosition() models.Location { |
no outgoing calls
no test coverage detected