scanner: implement remaning tokens

This commit is contained in:
Fatih Arslan 2015-10-05 13:12:48 +03:00
parent dd848e3dab
commit 9096153a34
2 changed files with 35 additions and 1 deletions

View File

@ -121,12 +121,30 @@ func (s *Scanner) Scan() (tok token.Token) {
tok = token.STRING
s.scanString()
case '.':
ch = s.next()
ch = s.peek()
if isDecimal(ch) {
tok = token.FLOAT
ch = s.scanMantissa(ch)
ch = s.scanExponent(ch)
} else {
tok = token.PERIOD
}
case '[':
tok = token.LBRACK
case ']':
tok = token.RBRACK
case '{':
tok = token.LBRACE
case '}':
tok = token.RBRACE
case ',':
tok = token.COMMA
case '=':
tok = token.ASSIGN
case '+':
tok = token.ADD
case '-':
tok = token.SUB
}
}

View File

@ -40,6 +40,22 @@ func testTokenList(t *testing.T, tokenList []tokenPair) {
}
}
func TestOperator(t *testing.T) {
var tokenList = []tokenPair{
{token.LBRACK, "["},
{token.LBRACE, "{"},
{token.COMMA, ","},
{token.PERIOD, "."},
{token.RBRACK, "]"},
{token.RBRACE, "}"},
{token.ASSIGN, "="},
{token.ADD, "+"},
{token.SUB, "-"},
}
testTokenList(t, tokenList)
}
func TestBool(t *testing.T) {
var tokenList = []tokenPair{
{token.BOOL, "true"},