Add metadata entities

This commit is contained in:
Sasha Koshka 2024-02-13 13:29:30 -05:00
parent 27947f7ca4
commit 364141ad0d
3 changed files with 46 additions and 12 deletions

View File

@ -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

29
entity/meta.go Normal file
View File

@ -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)
}

View File

@ -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 + "'"
}