z7zmey / php-parser

PHP parser written in Go

Home Page:https://php-parser.com

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

`Expr` and `Expression`

blue-bird1 opened this issue · comments

I noticed that there are Expr and Expression names in the node field naming. Is there any difference between them?

No, I just haven't chosen a naming convention yet. I am going to fix it before v1.0.
How do you think, is it better full or short field names?

Short field names are more elegant. I have another suggestion. Is it possible to use getter and setattr? I am having trouble with it. I am only interested in the value field, but I have to write a very long switch. If I can, I can use a more elegant type assertion.

For scalar fields there are function Attributes() map[string]interface{} in Node interface.
There is a problem with long switches because every node has its type with different fields. I know it, and I am looking for a new AST data model.

I think the type uses interface, it might be a good idea.

type BitwiseXor struct {
	FreeFloating freefloating.Collection
	Position     *position.Position
	Left         node.Node
	Right        node.Node
}

E.g

type BitwiseXor struct {
	FreeFloating freefloating.Collection
	Position     *position.Position
	left         node.Node
	right        node.Node
}
type func (n *BitwiseXor) Left() node.Node {
       return n.left  
} 
type func (n *BitwiseXor) Right() node.Node {
       return n.right  
} 

This can be defined

type test interface {
  Left() node.Node
 Right() node.Node
}

Use type assertions to determine if there are left and right values