diff --git a/src/deprecated/parse.rs b/src/deprecated/parse.rs index f7f5cb12f3..6dd784af03 100644 --- a/src/deprecated/parse.rs +++ b/src/deprecated/parse.rs @@ -62,7 +62,7 @@ where }) } -fn indentation() -> impl Parser +fn indentation() -> impl Parser where I: Stream, I::Error: ParseError, @@ -136,7 +136,7 @@ where .with(value(())) } -fn indented_whitespaces(min_indent: u32) -> impl Parser +fn indented_whitespaces(min_indent: u16) -> impl Parser where I: Stream, I::Error: ParseError, @@ -144,7 +144,7 @@ where skip_many(skipped_indented_whitespace_char(min_indent)) } -fn indented_whitespaces1(min_indent: u32) -> impl Parser +fn indented_whitespaces1(min_indent: u16) -> impl Parser where I: Stream, I::Error: ParseError, @@ -152,7 +152,7 @@ where skip_many1(skipped_indented_whitespace_char(min_indent)) } -fn skipped_indented_whitespace_char(min_indent: u32) -> impl Parser +fn skipped_indented_whitespace_char(min_indent: u16) -> impl Parser where I: Stream, I::Error: ParseError, @@ -186,7 +186,7 @@ where /// This is separate from expr_body for the sake of function application, /// so it can stop parsing when it reaches an operator (since they have /// higher precedence.) -fn function_arg_expr(min_indent: u32) -> impl Parser +fn function_arg_expr(min_indent: u16) -> impl Parser where I: Stream, I::Error: ParseError, @@ -196,10 +196,10 @@ where parser! { #[inline(always)] - fn function_arg_expr_[I](min_indent_ref: u32)(I) -> Expr + fn function_arg_expr_[I](min_indent_ref: u16)(I) -> Expr where [ I: Stream ] { - // TODO figure out why min_indent_ref has the type &mut u32 + // TODO figure out why min_indent_ref has the type &mut u16 let min_indent = *min_indent_ref; // Rules for expressions that can go in function arguments: @@ -225,7 +225,7 @@ parser! { } } -fn expr_body(min_indent: u32) -> impl Parser +fn expr_body(min_indent: u16) -> impl Parser where I: Stream, I::Error: ParseError, @@ -236,10 +236,10 @@ where // This macro allows recursive parsers parser! { #[inline(always)] - fn expr_body_[I](min_indent_ref: u32)(I) -> Expr + fn expr_body_[I](min_indent_ref: u16)(I) -> Expr where [ I: Stream ] { - // TODO figure out why min_indent_ref has the type &mut u32 + // TODO figure out why min_indent_ref has the type &mut u16 let min_indent = *min_indent_ref; located(choice(( @@ -272,7 +272,7 @@ parser! { } } -pub fn if_expr(min_indent: u32) -> impl Parser +pub fn if_expr(min_indent: u16) -> impl Parser where I: Stream, I::Error: ParseError, @@ -296,7 +296,7 @@ where }) } -pub fn case_expr(min_indent: u32) -> impl Parser +pub fn case_expr(min_indent: u16) -> impl Parser where I: Stream, I::Error: ParseError, @@ -324,7 +324,7 @@ where }) } -pub fn list(min_indent: u32) -> impl Parser +pub fn list(min_indent: u16) -> impl Parser where I: Stream, I::Error: ParseError, @@ -348,7 +348,7 @@ where }) } -pub fn apply_with_parens(min_indent: u32) -> impl Parser +pub fn apply_with_parens(min_indent: u16) -> impl Parser where I: Stream, I::Error: ParseError, @@ -376,7 +376,7 @@ where } #[inline(always)] -fn function_arg(min_indent: u32) -> impl Parser> +fn function_arg(min_indent: u16) -> impl Parser> where I: Stream, I::Error: ParseError, @@ -405,7 +405,7 @@ where ))) } -pub fn apply_args(min_indent: u32) -> impl Parser>> +pub fn apply_args(min_indent: u16) -> impl Parser>> where I: Stream, I::Error: ParseError, @@ -493,7 +493,7 @@ where } pub fn nested_assignment( - min_indent: u32, + min_indent: u16, ) -> impl Parser, Located)> where I: Stream, @@ -530,7 +530,7 @@ where ) } -pub fn assignment(min_indent: u32) -> impl Parser +pub fn assignment(min_indent: u16) -> impl Parser where I: Stream, I::Error: ParseError, @@ -570,7 +570,7 @@ where }) } -pub fn func_or_var(min_indent: u32) -> impl Parser +pub fn func_or_var(min_indent: u16) -> impl Parser where I: Stream, I::Error: ParseError, @@ -594,7 +594,7 @@ where } /// e.g. \x y => expr -pub fn closure(min_indent: u32) -> impl Parser +pub fn closure(min_indent: u16) -> impl Parser where I: Stream, I::Error: ParseError, @@ -616,7 +616,7 @@ where parser! { #[inline(always)] - fn pattern[I](min_indent_ref: u32)(I) -> Pattern + fn pattern[I](min_indent_ref: u16)(I) -> Pattern where [ I: Stream ] { let min_indent = *min_indent_ref; @@ -631,7 +631,7 @@ parser! { } } -pub fn apply_variant(min_indent: u32) -> impl Parser +pub fn apply_variant(min_indent: u16) -> impl Parser where I: Stream, I::Error: ParseError, @@ -643,7 +643,7 @@ where }) } -pub fn match_variant(min_indent: u32) -> impl Parser +pub fn match_variant(min_indent: u16) -> impl Parser where I: Stream, I::Error: ParseError, diff --git a/src/deprecated/parse_state.rs b/src/deprecated/parse_state.rs index 66afe99487..970b9b36fb 100644 --- a/src/deprecated/parse_state.rs +++ b/src/deprecated/parse_state.rs @@ -18,10 +18,10 @@ pub struct IndentablePosition { /// Current line of the input pub line: u32, /// Current column of the input - pub column: u32, + pub column: u16, /// Current indentation level, in columns (so no indent is col 1 - this saves an arithmetic operation.) - pub indent_col: u32, + pub indent_col: u16, // true at the beginning of each line, then false after encountering the first nonspace char. pub is_indenting: bool, diff --git a/src/parse/mod.rs b/src/parse/mod.rs index 0ec8dc8ebf..c9816d6d70 100644 --- a/src/parse/mod.rs +++ b/src/parse/mod.rs @@ -7,9 +7,6 @@ use parse::ast::Expr; use parse::parser::Parser; use parse::string_literal::string_literal; -pub fn expr<'a, 'p>() -> impl Parser<'a, 'p, Expr<'a>> -where - 'p: 'a, -{ +pub fn expr<'a>() -> impl Parser<'a, Expr<'a>> { string_literal() } diff --git a/src/parse/string_literal.rs b/src/parse/string_literal.rs index 7a7203aa5b..833a7dc2ed 100644 --- a/src/parse/string_literal.rs +++ b/src/parse/string_literal.rs @@ -99,7 +99,7 @@ fn escaped_char_problem<'a, 'p>( buf_len: usize, ) { let start_line = state.line; - let start_col = state.column + buf_len as u32; + let start_col = state.column + buf_len as u16; let end_line = start_line; // escapes should all be 2 chars long let end_col = state.column + 1; @@ -126,11 +126,11 @@ fn escaped_unicode_problem<'a, 'p>( ) { let start_line = state.line; // +1 due to the `"` which precedes buf. - let start_col = state.column + buf_len as u32 + 1; + let start_col = state.column + buf_len as u16 + 1; let end_line = start_line; // +3 due to the `\u{` and another + 1 due to the `}` // -1 to prevent overshooting because end col is inclusive. - let end_col = start_col + 3 + hex_str_len as u32 + 1 - 1; + let end_col = start_col + 3 + hex_str_len as u16 + 1 - 1; let region = Region { start_line, @@ -209,7 +209,7 @@ where if chars.next() != Some('{') { let start_line = state.line; // +1 due to the `"` which precedes buf - let start_col = state.column + 1 + buf.len() as u32; + let start_col = state.column + 1 + buf.len() as u16; let end_line = start_line; // All we parsed was `\u`, so end on the column after `\`'s column. @@ -251,13 +251,13 @@ where let start_line = state.line; // +1 due to the `"` which precedes buf // +3 due to the `\u{` which precedes the hex digits - let start_col = state.column + 1 + buf.len() as u32 + 3; + let start_col = state.column + 1 + buf.len() as u16 + 3; let end_line = start_line; // We want to underline only the number. That's the error! // -1 because we want to end on the last digit, not // overshoot it. - let end_col = start_col + hex_str.len() as u32 - 1; + let end_col = start_col + hex_str.len() as u16 - 1; let region = Region { start_line, @@ -355,11 +355,11 @@ where // parsing logic can consume the quote and do its job as normal. let start_line = state.line; // +1 due to the `"` which precedes buf. - let start_col = state.column + buf.len() as u32 + 1; + let start_col = state.column + buf.len() as u16 + 1; let end_line = start_line; // +3 due to the `\u{` // -1 to prevent overshooting because end col is inclusive. - let end_col = start_col + 3 + hex_str.len() as u32 - 1; + let end_col = start_col + 3 + hex_str.len() as u16 - 1; let region = Region { start_line, diff --git a/src/region.rs b/src/region.rs index a647f57a9f..add2a11049 100644 --- a/src/region.rs +++ b/src/region.rs @@ -5,11 +5,16 @@ pub type Loc = Located; #[derive(Clone, Eq, PartialEq, PartialOrd, Ord)] pub struct Region { + pub start_col: u16, + pub end_col: u16, pub start_line: u32, - pub start_col: u32, - pub end_line: u32, - pub end_col: u32, +} + +#[test] +fn region_size() { + // Region is used all over the place. Avoid increasing its size! + assert_eq!(std::mem::size_of::(), 8); } impl fmt::Debug for Region {