#51 saving optional tokes and tokens that have different representation as meta

This commit is contained in:
z7zmey
2018-07-29 11:44:38 +03:00
parent 0138749c6d
commit 4989d31874
223 changed files with 9832 additions and 5976 deletions

View File

@@ -8,7 +8,7 @@ import (
// Dnumber node
type Dnumber struct {
Meta []meta.Meta
Meta meta.Collection
Position *position.Position
Value string
}
@@ -30,12 +30,8 @@ func (n *Dnumber) GetPosition() *position.Position {
return n.Position
}
func (n *Dnumber) AddMeta(m []meta.Meta) {
n.Meta = append(n.Meta, m...)
}
func (n *Dnumber) GetMeta() []meta.Meta {
return n.Meta
func (n *Dnumber) GetMeta() *meta.Collection {
return &n.Meta
}
// Attributes returns node attributes as map

View File

@@ -9,7 +9,7 @@ import (
// Encapsed node
type Encapsed struct {
Meta []meta.Meta
Meta meta.Collection
Position *position.Position
Parts []node.Node
}
@@ -31,12 +31,8 @@ func (n *Encapsed) GetPosition() *position.Position {
return n.Position
}
func (n *Encapsed) AddMeta(m []meta.Meta) {
n.Meta = append(n.Meta, m...)
}
func (n *Encapsed) GetMeta() []meta.Meta {
return n.Meta
func (n *Encapsed) GetMeta() *meta.Collection {
return &n.Meta
}
// Attributes returns node attributes as map

View File

@@ -8,7 +8,7 @@ import (
// EncapsedStringPart node
type EncapsedStringPart struct {
Meta []meta.Meta
Meta meta.Collection
Position *position.Position
Value string
}
@@ -30,12 +30,8 @@ func (n *EncapsedStringPart) GetPosition() *position.Position {
return n.Position
}
func (n *EncapsedStringPart) AddMeta(m []meta.Meta) {
n.Meta = append(n.Meta, m...)
}
func (n *EncapsedStringPart) GetMeta() []meta.Meta {
return n.Meta
func (n *EncapsedStringPart) GetMeta() *meta.Collection {
return &n.Meta
}
// Attributes returns node attributes as map

View File

@@ -9,7 +9,7 @@ import (
// Heredoc node
type Heredoc struct {
Meta []meta.Meta
Meta meta.Collection
Position *position.Position
Label string
Parts []node.Node
@@ -33,12 +33,8 @@ func (n *Heredoc) GetPosition() *position.Position {
return n.Position
}
func (n *Heredoc) AddMeta(m []meta.Meta) {
n.Meta = append(n.Meta, m...)
}
func (n *Heredoc) GetMeta() []meta.Meta {
return n.Meta
func (n *Heredoc) GetMeta() *meta.Collection {
return &n.Meta
}
// Attributes returns node attributes as map

View File

@@ -8,7 +8,7 @@ import (
// Lnumber node
type Lnumber struct {
Meta []meta.Meta
Meta meta.Collection
Position *position.Position
Value string
}
@@ -30,12 +30,8 @@ func (n *Lnumber) GetPosition() *position.Position {
return n.Position
}
func (n *Lnumber) AddMeta(m []meta.Meta) {
n.Meta = append(n.Meta, m...)
}
func (n *Lnumber) GetMeta() []meta.Meta {
return n.Meta
func (n *Lnumber) GetMeta() *meta.Collection {
return &n.Meta
}
// Attributes returns node attributes as map

View File

@@ -8,7 +8,7 @@ import (
// MagicConstant node
type MagicConstant struct {
Meta []meta.Meta
Meta meta.Collection
Position *position.Position
Value string
}
@@ -30,12 +30,8 @@ func (n *MagicConstant) GetPosition() *position.Position {
return n.Position
}
func (n *MagicConstant) AddMeta(m []meta.Meta) {
n.Meta = append(n.Meta, m...)
}
func (n *MagicConstant) GetMeta() []meta.Meta {
return n.Meta
func (n *MagicConstant) GetMeta() *meta.Collection {
return &n.Meta
}
// Attributes returns node attributes as map

View File

@@ -8,7 +8,7 @@ import (
// String node
type String struct {
Meta []meta.Meta
Meta meta.Collection
Position *position.Position
Value string
}
@@ -30,12 +30,8 @@ func (n *String) GetPosition() *position.Position {
return n.Position
}
func (n *String) AddMeta(m []meta.Meta) {
n.Meta = append(n.Meta, m...)
}
func (n *String) GetMeta() []meta.Meta {
return n.Meta
func (n *String) GetMeta() *meta.Collection {
return &n.Meta
}
// Attributes returns node attributes as map

View File

@@ -453,6 +453,7 @@ func TestDollarOpenCurlyBraces(t *testing.T) {
StartPos: 10,
EndPos: 15,
},
StringVar: true,
VarName: &node.Identifier{
Position: &position.Position{
StartLine: 1,
@@ -529,6 +530,7 @@ func TestDollarOpenCurlyBracesDimNumber(t *testing.T) {
StartPos: 12,
EndPos: 14,
},
StringVar: true,
VarName: &node.Identifier{
Position: &position.Position{
StartLine: 1,

View File

@@ -21,12 +21,20 @@ var nodes = []node.Node{
}
func TestMeta(t *testing.T) {
expected := []meta.Meta{
meta.NewComment("//comment\n", nil),
meta.NewWhiteSpace(" ", nil),
expected := &meta.Collection{
&meta.Data{
Value: "//comment\n",
Type: meta.CommentType,
Position: nil,
},
&meta.Data{
Value: " ",
Type: meta.WhiteSpaceType,
Position: nil,
},
}
for _, n := range nodes {
n.AddMeta(expected)
n.GetMeta().Push(*expected...)
actual := n.GetMeta()
assertEqual(t, expected, actual)
}