This commit is contained in:
Ayaz Hafiz 2022-09-28 12:47:25 -05:00
parent 0cc9ea4b05
commit 852fd0a127
No known key found for this signature in database
GPG key ID: 0E2A37416A25EF58
8 changed files with 37 additions and 37 deletions

View file

@ -3112,7 +3112,7 @@ fn load_platform_module<'a>(
let parse_start = Instant::now(); let parse_start = Instant::now();
let bytes = arena.alloc(bytes_vec); let bytes = arena.alloc(bytes_vec);
let parse_state = roc_parse::state::State::new(bytes); let parse_state = roc_parse::state::State::new(bytes);
let parsed = roc_parse::module::parse_header(arena, parse_state.clone()); let parsed = roc_parse::module::parse_header(arena, parse_state);
let parse_header_duration = parse_start.elapsed(); let parse_header_duration = parse_start.elapsed();
// Insert the first entries for this module's timings // Insert the first entries for this module's timings
@ -3182,7 +3182,7 @@ fn load_builtin_module_help<'a>(
let filename = PathBuf::from(filename); let filename = PathBuf::from(filename);
let parse_state = roc_parse::state::State::new(src_bytes.as_bytes()); let parse_state = roc_parse::state::State::new(src_bytes.as_bytes());
let parsed = roc_parse::module::parse_header(arena, parse_state.clone()); let parsed = roc_parse::module::parse_header(arena, parse_state);
match parsed { match parsed {
Ok((ast::Module::Interface { header }, parse_state)) => { Ok((ast::Module::Interface { header }, parse_state)) => {
@ -3430,7 +3430,7 @@ fn parse_header<'a>(
) -> Result<(ModuleId, Msg<'a>), LoadingProblem<'a>> { ) -> Result<(ModuleId, Msg<'a>), LoadingProblem<'a>> {
let parse_start = Instant::now(); let parse_start = Instant::now();
let parse_state = roc_parse::state::State::new(src_bytes); let parse_state = roc_parse::state::State::new(src_bytes);
let parsed = roc_parse::module::parse_header(arena, parse_state.clone()); let parsed = roc_parse::module::parse_header(arena, parse_state);
let parse_header_duration = parse_start.elapsed(); let parse_header_duration = parse_start.elapsed();
// Insert the first entries for this module's timings // Insert the first entries for this module's timings
@ -5737,7 +5737,7 @@ fn to_file_problem_report(filename: &Path, error: io::ErrorKind) -> String {
buf buf
} }
fn to_import_cycle_report<'a>( fn to_import_cycle_report(
module_ids: ModuleIds, module_ids: ModuleIds,
all_ident_ids: IdentIdsByModule, all_ident_ids: IdentIdsByModule,
import_cycle: Vec<ModuleId>, import_cycle: Vec<ModuleId>,

View file

@ -287,7 +287,7 @@ fn loc_possibly_negative_or_negated_term<'a>(
) -> impl Parser<'a, Loc<Expr<'a>>, EExpr<'a>> { ) -> impl Parser<'a, Loc<Expr<'a>>, EExpr<'a>> {
one_of![ one_of![
|arena, state: State<'a>| { |arena, state: State<'a>| {
let initial = state.clone(); let initial = state;
let (_, (loc_op, loc_expr), state) = and!(loc!(unary_negate()), |a, s| parse_loc_term( let (_, (loc_op, loc_expr), state) = and!(loc!(unary_negate()), |a, s| parse_loc_term(
min_indent, options, a, s min_indent, options, a, s
@ -372,7 +372,7 @@ fn parse_expr_operator_chain<'a>(
let (_, expr, state) = let (_, expr, state) =
loc_possibly_negative_or_negated_term(min_indent, options).parse(arena, state)?; loc_possibly_negative_or_negated_term(min_indent, options).parse(arena, state)?;
let initial = state.clone(); let initial = state;
let end = state.pos(); let end = state.pos();
match space0_e(min_indent, EExpr::IndentEnd).parse(arena, state) { match space0_e(min_indent, EExpr::IndentEnd).parse(arena, state) {
@ -615,7 +615,7 @@ fn parse_defs_end<'a>(
loop { loop {
let state = global_state; let state = global_state;
let initial = state.clone(); let initial = state;
let mut spaces_before_current = &[] as &[_]; let mut spaces_before_current = &[] as &[_];
let spaces_before_current_start = state.pos(); let spaces_before_current_start = state.pos();
@ -643,7 +643,7 @@ fn parse_defs_end<'a>(
min_indent, min_indent,
EPattern::IndentEnd, EPattern::IndentEnd,
) )
.parse(arena, state.clone()) .parse(arena, state)
{ {
Err((NoProgress, _, _)) => { Err((NoProgress, _, _)) => {
match parse_expect.parse(arena, state) { match parse_expect.parse(arena, state) {
@ -720,7 +720,7 @@ fn parse_defs_end<'a>(
if let Some((name, name_region, args)) = opt_tag_and_args { if let Some((name, name_region, args)) = opt_tag_and_args {
if let Ok((_, loc_has, state)) = if let Ok((_, loc_has, state)) =
loc_has_parser(min_indent).parse(arena, state.clone()) loc_has_parser(min_indent).parse(arena, state)
{ {
let (_, (type_def, def_region), state) = finish_parsing_ability_def_help( let (_, (type_def, def_region), state) = finish_parsing_ability_def_help(
start_column, start_column,
@ -1063,7 +1063,7 @@ fn finish_parsing_alias_or_opaque<'a>(
let (expr, arguments) = expr_state let (expr, arguments) = expr_state
.validate_is_type_def(arena, loc_op, kind) .validate_is_type_def(arena, loc_op, kind)
.map_err(|fail| (MadeProgress, fail, state.clone()))?; .map_err(|fail| (MadeProgress, fail, state))?;
let mut defs = Defs::default(); let mut defs = Defs::default();
@ -1226,7 +1226,7 @@ mod ability {
indent: IndentLevel, indent: IndentLevel,
) -> impl Parser<'a, (u32, AbilityMember<'a>), EAbility<'a>> { ) -> impl Parser<'a, (u32, AbilityMember<'a>), EAbility<'a>> {
move |arena, state: State<'a>| { move |arena, state: State<'a>| {
let initial = state.clone(); let initial = state;
// Put no restrictions on the indent after the spaces; we'll check it manually. // Put no restrictions on the indent after the spaces; we'll check it manually.
match space0_e(0, EAbility::DemandName).parse(arena, state) { match space0_e(0, EAbility::DemandName).parse(arena, state) {
@ -1323,7 +1323,7 @@ fn finish_parsing_ability_def_help<'a>(
let demand_parser = ability::parse_demand(demand_indent); let demand_parser = ability::parse_demand(demand_indent);
loop { loop {
match demand_parser.parse(arena, state.clone()) { match demand_parser.parse(arena, state) {
Ok((_, (_indent, demand), next_state)) => { Ok((_, (_indent, demand), next_state)) => {
state = next_state; state = next_state;
demands.push(demand); demands.push(demand);
@ -1385,7 +1385,7 @@ fn parse_expr_operator<'a>(
expr_state.spaces_after, expr_state.spaces_after,
); );
expr_state.initial = state.clone(); expr_state.initial = state;
let (spaces, state) = match space0_e(min_indent, EExpr::IndentEnd).parse(arena, state) { let (spaces, state) = match space0_e(min_indent, EExpr::IndentEnd).parse(arena, state) {
Err((_, _, state)) => (&[] as &[_], state), Err((_, _, state)) => (&[] as &[_], state),
@ -1404,7 +1404,7 @@ fn parse_expr_operator<'a>(
let call = expr_state let call = expr_state
.validate_assignment_or_backpassing(arena, loc_op, EExpr::ElmStyleFunction) .validate_assignment_or_backpassing(arena, loc_op, EExpr::ElmStyleFunction)
.map_err(|fail| (MadeProgress, fail, state.clone()))?; .map_err(|fail| (MadeProgress, fail, state))?;
let (value_def, def_region, state) = { let (value_def, def_region, state) = {
match expr_to_pattern_help(arena, &call.value) { match expr_to_pattern_help(arena, &call.value) {
@ -1449,7 +1449,7 @@ fn parse_expr_operator<'a>(
.validate_assignment_or_backpassing(arena, loc_op, |_, pos| { .validate_assignment_or_backpassing(arena, loc_op, |_, pos| {
EExpr::BadOperator("<-", pos) EExpr::BadOperator("<-", pos)
}) })
.map_err(|fail| (MadeProgress, fail, state.clone()))?; .map_err(|fail| (MadeProgress, fail, state))?;
let (loc_pattern, loc_body, state) = { let (loc_pattern, loc_body, state) = {
match expr_to_pattern_help(arena, &call.value) { match expr_to_pattern_help(arena, &call.value) {
@ -1510,7 +1510,7 @@ fn parse_expr_operator<'a>(
Ok((_, mut new_expr, state)) => { Ok((_, mut new_expr, state)) => {
let new_end = state.pos(); let new_end = state.pos();
expr_state.initial = state.clone(); expr_state.initial = state;
// put the spaces from after the operator in front of the new_expr // put the spaces from after the operator in front of the new_expr
if !spaces_after_operator.is_empty() { if !spaces_after_operator.is_empty() {
@ -1567,7 +1567,7 @@ fn parse_expr_end<'a>(
move |a, s| parse_loc_term_or_underscore(min_indent, options, a, s) move |a, s| parse_loc_term_or_underscore(min_indent, options, a, s)
); );
match parser.parse(arena, state.clone()) { match parser.parse(arena, state) {
Err((MadeProgress, f, s)) => Err((MadeProgress, f, s)), Err((MadeProgress, f, s)) => Err((MadeProgress, f, s)),
Ok(( Ok((
_, _,
@ -1636,7 +1636,7 @@ fn parse_expr_end<'a>(
expr_state.spaces_after = &[]; expr_state.spaces_after = &[];
} }
expr_state.initial = state.clone(); expr_state.initial = state;
match space0_e(min_indent, EExpr::IndentEnd).parse(arena, state) { match space0_e(min_indent, EExpr::IndentEnd).parse(arena, state) {
Err((_, _, state)) => { Err((_, _, state)) => {
@ -1656,7 +1656,7 @@ fn parse_expr_end<'a>(
} }
} }
Err((NoProgress, _, _)) => { Err((NoProgress, _, _)) => {
let before_op = state.clone(); let before_op = state;
// try an operator // try an operator
match loc!(operator()).parse(arena, state) { match loc!(operator()).parse(arena, state) {
Err((MadeProgress, f, s)) => Err((MadeProgress, f, s)), Err((MadeProgress, f, s)) => Err((MadeProgress, f, s)),
@ -1736,7 +1736,7 @@ fn parse_expr_end<'a>(
Err((MadeProgress, EExpr::BadOperator("->", state.pos()), state)) Err((MadeProgress, EExpr::BadOperator("->", state.pos()), state))
} else { } else {
// roll back space parsing // roll back space parsing
let state = expr_state.initial.clone(); let state = expr_state.initial;
parse_expr_final(expr_state, arena, state) parse_expr_final(expr_state, arena, state)
} }
@ -2211,7 +2211,7 @@ mod when {
pattern_indent_level: Option<u32>, pattern_indent_level: Option<u32>,
) -> impl Parser<'a, (u32, Vec<'a, Loc<Pattern<'a>>>), EWhen<'a>> { ) -> impl Parser<'a, (u32, Vec<'a, Loc<Pattern<'a>>>), EWhen<'a>> {
move |arena, state: State<'a>| { move |arena, state: State<'a>| {
let initial = state.clone(); let initial = state;
// put no restrictions on the indent after the spaces; we'll check it manually // put no restrictions on the indent after the spaces; we'll check it manually
match space0_e(0, EWhen::IndentPattern).parse(arena, state) { match space0_e(0, EWhen::IndentPattern).parse(arena, state) {

View file

@ -152,7 +152,7 @@ macro_rules! advance_state {
} }
pub fn parse_ident<'a>(arena: &'a Bump, state: State<'a>) -> ParseResult<'a, Ident<'a>, EExpr<'a>> { pub fn parse_ident<'a>(arena: &'a Bump, state: State<'a>) -> ParseResult<'a, Ident<'a>, EExpr<'a>> {
let initial = state.clone(); let initial = state;
match parse_ident_help(arena, state) { match parse_ident_help(arena, state) {
Ok((progress, ident, state)) => { Ok((progress, ident, state)) => {

View file

@ -1152,7 +1152,7 @@ where
move |arena: &'a Bump, state: State<'a>| { move |arena: &'a Bump, state: State<'a>| {
// We have to clone this because if the optional parser fails, // We have to clone this because if the optional parser fails,
// we need to revert back to the original state. // we need to revert back to the original state.
let original_state = state.clone(); let original_state = state;
match parser.parse(arena, state) { match parser.parse(arena, state) {
Ok((progress, out1, state)) => Ok((progress, Some(out1), state)), Ok((progress, out1, state)) => Ok((progress, Some(out1), state)),
@ -1196,7 +1196,7 @@ macro_rules! loc {
macro_rules! skip_first { macro_rules! skip_first {
($p1:expr, $p2:expr) => { ($p1:expr, $p2:expr) => {
move |arena, state: $crate::state::State<'a>| { move |arena, state: $crate::state::State<'a>| {
let original_state = state.clone(); let original_state = state;
match $p1.parse(arena, state) { match $p1.parse(arena, state) {
Ok((p1, _, state)) => match $p2.parse(arena, state) { Ok((p1, _, state)) => match $p2.parse(arena, state) {
@ -1215,7 +1215,7 @@ macro_rules! skip_first {
macro_rules! skip_second { macro_rules! skip_second {
($p1:expr, $p2:expr) => { ($p1:expr, $p2:expr) => {
move |arena, state: $crate::state::State<'a>| { move |arena, state: $crate::state::State<'a>| {
let original_state = state.clone(); let original_state = state;
match $p1.parse(arena, state) { match $p1.parse(arena, state) {
Ok((p1, out1, state)) => match $p2.parse(arena, state) { Ok((p1, out1, state)) => match $p2.parse(arena, state) {
@ -1330,7 +1330,7 @@ macro_rules! and {
move |arena: &'a bumpalo::Bump, state: $crate::state::State<'a>| { move |arena: &'a bumpalo::Bump, state: $crate::state::State<'a>| {
// We have to clone this because if the first parser passes and then // We have to clone this because if the first parser passes and then
// the second one fails, we need to revert back to the original state. // the second one fails, we need to revert back to the original state.
let original_state = state.clone(); let original_state = state;
match $p1.parse(arena, state) { match $p1.parse(arena, state) {
Ok((p1, out1, state)) => match $p2.parse(arena, state) { Ok((p1, out1, state)) => match $p2.parse(arena, state) {
@ -1709,7 +1709,7 @@ where
Error: 'a, Error: 'a,
{ {
move |arena: &'a Bump, state: State<'a>| { move |arena: &'a Bump, state: State<'a>| {
let old_state = state.clone(); let old_state = state;
match parser.parse(arena, state) { match parser.parse(arena, state) {
Ok((_, a, s1)) => Ok((NoProgress, a, s1)), Ok((_, a, s1)) => Ok((NoProgress, a, s1)),

View file

@ -86,7 +86,7 @@ fn loc_tag_pattern_arg<'a>(
// If we encounter one, we're done parsing function args! // If we encounter one, we're done parsing function args!
move |arena, original_state: State<'a>| { move |arena, original_state: State<'a>| {
let (_, spaces, state) = backtrackable(space0_e(min_indent, EPattern::IndentStart)) let (_, spaces, state) = backtrackable(space0_e(min_indent, EPattern::IndentStart))
.parse(arena, original_state.clone())?; .parse(arena, original_state)?;
let (_, loc_pat, state) = loc_parse_tag_pattern_arg(min_indent, arena, state)?; let (_, loc_pat, state) = loc_parse_tag_pattern_arg(min_indent, arena, state)?;
@ -207,7 +207,7 @@ fn loc_ident_pattern_help<'a>(
can_have_arguments: bool, can_have_arguments: bool,
) -> impl Parser<'a, Loc<Pattern<'a>>, EPattern<'a>> { ) -> impl Parser<'a, Loc<Pattern<'a>>, EPattern<'a>> {
move |arena: &'a Bump, state: State<'a>| { move |arena: &'a Bump, state: State<'a>| {
let original_state = state.clone(); let original_state = state;
let (_, loc_ident, state) = let (_, loc_ident, state) =
specialize(|_, pos| EPattern::Start(pos), loc!(parse_ident)).parse(arena, state)?; specialize(|_, pos| EPattern::Start(pos), loc!(parse_ident)).parse(arena, state)?;

View file

@ -173,7 +173,7 @@ pub fn parse<'a>() -> impl Parser<'a, StrLiteral<'a>, EString<'a>> {
let start_state; let start_state;
if state.consume_mut("\"\"\"") { if state.consume_mut("\"\"\"") {
start_state = state.clone(); start_state = state;
// we will be parsing a multi-line string // we will be parsing a multi-line string
is_multiline = true; is_multiline = true;
@ -182,7 +182,7 @@ pub fn parse<'a>() -> impl Parser<'a, StrLiteral<'a>, EString<'a>> {
state = consume_indent(state, indent)?; state = consume_indent(state, indent)?;
} }
} else if state.consume_mut("\"") { } else if state.consume_mut("\"") {
start_state = state.clone(); start_state = state;
// we will be parsing a single-line string // we will be parsing a single-line string
is_multiline = false; is_multiline = false;
@ -322,10 +322,10 @@ pub fn parse<'a>() -> impl Parser<'a, StrLiteral<'a>, EString<'a>> {
if state.bytes().starts_with(b"\"\"\"") { if state.bytes().starts_with(b"\"\"\"") {
// ending the string; don't use the last newline // ending the string; don't use the last newline
segments segments
.push(StrSegment::Plaintext(utf8(state.clone(), without_newline)?)); .push(StrSegment::Plaintext(utf8(state, without_newline)?));
} else { } else {
segments segments
.push(StrSegment::Plaintext(utf8(state.clone(), with_newline)?)); .push(StrSegment::Plaintext(utf8(state, with_newline)?));
} }
segment_parsed_bytes = 0; segment_parsed_bytes = 0;

View file

@ -25,7 +25,7 @@ pub fn parse_loc_with<'a>(
) -> Result<Loc<ast::Expr<'a>>, SourceError<'a, SyntaxError<'a>>> { ) -> Result<Loc<ast::Expr<'a>>, SourceError<'a, SyntaxError<'a>>> {
let state = State::new(input.trim().as_bytes()); let state = State::new(input.trim().as_bytes());
match crate::expr::test_parse_expr(0, arena, state.clone()) { match crate::expr::test_parse_expr(0, arena, state) {
Ok(loc_expr) => Ok(loc_expr), Ok(loc_expr) => Ok(loc_expr),
Err(fail) => Err(SyntaxError::Expr(fail, Position::default()).into_source_error(&state)), Err(fail) => Err(SyntaxError::Expr(fail, Position::default()).into_source_error(&state)),
} }

View file

@ -576,7 +576,7 @@ fn expression<'a>(
) )
.trace("type_annotation:expression:arrow") .trace("type_annotation:expression:arrow")
] ]
.parse(arena, state.clone()); .parse(arena, state);
let (progress, annot, state) = match result { let (progress, annot, state) = match result {
Ok((p2, (rest, _dropped_spaces), state)) => { Ok((p2, (rest, _dropped_spaces), state)) => {
@ -609,7 +609,7 @@ fn expression<'a>(
word1(b',', EType::TStart) word1(b',', EType::TStart)
)) ))
.trace("check trailing comma") .trace("check trailing comma")
.parse(arena, state.clone())?; .parse(arena, state)?;
if comma.is_some() { if comma.is_some() {
// If the surrounding scope has declared that a trailing comma is not a valid state // If the surrounding scope has declared that a trailing comma is not a valid state
@ -628,7 +628,7 @@ fn expression<'a>(
// Finally, try to parse a where clause if there is one. // Finally, try to parse a where clause if there is one.
// The where clause must be at least as deep as where the type annotation started. // The where clause must be at least as deep as where the type annotation started.
let min_where_clause_indent = min_indent; let min_where_clause_indent = min_indent;
match has_clause_chain(min_where_clause_indent).parse(arena, state.clone()) { match has_clause_chain(min_where_clause_indent).parse(arena, state) {
Ok((where_progress, (spaces_before, has_chain), state)) => { Ok((where_progress, (spaces_before, has_chain), state)) => {
use crate::ast::Spaceable; use crate::ast::Spaceable;