summaryrefslogtreecommitdiff
path: root/tnslc/compile/tokenizer.tnsl
blob: 428815ff3c80a074dd0d564c89f4ce809263824b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
struct Token {
	~uint8 data,
	int
		_type,
		line,
		col
}

/; method Token
	/; eq (Token tok) [bool]
		return utils.strcmp(self.data, tok.data)
	;/

	/; eq_str(~uint8 str) [bool]
		return utils.strcmp(self.data, str)
	;/
;/

/; _is_space(uint8 char) [bool]
	/; if (char == '\t' || char == '\n' || char == '\r' || char == ' ')
		return true
	;/
	return false
;/

/; _in_csv (~uint8 csv, ~uint8 str) [bool]
	int along = 0

	/; loop (csv` !== 0) [csv++]
		/; if (csv` == ',')
			/; if (along !< 0 && str{along} == 0)
				return true
			;/
			along = 0
		;; else if (along !< 0 && str{along} == csv`)
			along++
		;; else
			along = 0
			along--
		;/
	;/

	return along !< 0 && str{along} == 0
;/

/; tokenize(utils.File fin) [utils.Vector]
	Token tok

	utils.Vector out
	out.init(len tok)

	return out
;/