mirror of
https://github.com/roc-lang/roc.git
synced 2025-10-03 08:34:33 +00:00
checkpoint 2
This commit is contained in:
parent
ba820a3179
commit
449f205781
1 changed files with 45 additions and 22 deletions
|
@ -1,13 +1,13 @@
|
||||||
use crate::ast::{AssignedField, CommentOrNewline, Tag, TypeAnnotation};
|
use crate::ast::{AssignedField, CommentOrNewline, Tag, TypeAnnotation};
|
||||||
use crate::blankspace::{
|
use crate::blankspace::{
|
||||||
space0_around, space0_around_e, space0_before, space0_before_e, space1, space1_before,
|
space0, space0_around, space0_around_e, space0_before, space0_before_e, space1, space1_before,
|
||||||
};
|
};
|
||||||
use crate::expr::{global_tag, private_tag};
|
use crate::expr::{global_tag, private_tag};
|
||||||
use crate::ident::join_module_parts;
|
use crate::ident::join_module_parts;
|
||||||
use crate::keyword;
|
use crate::keyword;
|
||||||
use crate::parser::{
|
use crate::parser::{
|
||||||
allocated, ascii_char, ascii_string, not, not_e, optional, peek_utf8_char_e, specialize,
|
allocated, ascii_char, ascii_string, backtrackable, not, not_e, optional, peek_utf8_char_e,
|
||||||
specialize_ref, word1, BadInputError, Either, ParseResult, Parser,
|
specialize, specialize_ref, word1, BadInputError, Either, ParseResult, Parser,
|
||||||
Progress::{self, *},
|
Progress::{self, *},
|
||||||
State, SyntaxError, TApply, TInParens, TRecord, TTagUnion, TVariable, Type,
|
State, SyntaxError, TApply, TInParens, TRecord, TTagUnion, TVariable, Type,
|
||||||
};
|
};
|
||||||
|
@ -164,24 +164,44 @@ fn loc_wildcard_e<'a>() -> impl Parser<'a, Located<TypeAnnotation<'a>>, Type<'a>
|
||||||
fn loc_applied_arg<'a>(
|
fn loc_applied_arg<'a>(
|
||||||
min_indent: u16,
|
min_indent: u16,
|
||||||
) -> impl Parser<'a, Located<TypeAnnotation<'a>>, SyntaxError<'a>> {
|
) -> impl Parser<'a, Located<TypeAnnotation<'a>>, SyntaxError<'a>> {
|
||||||
skip_first!(
|
use crate::ast::Spaceable;
|
||||||
// Once we hit an "as", stop parsing args
|
|
||||||
// and roll back parsing of preceding spaces
|
map_with_arena!(
|
||||||
not(and!(
|
and!(
|
||||||
space1(min_indent),
|
backtrackable(space0(min_indent)),
|
||||||
crate::parser::keyword(keyword::AS, min_indent)
|
skip_first!(
|
||||||
)),
|
// Once we hit an "as", stop parsing args
|
||||||
space1_before(
|
// and roll back parsing of preceding spaces
|
||||||
one_of!(
|
not(crate::parser::keyword(keyword::AS, min_indent)),
|
||||||
loc_wildcard(),
|
one_of!(
|
||||||
loc_type_in_parens(min_indent),
|
specialize(|x, _row, _col| SyntaxError::Type(x), loc_wildcard_e()),
|
||||||
loc!(record_type(min_indent)),
|
specialize(
|
||||||
loc!(tag_union_type(min_indent)),
|
|x, row, col| SyntaxError::Type(Type::TInParens(x, row, col)),
|
||||||
loc!(parse_concrete_type),
|
loc_type_in_parens_help(min_indent)
|
||||||
loc!(parse_type_variable)
|
),
|
||||||
),
|
specialize(
|
||||||
min_indent
|
|x, row, col| SyntaxError::Type(Type::TRecord(x, row, col)),
|
||||||
)
|
loc!(record_type_internal(min_indent))
|
||||||
|
),
|
||||||
|
specialize(
|
||||||
|
|x, row, col| SyntaxError::Type(Type::TTagUnion(x, row, col)),
|
||||||
|
loc!(tag_union_type_internal(min_indent))
|
||||||
|
),
|
||||||
|
specialize(
|
||||||
|
|x, row, col| SyntaxError::Type(Type::TApply(x, row, col)),
|
||||||
|
loc!(parse_concrete_type_help),
|
||||||
|
),
|
||||||
|
specialize(
|
||||||
|
|x, row, col| SyntaxError::Type(Type::TVariable(x, row, col)),
|
||||||
|
loc!(parse_type_variable_help)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
),
|
||||||
|
|arena: &'a Bump, (spaces, argument): (_, Located<TypeAnnotation<'a>>)| {
|
||||||
|
let Located { region, value } = argument;
|
||||||
|
arena.alloc(value).with_spaces_before(spaces, region)
|
||||||
|
}
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -361,7 +381,10 @@ fn record_type_internal<'a>(min_indent: u16) -> impl Parser<'a, TypeAnnotation<'
|
||||||
fn applied_type<'a>(min_indent: u16) -> impl Parser<'a, TypeAnnotation<'a>, SyntaxError<'a>> {
|
fn applied_type<'a>(min_indent: u16) -> impl Parser<'a, TypeAnnotation<'a>, SyntaxError<'a>> {
|
||||||
map!(
|
map!(
|
||||||
and!(
|
and!(
|
||||||
parse_concrete_type,
|
specialize(
|
||||||
|
|x, row, col| SyntaxError::Type(Type::TApply(x, row, col)),
|
||||||
|
parse_concrete_type_help,
|
||||||
|
),
|
||||||
// Optionally parse space-separated arguments for the constructor,
|
// Optionally parse space-separated arguments for the constructor,
|
||||||
// e.g. `Str Float` in `Map Str Float`
|
// e.g. `Str Float` in `Map Str Float`
|
||||||
loc_applied_args(min_indent)
|
loc_applied_args(min_indent)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue