mirror of
https://github.com/Open-Argon/argon-v3.git
synced 2025-12-06 08:56:07 +00:00
Start supporting numbers and strings
This commit is contained in:
@@ -2,9 +2,42 @@ package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"log"
|
||||
)
|
||||
|
||||
func translate(code string) {
|
||||
output, _ := newNumber().SetString("3.1415")
|
||||
fmt.Println(numberToString(output, 0))
|
||||
// returns (translateNumber | translateString), success, error
|
||||
func translateVal(code UNPARSEcode, index int, codelines []UNPARSEcode, isLine bool) (any, bool, string) {
|
||||
if isLine {
|
||||
if isComment(code) {
|
||||
return nil, true, ""
|
||||
}
|
||||
}
|
||||
|
||||
if isNumber(code) {
|
||||
return parseNumber(code)
|
||||
} else if isString(code) {
|
||||
return parseString(code)
|
||||
}
|
||||
if isLine {
|
||||
return nil, false, "Syntax Error: invalid code on line " + fmt.Sprint(code.line) + ": " + code.code
|
||||
}
|
||||
return nil, false, ""
|
||||
}
|
||||
|
||||
// returns [](translateNumber | translateString), error
|
||||
func translate(codelines []UNPARSEcode) ([]any, string) {
|
||||
translated := []any{}
|
||||
for i, code := range codelines {
|
||||
val, _, err := translateVal(code, i, codelines, true)
|
||||
|
||||
if err != "" {
|
||||
log.Fatal(err)
|
||||
return nil, err
|
||||
}
|
||||
if val == nil {
|
||||
continue
|
||||
}
|
||||
translated = append(translated, val)
|
||||
}
|
||||
return translated, ""
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user