z_mirror/luapls

git clone https://git.raiguard.me/z_mirror/luapls

Caleb HeuerRevert "Convert trivia to an interface in preparation annotations-in-AST"5c64afc

main
1.1 KiB63 linesraw
1package ast
2
3import (
4	"github.com/raiguard/luapls/lua/token"
5)
6
7type Node interface {
8	Pos() token.Pos
9	End() token.Pos
10	String() string
11	GetLeadingTrivia() []token.Token
12	GetSemanticChildren() []Node
13}
14
15func Range(n Node) token.Range {
16	return token.Range{Start: n.Pos(), End: n.End()}
17}
18
19type Unit struct {
20	LeadingTrivia  []token.Token
21	Token          token.Token
22	TrailingTrivia []token.Token // Comments and whitespace up to the next newline
23}
24
25func (u *Unit) Type() token.TokenType {
26	return u.Token.Type
27}
28
29func (u *Unit) Pos() token.Pos {
30	return u.Token.Pos
31}
32
33func (u *Unit) End() token.Pos {
34	return u.Token.End()
35}
36
37func (u *Unit) Range() token.Range {
38	return token.Range{Start: u.Pos(), End: u.End()}
39}
40
41func (u *Unit) String() string {
42	return u.Token.Literal
43}
44
45type Block = Punctuated[Statement]
46
47type Invalid struct {
48	Position token.Pos
49}
50
51func (i *Invalid) expressionNode() {}
52func (i *Invalid) statementNode()  {}
53func (i *Invalid) Pos() token.Pos {
54	return i.Position
55}
56func (i *Invalid) End() token.Pos {
57	return i.Position
58}
59
60// A Leaf node has no children and is interactable in the editor.
61type LeafNode interface {
62	leaf()
63}