diff options
author | bors[bot] <bors[bot]@users.noreply.github.com> | 2018-09-05 16:07:17 +0100 |
---|---|---|
committer | bors[bot] <bors[bot]@users.noreply.github.com> | 2018-09-05 16:07:17 +0100 |
commit | ad451686a807cf5f86826c80ad22c04c559a8589 (patch) | |
tree | 96633364368463feda5ae136fe2a993a15d5b1d3 /crates/libsyntax2/src/lexer/strings.rs | |
parent | 649f7faf7d6eb25635dd624a2ea50a47ac090e09 (diff) | |
parent | d21fead150d502aa69db82d35967e5e9d73aed56 (diff) |
Merge #56
56: Unify lookahead naming between parser and lexer. r=matklad a=zachlute
Resolves Issue #26.
I wanted to play around with libsyntax2, and fixing a random issue seemed like a good way to mess around in the code.
This PR mostly does what's suggested in that issue. I elected to go with `at` and `at_str` instead of trying to do any fancy overloading shenanigans, because...uh, well, frankly I don't really know how to do any fancy overloading shenanigans. The only really questionable bit is `nth_is_p`, which could also have potentially been named `nth_at_p`, but `is` seemed more apropos.
I also added simple tests for `Ptr` so I could be less terrified I broke something.
Comments and criticisms very welcome. I'm still pretty new to Rust.
Co-authored-by: Zach Lute <[email protected]>
Diffstat (limited to 'crates/libsyntax2/src/lexer/strings.rs')
-rw-r--r-- | crates/libsyntax2/src/lexer/strings.rs | 16 |
1 files changed, 8 insertions, 8 deletions
diff --git a/crates/libsyntax2/src/lexer/strings.rs b/crates/libsyntax2/src/lexer/strings.rs index e6ade54a4..5ff483d14 100644 --- a/crates/libsyntax2/src/lexer/strings.rs +++ b/crates/libsyntax2/src/lexer/strings.rs | |||
@@ -15,11 +15,11 @@ pub(crate) fn is_string_literal_start(c: char, c1: Option<char>, c2: Option<char | |||
15 | } | 15 | } |
16 | 16 | ||
17 | pub(crate) fn scan_char(ptr: &mut Ptr) { | 17 | pub(crate) fn scan_char(ptr: &mut Ptr) { |
18 | while let Some(c) = ptr.next() { | 18 | while let Some(c) = ptr.current() { |
19 | match c { | 19 | match c { |
20 | '\\' => { | 20 | '\\' => { |
21 | ptr.bump(); | 21 | ptr.bump(); |
22 | if ptr.next_is('\\') || ptr.next_is('\'') { | 22 | if ptr.at('\\') || ptr.at('\'') { |
23 | ptr.bump(); | 23 | ptr.bump(); |
24 | } | 24 | } |
25 | } | 25 | } |
@@ -57,11 +57,11 @@ pub(crate) fn scan_byte_char_or_string(ptr: &mut Ptr) -> SyntaxKind { | |||
57 | } | 57 | } |
58 | 58 | ||
59 | pub(crate) fn scan_string(ptr: &mut Ptr) { | 59 | pub(crate) fn scan_string(ptr: &mut Ptr) { |
60 | while let Some(c) = ptr.next() { | 60 | while let Some(c) = ptr.current() { |
61 | match c { | 61 | match c { |
62 | '\\' => { | 62 | '\\' => { |
63 | ptr.bump(); | 63 | ptr.bump(); |
64 | if ptr.next_is('\\') || ptr.next_is('"') { | 64 | if ptr.at('\\') || ptr.at('"') { |
65 | ptr.bump(); | 65 | ptr.bump(); |
66 | } | 66 | } |
67 | } | 67 | } |
@@ -78,11 +78,11 @@ pub(crate) fn scan_string(ptr: &mut Ptr) { | |||
78 | 78 | ||
79 | pub(crate) fn scan_raw_string(ptr: &mut Ptr) { | 79 | pub(crate) fn scan_raw_string(ptr: &mut Ptr) { |
80 | let mut hashes = 0; | 80 | let mut hashes = 0; |
81 | while ptr.next_is('#') { | 81 | while ptr.at('#') { |
82 | hashes += 1; | 82 | hashes += 1; |
83 | ptr.bump(); | 83 | ptr.bump(); |
84 | } | 84 | } |
85 | if !ptr.next_is('"') { | 85 | if !ptr.at('"') { |
86 | return; | 86 | return; |
87 | } | 87 | } |
88 | ptr.bump(); | 88 | ptr.bump(); |
@@ -90,7 +90,7 @@ pub(crate) fn scan_raw_string(ptr: &mut Ptr) { | |||
90 | while let Some(c) = ptr.bump() { | 90 | while let Some(c) = ptr.bump() { |
91 | if c == '"' { | 91 | if c == '"' { |
92 | let mut hashes_left = hashes; | 92 | let mut hashes_left = hashes; |
93 | while ptr.next_is('#') && hashes_left > 0{ | 93 | while ptr.at('#') && hashes_left > 0{ |
94 | hashes_left -= 1; | 94 | hashes_left -= 1; |
95 | ptr.bump(); | 95 | ptr.bump(); |
96 | } | 96 | } |
@@ -110,7 +110,7 @@ fn scan_byte_string(ptr: &mut Ptr) { | |||
110 | } | 110 | } |
111 | 111 | ||
112 | fn scan_raw_byte_string(ptr: &mut Ptr) { | 112 | fn scan_raw_byte_string(ptr: &mut Ptr) { |
113 | if !ptr.next_is('"') { | 113 | if !ptr.at('"') { |
114 | return; | 114 | return; |
115 | } | 115 | } |
116 | ptr.bump(); | 116 | ptr.bump(); |