From b023686c815311ed69756b0a68a019dedac0dbc9 Mon Sep 17 00:00:00 2001 From: Jordan Orelli Date: Sun, 21 Oct 2012 13:21:38 -0400 Subject: [PATCH] added support for unary - --- lex.go | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/lex.go b/lex.go index 1d28262..9abbdd4 100644 --- a/lex.go +++ b/lex.go @@ -109,6 +109,26 @@ func lexOpenParen(l *lexer) (stateFn, error) { case '.': l.keep() return lexFloat, nil + case '-': + l.keep() + return lexMinus, nil + } + if isDigit(l.cur) { + l.keep() + return lexInt, nil + } + l.keep() + return lexSymbol, nil +} + +func lexMinus(l *lexer) (stateFn, error) { + switch l.cur { + case ' ', '\t', '\n', '\r': + l.emit(symbolToken) + return lexWhitespace, nil + case '.': + l.keep() + return lexFloat, nil } if isDigit(l.cur) { l.keep() @@ -137,6 +157,9 @@ func lexWhitespace(l *lexer) (stateFn, error) { case '.': l.keep() return lexFloat, nil + case '-': + l.keep() + return lexMinus, nil } if isDigit(l.cur) { l.keep()