ast.go 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646
  1. // Abstract Syntax tree for the MUESLI interpreter
  2. package muesli
  3. import (
  4. "fmt"
  5. "strings"
  6. )
  7. type AstBasicMetaKind string
  8. type AstMetaKindNone AstBasicMetaKind
  9. type AstMetaKindProgram AstBasicMetaKind
  10. type AstMetaKindStatements AstBasicMetaKind
  11. type AstMetaKindStatement AstBasicMetaKind
  12. type AstMetaKindClosed AstBasicMetaKind
  13. type AstMetaKindSet AstBasicMetaKind
  14. type AstMetaKindGet AstBasicMetaKind
  15. type AstMetaKindTarget AstBasicMetaKind
  16. type AstMetaKindCommand AstBasicMetaKind
  17. type AstMetaKindArguments AstBasicMetaKind
  18. type AstMetaKindArgument AstBasicMetaKind
  19. type AstMetaKindExpression AstBasicMetaKind
  20. type AstMetaKindBlock AstBasicMetaKind
  21. type AstMetaKindParenthesis AstBasicMetaKind
  22. type AstMetaKindList AstBasicMetaKind
  23. type AstMetaKindCapture AstBasicMetaKind
  24. type AstMetaKindWordValue AstBasicMetaKind
  25. type AstMetaKindWord AstBasicMetaKind
  26. type AstMetaKindType AstBasicMetaKind
  27. type AstMetaKindValue AstBasicMetaKind
  28. type AstMetaKindEnd AstBasicMetaKind
  29. type AstMetaKindError AstBasicMetaKind
  30. type AstMetaKindFlatten AstBasicMetaKind
  31. /** The actual types are defined as constants, the meta types are used to be able to have different behavior for them.*/
  32. const (
  33. AstKindNone = AstMetaKindNone("None")
  34. AstKindProgram = AstMetaKindProgram("Program")
  35. AstKindStatements = AstMetaKindStatements("Statements")
  36. AstKindStatement = AstMetaKindStatement("Statement")
  37. // AstKindClosed = AstMetaKindClosed("Closed")
  38. AstKindSet = AstMetaKindSet("Set")
  39. AstKindGet = AstMetaKindGet("Get")
  40. AstKindTarget = AstMetaKindTarget("Target")
  41. AstKindCommand = AstMetaKindCommand("Command")
  42. AstKindArguments = AstMetaKindArguments("Arguments")
  43. // AstKindArgument = AstMetaKindArgument("Argument")
  44. // AstKindExpression = AstMetaKindExpression("Expression")
  45. AstKindBlock = AstMetaKindBlock("Block")
  46. AstKindParenthesis = AstMetaKindParenthesis("Parenthesis")
  47. AstKindList = AstMetaKindList("List")
  48. // AstKindCapture = AstMetaKindCapture("Capture")
  49. AstKindWordValue = AstMetaKindWordValue("WordValue")
  50. AstKindWord = AstMetaKindWord("Word")
  51. AstKindType = AstMetaKindType("Type")
  52. AstKindValue = AstMetaKindValue("Value")
  53. AstKindEnd = AstMetaKindEnd("End")
  54. AstKindError = AstMetaKindError("Error")
  55. // AstKindFlatten is a special ast kind that insruct the parser not to generate a token
  56. AstKindFlatten = AstMetaKindFlatten("Flatten")
  57. )
  58. func (astkind AstBasicMetaKind) String() string {
  59. return string(astkind)
  60. }
  61. func (astkind AstBasicMetaKind) Eval(vm *VM, ast Ast, val ...Value) []Value {
  62. return []Value{}
  63. }
  64. func (astkind AstMetaKindNone) String() string { return "AstNone " }
  65. func (astkind AstMetaKindProgram) String() string { return "AstProgram " }
  66. func (astkind AstMetaKindStatements) String() string { return "AstStatements " }
  67. func (astkind AstMetaKindStatement) String() string { return "AstStatement " }
  68. func (astkind AstMetaKindClosed) String() string { return "AstClosed " }
  69. func (astkind AstMetaKindSet) String() string { return "AstSet " }
  70. func (astkind AstMetaKindGet) String() string { return "AstGet " }
  71. func (astkind AstMetaKindTarget) String() string { return "AstTarget " }
  72. func (astkind AstMetaKindCommand) String() string { return "AstCommand " }
  73. func (astkind AstMetaKindArguments) String() string { return "AstArguments " }
  74. func (astkind AstMetaKindArgument) String() string { return "AstArgument " }
  75. func (astkind AstMetaKindExpression) String() string { return "AstExpression " }
  76. func (astkind AstMetaKindBlock) String() string { return "AstBlock " }
  77. func (astkind AstMetaKindParenthesis) String() string { return "AstParenthesis" }
  78. func (astkind AstMetaKindList) String() string { return "AstList " }
  79. func (astkind AstMetaKindCapture) String() string { return "AstCapture " }
  80. func (astkind AstMetaKindWordValue) String() string { return "AstWordValue " }
  81. func (astkind AstMetaKindWord) String() string { return "AstWord " }
  82. func (astkind AstMetaKindType) String() string { return "AstType " }
  83. func (astkind AstMetaKindValue) String() string { return "AstValue " }
  84. func (astkind AstMetaKindEnd) String() string { return "AstEnd " }
  85. func (astkind AstMetaKindError) String() string { return "AstError " }
  86. func (astkind AstMetaKindFlatten) String() string { return "AstFlatten " }
  87. func (astkind AstMetaKindNone) IsLeaf() bool { return false }
  88. func (astkind AstMetaKindProgram) IsLeaf() bool { return false }
  89. func (astkind AstMetaKindStatements) IsLeaf() bool { return false }
  90. func (astkind AstMetaKindStatement) IsLeaf() bool { return false }
  91. func (astkind AstMetaKindClosed) IsLeaf() bool { return false }
  92. func (astkind AstMetaKindSet) IsLeaf() bool { return false }
  93. func (astkind AstMetaKindGet) IsLeaf() bool { return false }
  94. func (astkind AstMetaKindTarget) IsLeaf() bool { return false }
  95. func (astkind AstMetaKindCommand) IsLeaf() bool { return false }
  96. func (astkind AstMetaKindArguments) IsLeaf() bool { return false }
  97. func (astkind AstMetaKindArgument) IsLeaf() bool { return false }
  98. func (astkind AstMetaKindExpression) IsLeaf() bool { return false }
  99. func (astkind AstMetaKindBlock) IsLeaf() bool { return true }
  100. func (astkind AstMetaKindParenthesis) IsLeaf() bool { return false }
  101. func (astkind AstMetaKindList) IsLeaf() bool { return false }
  102. func (astkind AstMetaKindCapture) IsLeaf() bool { return false }
  103. func (astkind AstMetaKindWordValue) IsLeaf() bool { return true }
  104. func (astkind AstMetaKindWord) IsLeaf() bool { return true }
  105. func (astkind AstMetaKindType) IsLeaf() bool { return true }
  106. func (astkind AstMetaKindValue) IsLeaf() bool { return true }
  107. func (astkind AstMetaKindEnd) IsLeaf() bool { return true }
  108. func (astkind AstMetaKindError) IsLeaf() bool { return true }
  109. func (astkind AstMetaKindFlatten) IsLeaf() bool { return false }
  110. func lastValue(val []Value) []Value {
  111. if len(val) < 1 {
  112. return ReturnEmpty()
  113. }
  114. return []Value{val[len(val) - 1]}
  115. }
  116. func firstValue(val []Value) []Value {
  117. if len(val) < 1 {
  118. return ReturnEmpty()
  119. }
  120. return []Value{val[0]}
  121. }
  122. func (astkind AstMetaKindNone) Eval(vm *VM, ast Ast, val ...Value) []Value { return ReturnEmpty() }
  123. func (astkind AstMetaKindProgram) Eval(vm *VM, ast Ast, val ...Value) []Value {
  124. return lastValue(val)
  125. }
  126. func (astkind AstMetaKindStatements) Eval(vm *VM, ast Ast, val ...Value) []Value {
  127. return lastValue(val)
  128. }
  129. func (astkind AstMetaKindStatement) Eval(vm *VM, ast Ast, val ...Value) []Value {
  130. return val
  131. }
  132. func (astkind AstMetaKindClosed) Eval(vm *VM, ast Ast, val ...Value) []Value {return ReturnEmpty() }
  133. func (astkind AstMetaKindSet) Eval(vm *VM, ast Ast, val ...Value) []Value {
  134. values := val
  135. if len(values) < 2 {
  136. return Fail(fmt.Errorf("set needs at least 2 arguments: received %v", values))
  137. }
  138. target := values[0].String()
  139. value := values[1]
  140. if target == "(" || target == "$" {
  141. if len(values) < 3 {
  142. return Fail(fmt.Errorf("indirect get needs results: received %v", values))
  143. }
  144. target = values[1].String()
  145. value = values[2]
  146. }
  147. // log.Printf("(astkind AstMetaKindSet) Run: %v %v", target, value)
  148. vm.Register(target, value)
  149. return Ok(value)
  150. }
  151. func (astkind AstMetaKindGet) Eval(vm *VM, ast Ast, val ...Value) []Value {
  152. targets := val
  153. target := targets[0].String()
  154. if target == "(" || target == "$" {
  155. if len(targets) < 2 {
  156. return Fail(fmt.Errorf("indirect get needs results: received %v", targets))
  157. }
  158. target = targets[1].String()
  159. }
  160. // log.Printf("(astkind AstMetaKindGet) Run: target %s", target)
  161. return Ok(vm.Lookup(target))
  162. }
  163. func (astkind AstMetaKindTarget) Eval(vm *VM, ast Ast, val ...Value) []Value {
  164. values := val
  165. values = append([]Value{ast.Value()}, values...)
  166. return values
  167. }
  168. func (astkind AstMetaKindCommand) Eval(vm *VM, ast Ast, val ...Value) []Value {
  169. commandName := ast.Value()
  170. arguments := val
  171. // log.Printf("Command execute: %s %v", commandName.String(), arguments)
  172. return vm.CallNamed(commandName.String(), arguments...)
  173. }
  174. func (astkind AstMetaKindArguments) Eval(vm *VM, ast Ast, val ...Value) []Value {
  175. return val
  176. }
  177. func (astkind AstMetaKindArgument) Eval(vm *VM, ast Ast, val ...Value) []Value {
  178. panic("AstMetaKindArgument")
  179. return ReturnEmpty()
  180. }
  181. func (astkind AstMetaKindExpression) Eval(vm *VM, ast Ast, val ...Value) []Value {
  182. panic("AstMetaKindExpression")
  183. return ReturnEmpty()
  184. }
  185. func (astkind AstMetaKindBlock) Eval(vm *VM, ast Ast, val ...Value) []Value {
  186. // A block encountered in the AST is not executed.
  187. // It results in an anonymous runnable with a clone of the AST embedded.
  188. return Ok(NewBlockValue(&ast))
  189. }
  190. func (astkind AstMetaKindParenthesis) Eval(vm *VM, ast Ast, val ...Value) []Value {
  191. return lastValue(val)
  192. }
  193. func (astkind AstMetaKindList) Eval(vm *VM, ast Ast, val ...Value) []Value {
  194. list := &ListValue{List:val}
  195. return []Value{list}
  196. }
  197. func (astkind AstMetaKindCapture) Eval(vm *VM, ast Ast, val ...Value) []Value {
  198. return val
  199. }
  200. func (astkind AstMetaKindWordValue) Eval(vm *VM, ast Ast, val ...Value) []Value {
  201. return []Value{ast.Value()}
  202. }
  203. func (astkind AstMetaKindWord) Eval(vm *VM, ast Ast, val ...Value) []Value {
  204. return []Value{ast.Value()}
  205. }
  206. func (astkind AstMetaKindType) Eval(vm *VM, ast Ast, val ...Value) []Value {
  207. return []Value{ast.Value()}
  208. }
  209. func (astkind AstMetaKindValue) Eval(vm *VM, ast Ast, val ...Value) []Value {
  210. return []Value{ast.Value()}
  211. }
  212. func (astkind AstMetaKindEnd) Eval(vm *VM, ast Ast, val ...Value) []Value {
  213. return []Value{EmptyValue{}}
  214. }
  215. func (astkind AstMetaKindError) Eval(vm *VM, ast Ast, val ...Value) []Value {
  216. return []Value{ast.Value()}
  217. }
  218. func (astkind AstMetaKindFlatten) Eval(vm *VM, ast Ast, val ...Value) []Value {
  219. return ReturnEmpty()
  220. }
  221. type AstKind interface {
  222. String() string
  223. Eval(vm *VM, ast Ast, val ...Value) []Value
  224. IsLeaf() bool
  225. }
  226. /*
  227. func (Ast Ast) String() string {
  228. switch astkind {
  229. case AstMetaKindProgram:
  230. return "AstMetaKindProgram"
  231. case AstMetaKindStatements:
  232. return "AstMetaKindStatements"
  233. case AstMetaKindStatement:
  234. return "AstMetaKindStatement"
  235. case AstMetaKindSet:
  236. return "AstMetaKindSet"
  237. case AstMetaKindGet:
  238. return "AstMetaKindGet"
  239. case AstMetaKindTarget:
  240. return "AstMetaKindTarget"
  241. case AstMetaKindCommand:
  242. return "AstMetaKindCommand"
  243. case AstMetaKindArguments:
  244. return "AstMetaKindArguments"
  245. case AstMetaKindArgument:
  246. return "AstMetaKindArgument"
  247. case AstMetaKindExpression:
  248. return "AstMetaKindExpression"
  249. case AstMetaKindBlock:
  250. return "AstMetaKindBlock"
  251. case AstMetaKindParenthesis:
  252. return "AstMetaKindParenthesis"
  253. case AstMetaKindList:
  254. return "AstMetaKindList"
  255. case AstMetaKindCapture:
  256. return "AstMetaKindCapture"
  257. case AstMetaKindWordValue:
  258. return "AstMetaKindWordValue"
  259. case AstMetaKindWord:
  260. return "AstMetaKindWord"
  261. case AstMetaKindType:
  262. return "AstMetaKindType"
  263. case AstMetaKindValue:
  264. return "AstMetaKindValue"
  265. case AstMetaKindEnd:
  266. return "AstMetaKindEnd"
  267. case AstMetaKindError:
  268. return "AstMetaKindError"
  269. default:
  270. return "Unknown AstMetaKind"
  271. }
  272. }
  273. */
  274. /*
  275. func AstAppendChild(parent Ast, child Ast) Ast {
  276. basicParent := parent.(*Ast)
  277. return basicParent.AppendChild(child)
  278. }
  279. func AstNewChild(parent Ast, kind AstMetaKind, token Token) Ast {
  280. basicParent := parent.(*Ast)
  281. return basicParent.NewChild(kind, token)
  282. }
  283. */
  284. /* AST node kind */
  285. type Ast struct {
  286. AstKind
  287. parent *Ast
  288. children []*Ast
  289. token Token
  290. }
  291. func (ast Ast) Value() Value {
  292. return ast.token.Value
  293. }
  294. func NewAst(kind AstKind, parent *Ast, children []*Ast, token Token) *Ast {
  295. ast := &Ast{AstKind: kind, parent: parent, token: token}
  296. return ast.AppendChildren(children...)
  297. }
  298. func (ast *Ast) AppendChildren(children ...*Ast) *Ast {
  299. for _, child := range children {
  300. ast.AppendChild(child)
  301. }
  302. return ast
  303. }
  304. func (ast *Ast) AppendChild(child * Ast) *Ast {
  305. child.SetParent(ast)
  306. ast.children = append(ast.children, child)
  307. return child
  308. }
  309. func (ast *Ast) NewChild(kind AstKind, token Token) *Ast {
  310. child := NewAst(kind, ast, make([]*Ast, 0), token)
  311. ast.AppendChild(child)
  312. return child
  313. }
  314. func (ast Ast) IsKind(astkind AstKind) bool {
  315. return ast.AstKind == astkind
  316. }
  317. func (ast Ast) IsError() bool {
  318. return ast.AstKind == AstKindError
  319. }
  320. func (ast Ast) IsNone() bool {
  321. return ast.AstKind == AstKindNone
  322. }
  323. func (ast Ast) IsFlatten() bool {
  324. return ast.AstKind == AstKindFlatten
  325. }
  326. func (ast Ast) Token() Token {
  327. return ast.token
  328. }
  329. func (ast Ast) Parent() *Ast {
  330. return ast.parent
  331. }
  332. func (ast Ast) Children() []*Ast {
  333. return ast.children
  334. }
  335. func (ast Ast) Kind() AstKind {
  336. return ast.AstKind
  337. }
  338. func (ast *Ast) SetParent(parent *Ast) {
  339. ast.parent = parent
  340. }
  341. func (ast Ast) Child(index int) *Ast {
  342. count := ast.CountChildren()
  343. if index < 0 || index > count {
  344. return nil
  345. }
  346. return ast.children[index]
  347. }
  348. func (ast Ast) Eval(vm *VM, val ...Value) []Value {
  349. res := ast.AstKind.Eval(vm, ast, val...)
  350. if vm != nil && vm.Tracer != nil {
  351. vm.Trace(*vm, ast, res...)
  352. }
  353. return res
  354. }
  355. func (ast *Ast) Walk(walker func(node *Ast) *Ast) *Ast {
  356. if found := walker(ast); found != nil {
  357. return found
  358. }
  359. for _, child := range ast.children {
  360. if found := child.Walk(walker); found != nil {
  361. return found
  362. }
  363. }
  364. return nil
  365. }
  366. func (ast Ast) String() string {
  367. return fmt.Sprintf("Ast %s: %s", ast.AstKind.String(), ast.token.String())
  368. }
  369. func (ast Ast) Display() {
  370. ast.Walk(func(node *Ast) *Ast {
  371. depth := node.Depth()
  372. fmt.Printf("%s", strings.Repeat("--", depth))
  373. if node != nil {
  374. fmt.Printf("Ast: %s\n", node.String())
  375. } else {
  376. fmt.Printf("Ast: nil node\n")
  377. }
  378. return nil
  379. })
  380. }
  381. func (ast Ast) Dump() string {
  382. result := ""
  383. ast.Walk(func(node *Ast) *Ast {
  384. depth := node.Depth()
  385. result += fmt.Sprintf("%s", strings.Repeat("--", depth))
  386. if node != nil {
  387. result += fmt.Sprintf("Ast: %s\n", node.String())
  388. } else {
  389. result += fmt.Sprintf("Ast: nil node\n")
  390. }
  391. return nil
  392. })
  393. return result
  394. }
  395. func (ast Ast) Depth() int {
  396. var depth int = 0
  397. parent := ast.Parent()
  398. for parent != nil {
  399. depth++
  400. parent = parent.Parent()
  401. }
  402. return depth
  403. }
  404. func (ast Ast) CountChildren() int {
  405. return len(ast.children)
  406. }
  407. func AstIsError(ast * Ast) bool {
  408. return ast.IsError()
  409. }
  410. func (ast Ast) Errors() []*Ast {
  411. res := make([]*Ast, 0)
  412. ast.Walk(func(node *Ast) *Ast {
  413. if node != nil && ast.IsError() {
  414. res = append(res, node)
  415. }
  416. return nil
  417. })
  418. return res
  419. }
  420. func EmptyAstArray() []*Ast {
  421. return make([]*Ast, 0)
  422. }
  423. func NewEmptyAst(astkind AstKind) *Ast {
  424. return NewAst(astkind, nil, EmptyAstArray(), NoToken())
  425. }
  426. func NewAstNone() *Ast {
  427. return NewEmptyAst(AstKindNone)
  428. }
  429. func NewAstWithToken(astkind AstKind, token Token) *Ast {
  430. return NewAst(astkind, nil, EmptyAstArray(), token)
  431. }
  432. // If AST has errors, return it as a merged error, otherwise returns nil
  433. func (ast *Ast) ToError() error {
  434. errlist := ast.Errors()
  435. if len(errlist) < 1 {
  436. return nil
  437. }
  438. sep := ""
  439. res := ""
  440. for _, err := range errlist {
  441. res = fmt.Sprintf("%s%s%s", res, sep, err)
  442. sep = "\n"
  443. }
  444. return fmt.Errorf("%s", res)
  445. }
  446. func (from Ast) Convert(to interface{}) error {
  447. switch toPtr := to.(type) {
  448. case *Ast:
  449. (*toPtr) = from
  450. default:
  451. return NewErrorValuef("Cannot convert Ast value %v to %v", from, to)
  452. }
  453. return nil
  454. }
  455. const TypeValueAst = TypeValue("Ast")
  456. func (ast Ast) Type() TypeValue {
  457. return TypeValueAst
  458. }
  459. /*
  460. type AstProgram struct{ Ast }
  461. type AstStatements struct{ Ast }
  462. type AstStatement struct{ Ast }
  463. type AstSet struct{ Ast }
  464. type AstGet struct{ Ast }
  465. type AstTarget struct{ Ast }
  466. type AstCommand struct{ Ast }
  467. type AstArguments struct{ Ast }
  468. type AstArgument struct{ Ast }
  469. type AstExpression struct{ Ast }
  470. type AstBlock struct{ Ast }
  471. type AstParenthesis struct{ Ast }
  472. type AstList struct{ Ast }
  473. type AstCapture struct{ Ast }
  474. type AstWordValue struct{ Ast }
  475. type AstWord struct{ Ast }
  476. type AstType struct{ Ast }
  477. type AstValue struct{ Ast }
  478. type AstEnd struct{ Ast }
  479. type AstError struct{ Ast }
  480. */
  481. var _ Ast = Ast{}
  482. /* The kind of an AST is also it's constructor function. This is so deep I'm almost
  483. getting scared. :) */
  484. // The type is defined as a constructor
  485. /*
  486. type AstMetaKind func(parent Ast, children []Ast, token Token) Ast
  487. type AstMetaKind2 interface {
  488. New(parent Ast, children []Ast, token Token) Ast
  489. }
  490. type AstTypeProgramImp struct{}
  491. func (ap AstTypeProgramImp) New(parent Ast, children []Ast, token Token) Ast {
  492. return AstProgram{NewBasicAst(parent, children, token)}
  493. }
  494. func NewAstProgram(parent Ast, children []Ast, token Token) Ast {
  495. return AstProgram{NewBasicAst(parent, children, token)}
  496. }
  497. var AstMetaKindBasic = AstMetaKind(func(parent Ast, children []Ast, token Token) Ast { return NewBasicAst(parent, children, token) })
  498. var AstMetaKindProgram = AstMetaKind(NewAstProgram)
  499. var AstMetaKindProgram2 = AstMetaKind2(AstTypeProgramImp{})
  500. var AstMetaKindStatements = AstMetaKind(func(parent Ast, children []Ast, token Token) Ast {
  501. return &AstStatements{NewBasicAst(parent, children, token)}
  502. })
  503. var AstMetaKindStatement = AstMetaKind(func(parent Ast, children []Ast, token Token) Ast {
  504. return &AstStatement{NewBasicAst(parent, children, token)}
  505. })
  506. var AstMetaKindSet = AstMetaKind(func(parent Ast, children []Ast, token Token) Ast {
  507. return &AstSet{NewBasicAst(parent, children, token)}
  508. })
  509. var AstMetaKindGet = AstMetaKind(func(parent Ast, children []Ast, token Token) Ast {
  510. return &AstGet{NewBasicAst(parent, children, token)}
  511. })
  512. var AstMetaKindTarget = AstMetaKind(func(parent Ast, children []Ast, token Token) Ast {
  513. return &AstTarget{NewBasicAst(parent, children, token)}
  514. })
  515. var AstMetaKindCommand = AstMetaKind(func(parent Ast, children []Ast, token Token) Ast {
  516. return &AstCommand{NewBasicAst(parent, children, token)}
  517. })
  518. var AstMetaKindArguments = AstMetaKind(func(parent Ast, children []Ast, token Token) Ast {
  519. return &AstArguments{NewBasicAst(parent, children, token)}
  520. })
  521. var AstMetaKindArgument = AstMetaKind(func(parent Ast, children []Ast, token Token) Ast {
  522. return &AstArgument{NewBasicAst(parent, children, token)}
  523. })
  524. var AstMetaKindExpression = AstMetaKind(func(parent Ast, children []Ast, token Token) Ast {
  525. return &AstExpression{NewBasicAst(parent, children, token)}
  526. })
  527. var AstMetaKindBlock = AstMetaKind(func(parent Ast, children []Ast, token Token) Ast {
  528. return &AstBlock{NewBasicAst(parent, children, token)}
  529. })
  530. var AstMetaKindParenthesis = AstMetaKind(func(parent Ast, children []Ast, token Token) Ast {
  531. return &AstParenthesis{NewBasicAst(parent, children, token)}
  532. })
  533. var AstMetaKindList = AstMetaKind(func(parent Ast, children []Ast, token Token) Ast {
  534. return &AstList{NewBasicAst(parent, children, token)}
  535. })
  536. var AstMetaKindCapture = AstMetaKind(func(parent Ast, children []Ast, token Token) Ast {
  537. return &AstCapture{NewBasicAst(parent, children, token)}
  538. })
  539. var AstMetaKindWordValue = AstMetaKind(func(parent Ast, children []Ast, token Token) Ast {
  540. return &AstWordValue{NewBasicAst(parent, children, token)}
  541. })
  542. var AstMetaKindWord = AstMetaKind(func(parent Ast, children []Ast, token Token) Ast {
  543. return &AstWord{NewBasicAst(parent, children, token)}
  544. })
  545. var AstMetaKindType = AstMetaKind(func(parent Ast, children []Ast, token Token) Ast {
  546. return &AstType{NewBasicAst(parent, children, token)}
  547. })
  548. var AstMetaKindValue = AstMetaKind(func(parent Ast, children []Ast, token Token) Ast {
  549. return &AstValue{NewBasicAst(parent, children, token)}
  550. })
  551. var AstMetaKindEnd = AstMetaKind(func(parent Ast, children []Ast, token Token) Ast {
  552. return &AstEnd{NewBasicAst(parent, children, token)}
  553. })
  554. var AstMetaKindError = AstMetaKind(func(parent Ast, children []Ast, token Token) Ast {
  555. return &AstError{NewBasicAst(parent, children, token)}
  556. })
  557. */