Start supporting numbers and strings

This commit is contained in:
2023-02-25 16:45:54 +00:00
parent cbae1c4629
commit 636101f1fa
15 changed files with 379 additions and 37 deletions

View File

@@ -6,6 +6,8 @@ import (
"strings"
)
var numberCompile = makeRegex("( *)((\\-)?(([0-9]*(\\.[0-9]+)?)(e((\\-|\\+)?([0-9]+(\\.[0-9]+)?)))?)|(0b[10]+(.[10]+)?(e((\\-|\\+)?([0-9]+(\\.[0-9]+)?)))?)|(0x[a-fA-F0-9]+(.[a-fA-F0-9]+)?)|(0o[0-7]+(.[0-7]+)?(e((\\-|\\+)?([0-9]+(\\.[0-9]+)?)))?))( *)")
// a number type
type number = *big.Rat
@@ -19,6 +21,10 @@ func stringToNumber(str string) (*big.Rat, bool) {
return newNumber().SetString(str)
}
func isNumber(code UNPARSEcode) bool {
return numberCompile.MatchString(code.code)
}
// converts a number type to a string
func numberToString(num number, fraction int) string {
if fraction != 0 {
@@ -72,3 +78,12 @@ var subscript = map[byte]string{
'8': "₈",
'9': "₉",
}
// returns translateNumber, success, error
func parseNumber(code UNPARSEcode) (translateNumber, bool, string) {
output, _ := newNumber().SetString(code.code)
return translateNumber{
number: output,
line: code.line,
}, true, ""
}