aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAleksey Kladov <[email protected]>2017-12-30 13:30:37 +0000
committerAleksey Kladov <[email protected]>2017-12-30 13:30:44 +0000
commitfad3e50987311a3c42a45bd3d9dbcf7c7a77e544 (patch)
treeb5f1d262e5ecb1226dc73780db50ee3eebe66ff8 /src
parent3e91e8b77db443775eea2ccd40b0cf1e27dc77d8 (diff)
Lexer: symbols
Diffstat (limited to 'src')
-rw-r--r--src/lexer/mod.rs41
-rw-r--r--src/syntax_kinds.rs40
2 files changed, 80 insertions, 1 deletions
diff --git a/src/lexer/mod.rs b/src/lexer/mod.rs
index e60dbbe8e..d2d4aaa22 100644
--- a/src/lexer/mod.rs
+++ b/src/lexer/mod.rs
@@ -37,6 +37,47 @@ fn next_token_inner(c: char, ptr: &mut Ptr) -> SyntaxKind {
37 return scan_number(c, ptr); 37 return scan_number(c, ptr);
38 } 38 }
39 39
40 // One-byte tokens.
41 match c {
42 ';' => return SEMI,
43 ',' => return COMMA,
44 '(' => return L_PAREN,
45 ')' => return R_PAREN,
46 '{' => return L_CURLY,
47 '}' => return R_CURLY,
48 '[' => return L_BRACK,
49 ']' => return R_BRACK,
50 '@' => return AT,
51 '#' => return POUND,
52 '~' => return TILDE,
53 '?' => return QUESTION,
54 '$' => return DOLLAR,
55 '.' => return match (ptr.next(), ptr.nnext()) {
56 (Some('.'), Some('.')) => {
57 ptr.bump();
58 ptr.bump();
59 DOTDOTDOT
60 },
61 (Some('.'), Some('=')) => {
62 ptr.bump();
63 ptr.bump();
64 DOTDOTEQ
65 },
66 (Some('.'), _) => {
67 ptr.bump();
68 DOTDOT
69 },
70 _ => DOT
71 },
72 ':' => return match ptr.next() {
73 Some(':') => {
74 ptr.bump();
75 COLONCOLON
76 }
77 _ => COLON
78 },
79 _ => (),
80 }
40 ERROR 81 ERROR
41} 82}
42 83
diff --git a/src/syntax_kinds.rs b/src/syntax_kinds.rs
index bd1265bde..6982cba95 100644
--- a/src/syntax_kinds.rs
+++ b/src/syntax_kinds.rs
@@ -7,14 +7,52 @@ pub const UNDERSCORE: SyntaxKind = SyntaxKind(2);
7pub const WHITESPACE: SyntaxKind = SyntaxKind(3); 7pub const WHITESPACE: SyntaxKind = SyntaxKind(3);
8pub const INT_NUMBER: SyntaxKind = SyntaxKind(4); 8pub const INT_NUMBER: SyntaxKind = SyntaxKind(4);
9pub const FLOAT_NUMBER: SyntaxKind = SyntaxKind(5); 9pub const FLOAT_NUMBER: SyntaxKind = SyntaxKind(5);
10pub const SEMI: SyntaxKind = SyntaxKind(6);
11pub const COMMA: SyntaxKind = SyntaxKind(7);
12pub const DOT: SyntaxKind = SyntaxKind(8);
13pub const DOTDOT: SyntaxKind = SyntaxKind(9);
14pub const DOTDOTDOT: SyntaxKind = SyntaxKind(10);
15pub const DOTDOTEQ: SyntaxKind = SyntaxKind(11);
16pub const L_PAREN: SyntaxKind = SyntaxKind(12);
17pub const R_PAREN: SyntaxKind = SyntaxKind(13);
18pub const L_CURLY: SyntaxKind = SyntaxKind(14);
19pub const R_CURLY: SyntaxKind = SyntaxKind(15);
20pub const L_BRACK: SyntaxKind = SyntaxKind(16);
21pub const R_BRACK: SyntaxKind = SyntaxKind(17);
22pub const AT: SyntaxKind = SyntaxKind(18);
23pub const POUND: SyntaxKind = SyntaxKind(19);
24pub const TILDE: SyntaxKind = SyntaxKind(20);
25pub const QUESTION: SyntaxKind = SyntaxKind(21);
26pub const COLON: SyntaxKind = SyntaxKind(22);
27pub const COLONCOLON: SyntaxKind = SyntaxKind(23);
28pub const DOLLAR: SyntaxKind = SyntaxKind(24);
10 29
11static INFOS: [SyntaxInfo; 6] = [ 30static INFOS: [SyntaxInfo; 25] = [
12 SyntaxInfo { name: "ERROR" }, 31 SyntaxInfo { name: "ERROR" },
13 SyntaxInfo { name: "IDENT" }, 32 SyntaxInfo { name: "IDENT" },
14 SyntaxInfo { name: "UNDERSCORE" }, 33 SyntaxInfo { name: "UNDERSCORE" },
15 SyntaxInfo { name: "WHITESPACE" }, 34 SyntaxInfo { name: "WHITESPACE" },
16 SyntaxInfo { name: "INT_NUMBER" }, 35 SyntaxInfo { name: "INT_NUMBER" },
17 SyntaxInfo { name: "FLOAT_NUMBER" }, 36 SyntaxInfo { name: "FLOAT_NUMBER" },
37 SyntaxInfo { name: "SEMI" },
38 SyntaxInfo { name: "COMMA" },
39 SyntaxInfo { name: "DOT" },
40 SyntaxInfo { name: "DOTDOT" },
41 SyntaxInfo { name: "DOTDOTDOT" },
42 SyntaxInfo { name: "DOTDOTEQ" },
43 SyntaxInfo { name: "L_PAREN" },
44 SyntaxInfo { name: "R_PAREN" },
45 SyntaxInfo { name: "L_CURLY" },
46 SyntaxInfo { name: "R_CURLY" },
47 SyntaxInfo { name: "L_BRACK" },
48 SyntaxInfo { name: "R_BRACK" },
49 SyntaxInfo { name: "AT" },
50 SyntaxInfo { name: "POUND" },
51 SyntaxInfo { name: "TILDE" },
52 SyntaxInfo { name: "QUESTION" },
53 SyntaxInfo { name: "COLON" },
54 SyntaxInfo { name: "COLONCOLON" },
55 SyntaxInfo { name: "DOLLAR" },
18]; 56];
19 57
20pub(crate) fn syntax_info(kind: SyntaxKind) -> &'static SyntaxInfo { 58pub(crate) fn syntax_info(kind: SyntaxKind) -> &'static SyntaxInfo {