php-parser/pkg/position/position.go

65 lines
1.1 KiB
Go
Raw Permalink Normal View History

2020-05-10 05:53:00 +00:00
package position
// Tests that were written before the addition of StartCol and EndCol can set this to false,
// Which will not check if StartCol or EndCol are equal in the Equal function.
var CheckColEquality = true
2020-05-10 05:53:00 +00:00
// Position represents node position
type Position struct {
StartLine int
EndLine int
StartCol int
EndCol int
2020-05-10 05:53:00 +00:00
StartPos int
EndPos int
}
// NewPosition Position constructor
func NewPosition(
StartLine int,
EndLine int,
StartPos int,
EndPos int,
StartCol int,
EndCol int,
) *Position {
2020-05-10 05:53:00 +00:00
return &Position{
StartLine: StartLine,
EndLine: EndLine,
StartPos: StartPos,
EndPos: EndPos,
StartCol: StartCol,
EndCol: EndCol,
}
}
func (p Position) Equal(other Position) bool {
if p.StartLine != other.StartLine {
return false
}
if p.StartPos != other.StartPos {
return false
}
if p.EndLine != other.EndLine {
return false
}
if p.EndPos != other.EndPos {
return false
2020-05-10 05:53:00 +00:00
}
if CheckColEquality {
if p.StartCol != other.StartCol {
return false
}
if p.EndCol != other.EndCol {
return false
}
}
return true
2020-05-10 05:53:00 +00:00
}