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

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