ast.go 945 B

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. package ast
  2. import (
  3. "kumachan/parser/scanner"
  4. "kumachan/parser/syntax"
  5. )
  6. const _MAX = syntax.MAX_NUM_PARTS
  7. type Tree struct {
  8. Name string
  9. Nodes []TreeNode
  10. Code scanner.Code
  11. Tokens scanner.Tokens
  12. Info scanner.RowColInfo
  13. SpanMap scanner.RowSpanMap
  14. }
  15. type TreeNode struct {
  16. Part syntax.Part // { Id, PartType, Required }
  17. Parent int // pointer of parent node
  18. Children [_MAX]int // pointers of children
  19. Length int // number of children
  20. Status NodeStatus // current status
  21. Tried int // number of tried branches
  22. Index int // index of the Part in the branch (reversed)
  23. Pos int // beginning position in Tokens
  24. Amount int // number of tokens that matched by the node
  25. Span scanner.Span // spanning interval in code (rune list)
  26. }
  27. type NodeStatus int
  28. const (
  29. Initial NodeStatus = iota
  30. Pending
  31. BranchFailed
  32. Success
  33. Failed
  34. )