diff options
author | Aleksey Kladov <[email protected]> | 2017-12-31 12:14:47 +0000 |
---|---|---|
committer | Aleksey Kladov <[email protected]> | 2017-12-31 12:14:47 +0000 |
commit | d76d7d2a7426e34b0fb358029cbaa2d71f0118e8 (patch) | |
tree | 3b535fe53705ac554068b78c137c1ddf0420cc06 /src/lexer | |
parent | b704eb708f5fd6440abc02eb52dbbfbd9feedaa6 (diff) |
Lexer: strings
Diffstat (limited to 'src/lexer')
-rw-r--r-- | src/lexer/mod.rs | 12 | ||||
-rw-r--r-- | src/lexer/strings.rs | 24 |
2 files changed, 34 insertions, 2 deletions
diff --git a/src/lexer/mod.rs b/src/lexer/mod.rs index d81ea0339..d66046ca1 100644 --- a/src/lexer/mod.rs +++ b/src/lexer/mod.rs | |||
@@ -11,7 +11,7 @@ mod numbers; | |||
11 | use self::numbers::scan_number; | 11 | use self::numbers::scan_number; |
12 | 12 | ||
13 | mod strings; | 13 | mod strings; |
14 | use self::strings::{string_literal_start, scan_char, scan_byte_char_or_string}; | 14 | use self::strings::{string_literal_start, scan_char, scan_byte_char_or_string, scan_string, scan_raw_string}; |
15 | 15 | ||
16 | pub fn next_token(text: &str) -> Token { | 16 | pub fn next_token(text: &str) -> Token { |
17 | assert!(!text.is_empty()); | 17 | assert!(!text.is_empty()); |
@@ -128,6 +128,16 @@ fn next_token_inner(c: char, ptr: &mut Ptr) -> SyntaxKind { | |||
128 | scan_literal_suffix(ptr); | 128 | scan_literal_suffix(ptr); |
129 | return kind | 129 | return kind |
130 | }, | 130 | }, |
131 | '"' => { | ||
132 | scan_string(ptr); | ||
133 | scan_literal_suffix(ptr); | ||
134 | return STRING; | ||
135 | } | ||
136 | 'r' => { | ||
137 | scan_raw_string(ptr); | ||
138 | scan_literal_suffix(ptr); | ||
139 | return RAW_STRING; | ||
140 | } | ||
131 | _ => (), | 141 | _ => (), |
132 | } | 142 | } |
133 | ERROR | 143 | ERROR |
diff --git a/src/lexer/strings.rs b/src/lexer/strings.rs index 283ce8feb..2c1d86374 100644 --- a/src/lexer/strings.rs +++ b/src/lexer/strings.rs | |||
@@ -47,6 +47,27 @@ pub(crate) fn scan_byte_char_or_string(ptr: &mut Ptr) -> SyntaxKind { | |||
47 | } | 47 | } |
48 | } | 48 | } |
49 | 49 | ||
50 | pub(crate) fn scan_string(ptr: &mut Ptr) { | ||
51 | while let Some(c) = ptr.bump() { | ||
52 | if c == '"' { | ||
53 | return | ||
54 | } | ||
55 | } | ||
56 | } | ||
57 | |||
58 | pub(crate) fn scan_raw_string(ptr: &mut Ptr) { | ||
59 | if !ptr.next_is('"') { | ||
60 | return | ||
61 | } | ||
62 | ptr.bump(); | ||
63 | |||
64 | while let Some(c) = ptr.bump() { | ||
65 | if c == '"' { | ||
66 | return | ||
67 | } | ||
68 | } | ||
69 | } | ||
70 | |||
50 | fn scan_byte(ptr: &mut Ptr) { | 71 | fn scan_byte(ptr: &mut Ptr) { |
51 | if ptr.next_is('\'') { | 72 | if ptr.next_is('\'') { |
52 | ptr.bump(); | 73 | ptr.bump(); |
@@ -83,4 +104,5 @@ fn scan_raw_byte_string(ptr: &mut Ptr) { | |||
83 | fn scan_char_or_byte(ptr: &mut Ptr) { | 104 | fn scan_char_or_byte(ptr: &mut Ptr) { |
84 | //FIXME: deal with escape sequencies | 105 | //FIXME: deal with escape sequencies |
85 | ptr.bump(); | 106 | ptr.bump(); |
86 | } \ No newline at end of file | 107 | } |
108 | |||