z_mirror/luapls

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

Caleb HeuerAdd Node.LeadingTrivia() method1373e5d

main
3.6 KiB180 linesraw
1package ast
2
3import (
4	"github.com/raiguard/luapls/lua/token"
5)
6
7type Expression interface {
8	Node
9	expressionNode()
10}
11
12type FunctionCall struct {
13	Name       Expression
14	LeftParen  *Unit // Optional
15	Args       Punctuated[Expression]
16	RightParen *Unit // Optional
17}
18
19func (fc *FunctionCall) expressionNode() {}
20func (fc *FunctionCall) statementNode()  {}
21func (fc *FunctionCall) Pos() token.Pos {
22	return fc.Name.Pos()
23}
24func (fc *FunctionCall) End() token.Pos {
25	if fc.RightParen != nil {
26		return fc.RightParen.End()
27	}
28	if len(fc.Args.Pairs) > 0 {
29		return fc.Args.Pairs[len(fc.Args.Pairs)-1].End()
30	}
31	if fc.LeftParen != nil {
32		return fc.LeftParen.End()
33	}
34	return fc.Name.End()
35}
36
37type FunctionExpression struct {
38	FuncTok   Unit
39	LeftParen  Unit
40	Params     Punctuated[*Identifier]
41	Vararg     *Unit
42	RightParen Unit
43	Body       Block
44	EndUnit    Unit
45}
46
47func (fe *FunctionExpression) expressionNode() {}
48func (fe *FunctionExpression) Pos() token.Pos {
49	return fe.FuncTok.Pos()
50}
51func (fe *FunctionExpression) End() token.Pos {
52	return fe.EndUnit.End()
53}
54
55type IndexExpression struct {
56	Prefix       Expression
57	LeftIndexer  Unit
58	Inner        Expression
59	RightIndexer *Unit
60}
61
62func (ie *IndexExpression) expressionNode() {}
63func (ie *IndexExpression) Pos() token.Pos {
64	return ie.Prefix.Pos()
65}
66func (ie *IndexExpression) End() token.Pos {
67	if ie.RightIndexer != nil {
68		return ie.RightIndexer.End()
69	}
70	return ie.Inner.End()
71}
72
73type InfixExpression struct {
74	Left     Expression
75	Operator Unit
76	Right    Expression
77}
78
79func (be *InfixExpression) expressionNode() {}
80func (be *InfixExpression) Pos() token.Pos {
81	return be.Left.Pos()
82}
83func (be *InfixExpression) End() token.Pos {
84	return be.Right.End()
85}
86
87type PrefixExpression struct {
88	Operator Unit
89	Right    Expression
90}
91
92func (pe *PrefixExpression) expressionNode() {}
93func (pe *PrefixExpression) Pos() token.Pos {
94	return pe.Operator.Pos()
95}
96func (pe *PrefixExpression) End() token.Pos {
97	return pe.Right.End()
98}
99
100// Literals (also expressions)
101
102type BooleanLiteral Unit
103
104func (bl *BooleanLiteral) expressionNode() {}
105func (bl *BooleanLiteral) Pos() token.Pos {
106	return bl.Token.Pos
107}
108func (bl *BooleanLiteral) End() token.Pos {
109	return bl.Token.End()
110}
111func (bl *BooleanLiteral) leaf() {}
112
113type Identifier Unit
114
115func (i *Identifier) expressionNode() {}
116func (i *Identifier) Pos() token.Pos {
117	return i.Token.Pos
118}
119func (i *Identifier) End() token.Pos {
120	return i.Token.End()
121}
122func (i *Identifier) leaf() {}
123
124type NilLiteral Unit
125
126func (i *NilLiteral) expressionNode() {}
127func (i *NilLiteral) Pos() token.Pos {
128	return i.Token.Pos
129}
130func (i *NilLiteral) End() token.Pos {
131	return i.Token.End()
132}
133func (n *NilLiteral) leaf() {}
134
135type NumberLiteral Unit
136
137func (nl *NumberLiteral) expressionNode() {}
138func (nl *NumberLiteral) Pos() token.Pos {
139	return nl.Token.Pos
140}
141func (nl *NumberLiteral) End() token.Pos {
142	return nl.Token.End()
143}
144func (nl *NumberLiteral) leaf() {}
145
146type StringLiteral Unit
147
148func (sl *StringLiteral) expressionNode() {}
149func (sl *StringLiteral) Pos() token.Pos {
150	return sl.Token.Pos
151}
152func (sl *StringLiteral) End() token.Pos {
153	return sl.Token.End()
154}
155func (sl *StringLiteral) leaf() {}
156
157type TableLiteral struct {
158	LeftBrace  Unit
159	Fields     Punctuated[TableField]
160	RightBrace Unit
161}
162
163func (tl *TableLiteral) expressionNode() {}
164func (tl *TableLiteral) Pos() token.Pos {
165	return tl.LeftBrace.Pos()
166}
167func (tl *TableLiteral) End() token.Pos {
168	return tl.RightBrace.End()
169}
170
171type Vararg Unit
172
173func (va *Vararg) expressionNode() {}
174func (va *Vararg) Pos() token.Pos {
175	return va.Token.Pos
176}
177func (va *Vararg) End() token.Pos {
178	return va.Token.End()
179}
180func (va *Vararg) leaf() {}