Add metadata entities
This commit is contained in:
parent
27947f7ca4
commit
364141ad0d
@ -1,7 +1,6 @@
|
|||||||
package entity
|
package entity
|
||||||
|
|
||||||
import "fmt"
|
import "fmt"
|
||||||
import "unicode"
|
|
||||||
import "git.tebibyte.media/sashakoshka/fspl/errors"
|
import "git.tebibyte.media/sashakoshka/fspl/errors"
|
||||||
|
|
||||||
// LiteralInt specifies an integer value. It can be assigned to any type that is
|
// 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 (*LiteralString) expression(){}
|
||||||
func (this *LiteralString) Type () Type { return this.Ty }
|
func (this *LiteralString) Type () Type { return this.Ty }
|
||||||
func (this *LiteralString) String () string {
|
func (this *LiteralString) String () string {
|
||||||
out := "'"
|
return Quote(this.ValueUTF8)
|
||||||
for _, char := range this.ValueUTF8 {
|
|
||||||
if char == '\'' {
|
|
||||||
out += "\\'"
|
|
||||||
} else if unicode.IsPrint(char) {
|
|
||||||
out += string(char)
|
|
||||||
} else {
|
|
||||||
out += fmt.Sprintf("\\%03o", char)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return out + "'"
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// LiteralArray is a composite array literal. It can contain any number of
|
// LiteralArray is a composite array literal. It can contain any number of
|
||||||
|
29
entity/meta.go
Normal file
29
entity/meta.go
Normal 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)
|
||||||
|
}
|
@ -1,6 +1,7 @@
|
|||||||
package entity
|
package entity
|
||||||
|
|
||||||
import "fmt"
|
import "fmt"
|
||||||
|
import "unicode"
|
||||||
import "git.tebibyte.media/sashakoshka/fspl/errors"
|
import "git.tebibyte.media/sashakoshka/fspl/errors"
|
||||||
|
|
||||||
// Signature is a function or method signature that is used in functions,
|
// 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 {
|
func (this Operator) String () string {
|
||||||
return operatorToString[this]
|
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 + "'"
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user