diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/tparse/preproc.go | 1 | ||||
-rw-r--r-- | src/tparse/tokenize.go | 34 | ||||
-rw-r--r-- | src/tparse/tree.go | 32 | ||||
-rw-r--r-- | src/tparse/type.go | 16 |
4 files changed, 71 insertions, 12 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, |