diff options
author | Aleksey Kladov <[email protected]> | 2017-12-30 13:30:37 +0000 |
---|---|---|
committer | Aleksey Kladov <[email protected]> | 2017-12-30 13:30:44 +0000 |
commit | fad3e50987311a3c42a45bd3d9dbcf7c7a77e544 (patch) | |
tree | b5f1d262e5ecb1226dc73780db50ee3eebe66ff8 /src | |
parent | 3e91e8b77db443775eea2ccd40b0cf1e27dc77d8 (diff) |
Lexer: symbols
Diffstat (limited to 'src')
-rw-r--r-- | src/lexer/mod.rs | 41 | ||||
-rw-r--r-- | src/syntax_kinds.rs | 40 |
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); | |||
7 | pub const WHITESPACE: SyntaxKind = SyntaxKind(3); | 7 | pub const WHITESPACE: SyntaxKind = SyntaxKind(3); |
8 | pub const INT_NUMBER: SyntaxKind = SyntaxKind(4); | 8 | pub const INT_NUMBER: SyntaxKind = SyntaxKind(4); |
9 | pub const FLOAT_NUMBER: SyntaxKind = SyntaxKind(5); | 9 | pub const FLOAT_NUMBER: SyntaxKind = SyntaxKind(5); |
10 | pub const SEMI: SyntaxKind = SyntaxKind(6); | ||
11 | pub const COMMA: SyntaxKind = SyntaxKind(7); | ||
12 | pub const DOT: SyntaxKind = SyntaxKind(8); | ||
13 | pub const DOTDOT: SyntaxKind = SyntaxKind(9); | ||
14 | pub const DOTDOTDOT: SyntaxKind = SyntaxKind(10); | ||
15 | pub const DOTDOTEQ: SyntaxKind = SyntaxKind(11); | ||
16 | pub const L_PAREN: SyntaxKind = SyntaxKind(12); | ||
17 | pub const R_PAREN: SyntaxKind = SyntaxKind(13); | ||
18 | pub const L_CURLY: SyntaxKind = SyntaxKind(14); | ||
19 | pub const R_CURLY: SyntaxKind = SyntaxKind(15); | ||
20 | pub const L_BRACK: SyntaxKind = SyntaxKind(16); | ||
21 | pub const R_BRACK: SyntaxKind = SyntaxKind(17); | ||
22 | pub const AT: SyntaxKind = SyntaxKind(18); | ||
23 | pub const POUND: SyntaxKind = SyntaxKind(19); | ||
24 | pub const TILDE: SyntaxKind = SyntaxKind(20); | ||
25 | pub const QUESTION: SyntaxKind = SyntaxKind(21); | ||
26 | pub const COLON: SyntaxKind = SyntaxKind(22); | ||
27 | pub const COLONCOLON: SyntaxKind = SyntaxKind(23); | ||
28 | pub const DOLLAR: SyntaxKind = SyntaxKind(24); | ||
10 | 29 | ||
11 | static INFOS: [SyntaxInfo; 6] = [ | 30 | static 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 | ||
20 | pub(crate) fn syntax_info(kind: SyntaxKind) -> &'static SyntaxInfo { | 58 | pub(crate) fn syntax_info(kind: SyntaxKind) -> &'static SyntaxInfo { |