expr.go 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187
  1. package ast
  2. import (
  3. "reflect"
  4. )
  5. // Expr provides all of interfaces for expression.
  6. type Expr interface {
  7. Pos
  8. }
  9. // ExprImpl provide commonly implementations for Expr.
  10. type ExprImpl struct {
  11. PosImpl // PosImpl provide Pos() function.
  12. }
  13. // OpExpr provide operator expression.
  14. type OpExpr struct {
  15. ExprImpl
  16. Op Operator
  17. }
  18. // LiteralExpr provide literal expression.
  19. type LiteralExpr struct {
  20. ExprImpl
  21. Literal reflect.Value
  22. }
  23. // ArrayExpr provide Array expression.
  24. type ArrayExpr struct {
  25. ExprImpl
  26. Exprs []Expr
  27. TypeData *TypeStruct
  28. }
  29. // MapExpr provide Map expression.
  30. type MapExpr struct {
  31. ExprImpl
  32. Keys []Expr
  33. Values []Expr
  34. TypeData *TypeStruct
  35. }
  36. // IdentExpr provide identity expression.
  37. type IdentExpr struct {
  38. ExprImpl
  39. Lit string
  40. }
  41. // UnaryExpr provide unary minus expression. ex: -1, ^1, ~1.
  42. type UnaryExpr struct {
  43. ExprImpl
  44. Operator string
  45. Expr Expr
  46. }
  47. // AddrExpr provide referencing address expression.
  48. type AddrExpr struct {
  49. ExprImpl
  50. Expr Expr
  51. }
  52. // DerefExpr provide dereferencing address expression.
  53. type DerefExpr struct {
  54. ExprImpl
  55. Expr Expr
  56. }
  57. // ParenExpr provide parent block expression.
  58. type ParenExpr struct {
  59. ExprImpl
  60. SubExpr Expr
  61. }
  62. // NilCoalescingOpExpr provide if invalid operator expression.
  63. type NilCoalescingOpExpr struct {
  64. ExprImpl
  65. LHS Expr
  66. RHS Expr
  67. }
  68. // TernaryOpExpr provide ternary operator expression.
  69. type TernaryOpExpr struct {
  70. ExprImpl
  71. Expr Expr
  72. LHS Expr
  73. RHS Expr
  74. }
  75. // CallExpr provide calling expression.
  76. type CallExpr struct {
  77. ExprImpl
  78. Func reflect.Value
  79. Name string
  80. SubExprs []Expr
  81. VarArg bool
  82. Go bool
  83. }
  84. // AnonCallExpr provide anonymous calling expression. ex: func(){}().
  85. type AnonCallExpr struct {
  86. ExprImpl
  87. Expr Expr
  88. SubExprs []Expr
  89. VarArg bool
  90. Go bool
  91. }
  92. // MemberExpr provide expression to refer member.
  93. type MemberExpr struct {
  94. ExprImpl
  95. Expr Expr
  96. Name string
  97. }
  98. // ItemExpr provide expression to refer Map/Array item.
  99. type ItemExpr struct {
  100. ExprImpl
  101. Item Expr
  102. Index Expr
  103. }
  104. // SliceExpr provide expression to refer slice of Array.
  105. type SliceExpr struct {
  106. ExprImpl
  107. Item Expr
  108. Begin Expr
  109. End Expr
  110. Cap Expr
  111. }
  112. // FuncExpr provide function expression.
  113. type FuncExpr struct {
  114. ExprImpl
  115. Name string
  116. Stmt Stmt
  117. Params []string
  118. VarArg bool
  119. }
  120. // LetsExpr provide multiple expression of let.
  121. type LetsExpr struct {
  122. ExprImpl
  123. LHSS []Expr
  124. RHSS []Expr
  125. }
  126. // ChanExpr provide chan expression.
  127. type ChanExpr struct {
  128. ExprImpl
  129. LHS Expr
  130. RHS Expr
  131. }
  132. // ImportExpr provide expression to import packages.
  133. type ImportExpr struct {
  134. ExprImpl
  135. Name Expr
  136. }
  137. // MakeExpr provide expression to make instance.
  138. type MakeExpr struct {
  139. ExprImpl
  140. TypeData *TypeStruct
  141. LenExpr Expr
  142. CapExpr Expr
  143. }
  144. // MakeTypeExpr provide expression to make type.
  145. type MakeTypeExpr struct {
  146. ExprImpl
  147. Name string
  148. Type Expr
  149. }
  150. // LenExpr provide expression to get length of array, map, etc.
  151. type LenExpr struct {
  152. ExprImpl
  153. Expr Expr
  154. }
  155. // IncludeExpr provide in expression
  156. type IncludeExpr struct {
  157. ExprImpl
  158. ItemExpr Expr
  159. ListExpr Expr
  160. }