feat: generate ast.Type "enum"

This commit is contained in:
Laytan Laats 2023-03-26 21:31:37 +02:00
parent b2e5aefaa7
commit 92d341cbb5
5 changed files with 904 additions and 0 deletions

View File

@ -21,6 +21,10 @@ func (n *ParserBrackets) GetPosition() *position.Position {
return n.Position return n.Position
} }
func (n *ParserBrackets) GetType() ast.Type {
return ast.TypeNone
}
type ParserSeparatedList struct { type ParserSeparatedList struct {
Position *position.Position Position *position.Position
Items []ast.Vertex Items []ast.Vertex
@ -35,6 +39,10 @@ func (n *ParserSeparatedList) GetPosition() *position.Position {
return n.Position return n.Position
} }
func (n *ParserSeparatedList) GetType() ast.Type {
return ast.TypeNone
}
// TraitAdaptationList node // TraitAdaptationList node
type TraitAdaptationList struct { type TraitAdaptationList struct {
Position *position.Position Position *position.Position
@ -51,6 +59,10 @@ func (n *TraitAdaptationList) GetPosition() *position.Position {
return n.Position return n.Position
} }
func (n *TraitAdaptationList) GetType() ast.Type {
return ast.TypeNone
}
// ArgumentList node // ArgumentList node
type ArgumentList struct { type ArgumentList struct {
Position *position.Position Position *position.Position
@ -68,6 +80,10 @@ func (n *ArgumentList) GetPosition() *position.Position {
return n.Position return n.Position
} }
func (n *ArgumentList) GetType() ast.Type {
return ast.TypeNone
}
type ReturnType struct { type ReturnType struct {
Position *position.Position Position *position.Position
ColonTkn *token.Token ColonTkn *token.Token
@ -82,6 +98,10 @@ func (n *ReturnType) GetPosition() *position.Position {
return n.Position return n.Position
} }
func (n *ReturnType) GetType() ast.Type {
return ast.TypeNone
}
// TraitMethodRef node // TraitMethodRef node
type TraitMethodRef struct { type TraitMethodRef struct {
Position *position.Position Position *position.Position
@ -97,3 +117,7 @@ func (n *TraitMethodRef) Accept(v ast.Visitor) {
func (n *TraitMethodRef) GetPosition() *position.Position { func (n *TraitMethodRef) GetPosition() *position.Position {
return n.Position return n.Position
} }
func (n *TraitMethodRef) GetType() ast.Type {
return ast.TypeNone
}

View File

@ -21,6 +21,10 @@ func (n *ParserBrackets) GetPosition() *position.Position {
return n.Position return n.Position
} }
func (n *ParserBrackets) GetType() ast.Type {
return ast.TypeNone
}
type ParserSeparatedList struct { type ParserSeparatedList struct {
Position *position.Position Position *position.Position
Items []ast.Vertex Items []ast.Vertex
@ -35,6 +39,10 @@ func (n *ParserSeparatedList) GetPosition() *position.Position {
return n.Position return n.Position
} }
func (n *ParserSeparatedList) GetType() ast.Type {
return ast.TypeNone
}
// TraitAdaptationList node // TraitAdaptationList node
type TraitAdaptationList struct { type TraitAdaptationList struct {
Position *position.Position Position *position.Position
@ -51,6 +59,10 @@ func (n *TraitAdaptationList) GetPosition() *position.Position {
return n.Position return n.Position
} }
func (n *TraitAdaptationList) GetType() ast.Type {
return ast.TypeNone
}
// ArgumentList node // ArgumentList node
type ArgumentList struct { type ArgumentList struct {
Position *position.Position Position *position.Position
@ -69,6 +81,10 @@ func (n *ArgumentList) GetPosition() *position.Position {
return n.Position return n.Position
} }
func (n *ArgumentList) GetType() ast.Type {
return ast.TypeNone
}
type EnumCaseExpr struct { type EnumCaseExpr struct {
Position *position.Position Position *position.Position
AssignTkn *token.Token AssignTkn *token.Token
@ -83,6 +99,10 @@ func (n *EnumCaseExpr) GetPosition() *position.Position {
return n.Position return n.Position
} }
func (n *EnumCaseExpr) GetType() ast.Type {
return ast.TypeNone
}
type ReturnType struct { type ReturnType struct {
Position *position.Position Position *position.Position
ColonTkn *token.Token ColonTkn *token.Token
@ -97,6 +117,10 @@ func (n *ReturnType) GetPosition() *position.Position {
return n.Position return n.Position
} }
func (n *ReturnType) GetType() ast.Type {
return ast.TypeNone
}
// TraitMethodRef node // TraitMethodRef node
type TraitMethodRef struct { type TraitMethodRef struct {
Position *position.Position Position *position.Position
@ -112,3 +136,7 @@ func (n *TraitMethodRef) Accept(v ast.Visitor) {
func (n *TraitMethodRef) GetPosition() *position.Position { func (n *TraitMethodRef) GetPosition() *position.Position {
return n.Position return n.Position
} }
func (n *TraitMethodRef) GetType() ast.Type {
return ast.TypeNone
}

View File

@ -14,6 +14,7 @@ var TypeToVisitorNameMap = map[string]string{
type Vertex interface { type Vertex interface {
Accept(v Visitor) Accept(v Visitor)
GetPosition() *position.Position GetPosition() *position.Position
GetType() Type
} }
type Visitor interface { type Visitor interface {

File diff suppressed because it is too large Load Diff

View File

@ -28,6 +28,16 @@ var fileTempl = template.Must(
package ast package ast
import "github.com/VKCOM/php-parser/pkg/position" import "github.com/VKCOM/php-parser/pkg/position"
type Type int
const (
TypeNone Type = iota
{{- range $i, $typ := .Types }}
Type{{ $typ.Name }}
{{- end }}
TypeCount
)
{{range $typ := .Types}} {{range $typ := .Types}}
var _ Vertex = &{{$typ.Name}}{} var _ Vertex = &{{$typ.Name}}{}
@ -38,6 +48,10 @@ func (n *{{$typ.Name}}) Accept(v Visitor) {
func (n *{{$typ.Name}}) GetPosition() *position.Position { func (n *{{$typ.Name}}) GetPosition() *position.Position {
return n.Position return n.Position
} }
func (n *{{$typ.Name}}) GetType() Type {
return Type{{$typ.Name}}
}
{{end}}`), {{end}}`),
) )