From f9f63f88c6555a18e4faa1844188cdda06afb782 Mon Sep 17 00:00:00 2001 From: Richard Feldman Date: Tue, 3 Sep 2019 22:37:53 -0400 Subject: [PATCH] Pass State by value. --- src/parse/parser.rs | 12 ++++++------ src/parse/string_literal.rs | 18 +++++++++--------- 2 files changed, 15 insertions(+), 15 deletions(-) diff --git a/src/parse/parser.rs b/src/parse/parser.rs index 4498d4633b..088f5063f3 100644 --- a/src/parse/parser.rs +++ b/src/parse/parser.rs @@ -149,17 +149,17 @@ fn state_size() { pub type ParseResult<'a, Output> = Result<(State<'a>, Output), (State<'a>, Attempting)>; pub trait Parser<'a, Output> { - fn parse(&self, &'a Bump, &'a State<'a>, attempting: Attempting) -> ParseResult<'a, Output>; + fn parse(&self, &'a Bump, State<'a>, attempting: Attempting) -> ParseResult<'a, Output>; } impl<'a, F, Output> Parser<'a, Output> for F where - F: Fn(&'a Bump, &'a State<'a>, Attempting) -> ParseResult<'a, Output>, + F: Fn(&'a Bump, State<'a>, Attempting) -> ParseResult<'a, Output>, { fn parse( &self, arena: &'a Bump, - state: &'a State<'a>, + state: State<'a>, attempting: Attempting, ) -> ParseResult<'a, Output> { self(arena, state, attempting) @@ -191,7 +191,7 @@ pub fn keyword<'a>(kw: &'static str) -> impl Parser<'a, ()> { // in the state, only the column. debug_assert!(!kw.contains("\n")); - move |_arena: &'a Bump, state: &'a State<'a>, attempting| { + move |_arena: &'a Bump, state: State<'a>, attempting| { let input = state.input; match input.get(0..kw.len()) { @@ -210,7 +210,7 @@ where P: Parser<'a, A>, F: Fn(&A) -> bool, { - move |arena: &'a Bump, state: &'a State<'a>, attempting| { + move |arena: &'a Bump, state: State<'a>, attempting| { if let Ok((next_state, output)) = parser.parse(arena, state, attempting) { if predicate(&output) { return Ok((next_state, output)); @@ -223,7 +223,7 @@ where pub fn any<'a>( _arena: &'a Bump, - state: &'a State<'a>, + state: State<'a>, attempting: Attempting, ) -> ParseResult<'a, char> { let input = state.input; diff --git a/src/parse/string_literal.rs b/src/parse/string_literal.rs index 833a7dc2ed..86c45cff47 100644 --- a/src/parse/string_literal.rs +++ b/src/parse/string_literal.rs @@ -8,14 +8,14 @@ use std::char; use std::iter::Peekable; pub fn string_literal<'a>() -> impl Parser<'a, Expr<'a>> { - move |arena: &'a Bump, state: &'a State<'a>, attempting: Attempting| { + move |arena: &'a Bump, state: State<'a>, attempting: Attempting| { let mut problems = Vec::new(); let mut chars = state.input.chars().peekable(); // String literals must start with a quote. // If this doesn't, it must not be a string literal! if chars.next() != Some('"') { - return Err((state.clone(), attempting)); + return Err((state, attempting)); } // If we have precisely an empty string here, don't bother allocating @@ -88,14 +88,14 @@ pub fn string_literal<'a>() -> impl Parser<'a, Expr<'a>> { } // We ran out of characters before finding a closed quote - Err((state.clone(), Attempting::StringLiteral)) + Err((state, Attempting::StringLiteral)) } } fn escaped_char_problem<'a, 'p>( problems: &'p mut Problems, problem: Problem, - state: &'a State<'a>, + state: State<'a>, buf_len: usize, ) { let start_line = state.line; @@ -120,7 +120,7 @@ fn escaped_char_problem<'a, 'p>( fn escaped_unicode_problem<'a, 'p>( problems: &'p mut Problems, problem: Problem, - state: &'a State<'a>, + state: State<'a>, buf_len: usize, hex_str_len: usize, ) { @@ -148,7 +148,7 @@ fn escaped_unicode_problem<'a, 'p>( #[inline(always)] fn handle_escaped_char<'a, 'p, I>( arena: &'a Bump, - state: &'a State<'a>, + state: State<'a>, ch: char, chars: &mut Peekable, buf: &mut String<'a>, @@ -181,7 +181,7 @@ where // We can't safely assume where the string was supposed to end. escaped_char_problem(problems, Problem::NewlineInLiteral, state, buf.len()); - return Err((state.clone(), Attempting::UnicodeEscape)); + return Err((state, Attempting::UnicodeEscape)); } _ => { // Report and continue. @@ -196,7 +196,7 @@ where #[inline(always)] fn handle_escaped_unicode<'a, 'p, I>( arena: &'a Bump, - state: &'a State<'a>, + state: State<'a>, chars: &mut Peekable, buf: &mut String<'a>, problems: &'p mut Problems, @@ -342,7 +342,7 @@ where hex_str.len(), ); - return Err((state.clone(), Attempting::UnicodeEscape)); + return Err((state, Attempting::UnicodeEscape)); } normal_char => hex_str.push(normal_char), }