summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKyle Gunger <corechg@gmail.com>2020-09-20 18:18:26 -0400
committerKyle Gunger <corechg@gmail.com>2020-09-20 18:18:26 -0400
commit4adc90d9a8e48a5c1841874cae0cb30c3deee6e1 (patch)
tree4025660d2f9cf825a3b6bf080c590f02405657bf
parent99a037c68522a9ff74449a6aa41c546d85d1bc15 (diff)
Basic updates
- Move preprocessor to it's own file - Begin working on new delimiters - Begin working on blocks in the tree
-rw-r--r--src/tparse/preproc.go1
-rw-r--r--src/tparse/tokenize.go34
-rw-r--r--src/tparse/tree.go32
-rw-r--r--src/tparse/type.go16
-rw-r--r--tests/block-test.tnsl29
-rw-r--r--tests/comment-test.tnsl16
-rw-r--r--tests/literal-test.tnsl4
-rw-r--r--tests/parameter-test.tnsl2
-rwxr-xr-xtests/run-tests.sh3
9 files changed, 101 insertions, 36 deletions
diff --git a/src/tparse/preproc.go b/src/tparse/preproc.go
new file mode 100644
index 0000000..f591b44
--- /dev/null
+++ b/src/tparse/preproc.go
@@ -0,0 +1 @@
+package tparse
diff --git a/src/tparse/tokenize.go b/src/tparse/tokenize.go
index 79a0605..f5e3f54 100644
--- a/src/tparse/tokenize.go
+++ b/src/tparse/tokenize.go
@@ -126,12 +126,32 @@ func stripBlockComments(t []Token) []Token {
out := []Token{}
bc := false
for _, tok := range t {
- if tok.Type == DELIMIT && tok.Data == "/#" {
- bc = true
- continue
- } else if tok.Type == DELIMIT && tok.Data == "#/" {
- bc = false
- continue
+
+ if tok.Type == DELIMIT {
+ switch tok.Data {
+ case ";#":
+ out = append(out, Token{DELIMIT, ";/", tok.Line, tok.Char})
+ bc = true
+ continue
+ case ":#":
+ out = append(out, Token{DELIMIT, ":/", tok.Line, tok.Char})
+ bc = true
+ continue
+ case "/#":
+ bc = true
+ continue
+ case "#;":
+ out = append(out, Token{DELIMIT, "/;", tok.Line, tok.Char})
+ bc = false
+ continue
+ case "#:":
+ out = append(out, Token{DELIMIT, "/:", tok.Line, tok.Char})
+ bc = false
+ continue
+ case "#/":
+ bc = false
+ continue
+ }
} else if bc {
continue
}
@@ -158,7 +178,7 @@ func TokenizeFile(path string) []Token {
max := maxResRunes()
- ln, cn, last := int(0), int(-1), int(0)
+ ln, cn, last := int(1), int(-1), int(0)
sp := false
for r := rune(' '); ; r, _, err = read.ReadRune() {
diff --git a/src/tparse/tree.go b/src/tparse/tree.go
index 48c198c..417580a 100644
--- a/src/tparse/tree.go
+++ b/src/tparse/tree.go
@@ -27,6 +27,38 @@ func handleCode(tokens *[]Token, start int) (Node, int) {
return out, start
}
+func handleBlock(tokens *[]Token, start int) (Node, int) {
+ var out Node
+ var tmp Node
+
+ l := len(*tokens)
+
+ if start >= l {
+ panic((*tokens)[l-1])
+ }
+
+ for ; start < l; start++ {
+ t := (*tokens)[start]
+ switch t.Type {
+ case LINESEP:
+ if t.Data == ";" {
+ tmp, start = handleCode(tokens, start+1)
+ }
+ break
+ case DELIMIT:
+ if t.Data == "/;" {
+ tmp, start = handleCode(tokens, start+1)
+ }
+ break
+ default:
+ panic(t)
+ }
+ out.SubNodes = append(out.SubNodes, tmp)
+ }
+
+ return out, start
+}
+
func handlePre(tokens *[]Token, start int) (Node, int) {
out := Node{}
diff --git a/src/tparse/type.go b/src/tparse/type.go
index 735f681..3e6ef50 100644
--- a/src/tparse/type.go
+++ b/src/tparse/type.go
@@ -34,14 +34,11 @@ var RESWORD = map[string]int{
"import": PREWORD,
"bool": KEYTYPE,
- "byte": KEYTYPE,
"char": KEYTYPE,
"int": KEYTYPE,
"float": KEYTYPE,
- "string": KEYTYPE,
-
"struct": KEYWORD,
"type": KEYWORD,
@@ -94,12 +91,12 @@ var RESRUNE = map[rune]int{
// Start of pre-proc directive
':': LINESEP,
- // Start of line
+ // Statement seperator
';': LINESEP,
// Comment line
'#': LINESEP,
- // Seperate arguments
+ // Seperate arguments or enclosed statements
',': ARGNSEP,
// Assignment
@@ -156,8 +153,17 @@ var RESRUNES = map[string]int{
// Comment block
"/#": DELIMIT,
"#/": DELIMIT,
+ // Preproc block
+ "/:": DELIMIT,
+ ":/": DELIMIT,
+ // Redef blocks
";;": DELIMIT,
+ "::": DELIMIT,
+ ";#": DELIMIT,
+ ":#": DELIMIT,
+ "#;": DELIMIT,
+ "#:": DELIMIT,
// Boolean equ
"==": AUGMENT,
diff --git a/tests/block-test.tnsl b/tests/block-test.tnsl
index a05ca60..e5c3aaf 100644
--- a/tests/block-test.tnsl
+++ b/tests/block-test.tnsl
@@ -1,33 +1,26 @@
-;int i = 0
-
/;if (i==0)
;i = 2
-
;/
-/;else
- ;i = 0
-;/
+/: import
+ "this"
+ "that"
+:/
# ;; can be used as a quick block re-definition
/;if (i==0)
;i = 2
-
;;else
;i = 0
-
;/
-/;if
- ;char ch = '\n'
-
-;;else
- ;int it = 90
-
-;/
+# Comment block switching
-/;main
- ;
-
+/; if (i == 2)
+ ;i = 4
+;#
+ Comment
+#; else
+ ;i = 6
;/ \ No newline at end of file
diff --git a/tests/comment-test.tnsl b/tests/comment-test.tnsl
index fe07b45..cdd33be 100644
--- a/tests/comment-test.tnsl
+++ b/tests/comment-test.tnsl
@@ -11,12 +11,20 @@ a/#
Ok, so this should give no output either
#/
-#;
+# ;
#a
# /;
-;#
+; # stuff
a#
/;#
-#;/
-;/ \ No newline at end of file
+# ;/
+;/
+
+# More intricate block changing checks
+
+/# Comment start
+Comment end #; if (thing)
+;; else if (other_thing)
+;# Comment start
+End #/ \ No newline at end of file
diff --git a/tests/literal-test.tnsl b/tests/literal-test.tnsl
index b447e57..e3b73da 100644
--- a/tests/literal-test.tnsl
+++ b/tests/literal-test.tnsl
@@ -1,6 +1,6 @@
# These should all work
-;string s = "\""
-;string st="\\"
+;[]char s = "\""
+;[]char st="\\"
;int i = 0
;int j=1
diff --git a/tests/parameter-test.tnsl b/tests/parameter-test.tnsl
new file mode 100644
index 0000000..c969427
--- /dev/null
+++ b/tests/parameter-test.tnsl
@@ -0,0 +1,2 @@
+/; loop (int initial = 0, int complex = 2) [initial < max || complex < 40, initial++, complex += 7, another += 2]
+;/
diff --git a/tests/run-tests.sh b/tests/run-tests.sh
index 0bc57b0..6f49335 100755
--- a/tests/run-tests.sh
+++ b/tests/run-tests.sh
@@ -12,4 +12,7 @@ PARSEFILE=comment
parse
PARSEFILE=literal
+parse
+
+PARSEFILE=parameter
parse \ No newline at end of file