diff options
author | Aleksey Kladov <[email protected]> | 2017-12-30 15:25:37 +0000 |
---|---|---|
committer | Aleksey Kladov <[email protected]> | 2017-12-30 15:25:37 +0000 |
commit | 412948c0e2f34b1db13201bf533468241ee881e6 (patch) | |
tree | 20664c2903806c87ceeb09bcc189b41a6c13192c | |
parent | fad3e50987311a3c42a45bd3d9dbcf7c7a77e544 (diff) |
More symbols
-rw-r--r-- | grammar.ron | 5 | ||||
-rw-r--r-- | src/lexer/mod.rs | 20 | ||||
-rw-r--r-- | src/syntax_kinds.rs | 12 | ||||
-rw-r--r-- | tests/data/lexer/0005_symbols.rs | 4 | ||||
-rw-r--r-- | tests/data/lexer/0005_symbols.txt | 8 |
5 files changed, 47 insertions, 2 deletions
diff --git a/grammar.ron b/grammar.ron index 56617f757..4c9291dfb 100644 --- a/grammar.ron +++ b/grammar.ron | |||
@@ -25,5 +25,10 @@ Grammar( | |||
25 | "COLON", | 25 | "COLON", |
26 | "COLONCOLON", | 26 | "COLONCOLON", |
27 | "DOLLAR", | 27 | "DOLLAR", |
28 | "EQ", | ||
29 | "EQEQ", | ||
30 | "FAT_ARROW", | ||
31 | "NEQ", | ||
32 | "NOT", | ||
28 | ] | 33 | ] |
29 | ) \ No newline at end of file | 34 | ) \ No newline at end of file |
diff --git a/src/lexer/mod.rs b/src/lexer/mod.rs index d2d4aaa22..5255c3d56 100644 --- a/src/lexer/mod.rs +++ b/src/lexer/mod.rs | |||
@@ -52,6 +52,8 @@ fn next_token_inner(c: char, ptr: &mut Ptr) -> SyntaxKind { | |||
52 | '~' => return TILDE, | 52 | '~' => return TILDE, |
53 | '?' => return QUESTION, | 53 | '?' => return QUESTION, |
54 | '$' => return DOLLAR, | 54 | '$' => return DOLLAR, |
55 | |||
56 | // Multi-byte tokens. | ||
55 | '.' => return match (ptr.next(), ptr.nnext()) { | 57 | '.' => return match (ptr.next(), ptr.nnext()) { |
56 | (Some('.'), Some('.')) => { | 58 | (Some('.'), Some('.')) => { |
57 | ptr.bump(); | 59 | ptr.bump(); |
@@ -76,6 +78,24 @@ fn next_token_inner(c: char, ptr: &mut Ptr) -> SyntaxKind { | |||
76 | } | 78 | } |
77 | _ => COLON | 79 | _ => COLON |
78 | }, | 80 | }, |
81 | '=' => return match ptr.next() { | ||
82 | Some('=') => { | ||
83 | ptr.bump(); | ||
84 | EQEQ | ||
85 | } | ||
86 | Some('>') => { | ||
87 | ptr.bump(); | ||
88 | FAT_ARROW | ||
89 | } | ||
90 | _ => EQ, | ||
91 | }, | ||
92 | '!' => return match ptr.next() { | ||
93 | Some('=') => { | ||
94 | ptr.bump(); | ||
95 | NEQ | ||
96 | } | ||
97 | _ => NOT, | ||
98 | }, | ||
79 | _ => (), | 99 | _ => (), |
80 | } | 100 | } |
81 | ERROR | 101 | ERROR |
diff --git a/src/syntax_kinds.rs b/src/syntax_kinds.rs index 6982cba95..a922056ce 100644 --- a/src/syntax_kinds.rs +++ b/src/syntax_kinds.rs | |||
@@ -26,8 +26,13 @@ pub const QUESTION: SyntaxKind = SyntaxKind(21); | |||
26 | pub const COLON: SyntaxKind = SyntaxKind(22); | 26 | pub const COLON: SyntaxKind = SyntaxKind(22); |
27 | pub const COLONCOLON: SyntaxKind = SyntaxKind(23); | 27 | pub const COLONCOLON: SyntaxKind = SyntaxKind(23); |
28 | pub const DOLLAR: SyntaxKind = SyntaxKind(24); | 28 | pub const DOLLAR: SyntaxKind = SyntaxKind(24); |
29 | pub const EQ: SyntaxKind = SyntaxKind(25); | ||
30 | pub const EQEQ: SyntaxKind = SyntaxKind(26); | ||
31 | pub const FAT_ARROW: SyntaxKind = SyntaxKind(27); | ||
32 | pub const NEQ: SyntaxKind = SyntaxKind(28); | ||
33 | pub const NOT: SyntaxKind = SyntaxKind(29); | ||
29 | 34 | ||
30 | static INFOS: [SyntaxInfo; 25] = [ | 35 | static INFOS: [SyntaxInfo; 30] = [ |
31 | SyntaxInfo { name: "ERROR" }, | 36 | SyntaxInfo { name: "ERROR" }, |
32 | SyntaxInfo { name: "IDENT" }, | 37 | SyntaxInfo { name: "IDENT" }, |
33 | SyntaxInfo { name: "UNDERSCORE" }, | 38 | SyntaxInfo { name: "UNDERSCORE" }, |
@@ -53,6 +58,11 @@ static INFOS: [SyntaxInfo; 25] = [ | |||
53 | SyntaxInfo { name: "COLON" }, | 58 | SyntaxInfo { name: "COLON" }, |
54 | SyntaxInfo { name: "COLONCOLON" }, | 59 | SyntaxInfo { name: "COLONCOLON" }, |
55 | SyntaxInfo { name: "DOLLAR" }, | 60 | SyntaxInfo { name: "DOLLAR" }, |
61 | SyntaxInfo { name: "EQ" }, | ||
62 | SyntaxInfo { name: "EQEQ" }, | ||
63 | SyntaxInfo { name: "FAT_ARROW" }, | ||
64 | SyntaxInfo { name: "NEQ" }, | ||
65 | SyntaxInfo { name: "NOT" }, | ||
56 | ]; | 66 | ]; |
57 | 67 | ||
58 | pub(crate) fn syntax_info(kind: SyntaxKind) -> &'static SyntaxInfo { | 68 | pub(crate) fn syntax_info(kind: SyntaxKind) -> &'static SyntaxInfo { |
diff --git a/tests/data/lexer/0005_symbols.rs b/tests/data/lexer/0005_symbols.rs index 79747d5e1..00ed44b65 100644 --- a/tests/data/lexer/0005_symbols.rs +++ b/tests/data/lexer/0005_symbols.rs | |||
@@ -1,3 +1,5 @@ | |||
1 | ; , ( ) { } [ ] @ # ~ ? $ | 1 | ; , ( ) { } [ ] @ # ~ ? $ |
2 | . .. ... ..= | 2 | . .. ... ..= |
3 | : :: \ No newline at end of file | 3 | : :: |
4 | = => | ||
5 | ! != \ No newline at end of file | ||
diff --git a/tests/data/lexer/0005_symbols.txt b/tests/data/lexer/0005_symbols.txt index c845d2dff..291872026 100644 --- a/tests/data/lexer/0005_symbols.txt +++ b/tests/data/lexer/0005_symbols.txt | |||
@@ -35,3 +35,11 @@ WHITESPACE 1 "\n" | |||
35 | COLON 1 ":" | 35 | COLON 1 ":" |
36 | WHITESPACE 1 " " | 36 | WHITESPACE 1 " " |
37 | COLONCOLON 2 "::" | 37 | COLONCOLON 2 "::" |
38 | WHITESPACE 1 "\n" | ||
39 | EQ 1 "=" | ||
40 | WHITESPACE 1 " " | ||
41 | FAT_ARROW 2 "=>" | ||
42 | WHITESPACE 1 "\n" | ||
43 | NOT 1 "!" | ||
44 | WHITESPACE 1 " " | ||
45 | NEQ 2 "!=" | ||