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:
42
src/string.go
Normal file
42
src/string.go
Normal file
@@ -0,0 +1,42 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strconv"
|
||||
"strings"
|
||||
)
|
||||
|
||||
var stringCompile = makeRegex("(( *)\"((\\\\([a-z\\\"'`]))|[^\\\"])*\"( *))|(( *)'((\\\\([a-z\\'\"`]))|[^\\'])*'( *))")
|
||||
|
||||
func isString(code UNPARSEcode) bool {
|
||||
return stringCompile.MatchString(code.code)
|
||||
}
|
||||
|
||||
func unquoted(
|
||||
str string,
|
||||
) (string, error) {
|
||||
str = strings.Trim(str, " ")
|
||||
if str[0] == '\'' {
|
||||
str = strings.Replace(str, "\\\"", "\"", -1)
|
||||
str = strings.Replace(str, "\"", "\\\"", -1)
|
||||
}
|
||||
str = str[1 : len(str)-1]
|
||||
str = strings.Replace(str, "\\'", "'", -1)
|
||||
str = "\"" + str + "\""
|
||||
return strconv.Unquote(str)
|
||||
}
|
||||
|
||||
// returns translateString, success, error
|
||||
func parseString(code UNPARSEcode) (translateString, bool, string) {
|
||||
trim := strings.Trim(code.code, " ")
|
||||
|
||||
unquoted, err := unquoted(trim)
|
||||
if err != nil {
|
||||
return translateString{}, false, "Syntax Error: invalid string on line " + fmt.Sprint(code.line) + ": " + code.code
|
||||
}
|
||||
|
||||
return translateString{
|
||||
str: unquoted,
|
||||
line: code.line,
|
||||
}, true, ""
|
||||
}
|
||||
Reference in New Issue
Block a user