php-parser icon indicating copy to clipboard operation
php-parser copied to clipboard

`Expr` and `Expression`

Open blue-bird1 opened this issue 6 years ago • 4 comments

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

blue-bird1 avatar Feb 28 '19 18:02 blue-bird1

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?

z7zmey avatar Feb 28 '19 19:02 z7zmey

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.

blue-bird1 avatar Feb 28 '19 19:02 blue-bird1

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.

z7zmey avatar Feb 28 '19 20:02 z7zmey

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

blue-bird1 avatar Mar 04 '19 10:03 blue-bird1