Fixed errors with parsing types
This commit is contained in:
parent
8972d5ad8e
commit
40514cfcf9
|
@ -8,9 +8,9 @@ import "github.com/alecthomas/participle/v2/lexer"
|
|||
// function.
|
||||
type Signature struct {
|
||||
Pos lexer.Position
|
||||
Name string `parser:" '[' @Ident "`
|
||||
Arguments []Declaration `parser:" @@* ']' "`
|
||||
Return Type `parser:" ( ':' @@ )? "`
|
||||
Name string `parser:" '[' @Ident "`
|
||||
Arguments []*Declaration `parser:" @@* ']' "`
|
||||
Return Type `parser:" ( ':' @@ )? "`
|
||||
}
|
||||
func (*Signature) ty(){}
|
||||
func (this *Signature) String () string {
|
||||
|
@ -20,7 +20,7 @@ func (this *Signature) String () string {
|
|||
}
|
||||
out += "]"
|
||||
if this.Return != nil {
|
||||
out += fmt.Sprint(": ", this.Return)
|
||||
out += fmt.Sprint(":", this.Return)
|
||||
}
|
||||
return out
|
||||
}
|
||||
|
|
|
@ -4,6 +4,18 @@ import "testing"
|
|||
|
||||
func TestType (test *testing.T) {
|
||||
testString (test,
|
||||
`Hello:Int`,
|
||||
`Hello: Int`)
|
||||
`BasicInt: Int
|
||||
Structure: (x:Int y:Int)
|
||||
Interface: ([aMethod x:Int]:*U8 [otherMethod arg:5:Int]:*U8)
|
||||
Array: 16:16:16:Int`,
|
||||
|
||||
`
|
||||
BasicInt: Int
|
||||
Structure: (
|
||||
x:Int
|
||||
y:Int)
|
||||
Interface: (
|
||||
[aMethod x:Int]:*U8
|
||||
[otherMethod arg:5:Int]:*U8)
|
||||
Array: 16:16:16:Int`)
|
||||
}
|
||||
|
|
|
@ -22,10 +22,8 @@ func testReader (test *testing.T, correct string, inputs ...io.Reader) {
|
|||
got := tree.String()
|
||||
if got != correct {
|
||||
test.Log("strings do not match")
|
||||
test.Log("tree.String():")
|
||||
test.Log(got)
|
||||
test.Log("correct:")
|
||||
test.Log(correct)
|
||||
test.Log("tree.String():\n" + got)
|
||||
test.Log("correct:\n" + correct)
|
||||
test.Fail()
|
||||
return
|
||||
}
|
||||
|
|
|
@ -21,7 +21,7 @@ type Typedef struct {
|
|||
}
|
||||
func (*Typedef) topLevel(){}
|
||||
func (this *Typedef) String () string {
|
||||
out := fmt.Sprint(this.Name, " : ", this.Type)
|
||||
out := fmt.Sprint(this.Name, ": ", this.Type)
|
||||
if this.Methods != nil {
|
||||
for _, method := range this.Methods {
|
||||
out += fmt.Sprint("\n", method)
|
||||
|
|
|
@ -31,12 +31,12 @@ func (this *TypePointer) String () string {
|
|||
// value unless a pointer is used.
|
||||
type TypeArray struct {
|
||||
Pos lexer.Position
|
||||
Length int `parser:" @Int 'x' "`
|
||||
Element Type `parser:" @@ "`
|
||||
Length int `parser:" @Int "`
|
||||
Element Type `parser:" ':' @@ "`
|
||||
}
|
||||
func (*TypeArray) ty(){}
|
||||
func (this *TypeArray) String () string {
|
||||
return fmt.Sprint(this.Length, "x", this.Element)
|
||||
return fmt.Sprint(this.Length, ":", this.Element)
|
||||
}
|
||||
|
||||
// Struct is a composite type that stores keyed values. The positions of the
|
||||
|
@ -49,7 +49,8 @@ type TypeStruct struct {
|
|||
func (*TypeStruct) ty(){}
|
||||
func (this *TypeStruct) String () string {
|
||||
out := "("
|
||||
for _, member := range this.Members {
|
||||
for index, member := range this.Members {
|
||||
if index > 0 { out += " " }
|
||||
out += fmt.Sprint(member)
|
||||
}
|
||||
return out + ")"
|
||||
|
@ -67,7 +68,8 @@ type TypeInterface struct {
|
|||
func (*TypeInterface) ty(){}
|
||||
func (this *TypeInterface) String () string {
|
||||
out := "("
|
||||
for _, behavior := range this.Behaviors {
|
||||
for index, behavior := range this.Behaviors {
|
||||
if index > 0 { out += " " }
|
||||
out += fmt.Sprint(behavior)
|
||||
}
|
||||
return out + ")"
|
||||
|
|
Loading…
Reference in New Issue