mirror of
https://github.com/roc-lang/roc.git
synced 2025-11-01 13:34:15 +00:00
Merge remote-tracking branch 'remote/main' into rebuild-platform
This commit is contained in:
commit
926014518f
221 changed files with 2990 additions and 2303 deletions
|
|
@ -16,6 +16,8 @@ roc_module = { path = "../module" }
|
|||
roc_region = { path = "../region" }
|
||||
roc_error_macros = { path = "../../error_macros" }
|
||||
|
||||
soa.workspace = true
|
||||
|
||||
bumpalo.workspace = true
|
||||
encode_unicode.workspace = true
|
||||
|
||||
|
|
|
|||
|
|
@ -8,11 +8,12 @@ use crate::ident::Accessor;
|
|||
use crate::parser::ESingleQuote;
|
||||
use bumpalo::collections::{String, Vec};
|
||||
use bumpalo::Bump;
|
||||
use roc_collections::soa::{EitherIndex, Index, Slice};
|
||||
use roc_collections::soa::{index_push_new, slice_extend_new};
|
||||
use roc_error_macros::internal_error;
|
||||
use roc_module::called_via::{BinOp, CalledVia, UnaryOp};
|
||||
use roc_module::ident::QualifiedModuleName;
|
||||
use roc_region::all::{Loc, Position, Region};
|
||||
use soa::{EitherIndex, Slice};
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct FullAst<'a> {
|
||||
|
|
@ -281,11 +282,10 @@ pub struct WhenPattern<'a> {
|
|||
|
||||
#[derive(Clone, Copy, Debug, PartialEq)]
|
||||
pub enum StrSegment<'a> {
|
||||
Plaintext(&'a str), // e.g. "foo"
|
||||
Unicode(Loc<&'a str>), // e.g. "00A0" in "\u(00A0)"
|
||||
EscapedChar(EscapedChar), // e.g. '\n' in "Hello!\n"
|
||||
Interpolated(Loc<&'a Expr<'a>>),
|
||||
DeprecatedInterpolated(Loc<&'a Expr<'a>>), // The old "$(...)" syntax - will be removed someday
|
||||
Plaintext(&'a str), // e.g. "foo"
|
||||
Unicode(Loc<&'a str>), // e.g. "00A0" in "\u(00A0)"
|
||||
EscapedChar(EscapedChar), // e.g. '\n' in "Hello!\n"
|
||||
Interpolated(Loc<&'a Expr<'a>>), // e.g. "$(expr)"
|
||||
}
|
||||
|
||||
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
|
||||
|
|
@ -379,7 +379,6 @@ impl<'a> TryFrom<StrSegment<'a>> for SingleQuoteSegment<'a> {
|
|||
StrSegment::Unicode(s) => Ok(SingleQuoteSegment::Unicode(s)),
|
||||
StrSegment::EscapedChar(s) => Ok(SingleQuoteSegment::EscapedChar(s)),
|
||||
StrSegment::Interpolated(_) => Err(ESingleQuote::InterpolationNotAllowed),
|
||||
StrSegment::DeprecatedInterpolated(_) => Err(ESingleQuote::InterpolationNotAllowed),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1313,10 +1312,10 @@ impl<'a> Defs<'a> {
|
|||
|
||||
self.regions.push(region);
|
||||
|
||||
let before = Slice::extend_new(&mut self.spaces, spaces_before.iter().copied());
|
||||
let before = slice_extend_new(&mut self.spaces, spaces_before.iter().copied());
|
||||
self.space_before.push(before);
|
||||
|
||||
let after = Slice::extend_new(&mut self.spaces, spaces_after.iter().copied());
|
||||
let after = slice_extend_new(&mut self.spaces, spaces_after.iter().copied());
|
||||
self.space_after.push(after);
|
||||
}
|
||||
|
||||
|
|
@ -1327,7 +1326,7 @@ impl<'a> Defs<'a> {
|
|||
spaces_before: &[CommentOrNewline<'a>],
|
||||
spaces_after: &[CommentOrNewline<'a>],
|
||||
) {
|
||||
let value_def_index = Index::push_new(&mut self.value_defs, value_def);
|
||||
let value_def_index = index_push_new(&mut self.value_defs, value_def);
|
||||
let tag = EitherIndex::from_right(value_def_index);
|
||||
self.push_def_help(tag, region, spaces_before, spaces_after)
|
||||
}
|
||||
|
|
@ -1361,7 +1360,7 @@ impl<'a> Defs<'a> {
|
|||
spaces_before: &[CommentOrNewline<'a>],
|
||||
spaces_after: &[CommentOrNewline<'a>],
|
||||
) {
|
||||
let type_def_index = Index::push_new(&mut self.type_defs, type_def);
|
||||
let type_def_index = index_push_new(&mut self.type_defs, type_def);
|
||||
let tag = EitherIndex::from_left(type_def_index);
|
||||
self.push_def_help(tag, region, spaces_before, spaces_after)
|
||||
}
|
||||
|
|
@ -1376,13 +1375,13 @@ impl<'a> Defs<'a> {
|
|||
for (tag_index, tag) in self.tags.iter().enumerate() {
|
||||
let region = self.regions[tag_index];
|
||||
let space_before = {
|
||||
let start = self.space_before[tag_index].start();
|
||||
let start = self.space_before[tag_index].start() as usize;
|
||||
let len = self.space_before[tag_index].len();
|
||||
|
||||
&self.spaces[start..(start + len)]
|
||||
};
|
||||
let space_after = {
|
||||
let start = self.space_after[tag_index].start();
|
||||
let start = self.space_after[tag_index].start() as usize;
|
||||
let len = self.space_after[tag_index].len();
|
||||
|
||||
&self.spaces[start..(start + len)]
|
||||
|
|
@ -1395,13 +1394,13 @@ impl<'a> Defs<'a> {
|
|||
match tag_index.cmp(&target) {
|
||||
std::cmp::Ordering::Less => {
|
||||
// before
|
||||
let type_def_index = Index::push_new(&mut before.type_defs, type_def);
|
||||
let type_def_index = index_push_new(&mut before.type_defs, type_def);
|
||||
let tag = EitherIndex::from_left(type_def_index);
|
||||
before.push_def_help(tag, region, space_before, space_after);
|
||||
}
|
||||
std::cmp::Ordering::Greater => {
|
||||
// after
|
||||
let type_def_index = Index::push_new(&mut after.type_defs, type_def);
|
||||
let type_def_index = index_push_new(&mut after.type_defs, type_def);
|
||||
let tag = EitherIndex::from_left(type_def_index);
|
||||
after.push_def_help(tag, region, space_before, space_after);
|
||||
}
|
||||
|
|
@ -1417,14 +1416,14 @@ impl<'a> Defs<'a> {
|
|||
std::cmp::Ordering::Less => {
|
||||
// before
|
||||
let new_value_def_index =
|
||||
Index::push_new(&mut before.value_defs, value_def);
|
||||
index_push_new(&mut before.value_defs, value_def);
|
||||
let tag = EitherIndex::from_right(new_value_def_index);
|
||||
before.push_def_help(tag, region, space_before, space_after);
|
||||
}
|
||||
std::cmp::Ordering::Greater => {
|
||||
// after
|
||||
let new_value_def_index =
|
||||
Index::push_new(&mut after.value_defs, value_def);
|
||||
index_push_new(&mut after.value_defs, value_def);
|
||||
let tag = EitherIndex::from_right(new_value_def_index);
|
||||
after.push_def_help(tag, region, space_before, space_after);
|
||||
}
|
||||
|
|
@ -2516,9 +2515,7 @@ impl<'a> Malformed for StrSegment<'a> {
|
|||
fn is_malformed(&self) -> bool {
|
||||
match self {
|
||||
StrSegment::Plaintext(_) | StrSegment::Unicode(_) | StrSegment::EscapedChar(_) => false,
|
||||
StrSegment::Interpolated(expr) | StrSegment::DeprecatedInterpolated(expr) => {
|
||||
expr.is_malformed()
|
||||
}
|
||||
StrSegment::Interpolated(expr) => expr.is_malformed(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -28,7 +28,7 @@ use crate::type_annotation;
|
|||
use crate::{header, keyword};
|
||||
use bumpalo::collections::Vec;
|
||||
use bumpalo::Bump;
|
||||
use roc_collections::soa::Slice;
|
||||
use roc_collections::soa::slice_extend_new;
|
||||
use roc_error_macros::internal_error;
|
||||
use roc_module::called_via::{BinOp, CalledVia, UnaryOp};
|
||||
use roc_region::all::{Loc, Position, Region};
|
||||
|
|
@ -2286,7 +2286,7 @@ pub fn parse_top_level_defs<'a>(
|
|||
}
|
||||
|
||||
if output.tags.len() > existing_len {
|
||||
let after = Slice::extend_new(&mut output.spaces, last_space.iter().copied());
|
||||
let after = slice_extend_new(&mut output.spaces, last_space.iter().copied());
|
||||
let last = output.tags.len() - 1;
|
||||
debug_assert!(output.space_after[last].is_empty() || after.is_empty());
|
||||
output.space_after[last] = after;
|
||||
|
|
|
|||
|
|
@ -649,13 +649,6 @@ fn normalize_str_segments<'a>(
|
|||
}
|
||||
new_segments.push(StrSegment::Interpolated(e.normalize(arena)));
|
||||
}
|
||||
StrSegment::DeprecatedInterpolated(e) => {
|
||||
if !last_text.is_empty() {
|
||||
let text = std::mem::replace(last_text, String::new_in(arena));
|
||||
new_segments.push(StrSegment::Plaintext(text.into_bump_str()));
|
||||
}
|
||||
new_segments.push(StrSegment::Interpolated(e.normalize(arena)));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -680,7 +673,6 @@ impl<'a> Normalize<'a> for StrSegment<'a> {
|
|||
StrSegment::Unicode(t) => StrSegment::Unicode(t.normalize(arena)),
|
||||
StrSegment::EscapedChar(c) => StrSegment::EscapedChar(c),
|
||||
StrSegment::Interpolated(t) => StrSegment::Interpolated(t.normalize(arena)),
|
||||
StrSegment::DeprecatedInterpolated(t) => StrSegment::Interpolated(t.normalize(arena)),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -364,36 +364,6 @@ pub fn parse_str_like_literal<'a>() -> impl Parser<'a, StrLikeLiteral<'a>, EStri
|
|||
// This is the start of a new escape. Look at the next byte
|
||||
// to figure out what type of escape it is.
|
||||
match bytes.next() {
|
||||
Some(b'(') => {
|
||||
// Advance past the `\(` before using the expr parser
|
||||
state.advance_mut(2);
|
||||
|
||||
let original_byte_count = state.bytes().len();
|
||||
|
||||
// This is an interpolated variable.
|
||||
// Parse an arbitrary expression, then give a
|
||||
// canonicalization error if that expression variant
|
||||
// is not allowed inside a string interpolation.
|
||||
let (_progress, loc_expr, new_state) = skip_second(
|
||||
specialize_err_ref(
|
||||
EString::Format,
|
||||
loc(allocated(reset_min_indent(expr::expr_help()))),
|
||||
),
|
||||
byte(b')', EString::FormatEnd),
|
||||
)
|
||||
.parse(arena, state, min_indent)?;
|
||||
|
||||
// Advance the iterator past the expr we just parsed.
|
||||
for _ in 0..(original_byte_count - new_state.bytes().len()) {
|
||||
bytes.next();
|
||||
}
|
||||
|
||||
segments.push(StrSegment::DeprecatedInterpolated(loc_expr));
|
||||
|
||||
// Reset the segment
|
||||
segment_parsed_bytes = 0;
|
||||
state = new_state;
|
||||
}
|
||||
Some(b'u') => {
|
||||
// Advance past the `\u` before using the expr parser
|
||||
state.advance_mut(2);
|
||||
|
|
@ -444,8 +414,8 @@ pub fn parse_str_like_literal<'a>() -> impl Parser<'a, StrLikeLiteral<'a>, EStri
|
|||
}
|
||||
_ => {
|
||||
// Invalid escape! A backslash must be followed
|
||||
// by either an open paren or else one of the
|
||||
// escapable characters (\n, \t, \", \\, etc)
|
||||
// by one of these escapable characters:
|
||||
// (\n, \t, \", \\, etc)
|
||||
return Err((MadeProgress, EString::UnknownEscape(state.pos())));
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue