Skip to content

Commit

Permalink
add xtask
Browse files Browse the repository at this point in the history
  • Loading branch information
withered-magic committed Dec 21, 2023
1 parent 6a7dfde commit b7d2726
Show file tree
Hide file tree
Showing 9 changed files with 396 additions and 21 deletions.
2 changes: 2 additions & 0 deletions .cargo/config.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[alias]
xtask = "run --package xtask --"
206 changes: 196 additions & 10 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 7 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
[workspace]
resolver = "2"
members = ["starpls", "starpls_lexer", "starpls_parser", "starpls_syntax"]
members = [
"starpls",
"starpls_lexer",
"starpls_parser",
"starpls_syntax",
"xtask",
]
24 changes: 14 additions & 10 deletions starpls_lexer/src/unescape.rs
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ fn scan_byte_string_escape<F>(
'x' => scan_byte_string_hexadecimal_escape(chars),

// unicode escapes start with either `u` or `U`
'u' => {
'u' | 'U' => {
let res = scan_unicode_escape(chars);
let end = input_len - chars.as_str().len();
match res {
Expand Down Expand Up @@ -271,19 +271,15 @@ fn scan_unicode_escape(chars: &mut Chars<'_>) -> Result<char, EscapeError> {
let digit = c.to_digit(16).expect("invalid hexadecimal digit");
value = value * 16 + digit;
num_digits += 1;
if num_digits == 4 || num_digits == 8 {
break char::from_u32(value).ok_or_else(|| {
if value > 0x10FFFF {
EscapeError::OutOfRangeUnicodeEscape
} else {
EscapeError::LoneSurrogateUnicodeEscape
}
});
if num_digits == 8 {
break;
}
}
_ => {
break Err(if num_digits == 0 {
return Err(if num_digits == 0 {
EscapeError::EmptyUnicodeEscape
} else if num_digits == 4 {
break;
} else if num_digits < 4 {
EscapeError::TooShort16BitUnicodeEscape
} else if num_digits < 8 {
Expand All @@ -294,4 +290,12 @@ fn scan_unicode_escape(chars: &mut Chars<'_>) -> Result<char, EscapeError> {
}
}
}

char::from_u32(value).ok_or_else(|| {
if value > 0x10FFFF {
EscapeError::OutOfRangeUnicodeEscape
} else {
EscapeError::LoneSurrogateUnicodeEscape
}
})
}
9 changes: 9 additions & 0 deletions starpls_lexer/src/unescape/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,15 @@ fn test_unescape_byte_string() {
6..10 "😿"
"#]],
);
check(
r#"\x41\u0400\u4e16\U0001F63F"#,
expect![[r#"
0..4 "A"
4..10 "Ѐ"
10..16 "世"
16..26 "😿"
"#]],
);
check(
r#"\377\378\x80\xff\xff"#,
expect![[r#"
Expand Down
10 changes: 10 additions & 0 deletions xtask/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
[package]
name = "xtask"
version = "0.1.0"
edition = "2021"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
anyhow = "1.0.76"
clap = { version = "4.4.11", features = ["derive"] }
Loading

0 comments on commit b7d2726

Please sign in to comment.