mirror of
https://github.com/roc-lang/roc.git
synced 2025-10-03 00:24:34 +00:00
Rename State::pos -> xyzlcol, temporarily
This commit is contained in:
parent
bd7b1e5013
commit
d2dcb462c7
10 changed files with 82 additions and 82 deletions
|
@ -160,10 +160,10 @@ where
|
|||
E: 'a,
|
||||
{
|
||||
move |_, state: State<'a>| {
|
||||
if state.pos.column >= min_indent {
|
||||
if state.xyzlcol.column >= min_indent {
|
||||
Ok((NoProgress, (), state))
|
||||
} else {
|
||||
Err((NoProgress, indent_problem(state.pos), state))
|
||||
Err((NoProgress, indent_problem(state.xyzlcol), state))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -193,11 +193,11 @@ where
|
|||
move |arena, mut state: State<'a>| {
|
||||
let comments_and_newlines = Vec::new_in(arena);
|
||||
|
||||
match eat_spaces(state.bytes(), state.pos, comments_and_newlines) {
|
||||
match eat_spaces(state.bytes(), state.xyzlcol, comments_and_newlines) {
|
||||
HasTab(pos) => {
|
||||
// there was a tab character
|
||||
let mut state = state;
|
||||
state.pos = pos;
|
||||
state.xyzlcol = pos;
|
||||
// TODO: it _seems_ like if we're changing the line/column, we should also be
|
||||
// advancing the state by the corresponding number of bytes.
|
||||
// Not doing this is likely a bug!
|
||||
|
@ -215,21 +215,21 @@ where
|
|||
} => {
|
||||
if bytes == state.bytes() {
|
||||
Ok((NoProgress, &[] as &[_], state))
|
||||
} else if state.pos.line != pos.line {
|
||||
} else if state.xyzlcol.line != pos.line {
|
||||
// we parsed at least one newline
|
||||
|
||||
state.indent_column = pos.column;
|
||||
|
||||
if pos.column >= min_indent {
|
||||
state.pos = pos;
|
||||
state.xyzlcol = pos;
|
||||
state = state.advance(state.bytes().len() - bytes.len());
|
||||
|
||||
Ok((MadeProgress, comments_and_newlines.into_bump_slice(), state))
|
||||
} else {
|
||||
Err((MadeProgress, indent_problem(state.pos), state))
|
||||
Err((MadeProgress, indent_problem(state.xyzlcol), state))
|
||||
}
|
||||
} else {
|
||||
state.pos.column = pos.column;
|
||||
state.xyzlcol.column = pos.column;
|
||||
state = state.advance(state.bytes().len() - bytes.len());
|
||||
|
||||
Ok((MadeProgress, comments_and_newlines.into_bump_slice(), state))
|
||||
|
|
|
@ -25,7 +25,7 @@ fn expr_end<'a>() -> impl Parser<'a, (), EExpr<'a>> {
|
|||
if state.has_reached_end() {
|
||||
Ok((NoProgress, (), state))
|
||||
} else {
|
||||
Err((NoProgress, EExpr::BadExprEnd(state.pos), state))
|
||||
Err((NoProgress, EExpr::BadExprEnd(state.xyzlcol), state))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -175,7 +175,7 @@ fn record_field_access_chain<'a>() -> impl Parser<'a, Vec<'a, &'a str>, EExpr<'a
|
|||
}
|
||||
}
|
||||
Err((MadeProgress, fail, state)) => Err((MadeProgress, fail, state)),
|
||||
Err((NoProgress, _, state)) => Err((NoProgress, EExpr::Access(state.pos), state)),
|
||||
Err((NoProgress, _, state)) => Err((NoProgress, EExpr::Access(state.xyzlcol), state)),
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -233,7 +233,7 @@ fn parse_loc_term<'a>(
|
|||
|
||||
fn underscore_expression<'a>() -> impl Parser<'a, Expr<'a>, EExpr<'a>> {
|
||||
move |arena: &'a Bump, state: State<'a>| {
|
||||
let start = state.pos;
|
||||
let start = state.xyzlcol;
|
||||
|
||||
let (_, _, next_state) = word1(b'_', EExpr::Underscore).parse(arena, state)?;
|
||||
|
||||
|
@ -280,7 +280,7 @@ fn loc_possibly_negative_or_negated_term<'a>(
|
|||
}
|
||||
|
||||
fn fail_expr_start_e<'a, T: 'a>() -> impl Parser<'a, T, EExpr<'a>> {
|
||||
|_arena, state: State<'a>| Err((NoProgress, EExpr::Start(state.pos), state))
|
||||
|_arena, state: State<'a>| Err((NoProgress, EExpr::Start(state.xyzlcol), state))
|
||||
}
|
||||
|
||||
fn unary_negate<'a>() -> impl Parser<'a, (), EExpr<'a>> {
|
||||
|
@ -298,11 +298,11 @@ fn unary_negate<'a>() -> impl Parser<'a, (), EExpr<'a>> {
|
|||
if state.bytes().starts_with(b"-") && !followed_by_whitespace {
|
||||
// the negate is only unary if it is not followed by whitespace
|
||||
let mut state = state.advance(1);
|
||||
state.pos.column += 1;
|
||||
state.xyzlcol.column += 1;
|
||||
Ok((MadeProgress, (), state))
|
||||
} else {
|
||||
// this is not a negated expression
|
||||
Err((NoProgress, EExpr::UnaryNot(state.pos), state))
|
||||
Err((NoProgress, EExpr::UnaryNot(state.xyzlcol), state))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -790,7 +790,7 @@ fn parse_defs_end<'a>(
|
|||
|
||||
let state = match space0_e(min_indent, EExpr::Space, EExpr::IndentStart).parse(arena, state) {
|
||||
Err((MadeProgress, _, s)) => {
|
||||
return Err((MadeProgress, EExpr::DefMissingFinalExpr(s.pos), s));
|
||||
return Err((MadeProgress, EExpr::DefMissingFinalExpr(s.xyzlcol), s));
|
||||
}
|
||||
Ok((_, spaces, state)) => {
|
||||
def_state.spaces_after = spaces;
|
||||
|
@ -916,7 +916,7 @@ fn parse_defs_expr<'a>(
|
|||
Err((_, fail, state)) => {
|
||||
return Err((
|
||||
MadeProgress,
|
||||
EExpr::DefMissingFinalExpr2(arena.alloc(fail), state.pos),
|
||||
EExpr::DefMissingFinalExpr2(arena.alloc(fail), state.xyzlcol),
|
||||
state,
|
||||
));
|
||||
}
|
||||
|
@ -1282,7 +1282,7 @@ fn parse_expr_end<'a>(
|
|||
// try multi-backpassing
|
||||
if options.accept_multi_backpassing && state.bytes().starts_with(b",") {
|
||||
state = state.advance(1);
|
||||
state.pos.column += 1;
|
||||
state.xyzlcol.column += 1;
|
||||
|
||||
let (_, mut patterns, state) = specialize_ref(
|
||||
EExpr::Pattern,
|
||||
|
@ -1342,7 +1342,7 @@ fn parse_expr_end<'a>(
|
|||
}
|
||||
}
|
||||
} else if options.check_for_arrow && state.bytes().starts_with(b"->") {
|
||||
Err((MadeProgress, EExpr::BadOperator("->", state.pos), state))
|
||||
Err((MadeProgress, EExpr::BadOperator("->", state.xyzlcol), state))
|
||||
} else {
|
||||
// roll back space parsing
|
||||
let state = expr_state.initial.clone();
|
||||
|
@ -1662,7 +1662,7 @@ mod when {
|
|||
return Err((
|
||||
progress,
|
||||
// TODO maybe pass case_indent here?
|
||||
EWhen::PatternAlignment(5, state.pos),
|
||||
EWhen::PatternAlignment(5, state.xyzlcol),
|
||||
state,
|
||||
));
|
||||
}
|
||||
|
@ -1733,7 +1733,7 @@ mod when {
|
|||
let indent = pattern_indent_level - indent_column;
|
||||
Err((
|
||||
MadeProgress,
|
||||
EWhen::PatternAlignment(indent, state.pos),
|
||||
EWhen::PatternAlignment(indent, state.xyzlcol),
|
||||
state,
|
||||
))
|
||||
}
|
||||
|
@ -1853,15 +1853,15 @@ mod when {
|
|||
Err((NoProgress, fail, _)) => Err((NoProgress, fail, initial)),
|
||||
Ok((_progress, spaces, state)) => {
|
||||
match pattern_indent_level {
|
||||
Some(wanted) if state.pos.column > wanted => {
|
||||
Some(wanted) if state.xyzlcol.column > wanted => {
|
||||
// this branch is indented too much
|
||||
Err((NoProgress, EWhen::IndentPattern(state.pos), initial))
|
||||
Err((NoProgress, EWhen::IndentPattern(state.xyzlcol), initial))
|
||||
}
|
||||
Some(wanted) if state.pos.column < wanted => {
|
||||
let indent = wanted - state.pos.column;
|
||||
Some(wanted) if state.xyzlcol.column < wanted => {
|
||||
let indent = wanted - state.xyzlcol.column;
|
||||
Err((
|
||||
NoProgress,
|
||||
EWhen::PatternAlignment(indent, state.pos),
|
||||
EWhen::PatternAlignment(indent, state.xyzlcol),
|
||||
initial,
|
||||
))
|
||||
}
|
||||
|
@ -1870,7 +1870,7 @@ mod when {
|
|||
min_indent.max(pattern_indent_level.unwrap_or(min_indent));
|
||||
// the region is not reliable for the indent column in the case of
|
||||
// parentheses around patterns
|
||||
let pattern_indent_column = state.pos.column;
|
||||
let pattern_indent_column = state.xyzlcol.column;
|
||||
|
||||
let parser = sep_by1(
|
||||
word1(b'|', EWhen::Bar),
|
||||
|
@ -2377,7 +2377,7 @@ where
|
|||
|
||||
macro_rules! good {
|
||||
($op:expr, $width:expr) => {{
|
||||
state.pos.column += $width;
|
||||
state.xyzlcol.column += $width;
|
||||
state = state.advance($width);
|
||||
|
||||
Ok((MadeProgress, $op, state))
|
||||
|
@ -2386,12 +2386,12 @@ where
|
|||
|
||||
macro_rules! bad_made_progress {
|
||||
($op:expr) => {{
|
||||
Err((MadeProgress, to_error($op, state.pos), state))
|
||||
Err((MadeProgress, to_error($op, state.xyzlcol), state))
|
||||
}};
|
||||
}
|
||||
|
||||
match chomped {
|
||||
"" => Err((NoProgress, to_expectation(state.pos), state)),
|
||||
"" => Err((NoProgress, to_expectation(state.xyzlcol), state)),
|
||||
"+" => good!(BinOp::Plus, 1),
|
||||
"-" => good!(BinOp::Minus, 1),
|
||||
"*" => good!(BinOp::Star, 1),
|
||||
|
@ -2402,7 +2402,7 @@ where
|
|||
"<" => good!(BinOp::LessThan, 1),
|
||||
"." => {
|
||||
// a `.` makes no progress, so it does not interfere with `.foo` access(or)
|
||||
Err((NoProgress, to_error(".", state.pos), state))
|
||||
Err((NoProgress, to_error(".", state.xyzlcol), state))
|
||||
}
|
||||
"=" => good!(BinOp::Assignment, 1),
|
||||
":" => good!(BinOp::HasType, 1),
|
||||
|
@ -2417,7 +2417,7 @@ where
|
|||
"%%" => good!(BinOp::DoublePercent, 2),
|
||||
"->" => {
|
||||
// makes no progress, so it does not interfere with `_ if isGood -> ...`
|
||||
Err((NoProgress, to_error("->", state.pos), state))
|
||||
Err((NoProgress, to_error("->", state.xyzlcol), state))
|
||||
}
|
||||
"<-" => good!(BinOp::Backpassing, 2),
|
||||
_ => bad_made_progress!(chomped),
|
||||
|
|
|
@ -250,7 +250,7 @@ pub fn package_entry<'a>() -> impl Parser<'a, Spaced<'a, PackageEntry<'a>>, EPac
|
|||
|
||||
pub fn package_name<'a>() -> impl Parser<'a, PackageName<'a>, EPackageName<'a>> {
|
||||
move |arena, state: State<'a>| {
|
||||
let pos = state.pos;
|
||||
let pos = state.pos();
|
||||
specialize(EPackageName::BadPath, string_literal::parse())
|
||||
.parse(arena, state)
|
||||
.and_then(|(progress, text, next_state)| match text {
|
||||
|
|
|
@ -80,7 +80,7 @@ pub fn lowercase_ident<'a>() -> impl Parser<'a, &'a str, ()> {
|
|||
pub fn tag_name<'a>() -> impl Parser<'a, &'a str, ()> {
|
||||
move |arena, state: State<'a>| {
|
||||
if state.bytes().starts_with(b"@") {
|
||||
match chomp_private_tag(state.bytes(), state.pos) {
|
||||
match chomp_private_tag(state.bytes(), state.xyzlcol) {
|
||||
Err(BadIdent::Start(_)) => Err((NoProgress, (), state)),
|
||||
Err(_) => Err((MadeProgress, (), state)),
|
||||
Ok(ident) => {
|
||||
|
@ -150,7 +150,7 @@ pub fn parse_ident<'a>(arena: &'a Bump, state: State<'a>) -> ParseResult<'a, Ide
|
|||
if let Some(first) = parts.first() {
|
||||
for keyword in crate::keyword::KEYWORDS.iter() {
|
||||
if first == keyword {
|
||||
return Err((NoProgress, EExpr::Start(initial.pos), initial));
|
||||
return Err((NoProgress, EExpr::Start(initial.xyzlcol), initial));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -159,7 +159,7 @@ pub fn parse_ident<'a>(arena: &'a Bump, state: State<'a>) -> ParseResult<'a, Ide
|
|||
|
||||
Ok((progress, ident, state))
|
||||
}
|
||||
Err((NoProgress, _, state)) => Err((NoProgress, EExpr::Start(state.pos), state)),
|
||||
Err((NoProgress, _, state)) => Err((NoProgress, EExpr::Start(state.xyzlcol), state)),
|
||||
Err((MadeProgress, fail, state)) => match fail {
|
||||
BadIdent::Start(pos) => Err((NoProgress, EExpr::Start(pos), state)),
|
||||
BadIdent::Space(e, pos) => Err((NoProgress, EExpr::Space(e, pos), state)),
|
||||
|
@ -528,7 +528,7 @@ fn parse_ident_help<'a>(
|
|||
arena: &'a Bump,
|
||||
mut state: State<'a>,
|
||||
) -> ParseResult<'a, Ident<'a>, BadIdent> {
|
||||
match chomp_identifier_chain(arena, state.bytes(), state.pos) {
|
||||
match chomp_identifier_chain(arena, state.bytes(), state.xyzlcol) {
|
||||
Ok((width, ident)) => {
|
||||
state = advance_state!(state, width as usize)?;
|
||||
Ok((MadeProgress, ident, state))
|
||||
|
|
|
@ -21,7 +21,7 @@ fn end_of_file<'a>() -> impl Parser<'a, (), SyntaxError<'a>> {
|
|||
if state.has_reached_end() {
|
||||
Ok((NoProgress, (), state))
|
||||
} else {
|
||||
Err((NoProgress, SyntaxError::NotEndOfFile(state.pos), state))
|
||||
Err((NoProgress, SyntaxError::NotEndOfFile(state.xyzlcol), state))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -167,7 +167,7 @@ fn module_name<'a>() -> impl Parser<'a, ModuleName<'a>, ()> {
|
|||
|_, mut state: State<'a>| match chomp_module_name(state.bytes()) {
|
||||
Ok(name) => {
|
||||
let width = name.len();
|
||||
state.pos.column += width as u16;
|
||||
state.xyzlcol.column += width as u16;
|
||||
state = state.advance(width);
|
||||
|
||||
Ok((MadeProgress, ModuleName::new(name), state))
|
||||
|
|
|
@ -723,23 +723,23 @@ where
|
|||
let width = keyword.len();
|
||||
|
||||
if !state.bytes().starts_with(keyword.as_bytes()) {
|
||||
return Err((NoProgress, if_error(state.pos), state));
|
||||
return Err((NoProgress, if_error(state.xyzlcol), state));
|
||||
}
|
||||
|
||||
// the next character should not be an identifier character
|
||||
// to prevent treating `whence` or `iffy` as keywords
|
||||
match state.bytes().get(width) {
|
||||
Some(next) if *next == b' ' || *next == b'#' || *next == b'\n' => {
|
||||
state.pos.column += width as u16;
|
||||
state.xyzlcol.column += width as u16;
|
||||
state = state.advance(width);
|
||||
Ok((MadeProgress, (), state))
|
||||
}
|
||||
None => {
|
||||
state.pos.column += width as u16;
|
||||
state.xyzlcol.column += width as u16;
|
||||
state = state.advance(width);
|
||||
Ok((MadeProgress, (), state))
|
||||
}
|
||||
Some(_) => Err((NoProgress, if_error(state.pos), state)),
|
||||
Some(_) => Err((NoProgress, if_error(state.xyzlcol), state)),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -964,7 +964,7 @@ where
|
|||
return Err((MadeProgress, fail, state));
|
||||
}
|
||||
Err((NoProgress, _fail, state)) => {
|
||||
return Err((NoProgress, to_element_error(state.pos), state));
|
||||
return Err((NoProgress, to_element_error(state.xyzlcol), state));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -989,7 +989,7 @@ where
|
|||
|
||||
Err((MadeProgress, fail, state)) => Err((MadeProgress, fail, state)),
|
||||
Err((NoProgress, _fail, state)) => {
|
||||
Err((NoProgress, to_element_error(state.pos), state))
|
||||
Err((NoProgress, to_element_error(state.xyzlcol), state))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1039,11 +1039,11 @@ macro_rules! loc {
|
|||
move |arena, state: $crate::state::State<'a>| {
|
||||
use roc_region::all::{Loc, Region};
|
||||
|
||||
let start = state.pos;
|
||||
let start = state.xyzlcol;
|
||||
|
||||
match $parser.parse(arena, state) {
|
||||
Ok((progress, value, state)) => {
|
||||
let end = state.pos;
|
||||
let end = state.xyzlcol;
|
||||
let region = Region::new(start, end);
|
||||
|
||||
Ok((progress, Loc { region, value }, state))
|
||||
|
@ -1245,7 +1245,7 @@ macro_rules! one_of_with_error {
|
|||
match $p1.parse(arena, state) {
|
||||
valid @ Ok(_) => valid,
|
||||
Err((MadeProgress, fail, state)) => Err((MadeProgress, fail, state )),
|
||||
Err((NoProgress, _, state)) => Err((MadeProgress, $toerror(state.pos), state)),
|
||||
Err((NoProgress, _, state)) => Err((MadeProgress, $toerror(state.xyzlcol), state)),
|
||||
}
|
||||
}
|
||||
};
|
||||
|
@ -1263,7 +1263,7 @@ where
|
|||
{
|
||||
move |a, s| match parser.parse(a, s) {
|
||||
Ok(t) => Ok(t),
|
||||
Err((p, error, s)) => Err((p, map_error(error, s.pos), s)),
|
||||
Err((p, error, s)) => Err((p, map_error(error, s.xyzlcol), s)),
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1276,7 +1276,7 @@ where
|
|||
{
|
||||
move |a, s| match parser.parse(a, s) {
|
||||
Ok(t) => Ok(t),
|
||||
Err((p, error, s)) => Err((p, map_error(a.alloc(error), s.pos), s)),
|
||||
Err((p, error, s)) => Err((p, map_error(a.alloc(error), s.xyzlcol), s)),
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1290,10 +1290,10 @@ where
|
|||
move |_arena: &'a Bump, state: State<'a>| match state.bytes().get(0) {
|
||||
Some(x) if *x == word => {
|
||||
let mut state = state.advance(1);
|
||||
state.pos.column += 1;
|
||||
state.xyzlcol.column += 1;
|
||||
Ok((MadeProgress, (), state))
|
||||
}
|
||||
_ => Err((NoProgress, to_error(state.pos), state)),
|
||||
_ => Err((NoProgress, to_error(state.xyzlcol), state)),
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1310,10 +1310,10 @@ where
|
|||
move |_arena: &'a Bump, state: State<'a>| {
|
||||
if state.bytes().starts_with(&needle) {
|
||||
let mut state = state.advance(2);
|
||||
state.pos.column += 2;
|
||||
state.xyzlcol.column += 2;
|
||||
Ok((MadeProgress, (), state))
|
||||
} else {
|
||||
Err((NoProgress, to_error(state.pos), state))
|
||||
Err((NoProgress, to_error(state.xyzlcol), state))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1326,7 +1326,7 @@ where
|
|||
move |_arena, state: State<'a>| {
|
||||
dbg!(state.indent_column, min_indent);
|
||||
if state.indent_column < min_indent {
|
||||
Err((NoProgress, to_problem(state.pos), state))
|
||||
Err((NoProgress, to_problem(state.xyzlcol), state))
|
||||
} else {
|
||||
Ok((NoProgress, (), state))
|
||||
}
|
||||
|
|
|
@ -232,7 +232,7 @@ fn loc_ident_pattern_help<'a>(
|
|||
if crate::keyword::KEYWORDS.contains(&parts[0]) {
|
||||
Err((
|
||||
NoProgress,
|
||||
EPattern::End(original_state.pos),
|
||||
EPattern::End(original_state.xyzlcol),
|
||||
original_state,
|
||||
))
|
||||
} else if module_name.is_empty() && parts.len() == 1 {
|
||||
|
@ -304,7 +304,7 @@ fn lowercase_ident_pattern<'a>(
|
|||
arena: &'a Bump,
|
||||
state: State<'a>,
|
||||
) -> ParseResult<'a, &'a str, EPattern<'a>> {
|
||||
let pos = state.pos;
|
||||
let pos = state.xyzlcol;
|
||||
|
||||
specialize(move |_, _| EPattern::End(pos), lowercase_ident()).parse(arena, state)
|
||||
}
|
||||
|
@ -339,7 +339,7 @@ fn record_pattern_field<'a>(min_indent: u16) -> impl Parser<'a, Loc<Pattern<'a>>
|
|||
move |arena, state: State<'a>| {
|
||||
// You must have a field name, e.g. "email"
|
||||
// using the initial pos is important for error reporting
|
||||
let pos = state.pos;
|
||||
let pos = state.xyzlcol;
|
||||
let (progress, loc_label, state) = loc!(specialize(
|
||||
move |_, _| PRecord::Field(pos),
|
||||
lowercase_ident()
|
||||
|
|
|
@ -11,7 +11,7 @@ pub struct State<'a> {
|
|||
bytes: &'a [u8],
|
||||
|
||||
/// Current position within the input (line/column)
|
||||
pub pos: Position,
|
||||
pub xyzlcol: Position,
|
||||
|
||||
/// Current indentation level, in columns
|
||||
/// (so no indent is col 1 - this saves an arithmetic operation.)
|
||||
|
@ -22,7 +22,7 @@ impl<'a> State<'a> {
|
|||
pub fn new(bytes: &'a [u8]) -> State<'a> {
|
||||
State {
|
||||
bytes,
|
||||
pos: Position::default(),
|
||||
xyzlcol: Position::default(),
|
||||
indent_column: 0,
|
||||
}
|
||||
}
|
||||
|
@ -40,7 +40,7 @@ impl<'a> State<'a> {
|
|||
|
||||
/// Returns the current position
|
||||
pub const fn pos(&self) -> Position {
|
||||
self.pos
|
||||
self.xyzlcol
|
||||
}
|
||||
|
||||
/// Returns whether the parser has reached the end of the input
|
||||
|
@ -71,19 +71,19 @@ impl<'a> State<'a> {
|
|||
where
|
||||
TE: Fn(Position) -> E,
|
||||
{
|
||||
match (self.pos.column as usize).checked_add(quantity) {
|
||||
match (self.xyzlcol.column as usize).checked_add(quantity) {
|
||||
Some(column_usize) if column_usize <= u16::MAX as usize => {
|
||||
Ok(State {
|
||||
bytes: &self.bytes[quantity..],
|
||||
pos: Position {
|
||||
line: self.pos.line,
|
||||
xyzlcol: Position {
|
||||
line: self.xyzlcol.line,
|
||||
column: column_usize as u16,
|
||||
},
|
||||
// Once we hit a nonspace character, we are no longer indenting.
|
||||
..self
|
||||
})
|
||||
}
|
||||
_ => Err((NoProgress, to_error(self.pos), self)),
|
||||
_ => Err((NoProgress, to_error(self.xyzlcol), self)),
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -93,11 +93,11 @@ impl<'a> State<'a> {
|
|||
/// and thus wanting a Region while not having access to loc().
|
||||
pub fn len_region(&self, length: u16) -> Region {
|
||||
Region::new(
|
||||
self.pos,
|
||||
self.xyzlcol,
|
||||
Position {
|
||||
line: self.pos.line,
|
||||
line: self.xyzlcol.line,
|
||||
column: self
|
||||
.pos
|
||||
.xyzlcol
|
||||
.column
|
||||
.checked_add(length)
|
||||
.unwrap_or_else(|| panic!("len_region overflowed")),
|
||||
|
@ -128,7 +128,7 @@ impl<'a> fmt::Debug for State<'a> {
|
|||
write!(
|
||||
f,
|
||||
"\n\t(line, col): ({}, {}),",
|
||||
self.pos.line, self.pos.column
|
||||
self.xyzlcol.line, self.xyzlcol.column
|
||||
)?;
|
||||
write!(f, "\n\tindent_column: {}", self.indent_column)?;
|
||||
write!(f, "\n}}")
|
||||
|
|
|
@ -17,7 +17,7 @@ fn ascii_hex_digits<'a>() -> impl Parser<'a, &'a str, EString<'a>> {
|
|||
buf.push(byte as char);
|
||||
} else if buf.is_empty() {
|
||||
// We didn't find any hex digits!
|
||||
return Err((NoProgress, EString::CodePtEnd(state.pos), state));
|
||||
return Err((NoProgress, EString::CodePtEnd(state.xyzlcol), state));
|
||||
} else {
|
||||
let state = state.advance_without_indenting_ee(buf.len(), |pos| {
|
||||
EString::Space(BadInputError::LineTooLong, pos)
|
||||
|
@ -27,7 +27,7 @@ fn ascii_hex_digits<'a>() -> impl Parser<'a, &'a str, EString<'a>> {
|
|||
}
|
||||
}
|
||||
|
||||
Err((NoProgress, EString::CodePtEnd(state.pos), state))
|
||||
Err((NoProgress, EString::CodePtEnd(state.xyzlcol), state))
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -56,7 +56,7 @@ pub fn parse<'a>() -> impl Parser<'a, StrLiteral<'a>, EString<'a>> {
|
|||
bytes = state.bytes()[1..].iter();
|
||||
state = advance_state!(state, 1)?;
|
||||
} else {
|
||||
return Err((NoProgress, EString::Open(state.pos), state));
|
||||
return Err((NoProgress, EString::Open(state.xyzlcol), state));
|
||||
}
|
||||
|
||||
// At the parsing stage we keep the entire raw string, because the formatter
|
||||
|
@ -100,7 +100,7 @@ pub fn parse<'a>() -> impl Parser<'a, StrLiteral<'a>, EString<'a>> {
|
|||
Err(_) => {
|
||||
return Err((
|
||||
MadeProgress,
|
||||
EString::Space(BadInputError::BadUtf8, state.pos),
|
||||
EString::Space(BadInputError::BadUtf8, state.xyzlcol),
|
||||
state,
|
||||
));
|
||||
}
|
||||
|
@ -192,7 +192,7 @@ pub fn parse<'a>() -> impl Parser<'a, StrLiteral<'a>, EString<'a>> {
|
|||
// all remaining chars. This will mask all other errors, but
|
||||
// it should make it easiest to debug; the file will be a giant
|
||||
// error starting from where the open quote appeared.
|
||||
return Err((MadeProgress, EString::EndlessSingle(state.pos), state));
|
||||
return Err((MadeProgress, EString::EndlessSingle(state.xyzlcol), state));
|
||||
}
|
||||
}
|
||||
b'\\' => {
|
||||
|
@ -281,7 +281,7 @@ pub fn parse<'a>() -> impl Parser<'a, StrLiteral<'a>, EString<'a>> {
|
|||
// Invalid escape! A backslash must be followed
|
||||
// by either an open paren or else one of the
|
||||
// escapable characters (\n, \t, \", \\, etc)
|
||||
return Err((MadeProgress, EString::UnknownEscape(state.pos), state));
|
||||
return Err((MadeProgress, EString::UnknownEscape(state.xyzlcol), state));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -295,9 +295,9 @@ pub fn parse<'a>() -> impl Parser<'a, StrLiteral<'a>, EString<'a>> {
|
|||
Err((
|
||||
MadeProgress,
|
||||
if is_multiline {
|
||||
EString::EndlessMulti(state.pos)
|
||||
EString::EndlessMulti(state.xyzlcol)
|
||||
} else {
|
||||
EString::EndlessSingle(state.pos)
|
||||
EString::EndlessSingle(state.xyzlcol)
|
||||
},
|
||||
state,
|
||||
))
|
||||
|
|
|
@ -101,7 +101,7 @@ fn parse_type_alias_after_as<'a>(min_indent: u16) -> impl Parser<'a, AliasHeader
|
|||
}
|
||||
|
||||
fn fail_type_start<'a, T: 'a>() -> impl Parser<'a, T, EType<'a>> {
|
||||
|_arena, state: State<'a>| Err((NoProgress, EType::TStart(state.pos), state))
|
||||
|_arena, state: State<'a>| Err((NoProgress, EType::TStart(state.xyzlcol), state))
|
||||
}
|
||||
|
||||
fn term<'a>(min_indent: u16) -> impl Parser<'a, Loc<TypeAnnotation<'a>>, EType<'a>> {
|
||||
|
@ -240,7 +240,7 @@ where
|
|||
{
|
||||
move |arena, state: State<'a>| match crate::ident::tag_name().parse(arena, state) {
|
||||
Ok(good) => Ok(good),
|
||||
Err((progress, _, state)) => Err((progress, to_problem(state.pos), state)),
|
||||
Err((progress, _, state)) => Err((progress, to_problem(state.xyzlcol), state)),
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -254,7 +254,7 @@ fn record_type_field<'a>(
|
|||
(move |arena, state: State<'a>| {
|
||||
// You must have a field name, e.g. "email"
|
||||
// using the initial pos is important for error reporting
|
||||
let pos = state.pos;
|
||||
let pos = state.xyzlcol;
|
||||
let (progress, loc_label, state) = loc!(specialize(
|
||||
move |_, _| ETypeRecord::Field(pos),
|
||||
lowercase_ident()
|
||||
|
@ -410,7 +410,7 @@ fn expression<'a>(
|
|||
),
|
||||
|_, state: State<'a>| Err((
|
||||
NoProgress,
|
||||
EType::TFunctionArgument(state.pos),
|
||||
EType::TFunctionArgument(state.xyzlcol),
|
||||
state
|
||||
))
|
||||
]
|
||||
|
@ -503,7 +503,7 @@ fn parse_concrete_type<'a>(
|
|||
|
||||
Ok((MadeProgress, answer, state))
|
||||
}
|
||||
Err((NoProgress, _, state)) => Err((NoProgress, ETypeApply::End(state.pos), state)),
|
||||
Err((NoProgress, _, state)) => Err((NoProgress, ETypeApply::End(state.xyzlcol), state)),
|
||||
Err((MadeProgress, _, mut state)) => {
|
||||
// we made some progress, but ultimately failed.
|
||||
// that means a malformed type name
|
||||
|
@ -531,6 +531,6 @@ fn parse_type_variable<'a>(
|
|||
|
||||
Ok((MadeProgress, answer, state))
|
||||
}
|
||||
Err((progress, _, state)) => Err((progress, EType::TBadTypeVariable(state.pos), state)),
|
||||
Err((progress, _, state)) => Err((progress, EType::TBadTypeVariable(state.xyzlcol), state)),
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue