MCPcopy Create free account
hub / github.com/ajitpratap0/GoSQLX / toSQLPosition

Method toSQLPosition

pkg/sql/tokenizer/tokenizer.go:1742–1776  ·  view source on GitHub ↗

toSQLPosition converts an internal Position => a models.Location

(pos Position)

Source from the content-addressed store, hash-verified

1740
1741// toSQLPosition converts an internal Position => a models.Location
1742func (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
1779func (t *Tokenizer) getCurrentPosition() models.Location {

Callers 8

TokenizeMethod · 0.95
TokenizeContextMethod · 0.95
readQuotedIdentifierMethod · 0.95
readQuotedStringMethod · 0.95
readPunctuationMethod · 0.95
getCurrentPositionMethod · 0.95

Calls

no outgoing calls

Tested by

no test coverage detected