Skip to content

Commit

Permalink
Add record and foreign types
Browse files Browse the repository at this point in the history
  • Loading branch information
v1def committed Jan 10, 2023
1 parent 289644d commit 711a4ce
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 6 deletions.
18 changes: 12 additions & 6 deletions ast/type.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,18 +18,24 @@ const (
String BasicType = iota + 1
Number
Boolean
Record
)

var (
typeToString = map[BasicType]string{String: "string", Number: "number", Boolean: "boolean"}
stringToType = map[string]BasicType{"string": String, "number": Number, "boolean": Boolean}
typeToString = map[BasicType]string{
String: "string", Number: "number", Boolean: "boolean", Record: "record",
}
stringToType = map[string]BasicType{
"string": String, "number": Number, "boolean": Boolean, "record": Record,
}
)

type Type struct {
Basic BasicType `parser:"@@"`
Array bool `parser:"@( '[' ']' )?"`
Map *Map `parser:"| @@"`
Object []*Field `parser:"| '{' ( ( @@ ';' )* )? '}'"`
Basic BasicType `parser:"@@"`
Array bool `parser:"@( '[' ']' )?"`
Map *Map `parser:"| @@"`
Object []*Field `parser:"| '{' ( ( @@ ';' )* )? '}'"`
Foreign string `parser:"| @Ident"`
}

type Map struct {
Expand Down
5 changes: 5 additions & 0 deletions ast/type_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,11 @@ func Test_Type(t *testing.T) {
},
},
},
{
name: "Foreign",
code: "ForeignCollection",
want: &ast.Type{Foreign: "ForeignCollection"},
},
}

for _, tt := range tests {
Expand Down

0 comments on commit 711a4ce

Please sign in to comment.