mirror of
https://github.com/roc-lang/roc.git
synced 2025-09-30 15:21:12 +00:00
fix top level def
This commit is contained in:
parent
851f472167
commit
e83cb0d027
6 changed files with 31 additions and 28 deletions
|
@ -280,7 +280,7 @@ pub fn spaces_exactly<'a>(spaces_expected: u16) -> impl Parser<'a, ()> {
|
||||||
|
|
||||||
Err(FailReason::BadUtf8) => {
|
Err(FailReason::BadUtf8) => {
|
||||||
// If we hit an invalid UTF-8 character, bail out immediately.
|
// If we hit an invalid UTF-8 character, bail out immediately.
|
||||||
let progress = Progress::from_bool(spaces_seen != 0);
|
let progress = Progress::progress_when(spaces_seen != 0);
|
||||||
return state.fail(progress, FailReason::BadUtf8);
|
return state.fail(progress, FailReason::BadUtf8);
|
||||||
}
|
}
|
||||||
Err(_) => {
|
Err(_) => {
|
||||||
|
|
|
@ -121,7 +121,7 @@ pub fn parse_ident<'a>(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Err(reason) => {
|
Err(reason) => {
|
||||||
let progress = Progress::from_bool(state.bytes.len() == start_bytes_len);
|
let progress = Progress::from_lengths(start_bytes_len, state.bytes.len());
|
||||||
return state.fail(progress, reason);
|
return state.fail(progress, reason);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -130,7 +130,7 @@ pub fn parse_ident<'a>(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Err(reason) => {
|
Err(reason) => {
|
||||||
let progress = Progress::from_bool(state.bytes.len() == start_bytes_len);
|
let progress = Progress::from_lengths(start_bytes_len, state.bytes.len());
|
||||||
return state.fail(progress, reason);
|
return state.fail(progress, reason);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -195,7 +195,7 @@ pub fn parse_ident<'a>(
|
||||||
state = state.advance_without_indenting(bytes_parsed)?;
|
state = state.advance_without_indenting(bytes_parsed)?;
|
||||||
}
|
}
|
||||||
Err(reason) => {
|
Err(reason) => {
|
||||||
let progress = Progress::from_bool(state.bytes.len() == start_bytes_len);
|
let progress = Progress::from_lengths(start_bytes_len, state.bytes.len());
|
||||||
return state.fail(progress, reason);
|
return state.fail(progress, reason);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -267,7 +267,7 @@ pub fn parse_ident<'a>(
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
let progress = Progress::from_bool(state.bytes.len() != start_bytes_len);
|
let progress = Progress::from_lengths(start_bytes_len, state.bytes.len());
|
||||||
debug_assert_eq!(progress, Progress::MadeProgress,);
|
debug_assert_eq!(progress, Progress::MadeProgress,);
|
||||||
Ok((Progress::MadeProgress, (answer, None), state))
|
Ok((Progress::MadeProgress, (answer, None), state))
|
||||||
}
|
}
|
||||||
|
|
|
@ -99,12 +99,12 @@ pub fn parse_package_part<'a>(arena: &'a Bump, mut state: State<'a>) -> ParseRes
|
||||||
|
|
||||||
state = state.advance_without_indenting(bytes_parsed)?;
|
state = state.advance_without_indenting(bytes_parsed)?;
|
||||||
} else {
|
} else {
|
||||||
let progress = Progress::from_bool(!part_buf.is_empty());
|
let progress = Progress::progress_when(!part_buf.is_empty());
|
||||||
return Ok((progress, part_buf.into_bump_str(), state));
|
return Ok((progress, part_buf.into_bump_str(), state));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Err(reason) => {
|
Err(reason) => {
|
||||||
let progress = Progress::from_bool(!part_buf.is_empty());
|
let progress = Progress::progress_when(!part_buf.is_empty());
|
||||||
return state.fail(progress, reason);
|
return state.fail(progress, reason);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -299,7 +299,7 @@ pub fn platform_header<'a>() -> impl Parser<'a, PlatformHeader<'a>> {
|
||||||
pub fn module_defs<'a>() -> impl Parser<'a, Vec<'a, Located<Def<'a>>>> {
|
pub fn module_defs<'a>() -> impl Parser<'a, Vec<'a, Located<Def<'a>>>> {
|
||||||
move |a: &'a Bump, s: State<'a>| {
|
move |a: &'a Bump, s: State<'a>| {
|
||||||
// this parses just the defs
|
// this parses just the defs
|
||||||
let defs = zero_or_more!(space0_around(loc(def(0)), 0));
|
let defs = zero_or_more!(space0_around(loc(debug!(def(0))), 0));
|
||||||
|
|
||||||
// let result = skip_second!(defs, end_of_file()).parse(a, s);
|
// let result = skip_second!(defs, end_of_file()).parse(a, s);
|
||||||
let result = defs.parse(a, s);
|
let result = defs.parse(a, s);
|
||||||
|
|
|
@ -239,10 +239,10 @@ impl Progress {
|
||||||
Self::from_consumed(before - after)
|
Self::from_consumed(before - after)
|
||||||
}
|
}
|
||||||
pub fn from_consumed(chars_consumed: usize) -> Self {
|
pub fn from_consumed(chars_consumed: usize) -> Self {
|
||||||
Self::from_bool(chars_consumed != 0)
|
Self::progress_when(chars_consumed != 0)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn from_bool(made_progress: bool) -> Self {
|
pub fn progress_when(made_progress: bool) -> Self {
|
||||||
if made_progress {
|
if made_progress {
|
||||||
Progress::MadeProgress
|
Progress::MadeProgress
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -53,12 +53,12 @@ pub fn term<'a>(min_indent: u16) -> impl Parser<'a, Located<TypeAnnotation<'a>>>
|
||||||
map_with_arena!(
|
map_with_arena!(
|
||||||
and!(
|
and!(
|
||||||
one_of!(
|
one_of!(
|
||||||
// loc_wildcard(),
|
loc_wildcard(),
|
||||||
// loc_parenthetical_type(min_indent),
|
loc_parenthetical_type(min_indent),
|
||||||
// loc!(record_type(min_indent)),
|
loc!(record_type(min_indent)),
|
||||||
// loc!(tag_union!(min_indent)),
|
loc!(tag_union!(min_indent)),
|
||||||
|a, s| dbg!(loc!(applied_type(min_indent)).parse(a, s)),
|
loc!(applied_type(min_indent)),
|
||||||
|a, s| dbg!(loc!(parse_type_variable).parse(a, s))
|
loc!(parse_type_variable)
|
||||||
),
|
),
|
||||||
|a, s| {
|
|a, s| {
|
||||||
dbg!("term state", &s);
|
dbg!("term state", &s);
|
||||||
|
@ -220,6 +220,7 @@ fn applied_type<'a>(min_indent: u16) -> impl Parser<'a, TypeAnnotation<'a>> {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn expression<'a>(min_indent: u16) -> impl Parser<'a, Located<TypeAnnotation<'a>>> {
|
fn expression<'a>(min_indent: u16) -> impl Parser<'a, Located<TypeAnnotation<'a>>> {
|
||||||
|
dbg!("parsing type ig");
|
||||||
use crate::blankspace::space0;
|
use crate::blankspace::space0;
|
||||||
move |arena, state: State<'a>| {
|
move |arena, state: State<'a>| {
|
||||||
let (p1, first, state) = space0_before(term(min_indent), min_indent).parse(arena, state)?;
|
let (p1, first, state) = space0_before(term(min_indent), min_indent).parse(arena, state)?;
|
||||||
|
@ -293,7 +294,7 @@ fn parse_concrete_type<'a>(
|
||||||
let mut part_buf = String::new_in(arena); // The current "part" (parts are dot-separated.)
|
let mut part_buf = String::new_in(arena); // The current "part" (parts are dot-separated.)
|
||||||
let mut parts: Vec<&'a str> = Vec::new_in(arena);
|
let mut parts: Vec<&'a str> = Vec::new_in(arena);
|
||||||
|
|
||||||
let start_bytes_remaining = state.bytes.len();
|
let start_bytes_len = state.bytes.len();
|
||||||
|
|
||||||
// Qualified types must start with a capitalized letter.
|
// Qualified types must start with a capitalized letter.
|
||||||
match peek_utf8_char(&state) {
|
match peek_utf8_char(&state) {
|
||||||
|
@ -353,9 +354,9 @@ fn parse_concrete_type<'a>(
|
||||||
state = state.advance_without_indenting(bytes_parsed)?;
|
state = state.advance_without_indenting(bytes_parsed)?;
|
||||||
}
|
}
|
||||||
Err(reason) => {
|
Err(reason) => {
|
||||||
let made_progress = state.bytes.len() != start_bytes_remaining;
|
let progress = Progress::from_lengths(start_bytes_len, state.bytes.len());
|
||||||
|
|
||||||
return state.fail(Progress::from_bool(made_progress), reason);
|
return state.fail(progress, reason);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -383,8 +384,8 @@ fn parse_concrete_type<'a>(
|
||||||
&[],
|
&[],
|
||||||
);
|
);
|
||||||
|
|
||||||
let made_progress = state.bytes.len() != start_bytes_remaining;
|
let progress = Progress::from_lengths(start_bytes_len, state.bytes.len());
|
||||||
Ok((Progress::from_bool(made_progress), answer, state))
|
Ok((progress, answer, state))
|
||||||
}
|
}
|
||||||
|
|
||||||
fn parse_type_variable<'a>(
|
fn parse_type_variable<'a>(
|
||||||
|
@ -393,7 +394,7 @@ fn parse_type_variable<'a>(
|
||||||
) -> ParseResult<'a, TypeAnnotation<'a>> {
|
) -> ParseResult<'a, TypeAnnotation<'a>> {
|
||||||
let mut buf = String::new_in(arena);
|
let mut buf = String::new_in(arena);
|
||||||
|
|
||||||
let start_bytes_remaining = state.bytes.len();
|
let start_bytes_len = state.bytes.len();
|
||||||
|
|
||||||
match peek_utf8_char(&state) {
|
match peek_utf8_char(&state) {
|
||||||
Ok((first_letter, bytes_parsed)) => {
|
Ok((first_letter, bytes_parsed)) => {
|
||||||
|
@ -407,8 +408,8 @@ fn parse_type_variable<'a>(
|
||||||
state = state.advance_without_indenting(bytes_parsed)?;
|
state = state.advance_without_indenting(bytes_parsed)?;
|
||||||
}
|
}
|
||||||
Err(reason) => {
|
Err(reason) => {
|
||||||
let made_progress = state.bytes.len() != start_bytes_remaining;
|
let progress = Progress::from_lengths(start_bytes_len, state.bytes.len());
|
||||||
return state.fail(Progress::from_bool(made_progress), reason);
|
return state.fail(progress, reason);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -429,16 +430,16 @@ fn parse_type_variable<'a>(
|
||||||
state = state.advance_without_indenting(bytes_parsed)?;
|
state = state.advance_without_indenting(bytes_parsed)?;
|
||||||
}
|
}
|
||||||
Err(reason) => {
|
Err(reason) => {
|
||||||
let made_progress = state.bytes.len() != start_bytes_remaining;
|
let progress = Progress::from_lengths(start_bytes_len, state.bytes.len());
|
||||||
return state.fail(Progress::from_bool(made_progress), reason);
|
return state.fail(progress, reason);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
let answer = TypeAnnotation::BoundVariable(buf.into_bump_str());
|
let answer = TypeAnnotation::BoundVariable(buf.into_bump_str());
|
||||||
|
|
||||||
let made_progress = state.bytes.len() != start_bytes_remaining;
|
let progress = Progress::from_lengths(start_bytes_len, state.bytes.len());
|
||||||
Ok((Progress::from_bool(made_progress), answer, state))
|
Ok((progress, answer, state))
|
||||||
}
|
}
|
||||||
|
|
||||||
fn malformed<'a>(
|
fn malformed<'a>(
|
||||||
|
|
|
@ -2762,6 +2762,7 @@ mod test_parse {
|
||||||
Located::new(2, 2, 0, 10, def2),
|
Located::new(2, 2, 0, 10, def2),
|
||||||
Located::new(3, 3, 0, 13, def3),
|
Located::new(3, 3, 0, 13, def3),
|
||||||
];
|
];
|
||||||
|
|
||||||
let src = indoc!(
|
let src = indoc!(
|
||||||
r#"
|
r#"
|
||||||
foo = 1
|
foo = 1
|
||||||
|
@ -2770,6 +2771,7 @@ mod test_parse {
|
||||||
baz = "stuff"
|
baz = "stuff"
|
||||||
"#
|
"#
|
||||||
);
|
);
|
||||||
|
|
||||||
let actual = module_defs()
|
let actual = module_defs()
|
||||||
.parse(&arena, State::new(src.as_bytes(), Attempting::Module))
|
.parse(&arena, State::new(src.as_bytes(), Attempting::Module))
|
||||||
.map(|tuple| tuple.1);
|
.map(|tuple| tuple.1);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue