#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

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@@ -29,12 +29,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)
}