Debian Codegraph @

selector/ast/ast.go

raw symbols SCIP
1 package ast
2
3 type Program struct {
4 Statements []Statement
5 }
6
7 type Statement struct {
8 Expressions Expr
9 }
10
11 type Expressions []Expr
12
13 type Expr interface {
14 expr()
15 }
16
17 func IsType[T Expr](e Expr) bool {
18 _, ok := AsType[T](e)
19 return ok
20 }
21
22 func AsType[T Expr](e Expr) (T, bool) {
23 v, ok := e.(T)
24 return v, ok
25 }
26
27 func LastAsType[T Expr](e Expr) (T, bool) {
28 return AsType[T](Last(e))
29 }
30
31 func Last(e Expr) Expr {
32 if v, ok := e.(ChainedExpr); ok {
33 return v.Exprs[len(v.Exprs)-1]
34 }
35 return e
36 }
37
38 func RemoveLast(e Expr) Expr {
39 var res Expressions
40 if v, ok := e.(ChainedExpr); ok {
41 res = v.Exprs[0 : len(v.Exprs)-1]
42 }
43 return ChainExprs(res...)
44 }