Merge remote-tracking branch 'origin/main' into repl

This commit is contained in:
Richard Feldman 2022-11-05 01:02:08 -04:00
commit c03dc17ab4
No known key found for this signature in database
GPG key ID: F1F21AA5B1D9E43B
197 changed files with 5171 additions and 2946 deletions

View file

@ -109,7 +109,7 @@ pub enum StrSegment<'a> {
Interpolated(Loc<&'a Expr<'a>>), // e.g. (name) in "Hi, \(name)!"
}
#[derive(Clone, Copy, Debug, PartialEq)]
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub enum EscapedChar {
Newline, // \n
Tab, // \t
@ -581,7 +581,7 @@ pub enum AssignedField<'a, Val> {
Malformed(&'a str),
}
#[derive(Clone, Copy, Debug, PartialEq)]
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub enum CommentOrNewline<'a> {
Newline,
LineComment(&'a str),
@ -888,7 +888,7 @@ impl<'a, T> Collection<'a, T> {
pub fn final_comments(&self) -> &'a [CommentOrNewline<'a>] {
if let Some(final_comments) = self.final_comments {
*final_comments
final_comments
} else {
&[]
}

View file

@ -346,6 +346,7 @@ fn parse_expr_start<'a>(
loc!(move |a, s, m| parse_expr_operator_chain(m, options, a, s)),
fail_expr_start_e()
]
.trace("expr_start")
.parse(arena, state, min_indent)
}
@ -546,7 +547,7 @@ fn numeric_negate_expression<'a, T>(
expr: Loc<Expr<'a>>,
spaces: &'a [CommentOrNewline<'a>],
) -> Loc<Expr<'a>> {
debug_assert_eq!(state.bytes().get(0), Some(&b'-'));
debug_assert_eq!(state.bytes().first(), Some(&b'-'));
// for overflow reasons, we must make the unary minus part of the number literal.
let start = state.pos();
let region = Region::new(start, expr.region.end());
@ -1933,7 +1934,7 @@ fn expr_to_pattern_help<'a>(arena: &'a Bump, expr: &Expr<'a>) -> Result<Pattern<
| Expr::UnaryOp(_, _) => Err(()),
Expr::Str(string) => Ok(Pattern::StrLiteral(*string)),
Expr::SingleQuote(string) => Ok(Pattern::SingleQuote(*string)),
Expr::SingleQuote(string) => Ok(Pattern::SingleQuote(string)),
Expr::MalformedIdent(string, _problem) => Ok(Pattern::Malformed(string)),
}
}
@ -2105,10 +2106,10 @@ mod when {
parser::keyword_e(keyword::IS, EWhen::Is)
)
),
move |arena, state, progress, (case_indent, loc_condition), min_indent| {
move |arena, state, _progress, (case_indent, loc_condition), min_indent| {
if case_indent < min_indent {
return Err((
progress,
MadeProgress,
// TODO maybe pass case_indent here?
EWhen::PatternAlignment(5, state.pos()),
state,
@ -2118,15 +2119,18 @@ mod when {
// Everything in the branches must be indented at least as much as the case itself.
let min_indent = case_indent;
let (p1, branches, state) = branches(options).parse(arena, state, min_indent)?;
let (_p1, branches, state) = branches(options)
.parse(arena, state, min_indent)
.map_err(|(_p, e, s)| (MadeProgress, e, s))?;
Ok((
progress.or(p1),
MadeProgress,
Expr::When(arena.alloc(loc_condition), branches.into_bump_slice()),
state,
))
},
)
.trace("when")
}
/// Parsing when with indentation.

View file

@ -52,7 +52,7 @@ pub enum VersionComparison {
DisallowsEqual,
}
#[derive(Copy, Clone, PartialEq, Debug)]
#[derive(Copy, Clone, PartialEq, Eq, Debug)]
pub struct PackageName<'a>(&'a str);
impl<'a> PackageName<'a> {
@ -160,7 +160,7 @@ pub struct HostedHeader<'a> {
pub after_with: &'a [CommentOrNewline<'a>],
}
#[derive(Copy, Clone, Debug, PartialEq)]
#[derive(Copy, Clone, Debug, PartialEq, Eq)]
pub enum To<'a> {
ExistingPackage(&'a str),
NewPackage(PackageName<'a>),
@ -262,7 +262,7 @@ pub struct TypedIdent<'a> {
pub ann: Loc<TypeAnnotation<'a>>,
}
#[derive(Copy, Clone, Debug, PartialEq)]
#[derive(Copy, Clone, Debug, PartialEq, Eq)]
pub struct PackageEntry<'a> {
pub shorthand: &'a str,
pub spaces_after_shorthand: &'a [CommentOrNewline<'a>],

View file

@ -737,6 +737,7 @@ pub trait Parser<'a, Output, Error> {
) -> ParseResult<'a, Output, Error>;
#[cfg(not(feature = "parse_debug_trace"))]
#[inline(always)]
fn trace(self, _message: &'static str) -> Self
where
Self: Sized,
@ -789,7 +790,7 @@ impl<'a, O: std::fmt::Debug, E: std::fmt::Debug, P: Parser<'a, O, E>> Parser<'a,
where
E: 'a,
{
fn parse(&self, arena: &'a Bump, state: State<'a>) -> ParseResult<'a, O, E> {
fn parse(&self, arena: &'a Bump, state: State<'a>, min_indent: u32) -> ParseResult<'a, O, E> {
use std::cell::RefCell;
thread_local! {
@ -803,7 +804,7 @@ where
let cur_indent = INDENT.with(|i| *i.borrow());
println!(
"{:>5?}: {}{:<50}",
"{:<5?}: {}{:<50}",
state.pos(),
&indent_text[..cur_indent * 2],
self.message
@ -1379,11 +1380,12 @@ macro_rules! and {
macro_rules! one_of {
($p1:expr, $p2:expr) => {
move |arena: &'a bumpalo::Bump, state: $crate::state::State<'a>, min_indent: u32| {
let original_state = state.clone();
match $p1.parse(arena, state, min_indent) {
valid @ Ok(_) => valid,
Err((MadeProgress, fail, state)) => Err((MadeProgress, fail, state)),
Err((NoProgress, _, state)) => $p2.parse(arena, state, min_indent),
Err((NoProgress, _, _)) => $p2.parse(arena, original_state, min_indent),
}
}
};

View file

@ -122,10 +122,7 @@ pub fn parse_single_quote<'a>() -> impl Parser<'a, &'a str, EString<'a>> {
}
}
fn consume_indent<'a>(
mut state: State<'a>,
mut indent: u32,
) -> Result<State, (Progress, EString<'a>, State<'a>)> {
fn consume_indent(mut state: State, mut indent: u32) -> Result<State, (Progress, EString, State)> {
while indent > 0 {
match state.bytes().first() {
Some(b' ') => {

View file

@ -0,0 +1 @@
Expr(When(Arrow(@24), @24), @0)

View file

@ -0,0 +1,6 @@
when Just 4 is
Just when ->
4
_ ->
2

View file

@ -0,0 +1 @@
Expr(When(Arrow(@26), @20), @0)

View file

@ -0,0 +1,3 @@
when 5 is
1 -> 2
_

View file

@ -124,6 +124,8 @@ mod test_parse {
fail/lambda_missing_indent.expr,
fail/type_argument_no_arrow.expr,
fail/type_double_comma.expr,
fail/when_missing_arrow.expr,
fail/pattern_binds_keyword.expr,
pass/ability_demand_signature_is_multiline.expr,
pass/ability_multi_line.expr,
pass/ability_single_line.expr,