45 строки
737 Б
Go
45 строки
737 Б
Go
package gherkin
|
|
|
|
import "github.com/l3pp4rd/go-behat/gherkin/lexer"
|
|
|
|
type item struct {
|
|
next, prev *item
|
|
value *lexer.Token
|
|
}
|
|
|
|
type AST struct {
|
|
head, tail *item
|
|
}
|
|
|
|
func newAST() *AST {
|
|
return &AST{}
|
|
}
|
|
|
|
func (l *AST) addTail(t *lexer.Token) *item {
|
|
it := &item{next: nil, prev: l.tail, value: t}
|
|
if l.head == nil {
|
|
l.head = it
|
|
} else {
|
|
l.tail.next = it
|
|
}
|
|
l.tail = it
|
|
return l.tail
|
|
}
|
|
|
|
func (l *AST) addBefore(t *lexer.Token, i *item) *item {
|
|
it := &item{next: i, prev: i.prev, value: t}
|
|
i.prev = it
|
|
if it.prev == nil {
|
|
l.head = it
|
|
}
|
|
return it
|
|
}
|
|
|
|
func (l *AST) addAfter(t *lexer.Token, i *item) *item {
|
|
it := &item{next: i.next, prev: i, value: t}
|
|
i.next = it
|
|
if it.next == nil {
|
|
l.tail = it
|
|
}
|
|
return it
|
|
}
|