|
|
@ -87,6 +87,8 @@ func lexRoot(l *lexer) (stateFn, error) {
|
|
|
|
return nil, err
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
switch r {
|
|
|
|
switch r {
|
|
|
|
|
|
|
|
case ';':
|
|
|
|
|
|
|
|
return lexComment, nil
|
|
|
|
case '(':
|
|
|
|
case '(':
|
|
|
|
return lexOpenParen, nil
|
|
|
|
return lexOpenParen, nil
|
|
|
|
case ' ', '\t', '\n':
|
|
|
|
case ' ', '\t', '\n':
|
|
|
@ -104,10 +106,12 @@ func lexOpenParen(l *lexer) (stateFn, error) {
|
|
|
|
return nil, err
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
switch r {
|
|
|
|
switch r {
|
|
|
|
case ' ', '\t', '\n':
|
|
|
|
case ' ', '\t', '\n', '\r':
|
|
|
|
return lexRoot, nil
|
|
|
|
return lexWhitespace, nil
|
|
|
|
case '(':
|
|
|
|
case '(':
|
|
|
|
return nil, fmt.Errorf("the whole (( thing isn't supported yet")
|
|
|
|
return nil, fmt.Errorf("the whole (( thing isn't supported yet")
|
|
|
|
|
|
|
|
case ';':
|
|
|
|
|
|
|
|
return lexComment, nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if isDigit(r) {
|
|
|
|
if isDigit(r) {
|
|
|
|
l.append(r)
|
|
|
|
l.append(r)
|
|
|
@ -132,6 +136,8 @@ func lexWhitespace(l *lexer) (stateFn, error) {
|
|
|
|
return lexString, nil
|
|
|
|
return lexString, nil
|
|
|
|
case '(':
|
|
|
|
case '(':
|
|
|
|
return lexOpenParen, nil
|
|
|
|
return lexOpenParen, nil
|
|
|
|
|
|
|
|
case ';':
|
|
|
|
|
|
|
|
return lexComment, nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if isDigit(r) {
|
|
|
|
if isDigit(r) {
|
|
|
|
l.append(r)
|
|
|
|
l.append(r)
|
|
|
@ -157,6 +163,7 @@ func lexString(l *lexer) (stateFn, error) {
|
|
|
|
return lexString, nil
|
|
|
|
return lexString, nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// lex the character *after* the string escape character \
|
|
|
|
func lexStringEsc(l *lexer) (stateFn, error) {
|
|
|
|
func lexStringEsc(l *lexer) (stateFn, error) {
|
|
|
|
r, err := l.next()
|
|
|
|
r, err := l.next()
|
|
|
|
if err != nil {
|
|
|
|
if err != nil {
|
|
|
@ -184,6 +191,9 @@ func lexInt(l *lexer) (stateFn, error) {
|
|
|
|
case ')':
|
|
|
|
case ')':
|
|
|
|
l.emit(int3ger)
|
|
|
|
l.emit(int3ger)
|
|
|
|
return lexCloseParen, nil
|
|
|
|
return lexCloseParen, nil
|
|
|
|
|
|
|
|
case ';':
|
|
|
|
|
|
|
|
l.emit(int3ger)
|
|
|
|
|
|
|
|
return lexComment, nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if isDigit(r) {
|
|
|
|
if isDigit(r) {
|
|
|
|
l.append(r)
|
|
|
|
l.append(r)
|
|
|
@ -207,6 +217,9 @@ func lexFloat(l *lexer) (stateFn, error) {
|
|
|
|
case ')':
|
|
|
|
case ')':
|
|
|
|
l.emit(fl0at)
|
|
|
|
l.emit(fl0at)
|
|
|
|
return lexCloseParen, nil
|
|
|
|
return lexCloseParen, nil
|
|
|
|
|
|
|
|
case ';':
|
|
|
|
|
|
|
|
l.emit(fl0at)
|
|
|
|
|
|
|
|
return lexComment, nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if isDigit(r) {
|
|
|
|
if isDigit(r) {
|
|
|
|
l.append(r)
|
|
|
|
l.append(r)
|
|
|
@ -228,6 +241,9 @@ func lexSymbol(l *lexer) (stateFn, error) {
|
|
|
|
case ')':
|
|
|
|
case ')':
|
|
|
|
l.emit(symbol)
|
|
|
|
l.emit(symbol)
|
|
|
|
return lexCloseParen, nil
|
|
|
|
return lexCloseParen, nil
|
|
|
|
|
|
|
|
case ';':
|
|
|
|
|
|
|
|
l.emit(symbol)
|
|
|
|
|
|
|
|
return lexComment, nil
|
|
|
|
default:
|
|
|
|
default:
|
|
|
|
l.append(r)
|
|
|
|
l.append(r)
|
|
|
|
return lexSymbol, nil
|
|
|
|
return lexSymbol, nil
|
|
|
@ -252,10 +268,29 @@ func lexCloseParen(l *lexer) (stateFn, error) {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
case ')':
|
|
|
|
case ')':
|
|
|
|
return lexCloseParen, nil
|
|
|
|
return lexCloseParen, nil
|
|
|
|
|
|
|
|
case ';':
|
|
|
|
|
|
|
|
return lexComment, nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return nil, fmt.Errorf("unimplemented")
|
|
|
|
return nil, fmt.Errorf("unimplemented")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// lexes a comment
|
|
|
|
|
|
|
|
func lexComment(l *lexer) (stateFn, error) {
|
|
|
|
|
|
|
|
r, err := l.next()
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
|
|
|
|
return nil, err
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
switch r {
|
|
|
|
|
|
|
|
case '\n', '\r':
|
|
|
|
|
|
|
|
if l.depth == 0 {
|
|
|
|
|
|
|
|
return lexRoot, nil
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
return lexWhitespace, nil
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return lexComment, nil
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// lexes some lispy input from an io.Reader, emiting tokens on chan c. The
|
|
|
|
// lexes some lispy input from an io.Reader, emiting tokens on chan c. The
|
|
|
|
// channel is closed when the input reaches EOF, signaling that there are no
|
|
|
|
// channel is closed when the input reaches EOF, signaling that there are no
|
|
|
|
// new tokens.
|
|
|
|
// new tokens.
|
|
|
|