summaryrefslogtreecommitdiff
path: root/src/tparse/tree.go
diff options
context:
space:
mode:
authorKyle Gunger <corechg@gmail.com>2020-07-03 13:17:26 -0400
committerKyle Gunger <corechg@gmail.com>2020-07-03 13:17:26 -0400
commit5a022193a96e72fa5144755938e6a575aba165b0 (patch)
treeb04404711ee7aa232b116bb40fac10fd12637978 /src/tparse/tree.go
parent135c347a1d9ee7f121fea275139bce85fae33e0c (diff)
Extra Numbers
+ Add line and character numbers to tokens + Impliment line and character numbers ~ Line and char nums start at 0 for now ~ There's this itch in my mind like something is broken
Diffstat (limited to 'src/tparse/tree.go')
-rw-r--r--src/tparse/tree.go58
1 files changed, 58 insertions, 0 deletions
diff --git a/src/tparse/tree.go b/src/tparse/tree.go
new file mode 100644
index 0000000..41896fc
--- /dev/null
+++ b/src/tparse/tree.go
@@ -0,0 +1,58 @@
+package tparse
+
+// Node represents a group of nodes or a directive
+type Node struct {
+ SubNodes []Node
+
+ Dir Directive
+}
+
+// Directive represents a block or single directive
+type Directive struct {
+ Type string
+ ID string
+
+ Data []string
+}
+
+func handleCode(tokens *[]Token, start int) (Node, int) {
+ out := Node{}
+
+ return out, start
+}
+
+func handlePre(tokens *[]Token, start int) (Node, int) {
+ out := Node{}
+
+ return out, start
+}
+
+// CreateTree takes a series of tokens and converts them into an AST
+func CreateTree(tokens *[]Token, start int) Node {
+ out := Node{}
+ out.Dir = Directive{Type: "root", ID: "root"}
+
+ var tmp Node
+
+ for i, t := range *tokens {
+ switch t.Type {
+ case LINESEP:
+ if t.Data == ";" {
+ tmp, i = handleCode(tokens, i)
+ } else if t.Data == ":" {
+ tmp, i = handlePre(tokens, i)
+ }
+ break
+ case DELIMIT:
+ if t.Data == "/;" {
+ tmp, i = handleCode(tokens, i)
+ } else if t.Data == "/:" {
+ tmp, i = handlePre(tokens, i)
+ }
+ break
+ }
+ out.SubNodes = append(out.SubNodes, tmp)
+ }
+
+ return out
+}