mirror of
https://github.com/roc-lang/roc.git
synced 2025-09-29 06:44:46 +00:00
Remove bytes tracking
This commit is contained in:
parent
beb0629e05
commit
08a33aab1b
1 changed files with 14 additions and 33 deletions
|
@ -193,11 +193,10 @@ where
|
||||||
|
|
||||||
move |arena, mut state: State<'a>| {
|
move |arena, mut state: State<'a>| {
|
||||||
let comments_and_newlines = Vec::new_in(arena);
|
let comments_and_newlines = Vec::new_in(arena);
|
||||||
let col =state.xyzlcol;
|
let col = state.xyzlcol;
|
||||||
match eat_spaces(state.bytes(), state.clone(), false, col, state.pos(), comments_and_newlines) {
|
match eat_spaces(state.clone(), false, col, state.pos(), comments_and_newlines) {
|
||||||
HasTab(xyzlcol, pos, new_state) => {
|
HasTab(xyzlcol, pos, mut state) => {
|
||||||
// there was a tab character
|
// there was a tab character
|
||||||
let mut state = state;
|
|
||||||
state.xyzlcol = xyzlcol;
|
state.xyzlcol = xyzlcol;
|
||||||
// TODO: it _seems_ like if we're changing the line/column, we should also be
|
// TODO: it _seems_ like if we're changing the line/column, we should also be
|
||||||
// advancing the state by the corresponding number of bytes.
|
// advancing the state by the corresponding number of bytes.
|
||||||
|
@ -213,14 +212,9 @@ where
|
||||||
xyzcol: pos,
|
xyzcol: pos,
|
||||||
state: new_state,
|
state: new_state,
|
||||||
multiline,
|
multiline,
|
||||||
bytes,
|
|
||||||
comments_and_newlines,
|
comments_and_newlines,
|
||||||
} => {
|
} => {
|
||||||
assert_eq!(
|
if new_state.bytes() == state.bytes() {
|
||||||
std::str::from_utf8(new_state.bytes()).unwrap(),
|
|
||||||
std::str::from_utf8(bytes).unwrap());
|
|
||||||
|
|
||||||
if bytes == state.bytes() {
|
|
||||||
Ok((NoProgress, &[] as &[_], state))
|
Ok((NoProgress, &[] as &[_], state))
|
||||||
} else if multiline {
|
} else if multiline {
|
||||||
// we parsed at least one newline
|
// we parsed at least one newline
|
||||||
|
@ -229,7 +223,7 @@ where
|
||||||
|
|
||||||
if pos.column >= min_indent {
|
if pos.column >= min_indent {
|
||||||
state.xyzlcol = pos;
|
state.xyzlcol = pos;
|
||||||
state = state.advance(state.bytes().len() - bytes.len());
|
state = state.advance(state.bytes().len() - new_state.bytes().len());
|
||||||
|
|
||||||
Ok((MadeProgress, comments_and_newlines.into_bump_slice(), state))
|
Ok((MadeProgress, comments_and_newlines.into_bump_slice(), state))
|
||||||
} else {
|
} else {
|
||||||
|
@ -237,7 +231,7 @@ where
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
state.xyzlcol.column = pos.column;
|
state.xyzlcol.column = pos.column;
|
||||||
state = state.advance(state.bytes().len() - bytes.len());
|
state = state.advance(state.bytes().len() - new_state.bytes().len());
|
||||||
|
|
||||||
Ok((MadeProgress, comments_and_newlines.into_bump_slice(), state))
|
Ok((MadeProgress, comments_and_newlines.into_bump_slice(), state))
|
||||||
}
|
}
|
||||||
|
@ -251,14 +245,12 @@ enum SpaceState<'a> {
|
||||||
xyzcol: JustColumn,
|
xyzcol: JustColumn,
|
||||||
state: State<'a>,
|
state: State<'a>,
|
||||||
multiline: bool,
|
multiline: bool,
|
||||||
bytes: &'a [u8],
|
|
||||||
comments_and_newlines: Vec<'a, CommentOrNewline<'a>>,
|
comments_and_newlines: Vec<'a, CommentOrNewline<'a>>,
|
||||||
},
|
},
|
||||||
HasTab(JustColumn, Position, State<'a>),
|
HasTab(JustColumn, Position, State<'a>),
|
||||||
}
|
}
|
||||||
|
|
||||||
fn eat_spaces<'a>(
|
fn eat_spaces<'a>(
|
||||||
mut bytes: &'a [u8],
|
|
||||||
mut state: State<'a>,
|
mut state: State<'a>,
|
||||||
mut multiline: bool,
|
mut multiline: bool,
|
||||||
mut xyzlcol: JustColumn,
|
mut xyzlcol: JustColumn,
|
||||||
|
@ -267,16 +259,14 @@ fn eat_spaces<'a>(
|
||||||
) -> SpaceState<'a> {
|
) -> SpaceState<'a> {
|
||||||
use SpaceState::*;
|
use SpaceState::*;
|
||||||
|
|
||||||
for c in bytes {
|
for c in state.bytes() {
|
||||||
match c {
|
match c {
|
||||||
b' ' => {
|
b' ' => {
|
||||||
pos = pos.bump_column(1);
|
pos = pos.bump_column(1);
|
||||||
bytes = &bytes[1..];
|
|
||||||
state = state.advance(1);
|
state = state.advance(1);
|
||||||
xyzlcol.column += 1;
|
xyzlcol.column += 1;
|
||||||
}
|
}
|
||||||
b'\n' => {
|
b'\n' => {
|
||||||
bytes = &bytes[1..];
|
|
||||||
pos = pos.bump_newline();
|
pos = pos.bump_newline();
|
||||||
state = state.advance(1);
|
state = state.advance(1);
|
||||||
multiline = true;
|
multiline = true;
|
||||||
|
@ -284,7 +274,6 @@ fn eat_spaces<'a>(
|
||||||
comments_and_newlines.push(CommentOrNewline::Newline);
|
comments_and_newlines.push(CommentOrNewline::Newline);
|
||||||
}
|
}
|
||||||
b'\r' => {
|
b'\r' => {
|
||||||
bytes = &bytes[1..];
|
|
||||||
state = state.advance(1);
|
state = state.advance(1);
|
||||||
pos = pos.bump_invisible(1);
|
pos = pos.bump_invisible(1);
|
||||||
}
|
}
|
||||||
|
@ -295,7 +284,7 @@ fn eat_spaces<'a>(
|
||||||
xyzlcol.column += 1;
|
xyzlcol.column += 1;
|
||||||
state = state.advance(1);
|
state = state.advance(1);
|
||||||
pos = pos.bump_column(1);
|
pos = pos.bump_column(1);
|
||||||
return eat_line_comment(&bytes[1..], state, multiline, xyzlcol, pos, comments_and_newlines);
|
return eat_line_comment(state, multiline, xyzlcol, pos, comments_and_newlines);
|
||||||
}
|
}
|
||||||
_ => break,
|
_ => break,
|
||||||
}
|
}
|
||||||
|
@ -305,13 +294,11 @@ fn eat_spaces<'a>(
|
||||||
xyzcol: xyzlcol,
|
xyzcol: xyzlcol,
|
||||||
state,
|
state,
|
||||||
multiline,
|
multiline,
|
||||||
bytes,
|
|
||||||
comments_and_newlines,
|
comments_and_newlines,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn eat_line_comment<'a>(
|
fn eat_line_comment<'a>(
|
||||||
mut bytes: &'a [u8],
|
|
||||||
mut state: State<'a>,
|
mut state: State<'a>,
|
||||||
mut multiline: bool,
|
mut multiline: bool,
|
||||||
mut xyzlcol: JustColumn,
|
mut xyzlcol: JustColumn,
|
||||||
|
@ -320,10 +307,9 @@ fn eat_line_comment<'a>(
|
||||||
) -> SpaceState<'a> {
|
) -> SpaceState<'a> {
|
||||||
use SpaceState::*;
|
use SpaceState::*;
|
||||||
|
|
||||||
let is_doc_comment = if let Some(b'#') = bytes.get(0) {
|
let is_doc_comment = if let Some(b'#') = state.bytes().get(0) {
|
||||||
match bytes.get(1) {
|
match state.bytes().get(1) {
|
||||||
Some(b' ') => {
|
Some(b' ') => {
|
||||||
bytes = &bytes[2..];
|
|
||||||
xyzlcol.column += 2;
|
xyzlcol.column += 2;
|
||||||
pos = pos.bump_column(2);
|
pos = pos.bump_column(2);
|
||||||
state = state.advance(2);
|
state = state.advance(2);
|
||||||
|
@ -332,7 +318,6 @@ fn eat_line_comment<'a>(
|
||||||
}
|
}
|
||||||
Some(b'\n') => {
|
Some(b'\n') => {
|
||||||
// consume the second # and the \n
|
// consume the second # and the \n
|
||||||
bytes = &bytes[2..];
|
|
||||||
pos = pos.bump_column(1);
|
pos = pos.bump_column(1);
|
||||||
pos = pos.bump_newline();
|
pos = pos.bump_newline();
|
||||||
state = state.advance(2);
|
state = state.advance(2);
|
||||||
|
@ -340,12 +325,11 @@ fn eat_line_comment<'a>(
|
||||||
comments_and_newlines.push(CommentOrNewline::DocComment(""));
|
comments_and_newlines.push(CommentOrNewline::DocComment(""));
|
||||||
multiline = true;
|
multiline = true;
|
||||||
xyzlcol.column = 0;
|
xyzlcol.column = 0;
|
||||||
return eat_spaces(bytes, state, multiline, xyzlcol, pos, comments_and_newlines);
|
return eat_spaces(state, multiline, xyzlcol, pos, comments_and_newlines);
|
||||||
}
|
}
|
||||||
None => {
|
None => {
|
||||||
// consume the second #
|
// consume the second #
|
||||||
xyzlcol.column += 1;
|
xyzlcol.column += 1;
|
||||||
bytes = &bytes[1..];
|
|
||||||
state = state.advance(1);
|
state = state.advance(1);
|
||||||
// pos = pos.bump_column(1);
|
// pos = pos.bump_column(1);
|
||||||
|
|
||||||
|
@ -353,7 +337,6 @@ fn eat_line_comment<'a>(
|
||||||
xyzcol: xyzlcol,
|
xyzcol: xyzlcol,
|
||||||
state,
|
state,
|
||||||
multiline,
|
multiline,
|
||||||
bytes,
|
|
||||||
comments_and_newlines,
|
comments_and_newlines,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
@ -364,10 +347,10 @@ fn eat_line_comment<'a>(
|
||||||
false
|
false
|
||||||
};
|
};
|
||||||
|
|
||||||
let initial = bytes;
|
let initial = state.bytes();
|
||||||
let initial_column = xyzlcol.column;
|
let initial_column = xyzlcol.column;
|
||||||
|
|
||||||
for c in bytes {
|
for c in state.bytes() {
|
||||||
match c {
|
match c {
|
||||||
b'\t' => return HasTab(xyzlcol, pos, state),
|
b'\t' => return HasTab(xyzlcol, pos, state),
|
||||||
b'\n' => {
|
b'\n' => {
|
||||||
|
@ -383,10 +366,9 @@ fn eat_line_comment<'a>(
|
||||||
state = state.advance(1);
|
state = state.advance(1);
|
||||||
multiline = true;
|
multiline = true;
|
||||||
xyzlcol.column = 0;
|
xyzlcol.column = 0;
|
||||||
return eat_spaces(&bytes[1..], state, multiline, xyzlcol, pos, comments_and_newlines);
|
return eat_spaces(state, multiline, xyzlcol, pos, comments_and_newlines);
|
||||||
}
|
}
|
||||||
_ => {
|
_ => {
|
||||||
bytes = &bytes[1..];
|
|
||||||
state = state.advance(1);
|
state = state.advance(1);
|
||||||
pos = pos.bump_column(1);
|
pos = pos.bump_column(1);
|
||||||
xyzlcol.column += 1;
|
xyzlcol.column += 1;
|
||||||
|
@ -408,7 +390,6 @@ fn eat_line_comment<'a>(
|
||||||
xyzcol: xyzlcol,
|
xyzcol: xyzlcol,
|
||||||
state,
|
state,
|
||||||
multiline,
|
multiline,
|
||||||
bytes,
|
|
||||||
comments_and_newlines,
|
comments_and_newlines,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue