summaryrefslogtreecommitdiff
path: root/parser/node.go
diff options
context:
space:
mode:
authorMarc Vertes <marc.vertes@tendermint.com>2023-10-12 10:51:58 +0200
committerGitHub <noreply@github.com>2023-10-12 10:51:58 +0200
commit37b9da32d3b911091deb254f6cba2a137c471287 (patch)
treeb4451de0fa0473a937a77d39fd1f8a4f87c8f60d /parser/node.go
parenta21b9b12ad865a19ff687645082f9093c4101039 (diff)
move to a direct byte code compiler (#8)
* chore: refactor to keep only the new parser and bytecode vm * scanner: remove Token.value field * scanner: remove scanner.kind field * chore: move language specification in lang package This avoid a cyclic dependency in scanner_test which can now use the golang/GoSpec language specification for Go. * clean code * scanner: export scanner fields Also parser now generate function calls, including externals. * chore: fix lint issues * parser: handle strings * wip * parser: implement support for 'if, else, else if' statements Resolving labels in the compiler still in progress. * parser: support if statements, improve compiler * improve handling of functions * improve support of local variables * scanner: trim leading and trailing spaces * fixes to make fibonacci work * parser: improve README, fix function parameters parsing
Diffstat (limited to 'parser/node.go')
-rw-r--r--parser/node.go50
1 files changed, 0 insertions, 50 deletions
diff --git a/parser/node.go b/parser/node.go
deleted file mode 100644
index b6e34cd..0000000
--- a/parser/node.go
+++ /dev/null
@@ -1,50 +0,0 @@
-package parser
-
-import "github.com/gnolang/parscan/scanner"
-
-type Node struct {
- Child []*Node // sub-tree nodes
- *scanner.Token // token at origin of the node
- Kind // Node kind, depends on the language spec
-}
-
-// TODO: remove it in favor of Walk2
-func (n *Node) Walk(in, out func(*Node) bool) (stop bool) {
- if in != nil && !in(n) {
- return true
- }
- for _, child := range n.Child {
- if child.Walk(in, out) {
- return
- }
- }
- if out != nil {
- stop = !out(n)
- }
- return
-}
-
-// Idem to walk, but also propagates the ancestor of visited node and child index.
-func (n *Node) Walk2(a *Node, i int, in, out func(*Node, *Node, int) bool) (stop bool) {
- if in != nil && !in(n, a, i) {
- return true
- }
- for j, child := range n.Child {
- if child.Walk2(n, j, in, out) {
- return
- }
- }
- if out != nil {
- stop = !out(n, a, i)
- }
- return
-}
-
-func (n *Node) RemoveChild(i int) {
- n.Child = append(n.Child[:i], n.Child[i+1:]...)
-}
-
-func (n *Node) InsertChild(node *Node, i int) {
- n.Child = append(n.Child[:i+1], n.Child[i:]...)
- n.Child[i] = node
-}