summaryrefslogtreecommitdiff
path: root/internal/token/linked_token_list.go
blob: 5fe42a97255e43a983f9ef82168491da2e9eafcb (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
package token

type LinkedTokenList struct {
	head, tail *Token
}

func (lts *LinkedTokenList) GetHead() *Token {
	return lts.head
}

func (lts *LinkedTokenList) GetTail() *Token {
	return lts.tail
}

func (lts *LinkedTokenList) AddToken(content string) {
	newToken := &Token{
		content: content,
		prev:    nil,
		next:    nil,
	}

	if lts.head == nil {
		lts.head = newToken
		lts.tail = newToken
	} else {
		newToken.SetPreviousToken(lts.tail)
		lts.tail.SetNextToken(newToken)
		lts.tail = newToken
	}
}

func SliceToLinkedTokenSlice(slice []string, tokenSlice *LinkedTokenList) {
	for _, item := range slice {
		tokenSlice.AddToken(item)
	}
}