1
0
Fork 0

Get rid of loop labels

This commit is contained in:
Gregory Eremin 2015-02-16 18:25:33 +07:00
parent ca7f4c9acb
commit def30c216c
1 changed files with 7 additions and 18 deletions

View File

@ -167,13 +167,13 @@ func (l *Lexer) errorf(format string, args ...interface{}) stateFn {
// //
func lexInitial(l *Lexer) stateFn { func lexInitial(l *Lexer) stateFn {
loop:
for { for {
switch r := l.next(); r { switch r := l.next(); r {
case ' ', '\t': case ' ', '\t':
return lexSpace(l) return lexSpace(l)
case '\n': case '\n':
l.lineNum++ l.lineNum++
l.ignore()
case 'n': case 'n':
l.backup() l.backup()
return lexNull(l) return lexNull(l)
@ -198,20 +198,15 @@ loop:
case ',': case ',':
l.emit(Comma) l.emit(Comma)
case 0: case 0:
break loop l.emit(EOF)
return nil
default: default:
panic("Unexpected symbol: " + string(r)) panic("Unexpected symbol: " + string(r))
} }
} }
// Correctly reached EOF.
l.emit(EOF)
return nil
} }
// Skip all spaces // Skip all spaces
// One space has already been seen
func lexSpace(l *Lexer) stateFn { func lexSpace(l *Lexer) stateFn {
for { for {
if r := l.peek(); r == ' ' || r == '\t' { if r := l.peek(); r == ' ' || r == '\t' {
@ -243,7 +238,6 @@ func lexBool(l *Lexer) stateFn {
func lexNumber(l *Lexer) stateFn { func lexNumber(l *Lexer) stateFn {
hasDot := false hasDot := false
loop:
for { for {
switch r := l.peek(); r { switch r := l.peek(); r {
case '1', '2', '3', '4', '5', '6', '7', '8', '9', '0': case '1', '2', '3', '4', '5', '6', '7', '8', '9', '0':
@ -256,27 +250,24 @@ loop:
l.next() l.next()
} }
default: default:
break loop l.emit(Number)
return lexInitial
} }
} }
l.emit(Number)
return lexInitial
} }
func lexString(l *Lexer) stateFn { func lexString(l *Lexer) stateFn {
escaped := false escaped := false
loop:
for { for {
switch r := l.next(); r { switch r := l.next(); r {
case '\\': case '\\':
escaped = true escaped = !escaped
case '"': case '"':
if escaped { if escaped {
escaped = false escaped = false
} else { } else {
l.emit(String) l.emit(String)
break loop return lexInitial
} }
case '\n': case '\n':
l.lineNum++ l.lineNum++
@ -286,6 +277,4 @@ loop:
escaped = false escaped = false
} }
} }
return lexInitial
} }