Implemented numbers with different bases
This commit is contained in:
parent
0e999cae92
commit
6d77a8a120
11 changed files with 165 additions and 12 deletions
|
@ -2,6 +2,7 @@ package core
|
|||
|
||||
import (
|
||||
"strconv"
|
||||
"strings"
|
||||
"unicode/utf8"
|
||||
|
||||
"git.akyoto.dev/cli/q/src/build/errors"
|
||||
|
@ -12,7 +13,24 @@ import (
|
|||
func (f *Function) Number(t token.Token) (int, byte, error) {
|
||||
switch t.Kind {
|
||||
case token.Number:
|
||||
number, err := strconv.Atoi(t.Text(f.File.Bytes))
|
||||
digits := t.Text(f.File.Bytes)
|
||||
|
||||
if strings.HasPrefix(digits, "0x") {
|
||||
number, err := strconv.ParseInt(digits[2:], 16, 64)
|
||||
return int(number), 8, err
|
||||
}
|
||||
|
||||
if strings.HasPrefix(digits, "0o") {
|
||||
number, err := strconv.ParseInt(digits[2:], 8, 64)
|
||||
return int(number), 8, err
|
||||
}
|
||||
|
||||
if strings.HasPrefix(digits, "0b") {
|
||||
number, err := strconv.ParseInt(digits[2:], 2, 64)
|
||||
return int(number), 8, err
|
||||
}
|
||||
|
||||
number, err := strconv.Atoi(digits)
|
||||
return number, 8, err
|
||||
|
||||
case token.Rune:
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue