Merge remote-tracking branch 'origin/main' into abilities-syntax

This commit is contained in:
Richard Feldman 2023-08-10 20:29:27 -04:00
commit 2da41be29f
No known key found for this signature in database
GPG key ID: F1F21AA5B1D9E43B
524 changed files with 47536 additions and 15089 deletions

View file

@ -743,8 +743,8 @@ impl<'a> CommentOrNewline<'a> {
use CommentOrNewline::*;
match self {
Newline => "\n".to_owned(),
LineComment(comment_str) => format!("#{}", comment_str),
DocComment(comment_str) => format!("##{}", comment_str),
LineComment(comment_str) => format!("#{comment_str}"),
DocComment(comment_str) => format!("##{comment_str}"),
}
}

View file

@ -2,6 +2,7 @@ use crate::ast::{
Collection, CommentOrNewline, Malformed, Spaced, Spaces, StrLiteral, TypeAnnotation,
};
use crate::blankspace::space0_e;
use crate::expr::merge_spaces;
use crate::ident::{lowercase_ident, UppercaseIdent};
use crate::parser::{optional, then};
use crate::parser::{specialize, word1, EPackageEntry, EPackageName, Parser};
@ -300,7 +301,7 @@ pub struct PackageEntry<'a> {
}
pub fn package_entry<'a>() -> impl Parser<'a, Spaced<'a, PackageEntry<'a>>, EPackageEntry<'a>> {
map!(
map_with_arena!(
// You may optionally have a package shorthand,
// e.g. "uc" in `uc: roc/unicode 1.0.0`
//
@ -308,18 +309,25 @@ pub fn package_entry<'a>() -> impl Parser<'a, Spaced<'a, PackageEntry<'a>>, EPac
and!(
optional(and!(
skip_second!(
specialize(|_, pos| EPackageEntry::Shorthand(pos), lowercase_ident()),
and!(
specialize(|_, pos| EPackageEntry::Shorthand(pos), lowercase_ident()),
space0_e(EPackageEntry::IndentPackage)
),
word1(b':', EPackageEntry::Colon)
),
space0_e(EPackageEntry::IndentPackage)
)),
loc!(specialize(EPackageEntry::BadPackage, package_name()))
),
move |(opt_shorthand, package_or_path)| {
move |arena, (opt_shorthand, package_or_path)| {
let entry = match opt_shorthand {
Some((shorthand, spaces_after_shorthand)) => PackageEntry {
Some(((shorthand, spaces_before_colon), spaces_after_colon)) => PackageEntry {
shorthand,
spaces_after_shorthand,
spaces_after_shorthand: merge_spaces(
arena,
spaces_before_colon,
spaces_after_colon,
),
package_name: package_or_path,
},
None => PackageEntry {

View file

@ -136,7 +136,7 @@ impl<'a> fmt::Debug for State<'a> {
write!(f, "State {{")?;
match std::str::from_utf8(self.bytes()) {
Ok(string) => write!(f, "\n\tbytes: [utf8] {:?}", string)?,
Ok(string) => write!(f, "\n\tbytes: [utf8] {string:?}")?,
Err(_) => write!(f, "\n\tbytes: [invalid utf8] {:?}", self.bytes())?,
}
@ -151,5 +151,5 @@ fn state_size() {
// cache line.
let state_size = std::mem::size_of::<State>();
let maximum = std::mem::size_of::<usize>() * 8;
assert!(state_size <= maximum, "{:?} <= {:?}", state_size, maximum);
assert!(state_size <= maximum, "{state_size:?} <= {maximum:?}");
}

View file

@ -81,7 +81,7 @@ mod test_parse {
#[test]
fn string_with_escaped_char_at_end() {
parses_with_escaped_char(
|esc| format!(r#""abcd{}""#, esc),
|esc| format!(r#""abcd{esc}""#),
|esc, arena| bumpalo::vec![in arena; Plaintext("abcd"), EscapedChar(esc)],
);
}
@ -89,7 +89,7 @@ mod test_parse {
#[test]
fn string_with_escaped_char_in_front() {
parses_with_escaped_char(
|esc| format!(r#""{}abcd""#, esc),
|esc| format!(r#""{esc}abcd""#),
|esc, arena| bumpalo::vec![in arena; EscapedChar(esc), Plaintext("abcd")],
);
}
@ -97,7 +97,7 @@ mod test_parse {
#[test]
fn string_with_escaped_char_in_middle() {
parses_with_escaped_char(
|esc| format!(r#""ab{}cd""#, esc),
|esc| format!(r#""ab{esc}cd""#),
|esc, arena| bumpalo::vec![in arena; Plaintext("ab"), EscapedChar(esc), Plaintext("cd")],
);
}
@ -105,7 +105,7 @@ mod test_parse {
#[test]
fn string_with_multiple_escaped_chars() {
parses_with_escaped_char(
|esc| format!(r#""{}abc{}de{}fghi{}""#, esc, esc, esc, esc),
|esc| format!(r#""{esc}abc{esc}de{esc}fghi{esc}""#),
|esc, arena| bumpalo::vec![in arena; EscapedChar(esc), Plaintext("abc"), EscapedChar(esc), Plaintext("de"), EscapedChar(esc), Plaintext("fghi"), EscapedChar(esc)],
);
}
@ -247,7 +247,7 @@ mod test_parse {
// These can potentially be whole numbers. `Display` omits the decimal point for those,
// causing them to no longer be parsed as fractional numbers by Roc.
// Using `Debug` instead of `Display` ensures they always have a decimal point.
let float_string = format!("{:?}", num);
let float_string = format!("{num:?}");
assert_parses_to(float_string.as_str(), Float(float_string.as_str()));
}
@ -284,7 +284,7 @@ mod test_parse {
// It should occur twice in the debug output - once for the pattern,
// and then again for the lookup.
let occurrences = format!("{:?}", actual).split("isTest").count() - 1;
let occurrences = format!("{actual:?}").split("isTest").count() - 1;
assert_eq!(occurrences, 2);
}