|
|
@ -10,27 +10,27 @@ type typ3 int
|
|
|
|
|
|
|
|
|
|
|
|
const (
|
|
|
|
const (
|
|
|
|
invalid typ3 = iota
|
|
|
|
invalid typ3 = iota
|
|
|
|
int3ger
|
|
|
|
integerToken
|
|
|
|
symbol
|
|
|
|
symbolToken
|
|
|
|
openParen
|
|
|
|
openParenToken
|
|
|
|
closeParen
|
|
|
|
closeParenToken
|
|
|
|
str1ng
|
|
|
|
stringToken
|
|
|
|
fl0at
|
|
|
|
floatToken
|
|
|
|
)
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
func (t typ3) String() string {
|
|
|
|
func (t typ3) String() string {
|
|
|
|
switch t {
|
|
|
|
switch t {
|
|
|
|
case int3ger:
|
|
|
|
case integerToken:
|
|
|
|
return "integer"
|
|
|
|
return "integer"
|
|
|
|
case symbol:
|
|
|
|
case symbolToken:
|
|
|
|
return "symbol"
|
|
|
|
return "symbol"
|
|
|
|
case openParen:
|
|
|
|
case openParenToken:
|
|
|
|
return "open_paren"
|
|
|
|
return "open_paren"
|
|
|
|
case closeParen:
|
|
|
|
case closeParenToken:
|
|
|
|
return "close_paren"
|
|
|
|
return "close_paren"
|
|
|
|
case str1ng:
|
|
|
|
case stringToken:
|
|
|
|
return "string"
|
|
|
|
return "string"
|
|
|
|
case fl0at:
|
|
|
|
case floatToken:
|
|
|
|
return "float"
|
|
|
|
return "float"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
panic("wtf")
|
|
|
|
panic("wtf")
|
|
|
@ -85,7 +85,7 @@ func debugPrint(s string) {
|
|
|
|
// lexes an open parenthesis
|
|
|
|
// lexes an open parenthesis
|
|
|
|
func lexOpenParen(l *lexer) (stateFn, error) {
|
|
|
|
func lexOpenParen(l *lexer) (stateFn, error) {
|
|
|
|
debugPrint("-->lexOpenParen")
|
|
|
|
debugPrint("-->lexOpenParen")
|
|
|
|
l.out <- token{"(", openParen}
|
|
|
|
l.out <- token{"(", openParenToken}
|
|
|
|
l.depth++
|
|
|
|
l.depth++
|
|
|
|
r, _, err := l.ReadRune()
|
|
|
|
r, _, err := l.ReadRune()
|
|
|
|
if err != nil {
|
|
|
|
if err != nil {
|
|
|
@ -146,7 +146,7 @@ func lexString(l *lexer) (stateFn, error) {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
switch r {
|
|
|
|
switch r {
|
|
|
|
case '"':
|
|
|
|
case '"':
|
|
|
|
l.emit(str1ng)
|
|
|
|
l.emit(stringToken)
|
|
|
|
return lexWhitespace, nil
|
|
|
|
return lexWhitespace, nil
|
|
|
|
case '\\':
|
|
|
|
case '\\':
|
|
|
|
return lexStringEsc, nil
|
|
|
|
return lexStringEsc, nil
|
|
|
@ -177,16 +177,16 @@ func lexInt(l *lexer) (stateFn, error) {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
switch r {
|
|
|
|
switch r {
|
|
|
|
case ' ', '\t', '\n', '\r':
|
|
|
|
case ' ', '\t', '\n', '\r':
|
|
|
|
l.emit(int3ger)
|
|
|
|
l.emit(integerToken)
|
|
|
|
return lexWhitespace, nil
|
|
|
|
return lexWhitespace, nil
|
|
|
|
case '.':
|
|
|
|
case '.':
|
|
|
|
l.append(r)
|
|
|
|
l.append(r)
|
|
|
|
return lexFloat, nil
|
|
|
|
return lexFloat, nil
|
|
|
|
case ')':
|
|
|
|
case ')':
|
|
|
|
l.emit(int3ger)
|
|
|
|
l.emit(integerToken)
|
|
|
|
return lexCloseParen, nil
|
|
|
|
return lexCloseParen, nil
|
|
|
|
case ';':
|
|
|
|
case ';':
|
|
|
|
l.emit(int3ger)
|
|
|
|
l.emit(integerToken)
|
|
|
|
return lexComment, nil
|
|
|
|
return lexComment, nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if isDigit(r) {
|
|
|
|
if isDigit(r) {
|
|
|
@ -207,13 +207,13 @@ func lexFloat(l *lexer) (stateFn, error) {
|
|
|
|
|
|
|
|
|
|
|
|
switch r {
|
|
|
|
switch r {
|
|
|
|
case ' ', '\t', '\n', '\r':
|
|
|
|
case ' ', '\t', '\n', '\r':
|
|
|
|
l.emit(fl0at)
|
|
|
|
l.emit(floatToken)
|
|
|
|
return lexWhitespace, nil
|
|
|
|
return lexWhitespace, nil
|
|
|
|
case ')':
|
|
|
|
case ')':
|
|
|
|
l.emit(fl0at)
|
|
|
|
l.emit(floatToken)
|
|
|
|
return lexCloseParen, nil
|
|
|
|
return lexCloseParen, nil
|
|
|
|
case ';':
|
|
|
|
case ';':
|
|
|
|
l.emit(fl0at)
|
|
|
|
l.emit(floatToken)
|
|
|
|
return lexComment, nil
|
|
|
|
return lexComment, nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if isDigit(r) {
|
|
|
|
if isDigit(r) {
|
|
|
@ -234,13 +234,13 @@ func lexSymbol(l *lexer) (stateFn, error) {
|
|
|
|
switch r {
|
|
|
|
switch r {
|
|
|
|
case ' ', '\t', '\n', '\r':
|
|
|
|
case ' ', '\t', '\n', '\r':
|
|
|
|
debugPrint("ending lexSymbol on whitespace")
|
|
|
|
debugPrint("ending lexSymbol on whitespace")
|
|
|
|
l.emit(symbol)
|
|
|
|
l.emit(symbolToken)
|
|
|
|
return lexWhitespace, nil
|
|
|
|
return lexWhitespace, nil
|
|
|
|
case ')':
|
|
|
|
case ')':
|
|
|
|
l.emit(symbol)
|
|
|
|
l.emit(symbolToken)
|
|
|
|
return lexCloseParen, nil
|
|
|
|
return lexCloseParen, nil
|
|
|
|
case ';':
|
|
|
|
case ';':
|
|
|
|
l.emit(symbol)
|
|
|
|
l.emit(symbolToken)
|
|
|
|
return lexComment, nil
|
|
|
|
return lexComment, nil
|
|
|
|
default:
|
|
|
|
default:
|
|
|
|
l.append(r)
|
|
|
|
l.append(r)
|
|
|
@ -252,7 +252,7 @@ func lexSymbol(l *lexer) (stateFn, error) {
|
|
|
|
// lex a close parenthesis
|
|
|
|
// lex a close parenthesis
|
|
|
|
func lexCloseParen(l *lexer) (stateFn, error) {
|
|
|
|
func lexCloseParen(l *lexer) (stateFn, error) {
|
|
|
|
debugPrint("-->lexCloseParen")
|
|
|
|
debugPrint("-->lexCloseParen")
|
|
|
|
l.out <- token{")", closeParen}
|
|
|
|
l.out <- token{")", closeParenToken}
|
|
|
|
l.depth--
|
|
|
|
l.depth--
|
|
|
|
r, _, err := l.ReadRune()
|
|
|
|
r, _, err := l.ReadRune()
|
|
|
|
if err != nil {
|
|
|
|
if err != nil {
|
|
|
|