diff --git a/entity/literal.go b/entity/literal.go index 87acc3c..84a15ea 100644 --- a/entity/literal.go +++ b/entity/literal.go @@ -1,7 +1,6 @@ package entity import "fmt" -import "unicode" import "git.tebibyte.media/sashakoshka/fspl/errors" // LiteralInt specifies an integer value. It can be assigned to any type that is @@ -69,17 +68,7 @@ type LiteralString struct { func (*LiteralString) expression(){} func (this *LiteralString) Type () Type { return this.Ty } func (this *LiteralString) String () string { - out := "'" - for _, char := range this.ValueUTF8 { - if char == '\'' { - out += "\\'" - } else if unicode.IsPrint(char) { - out += string(char) - } else { - out += fmt.Sprintf("\\%03o", char) - } - } - return out + "'" + return Quote(this.ValueUTF8) } // LiteralArray is a composite array literal. It can contain any number of diff --git a/entity/meta.go b/entity/meta.go new file mode 100644 index 0000000..8d28692 --- /dev/null +++ b/entity/meta.go @@ -0,0 +1,29 @@ +package entity + +import "fmt" +import "git.tebibyte.media/sashakoshka/fspl/errors" + +// Dependency is a metadata dependency listing. +type Dependency struct { + Position errors.Position + Address Address + Nickname Nickname +} + +func (this *Dependency) String () string { + return fmt.Sprint() +} + +// Address is the address of a unit. +type Address string + +func (addr Address) String () string { + return Quote(string(addr)) +} + +// Nickname is the nickname of a unit. +type Nickname string + +func (nick Nickname) String () string { + return string(nick) +} diff --git a/entity/misc.go b/entity/misc.go index 32803c7..bd60b35 100644 --- a/entity/misc.go +++ b/entity/misc.go @@ -1,6 +1,7 @@ package entity import "fmt" +import "unicode" import "git.tebibyte.media/sashakoshka/fspl/errors" // Signature is a function or method signature that is used in functions, @@ -137,3 +138,18 @@ func OperatorFromString (str string) Operator { func (this Operator) String () string { return operatorToString[this] } + +// Quote puts quotes around a string to turn it into a string literal. +func Quote (in string) string { + out := "'" + for _, char := range in { + if char == '\'' { + out += "\\'" + } else if unicode.IsPrint(char) { + out += string(char) + } else { + out += fmt.Sprintf("\\%03o", char) + } + } + return out + "'" +}