1
0
Fork 0

Respect starting line numbers for strings

This commit is contained in:
Gregory Eremin 2015-02-18 00:18:27 +07:00
parent eb86a5613d
commit 87f8cdded6
1 changed files with 13 additions and 11 deletions

View File

@ -17,6 +17,7 @@ type (
colNum int // Column number colNum int // Column number
pos int // Current position in the input pos int // Current position in the input
start int // Start position of this item start int // Start position of this item
startLine int // Start line of this item
startCol int // Start column of this item startCol int // Start column of this item
width int // Width of last rune read from input width int // Width of last rune read from input
items chan Item // Channel of scanned items items chan Item // Channel of scanned items
@ -136,6 +137,7 @@ func (l *Lexer) backup() {
// Skips over the pending input before this point // Skips over the pending input before this point
func (l *Lexer) ignore() { func (l *Lexer) ignore() {
l.start = l.pos l.start = l.pos
l.startLine = l.lineNum
l.startCol = l.colNum l.startCol = l.colNum
} }
@ -143,9 +145,9 @@ func (l *Lexer) ignore() {
func (l *Lexer) emit(t Token) { func (l *Lexer) emit(t Token) {
l.items <- Item{ l.items <- Item{
Token: t, Token: t,
Val: l.input[l.start:l.pos], Val: l.val(),
Pos: l.start, Pos: l.start,
Line: l.lineNum, Line: l.startLine,
Column: l.startCol, Column: l.startCol,
} }
l.ignore() // Cleaning up input l.ignore() // Cleaning up input
@ -160,7 +162,7 @@ func (l *Lexer) errorf(format string, args ...interface{}) stateFn {
Token: Error, Token: Error,
Val: fmt.Sprintf(format, args...), Val: fmt.Sprintf(format, args...),
Pos: l.start, Pos: l.start,
Line: l.lineNum, Line: l.startLine,
Column: l.startCol, Column: l.startCol,
} }
close(l.items) close(l.items)