mirror of
https://github.com/roc-lang/roc.git
synced 2025-09-29 23:04:49 +00:00
Rename Located -> Loc
This commit is contained in:
parent
c66c845cd2
commit
f19220473a
55 changed files with 680 additions and 683 deletions
|
@ -5,7 +5,7 @@ use crate::ident::Ident;
|
|||
use bumpalo::collections::{String, Vec};
|
||||
use bumpalo::Bump;
|
||||
use roc_module::called_via::{BinOp, CalledVia, UnaryOp};
|
||||
use roc_region::all::{Loc, Located, Position, Region};
|
||||
use roc_region::all::{Loc, Position, Region};
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct Spaces<'a, T> {
|
||||
|
@ -53,7 +53,7 @@ impl<'a, T: ExtractSpaces<'a>> ExtractSpaces<'a> for &'a T {
|
|||
}
|
||||
}
|
||||
|
||||
impl<'a, T: ExtractSpaces<'a>> ExtractSpaces<'a> for Located<T> {
|
||||
impl<'a, T: ExtractSpaces<'a>> ExtractSpaces<'a> for Loc<T> {
|
||||
type Item = T::Item;
|
||||
fn extract_spaces(&self) -> Spaces<'a, Self::Item> {
|
||||
let spaces = self.value.extract_spaces();
|
||||
|
@ -390,7 +390,7 @@ pub enum Pattern<'a> {
|
|||
PrivateTag(&'a str),
|
||||
Apply(&'a Loc<Pattern<'a>>, &'a [Loc<Pattern<'a>>]),
|
||||
|
||||
/// This is Loc<Pattern> rather than Loc<str> so we can record comments
|
||||
/// This is Located<Pattern> rather than Located<str> so we can record comments
|
||||
/// around the destructured names, e.g. { x ### x does stuff ###, y }
|
||||
/// In practice, these patterns will always be Identifier
|
||||
RecordDestructure(Collection<'a, Loc<Pattern<'a>>>),
|
||||
|
|
|
@ -4,7 +4,7 @@ use crate::parser::{self, and, backtrackable, BadInputError, Col, Parser, Progre
|
|||
use crate::state::State;
|
||||
use bumpalo::collections::vec::Vec;
|
||||
use bumpalo::Bump;
|
||||
use roc_region::all::Located;
|
||||
use roc_region::all::Loc;
|
||||
|
||||
pub fn space0_around_ee<'a, P, S, E>(
|
||||
parser: P,
|
||||
|
@ -12,11 +12,11 @@ pub fn space0_around_ee<'a, P, S, E>(
|
|||
space_problem: fn(BadInputError, Row, Col) -> E,
|
||||
indent_before_problem: fn(Row, Col) -> E,
|
||||
indent_after_problem: fn(Row, Col) -> E,
|
||||
) -> impl Parser<'a, Located<S>, E>
|
||||
) -> impl Parser<'a, Loc<S>, E>
|
||||
where
|
||||
S: Spaceable<'a>,
|
||||
S: 'a,
|
||||
P: Parser<'a, Located<S>, E>,
|
||||
P: Parser<'a, Loc<S>, E>,
|
||||
P: 'a,
|
||||
E: 'a,
|
||||
{
|
||||
|
@ -38,11 +38,11 @@ pub fn space0_before_optional_after<'a, P, S, E>(
|
|||
space_problem: fn(BadInputError, Row, Col) -> E,
|
||||
indent_before_problem: fn(Row, Col) -> E,
|
||||
indent_after_problem: fn(Row, Col) -> E,
|
||||
) -> impl Parser<'a, Located<S>, E>
|
||||
) -> impl Parser<'a, Loc<S>, E>
|
||||
where
|
||||
S: Spaceable<'a>,
|
||||
S: 'a,
|
||||
P: Parser<'a, Located<S>, E>,
|
||||
P: Parser<'a, Loc<S>, E>,
|
||||
P: 'a,
|
||||
E: 'a,
|
||||
{
|
||||
|
@ -65,9 +65,9 @@ fn spaces_around_help<'a, S>(
|
|||
arena: &'a Bump,
|
||||
tuples: (
|
||||
&'a [CommentOrNewline<'a>],
|
||||
(Located<S>, &'a [CommentOrNewline<'a>]),
|
||||
(Loc<S>, &'a [CommentOrNewline<'a>]),
|
||||
),
|
||||
) -> Located<S>
|
||||
) -> Loc<S>
|
||||
where
|
||||
S: Spaceable<'a>,
|
||||
S: 'a,
|
||||
|
@ -102,17 +102,17 @@ pub fn space0_before_e<'a, P, S, E>(
|
|||
min_indent: u16,
|
||||
space_problem: fn(BadInputError, Row, Col) -> E,
|
||||
indent_problem: fn(Row, Col) -> E,
|
||||
) -> impl Parser<'a, Located<S>, E>
|
||||
) -> impl Parser<'a, Loc<S>, E>
|
||||
where
|
||||
S: Spaceable<'a>,
|
||||
S: 'a,
|
||||
P: Parser<'a, Located<S>, E>,
|
||||
P: Parser<'a, Loc<S>, E>,
|
||||
P: 'a,
|
||||
E: 'a,
|
||||
{
|
||||
parser::map_with_arena(
|
||||
and!(space0_e(min_indent, space_problem, indent_problem), parser),
|
||||
|arena: &'a Bump, (space_list, loc_expr): (&'a [CommentOrNewline<'a>], Located<S>)| {
|
||||
|arena: &'a Bump, (space_list, loc_expr): (&'a [CommentOrNewline<'a>], Loc<S>)| {
|
||||
if space_list.is_empty() {
|
||||
loc_expr
|
||||
} else {
|
||||
|
@ -129,17 +129,17 @@ pub fn space0_after_e<'a, P, S, E>(
|
|||
min_indent: u16,
|
||||
space_problem: fn(BadInputError, Row, Col) -> E,
|
||||
indent_problem: fn(Row, Col) -> E,
|
||||
) -> impl Parser<'a, Located<S>, E>
|
||||
) -> impl Parser<'a, Loc<S>, E>
|
||||
where
|
||||
S: Spaceable<'a>,
|
||||
S: 'a,
|
||||
P: Parser<'a, Located<S>, E>,
|
||||
P: Parser<'a, Loc<S>, E>,
|
||||
P: 'a,
|
||||
E: 'a,
|
||||
{
|
||||
parser::map_with_arena(
|
||||
and!(parser, space0_e(min_indent, space_problem, indent_problem)),
|
||||
|arena: &'a Bump, (loc_expr, space_list): (Located<S>, &'a [CommentOrNewline<'a>])| {
|
||||
|arena: &'a Bump, (loc_expr, space_list): (Loc<S>, &'a [CommentOrNewline<'a>])| {
|
||||
if space_list.is_empty() {
|
||||
loc_expr
|
||||
} else {
|
||||
|
|
|
@ -16,7 +16,7 @@ use crate::type_annotation;
|
|||
use bumpalo::collections::Vec;
|
||||
use bumpalo::Bump;
|
||||
use roc_module::called_via::{BinOp, CalledVia, UnaryOp};
|
||||
use roc_region::all::{Located, Position, Region};
|
||||
use roc_region::all::{Loc, Position, Region};
|
||||
|
||||
use crate::parser::Progress::{self, *};
|
||||
|
||||
|
@ -38,7 +38,7 @@ pub fn test_parse_expr<'a>(
|
|||
min_indent: u16,
|
||||
arena: &'a bumpalo::Bump,
|
||||
state: State<'a>,
|
||||
) -> Result<Located<Expr<'a>>, EExpr<'a>> {
|
||||
) -> Result<Loc<Expr<'a>>, EExpr<'a>> {
|
||||
let parser = skip_second!(
|
||||
space0_before_e(
|
||||
move |a, s| parse_loc_expr(min_indent, a, s),
|
||||
|
@ -87,13 +87,13 @@ pub fn expr_help<'a>(min_indent: u16) -> impl Parser<'a, Expr<'a>, EExpr<'a>> {
|
|||
|
||||
fn loc_expr_in_parens_help<'a>(
|
||||
min_indent: u16,
|
||||
) -> impl Parser<'a, Located<Expr<'a>>, EInParens<'a>> {
|
||||
) -> impl Parser<'a, Loc<Expr<'a>>, EInParens<'a>> {
|
||||
move |arena, state| {
|
||||
let (_, loc_expr, state) = loc_expr_in_parens_help_help(min_indent).parse(arena, state)?;
|
||||
|
||||
Ok((
|
||||
MadeProgress,
|
||||
Located {
|
||||
Loc {
|
||||
region: loc_expr.region,
|
||||
value: Expr::ParensAround(arena.alloc(loc_expr.value)),
|
||||
},
|
||||
|
@ -104,7 +104,7 @@ fn loc_expr_in_parens_help<'a>(
|
|||
|
||||
fn loc_expr_in_parens_help_help<'a>(
|
||||
min_indent: u16,
|
||||
) -> impl Parser<'a, Located<Expr<'a>>, EInParens<'a>> {
|
||||
) -> impl Parser<'a, Loc<Expr<'a>>, EInParens<'a>> {
|
||||
between!(
|
||||
word1(b'(', EInParens::Open),
|
||||
space0_around_ee(
|
||||
|
@ -122,7 +122,7 @@ fn loc_expr_in_parens_help_help<'a>(
|
|||
|
||||
fn loc_expr_in_parens_etc_help<'a>(
|
||||
min_indent: u16,
|
||||
) -> impl Parser<'a, Located<Expr<'a>>, EExpr<'a>> {
|
||||
) -> impl Parser<'a, Loc<Expr<'a>>, EExpr<'a>> {
|
||||
move |arena, state: State<'a>| {
|
||||
let parser = loc!(and!(
|
||||
specialize(EExpr::InParens, loc_expr_in_parens_help(min_indent)),
|
||||
|
@ -135,7 +135,7 @@ fn loc_expr_in_parens_etc_help<'a>(
|
|||
|
||||
let (
|
||||
_,
|
||||
Located {
|
||||
Loc {
|
||||
mut region,
|
||||
value: (loc_expr, field_accesses),
|
||||
},
|
||||
|
@ -157,7 +157,7 @@ fn loc_expr_in_parens_etc_help<'a>(
|
|||
}
|
||||
}
|
||||
|
||||
let loc_expr = Located::at(region, value);
|
||||
let loc_expr = Loc::at(region, value);
|
||||
|
||||
Ok((MadeProgress, loc_expr, state))
|
||||
}
|
||||
|
@ -203,7 +203,7 @@ fn parse_loc_term_or_underscore<'a>(
|
|||
options: ExprParseOptions,
|
||||
arena: &'a Bump,
|
||||
state: State<'a>,
|
||||
) -> ParseResult<'a, Located<Expr<'a>>, EExpr<'a>> {
|
||||
) -> ParseResult<'a, Loc<Expr<'a>>, EExpr<'a>> {
|
||||
one_of!(
|
||||
loc_expr_in_parens_etc_help(min_indent),
|
||||
loc!(specialize(EExpr::Str, string_literal_help())),
|
||||
|
@ -225,7 +225,7 @@ fn parse_loc_term<'a>(
|
|||
options: ExprParseOptions,
|
||||
arena: &'a Bump,
|
||||
state: State<'a>,
|
||||
) -> ParseResult<'a, Located<Expr<'a>>, EExpr<'a>> {
|
||||
) -> ParseResult<'a, Loc<Expr<'a>>, EExpr<'a>> {
|
||||
one_of!(
|
||||
loc_expr_in_parens_etc_help(min_indent),
|
||||
loc!(specialize(EExpr::Str, string_literal_help())),
|
||||
|
@ -263,7 +263,7 @@ fn underscore_expression<'a>() -> impl Parser<'a, Expr<'a>, EExpr<'a>> {
|
|||
fn loc_possibly_negative_or_negated_term<'a>(
|
||||
min_indent: u16,
|
||||
options: ExprParseOptions,
|
||||
) -> impl Parser<'a, Located<Expr<'a>>, EExpr<'a>> {
|
||||
) -> impl Parser<'a, Loc<Expr<'a>>, EExpr<'a>> {
|
||||
one_of![
|
||||
|arena, state: State<'a>| {
|
||||
let initial = state.clone();
|
||||
|
@ -283,10 +283,10 @@ fn loc_possibly_negative_or_negated_term<'a>(
|
|||
and!(loc!(word1(b'!', EExpr::Start)), |a, s| {
|
||||
parse_loc_term(min_indent, options, a, s)
|
||||
}),
|
||||
|arena: &'a Bump, (loc_op, loc_expr): (Located<_>, _)| {
|
||||
|arena: &'a Bump, (loc_op, loc_expr): (Loc<_>, _)| {
|
||||
Expr::UnaryOp(
|
||||
arena.alloc(loc_expr),
|
||||
Located::at(loc_op.region, UnaryOp::Not),
|
||||
Loc::at(loc_op.region, UnaryOp::Not),
|
||||
)
|
||||
}
|
||||
)),
|
||||
|
@ -328,7 +328,7 @@ fn parse_expr_start<'a>(
|
|||
start: Position,
|
||||
arena: &'a Bump,
|
||||
state: State<'a>,
|
||||
) -> ParseResult<'a, Located<Expr<'a>>, EExpr<'a>> {
|
||||
) -> ParseResult<'a, Loc<Expr<'a>>, EExpr<'a>> {
|
||||
one_of![
|
||||
loc!(specialize(EExpr::If, if_expr_help(min_indent, options))),
|
||||
loc!(specialize(
|
||||
|
@ -375,9 +375,9 @@ fn parse_expr_operator_chain<'a>(
|
|||
|
||||
#[derive(Debug)]
|
||||
struct ExprState<'a> {
|
||||
operators: Vec<'a, (Located<Expr<'a>>, Located<BinOp>)>,
|
||||
arguments: Vec<'a, &'a Located<Expr<'a>>>,
|
||||
expr: Located<Expr<'a>>,
|
||||
operators: Vec<'a, (Loc<Expr<'a>>, Loc<BinOp>)>,
|
||||
arguments: Vec<'a, &'a Loc<Expr<'a>>>,
|
||||
expr: Loc<Expr<'a>>,
|
||||
spaces_after: &'a [CommentOrNewline<'a>],
|
||||
initial: State<'a>,
|
||||
end: Position,
|
||||
|
@ -408,9 +408,9 @@ impl<'a> ExprState<'a> {
|
|||
fn validate_assignment_or_backpassing<F>(
|
||||
mut self,
|
||||
arena: &'a Bump,
|
||||
loc_op: Located<BinOp>,
|
||||
loc_op: Loc<BinOp>,
|
||||
argument_error: F,
|
||||
) -> Result<Located<Expr<'a>>, EExpr<'a>>
|
||||
) -> Result<Loc<Expr<'a>>, EExpr<'a>>
|
||||
where
|
||||
F: Fn(Region, Row, Col) -> EExpr<'a>,
|
||||
{
|
||||
|
@ -443,8 +443,8 @@ impl<'a> ExprState<'a> {
|
|||
fn validate_has_type(
|
||||
mut self,
|
||||
arena: &'a Bump,
|
||||
loc_op: Located<BinOp>,
|
||||
) -> Result<(Located<Expr<'a>>, Vec<'a, &'a Located<Expr<'a>>>), EExpr<'a>> {
|
||||
loc_op: Loc<BinOp>,
|
||||
) -> Result<(Loc<Expr<'a>>, Vec<'a, &'a Loc<Expr<'a>>>), EExpr<'a>> {
|
||||
debug_assert_eq!(loc_op.value, BinOp::HasType);
|
||||
|
||||
if !self.operators.is_empty() {
|
||||
|
@ -481,9 +481,9 @@ fn parse_expr_final<'a>(
|
|||
|
||||
fn to_call<'a>(
|
||||
arena: &'a Bump,
|
||||
mut arguments: Vec<'a, &'a Located<Expr<'a>>>,
|
||||
loc_expr1: Located<Expr<'a>>,
|
||||
) -> Located<Expr<'a>> {
|
||||
mut arguments: Vec<'a, &'a Loc<Expr<'a>>>,
|
||||
loc_expr1: Loc<Expr<'a>>,
|
||||
) -> Loc<Expr<'a>> {
|
||||
if arguments.is_empty() {
|
||||
loc_expr1
|
||||
} else {
|
||||
|
@ -501,7 +501,7 @@ fn to_call<'a>(
|
|||
} else {
|
||||
spaces.item
|
||||
};
|
||||
*last = arena.alloc(Located::at(last.region, inner));
|
||||
*last = arena.alloc(Loc::at(last.region, inner));
|
||||
|
||||
spaces.after
|
||||
}
|
||||
|
@ -519,17 +519,17 @@ fn to_call<'a>(
|
|||
apply = arena.alloc(apply).after(spaces)
|
||||
}
|
||||
|
||||
Located::at(region, apply)
|
||||
Loc::at(region, apply)
|
||||
}
|
||||
}
|
||||
|
||||
fn numeric_negate_expression<'a, T>(
|
||||
arena: &'a Bump,
|
||||
state: State<'a>,
|
||||
loc_op: Located<T>,
|
||||
expr: Located<Expr<'a>>,
|
||||
loc_op: Loc<T>,
|
||||
expr: Loc<Expr<'a>>,
|
||||
spaces: &'a [CommentOrNewline<'a>],
|
||||
) -> Located<Expr<'a>> {
|
||||
) -> Loc<Expr<'a>> {
|
||||
debug_assert_eq!(state.bytes().get(0), Some(&b'-'));
|
||||
// for overflow reasons, we must make the unary minus part of the number literal.
|
||||
let mut region = expr.region;
|
||||
|
@ -562,11 +562,11 @@ fn numeric_negate_expression<'a, T>(
|
|||
}
|
||||
_ => Expr::UnaryOp(
|
||||
arena.alloc(expr),
|
||||
Located::at(loc_op.region, UnaryOp::Negate),
|
||||
Loc::at(loc_op.region, UnaryOp::Negate),
|
||||
),
|
||||
};
|
||||
|
||||
let new_loc_expr = Located::at(region, new_expr);
|
||||
let new_loc_expr = Loc::at(region, new_expr);
|
||||
|
||||
if spaces.is_empty() {
|
||||
new_loc_expr
|
||||
|
@ -579,17 +579,17 @@ fn numeric_negate_expression<'a, T>(
|
|||
|
||||
fn append_body_definition<'a>(
|
||||
arena: &'a Bump,
|
||||
defs: &mut Vec<'a, &'a Located<Def<'a>>>,
|
||||
defs: &mut Vec<'a, &'a Loc<Def<'a>>>,
|
||||
spaces: &'a [CommentOrNewline<'a>],
|
||||
loc_pattern: Located<Pattern<'a>>,
|
||||
loc_def_body: Located<Expr<'a>>,
|
||||
loc_pattern: Loc<Pattern<'a>>,
|
||||
loc_def_body: Loc<Expr<'a>>,
|
||||
) {
|
||||
let region = Region::span_across(&loc_pattern.region, &loc_def_body.region);
|
||||
|
||||
if spaces.len() <= 1 {
|
||||
let last = defs.pop();
|
||||
match last {
|
||||
Some(Located {
|
||||
Some(Loc {
|
||||
value: Def::Annotation(ann_pattern, ann_type),
|
||||
..
|
||||
}) => {
|
||||
|
@ -605,7 +605,7 @@ fn append_body_definition<'a>(
|
|||
ann_type,
|
||||
);
|
||||
}
|
||||
Some(Located {
|
||||
Some(Loc {
|
||||
value: Def::SpaceBefore(Def::Annotation(ann_pattern, ann_type), before_ann_spaces),
|
||||
..
|
||||
}) => {
|
||||
|
@ -628,7 +628,7 @@ fn append_body_definition<'a>(
|
|||
}
|
||||
|
||||
// the previous and current def can't be joined up
|
||||
let mut loc_def = Located::at(
|
||||
let mut loc_def = Loc::at(
|
||||
region,
|
||||
Def::Body(arena.alloc(loc_pattern), &*arena.alloc(loc_def_body)),
|
||||
);
|
||||
|
@ -645,14 +645,14 @@ fn append_body_definition<'a>(
|
|||
#[allow(clippy::too_many_arguments)]
|
||||
fn append_body_definition_help<'a>(
|
||||
arena: &'a Bump,
|
||||
defs: &mut Vec<'a, &'a Located<Def<'a>>>,
|
||||
defs: &mut Vec<'a, &'a Loc<Def<'a>>>,
|
||||
region: Region,
|
||||
before_ann_spaces: &'a [CommentOrNewline<'a>],
|
||||
before_body_spaces: &'a [CommentOrNewline<'a>],
|
||||
loc_pattern_body: Located<Pattern<'a>>,
|
||||
loc_def_body: Located<Expr<'a>>,
|
||||
loc_pattern_ann: &'a Located<Pattern<'a>>,
|
||||
loc_ann: &'a Located<TypeAnnotation<'a>>,
|
||||
loc_pattern_body: Loc<Pattern<'a>>,
|
||||
loc_def_body: Loc<Expr<'a>>,
|
||||
loc_pattern_ann: &'a Loc<Pattern<'a>>,
|
||||
loc_ann: &'a Loc<TypeAnnotation<'a>>,
|
||||
) {
|
||||
let comment = match before_body_spaces.get(0) {
|
||||
Some(CommentOrNewline::LineComment(s)) => Some(*s),
|
||||
|
@ -660,7 +660,7 @@ fn append_body_definition_help<'a>(
|
|||
_ => None,
|
||||
};
|
||||
|
||||
let mut loc_def = Located::at(
|
||||
let mut loc_def = Loc::at(
|
||||
region,
|
||||
Def::AnnotatedBody {
|
||||
ann_pattern: loc_pattern_ann,
|
||||
|
@ -682,17 +682,17 @@ fn append_body_definition_help<'a>(
|
|||
|
||||
fn append_annotation_definition<'a>(
|
||||
arena: &'a Bump,
|
||||
defs: &mut Vec<'a, &'a Located<Def<'a>>>,
|
||||
defs: &mut Vec<'a, &'a Loc<Def<'a>>>,
|
||||
spaces: &'a [CommentOrNewline<'a>],
|
||||
loc_pattern: Located<Pattern<'a>>,
|
||||
loc_ann: Located<TypeAnnotation<'a>>,
|
||||
loc_pattern: Loc<Pattern<'a>>,
|
||||
loc_ann: Loc<TypeAnnotation<'a>>,
|
||||
) {
|
||||
let region = Region::span_across(&loc_pattern.region, &loc_ann.region);
|
||||
|
||||
// the previous and current def can't be joined up
|
||||
match &loc_pattern.value {
|
||||
Pattern::Apply(
|
||||
Located {
|
||||
Loc {
|
||||
value: Pattern::GlobalTag(name),
|
||||
..
|
||||
},
|
||||
|
@ -702,7 +702,7 @@ fn append_annotation_definition<'a>(
|
|||
defs,
|
||||
region,
|
||||
spaces,
|
||||
Located::at(loc_pattern.region, name),
|
||||
Loc::at(loc_pattern.region, name),
|
||||
alias_arguments,
|
||||
loc_ann,
|
||||
),
|
||||
|
@ -711,12 +711,12 @@ fn append_annotation_definition<'a>(
|
|||
defs,
|
||||
region,
|
||||
spaces,
|
||||
Located::at(loc_pattern.region, name),
|
||||
Loc::at(loc_pattern.region, name),
|
||||
&[],
|
||||
loc_ann,
|
||||
),
|
||||
_ => {
|
||||
let mut loc_def = Located::at(region, Def::Annotation(loc_pattern, loc_ann));
|
||||
let mut loc_def = Loc::at(region, Def::Annotation(loc_pattern, loc_ann));
|
||||
if !spaces.is_empty() {
|
||||
loc_def = arena
|
||||
.alloc(loc_def.value)
|
||||
|
@ -730,17 +730,17 @@ fn append_annotation_definition<'a>(
|
|||
|
||||
fn append_expect_definition<'a>(
|
||||
arena: &'a Bump,
|
||||
defs: &mut Vec<'a, &'a Located<Def<'a>>>,
|
||||
defs: &mut Vec<'a, &'a Loc<Def<'a>>>,
|
||||
start: Position,
|
||||
spaces: &'a [CommentOrNewline<'a>],
|
||||
loc_expect_body: Located<Expr<'a>>,
|
||||
loc_expect_body: Loc<Expr<'a>>,
|
||||
) {
|
||||
let def = Def::Expect(arena.alloc(loc_expect_body));
|
||||
|
||||
let end = loc_expect_body.region.end();
|
||||
let region = Region::between(start, end);
|
||||
|
||||
let mut loc_def = Located::at(region, def);
|
||||
let mut loc_def = Loc::at(region, def);
|
||||
|
||||
if !spaces.is_empty() {
|
||||
loc_def = arena
|
||||
|
@ -753,19 +753,19 @@ fn append_expect_definition<'a>(
|
|||
|
||||
fn append_alias_definition<'a>(
|
||||
arena: &'a Bump,
|
||||
defs: &mut Vec<'a, &'a Located<Def<'a>>>,
|
||||
defs: &mut Vec<'a, &'a Loc<Def<'a>>>,
|
||||
region: Region,
|
||||
spaces: &'a [CommentOrNewline<'a>],
|
||||
name: Located<&'a str>,
|
||||
pattern_arguments: &'a [Located<Pattern<'a>>],
|
||||
loc_ann: Located<TypeAnnotation<'a>>,
|
||||
name: Loc<&'a str>,
|
||||
pattern_arguments: &'a [Loc<Pattern<'a>>],
|
||||
loc_ann: Loc<TypeAnnotation<'a>>,
|
||||
) {
|
||||
let def = Def::Alias {
|
||||
name,
|
||||
vars: pattern_arguments,
|
||||
ann: loc_ann,
|
||||
};
|
||||
let mut loc_def = Located::at(region, def);
|
||||
let mut loc_def = Loc::at(region, def);
|
||||
|
||||
if !spaces.is_empty() {
|
||||
loc_def = arena
|
||||
|
@ -778,7 +778,7 @@ fn append_alias_definition<'a>(
|
|||
|
||||
#[derive(Debug)]
|
||||
struct DefState<'a> {
|
||||
defs: Vec<'a, &'a Located<Def<'a>>>,
|
||||
defs: Vec<'a, &'a Loc<Def<'a>>>,
|
||||
spaces_after: &'a [CommentOrNewline<'a>],
|
||||
}
|
||||
|
||||
|
@ -945,7 +945,7 @@ fn parse_expr_operator<'a>(
|
|||
options: ExprParseOptions,
|
||||
start: Position,
|
||||
mut expr_state: ExprState<'a>,
|
||||
loc_op: Located<BinOp>,
|
||||
loc_op: Loc<BinOp>,
|
||||
arena: &'a Bump,
|
||||
state: State<'a>,
|
||||
) -> ParseResult<'a, Expr<'a>, EExpr<'a>> {
|
||||
|
@ -1010,11 +1010,11 @@ fn parse_expr_operator<'a>(
|
|||
let alias_region = Region::span_across(&call.region, &ann_type.region);
|
||||
|
||||
let alias = Def::Body(
|
||||
arena.alloc(Located::at(expr_region, good)),
|
||||
arena.alloc(Loc::at(expr_region, good)),
|
||||
arena.alloc(ann_type),
|
||||
);
|
||||
|
||||
(&*arena.alloc(Located::at(alias_region, alias)), state)
|
||||
(&*arena.alloc(Loc::at(alias_region, alias)), state)
|
||||
}
|
||||
Err(_) => {
|
||||
// this `=` likely occurred inline; treat it as an invalid operator
|
||||
|
@ -1058,7 +1058,7 @@ fn parse_expr_operator<'a>(
|
|||
.with_spaces_before(spaces_after_operator, ann_type.region);
|
||||
}
|
||||
|
||||
(Located::at(expr_region, good), ann_type, state)
|
||||
(Loc::at(expr_region, good), ann_type, state)
|
||||
}
|
||||
Err(_) => {
|
||||
// this `=` likely occurred inline; treat it as an invalid operator
|
||||
|
@ -1105,7 +1105,7 @@ fn parse_expr_operator<'a>(
|
|||
for argument in arguments {
|
||||
match expr_to_pattern_help(arena, &argument.value) {
|
||||
Ok(good) => {
|
||||
type_arguments.push(Located::at(argument.region, good));
|
||||
type_arguments.push(Loc::at(argument.region, good));
|
||||
}
|
||||
Err(_) => panic!(),
|
||||
}
|
||||
|
@ -1125,12 +1125,12 @@ fn parse_expr_operator<'a>(
|
|||
let alias_region = Region::span_across(&expr.region, &ann_type.region);
|
||||
|
||||
let alias = Def::Alias {
|
||||
name: Located::at(expr.region, name),
|
||||
name: Loc::at(expr.region, name),
|
||||
vars: type_arguments.into_bump_slice(),
|
||||
ann: ann_type,
|
||||
};
|
||||
|
||||
(&*arena.alloc(Located::at(alias_region, alias)), state)
|
||||
(&*arena.alloc(Loc::at(alias_region, alias)), state)
|
||||
}
|
||||
|
||||
_ => {
|
||||
|
@ -1163,9 +1163,9 @@ fn parse_expr_operator<'a>(
|
|||
Region::span_across(&call.region, &ann_type.region);
|
||||
|
||||
let alias =
|
||||
Def::Annotation(Located::at(expr_region, good), ann_type);
|
||||
Def::Annotation(Loc::at(expr_region, good), ann_type);
|
||||
|
||||
(&*arena.alloc(Located::at(alias_region, alias)), state)
|
||||
(&*arena.alloc(Loc::at(alias_region, alias)), state)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1320,7 +1320,7 @@ fn parse_expr_end<'a>(
|
|||
expr_state.consume_spaces(arena);
|
||||
let call = to_call(arena, expr_state.arguments, expr_state.expr);
|
||||
|
||||
let loc_pattern = Located::at(
|
||||
let loc_pattern = Loc::at(
|
||||
call.region,
|
||||
expr_to_pattern_help(arena, &call.value).unwrap(),
|
||||
);
|
||||
|
@ -1381,7 +1381,7 @@ pub fn parse_loc_expr<'a>(
|
|||
min_indent: u16,
|
||||
arena: &'a Bump,
|
||||
state: State<'a>,
|
||||
) -> ParseResult<'a, Located<Expr<'a>>, EExpr<'a>> {
|
||||
) -> ParseResult<'a, Loc<Expr<'a>>, EExpr<'a>> {
|
||||
parse_loc_expr_with_options(
|
||||
min_indent,
|
||||
ExprParseOptions {
|
||||
|
@ -1397,7 +1397,7 @@ pub fn parse_loc_expr_no_multi_backpassing<'a>(
|
|||
min_indent: u16,
|
||||
arena: &'a Bump,
|
||||
state: State<'a>,
|
||||
) -> ParseResult<'a, Located<Expr<'a>>, EExpr<'a>> {
|
||||
) -> ParseResult<'a, Loc<Expr<'a>>, EExpr<'a>> {
|
||||
parse_loc_expr_with_options(
|
||||
min_indent,
|
||||
ExprParseOptions {
|
||||
|
@ -1414,7 +1414,7 @@ fn parse_loc_expr_with_options<'a>(
|
|||
options: ExprParseOptions,
|
||||
arena: &'a Bump,
|
||||
state: State<'a>,
|
||||
) -> ParseResult<'a, Located<Expr<'a>>, EExpr<'a>> {
|
||||
) -> ParseResult<'a, Loc<Expr<'a>>, EExpr<'a>> {
|
||||
let start = state.get_position();
|
||||
parse_expr_start(min_indent, options, start, arena, state)
|
||||
}
|
||||
|
@ -1436,7 +1436,7 @@ fn expr_to_pattern_help<'a>(arena: &'a Bump, expr: &Expr<'a>) -> Result<Pattern<
|
|||
Expr::Apply(loc_val, loc_args, _) => {
|
||||
let region = loc_val.region;
|
||||
let value = expr_to_pattern_help(arena, &loc_val.value)?;
|
||||
let val_pattern = arena.alloc(Located { region, value });
|
||||
let val_pattern = arena.alloc(Loc { region, value });
|
||||
|
||||
let mut arg_patterns = Vec::with_capacity_in(loc_args.len(), arena);
|
||||
|
||||
|
@ -1444,7 +1444,7 @@ fn expr_to_pattern_help<'a>(arena: &'a Bump, expr: &Expr<'a>) -> Result<Pattern<
|
|||
let region = loc_arg.region;
|
||||
let value = expr_to_pattern_help(arena, &loc_arg.value)?;
|
||||
|
||||
arg_patterns.push(Located { region, value });
|
||||
arg_patterns.push(Loc { region, value });
|
||||
}
|
||||
|
||||
let pattern = Pattern::Apply(val_pattern, arg_patterns.into_bump_slice());
|
||||
|
@ -1467,7 +1467,7 @@ fn expr_to_pattern_help<'a>(arena: &'a Bump, expr: &Expr<'a>) -> Result<Pattern<
|
|||
let patterns = fields.map_items_result(arena, |loc_assigned_field| {
|
||||
let region = loc_assigned_field.region;
|
||||
let value = assigned_expr_field_to_pattern_help(arena, &loc_assigned_field.value)?;
|
||||
Ok(Located { region, value })
|
||||
Ok(Loc { region, value })
|
||||
})?;
|
||||
|
||||
Ok(Pattern::RecordDestructure(patterns))
|
||||
|
@ -1513,7 +1513,7 @@ fn assigned_expr_field_to_pattern_help<'a>(
|
|||
Ok(match assigned_field {
|
||||
AssignedField::RequiredValue(name, spaces, value) => {
|
||||
let pattern = expr_to_pattern_help(arena, &value.value)?;
|
||||
let result = arena.alloc(Located {
|
||||
let result = arena.alloc(Loc {
|
||||
region: value.region,
|
||||
value: pattern,
|
||||
});
|
||||
|
@ -1527,7 +1527,7 @@ fn assigned_expr_field_to_pattern_help<'a>(
|
|||
}
|
||||
}
|
||||
AssignedField::OptionalValue(name, spaces, value) => {
|
||||
let result = arena.alloc(Located {
|
||||
let result = arena.alloc(Loc {
|
||||
region: value.region,
|
||||
value: value.value,
|
||||
});
|
||||
|
@ -1553,7 +1553,7 @@ fn assigned_expr_field_to_pattern_help<'a>(
|
|||
})
|
||||
}
|
||||
|
||||
pub fn defs<'a>(min_indent: u16) -> impl Parser<'a, Vec<'a, Located<Def<'a>>>, EExpr<'a>> {
|
||||
pub fn defs<'a>(min_indent: u16) -> impl Parser<'a, Vec<'a, Loc<Def<'a>>>, EExpr<'a>> {
|
||||
move |arena, state: State<'a>| {
|
||||
let def_state = DefState {
|
||||
defs: Vec::new_in(arena),
|
||||
|
@ -1646,8 +1646,8 @@ fn closure_help<'a>(
|
|||
)
|
||||
),
|
||||
|arena: &'a Bump, (params, loc_body)| {
|
||||
let params: Vec<'a, Located<Pattern<'a>>> = params;
|
||||
let params: &'a [Located<Pattern<'a>>] = params.into_bump_slice();
|
||||
let params: Vec<'a, Loc<Pattern<'a>>> = params;
|
||||
let params: &'a [Loc<Pattern<'a>>] = params.into_bump_slice();
|
||||
|
||||
Expr::Closure(params, arena.alloc(loc_body))
|
||||
}
|
||||
|
@ -1803,8 +1803,8 @@ mod when {
|
|||
) -> impl Parser<
|
||||
'a,
|
||||
(
|
||||
(Col, Vec<'a, Located<Pattern<'a>>>),
|
||||
Option<Located<Expr<'a>>>,
|
||||
(Col, Vec<'a, Loc<Pattern<'a>>>),
|
||||
Option<Loc<Expr<'a>>>,
|
||||
),
|
||||
EWhen<'a>,
|
||||
> {
|
||||
|
@ -1838,7 +1838,7 @@ mod when {
|
|||
|
||||
fn branch_single_alternative<'a>(
|
||||
min_indent: u16,
|
||||
) -> impl Parser<'a, Located<Pattern<'a>>, EWhen<'a>> {
|
||||
) -> impl Parser<'a, Loc<Pattern<'a>>, EWhen<'a>> {
|
||||
move |arena, state| {
|
||||
let (_, spaces, state) =
|
||||
backtrackable(space0_e(min_indent, EWhen::Space, EWhen::IndentPattern))
|
||||
|
@ -1869,7 +1869,7 @@ mod when {
|
|||
fn branch_alternatives_help<'a>(
|
||||
min_indent: u16,
|
||||
pattern_indent_level: Option<u16>,
|
||||
) -> impl Parser<'a, (Col, Vec<'a, Located<Pattern<'a>>>), EWhen<'a>> {
|
||||
) -> impl Parser<'a, (Col, Vec<'a, Loc<Pattern<'a>>>), EWhen<'a>> {
|
||||
move |arena, state: State<'a>| {
|
||||
let initial = state.clone();
|
||||
|
||||
|
@ -1937,7 +1937,7 @@ mod when {
|
|||
}
|
||||
|
||||
/// Parsing the righthandside of a branch in a when conditional.
|
||||
fn branch_result<'a>(indent: u16) -> impl Parser<'a, Located<Expr<'a>>, EWhen<'a>> {
|
||||
fn branch_result<'a>(indent: u16) -> impl Parser<'a, Loc<Expr<'a>>, EWhen<'a>> {
|
||||
skip_first!(
|
||||
word2(b'-', b'>', EWhen::Arrow),
|
||||
space0_before_e(
|
||||
|
@ -1954,7 +1954,7 @@ mod when {
|
|||
|
||||
fn if_branch<'a>(
|
||||
min_indent: u16,
|
||||
) -> impl Parser<'a, (Located<Expr<'a>>, Located<Expr<'a>>), EIf<'a>> {
|
||||
) -> impl Parser<'a, (Loc<Expr<'a>>, Loc<Expr<'a>>), EIf<'a>> {
|
||||
move |arena, state| {
|
||||
// NOTE: only parse spaces before the expression
|
||||
let (_, cond, state) = space0_around_ee(
|
||||
|
@ -2248,9 +2248,9 @@ fn record_help<'a>(
|
|||
) -> impl Parser<
|
||||
'a,
|
||||
(
|
||||
Option<Located<Expr<'a>>>,
|
||||
Located<(
|
||||
Vec<'a, Located<AssignedField<'a, Expr<'a>>>>,
|
||||
Option<Loc<Expr<'a>>>,
|
||||
Loc<(
|
||||
Vec<'a, Loc<AssignedField<'a, Expr<'a>>>>,
|
||||
&'a [CommentOrNewline<'a>],
|
||||
)>,
|
||||
),
|
||||
|
|
|
@ -15,7 +15,7 @@ use crate::state::State;
|
|||
use crate::string_literal;
|
||||
use crate::type_annotation;
|
||||
use bumpalo::collections::Vec;
|
||||
use roc_region::all::Located;
|
||||
use roc_region::all::Loc;
|
||||
|
||||
fn end_of_file<'a>() -> impl Parser<'a, (), SyntaxError<'a>> {
|
||||
|_arena, state: State<'a>| {
|
||||
|
@ -32,7 +32,7 @@ fn end_of_file<'a>() -> impl Parser<'a, (), SyntaxError<'a>> {
|
|||
}
|
||||
|
||||
#[inline(always)]
|
||||
pub fn module_defs<'a>() -> impl Parser<'a, Vec<'a, Located<Def<'a>>>, SyntaxError<'a>> {
|
||||
pub fn module_defs<'a>() -> impl Parser<'a, Vec<'a, Loc<Def<'a>>>, SyntaxError<'a>> {
|
||||
// force that we parse until the end of the input
|
||||
let min_indent = 0;
|
||||
skip_second!(
|
||||
|
@ -221,7 +221,7 @@ fn app_header<'a>() -> impl Parser<'a, AppHeader<'a>, EHeader<'a>> {
|
|||
#[allow(clippy::type_complexity)]
|
||||
let opt_imports: Option<(
|
||||
(&'a [CommentOrNewline<'a>], &'a [CommentOrNewline<'a>]),
|
||||
Collection<'a, Located<Spaced<'a, ImportsEntry<'a>>>>,
|
||||
Collection<'a, Loc<Spaced<'a, ImportsEntry<'a>>>>,
|
||||
)> = opt_imports;
|
||||
|
||||
let ((before_imports, after_imports), imports) =
|
||||
|
@ -304,8 +304,8 @@ fn platform_header<'a>() -> impl Parser<'a, PlatformHeader<'a>, EHeader<'a>> {
|
|||
|
||||
#[derive(Debug)]
|
||||
struct ProvidesTo<'a> {
|
||||
entries: Collection<'a, Located<Spaced<'a, ExposedName<'a>>>>,
|
||||
to: Located<To<'a>>,
|
||||
entries: Collection<'a, Loc<Spaced<'a, ExposedName<'a>>>>,
|
||||
to: Loc<To<'a>>,
|
||||
|
||||
before_provides_keyword: &'a [CommentOrNewline<'a>],
|
||||
after_provides_keyword: &'a [CommentOrNewline<'a>],
|
||||
|
@ -363,7 +363,7 @@ fn provides_without_to<'a>() -> impl Parser<
|
|||
'a,
|
||||
(
|
||||
(&'a [CommentOrNewline<'a>], &'a [CommentOrNewline<'a>]),
|
||||
Collection<'a, Located<Spaced<'a, ExposedName<'a>>>>,
|
||||
Collection<'a, Loc<Spaced<'a, ExposedName<'a>>>>,
|
||||
),
|
||||
EProvides<'a>,
|
||||
> {
|
||||
|
@ -393,7 +393,7 @@ fn provides_without_to<'a>() -> impl Parser<
|
|||
|
||||
fn exposes_entry<'a, F, E>(
|
||||
to_expectation: F,
|
||||
) -> impl Parser<'a, Located<Spaced<'a, ExposedName<'a>>>, E>
|
||||
) -> impl Parser<'a, Loc<Spaced<'a, ExposedName<'a>>>, E>
|
||||
where
|
||||
F: Fn(crate::parser::Row, crate::parser::Col) -> E,
|
||||
F: Copy,
|
||||
|
@ -445,7 +445,7 @@ fn platform_requires<'a>() -> impl Parser<'a, PlatformRequires<'a>, ERequires<'a
|
|||
#[inline(always)]
|
||||
fn requires_rigids<'a>(
|
||||
min_indent: u16,
|
||||
) -> impl Parser<'a, Collection<'a, Located<Spaced<'a, PlatformRigid<'a>>>>, ERequires<'a>> {
|
||||
) -> impl Parser<'a, Collection<'a, Loc<Spaced<'a, PlatformRigid<'a>>>>, ERequires<'a>> {
|
||||
collection_trailing_sep_e!(
|
||||
word1(b'{', ERequires::ListStart),
|
||||
specialize(|_, r, c| ERequires::Rigid(r, c), loc!(requires_rigid())),
|
||||
|
@ -471,7 +471,7 @@ fn requires_rigid<'a>() -> impl Parser<'a, Spaced<'a, PlatformRigid<'a>>, ()> {
|
|||
}
|
||||
|
||||
#[inline(always)]
|
||||
fn requires_typed_ident<'a>() -> impl Parser<'a, Located<Spaced<'a, TypedIdent<'a>>>, ERequires<'a>>
|
||||
fn requires_typed_ident<'a>() -> impl Parser<'a, Loc<Spaced<'a, TypedIdent<'a>>>, ERequires<'a>>
|
||||
{
|
||||
skip_first!(
|
||||
word1(b'{', ERequires::ListStart),
|
||||
|
@ -493,7 +493,7 @@ fn exposes_values<'a>() -> impl Parser<
|
|||
'a,
|
||||
(
|
||||
(&'a [CommentOrNewline<'a>], &'a [CommentOrNewline<'a>]),
|
||||
Collection<'a, Located<Spaced<'a, ExposedName<'a>>>>,
|
||||
Collection<'a, Loc<Spaced<'a, ExposedName<'a>>>>,
|
||||
),
|
||||
EExposes,
|
||||
> {
|
||||
|
@ -547,7 +547,7 @@ fn exposes_modules<'a>() -> impl Parser<
|
|||
'a,
|
||||
(
|
||||
(&'a [CommentOrNewline<'a>], &'a [CommentOrNewline<'a>]),
|
||||
Collection<'a, Located<Spaced<'a, ModuleName<'a>>>>,
|
||||
Collection<'a, Loc<Spaced<'a, ModuleName<'a>>>>,
|
||||
),
|
||||
EExposes,
|
||||
> {
|
||||
|
@ -578,7 +578,7 @@ fn exposes_modules<'a>() -> impl Parser<
|
|||
|
||||
fn exposes_module<'a, F, E>(
|
||||
to_expectation: F,
|
||||
) -> impl Parser<'a, Located<Spaced<'a, ModuleName<'a>>>, E>
|
||||
) -> impl Parser<'a, Loc<Spaced<'a, ModuleName<'a>>>, E>
|
||||
where
|
||||
F: Fn(crate::parser::Row, crate::parser::Col) -> E,
|
||||
F: Copy,
|
||||
|
@ -592,7 +592,7 @@ where
|
|||
|
||||
#[derive(Debug)]
|
||||
struct Packages<'a> {
|
||||
entries: Collection<'a, Located<Spaced<'a, PackageEntry<'a>>>>,
|
||||
entries: Collection<'a, Loc<Spaced<'a, PackageEntry<'a>>>>,
|
||||
before_packages_keyword: &'a [CommentOrNewline<'a>],
|
||||
after_packages_keyword: &'a [CommentOrNewline<'a>],
|
||||
}
|
||||
|
@ -641,7 +641,7 @@ fn imports<'a>() -> impl Parser<
|
|||
'a,
|
||||
(
|
||||
(&'a [CommentOrNewline<'a>], &'a [CommentOrNewline<'a>]),
|
||||
Collection<'a, Located<Spaced<'a, ImportsEntry<'a>>>>,
|
||||
Collection<'a, Loc<Spaced<'a, ImportsEntry<'a>>>>,
|
||||
),
|
||||
EImports,
|
||||
> {
|
||||
|
@ -785,7 +785,7 @@ fn imports_entry<'a>() -> impl Parser<'a, Spaced<'a, ImportsEntry<'a>>, EImports
|
|||
|
||||
type Temp<'a> = (
|
||||
(Option<&'a str>, ModuleName<'a>),
|
||||
Option<Collection<'a, Located<Spaced<'a, ExposedName<'a>>>>>,
|
||||
Option<Collection<'a, Loc<Spaced<'a, ExposedName<'a>>>>>,
|
||||
);
|
||||
|
||||
map_with_arena!(
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
use crate::state::State;
|
||||
use bumpalo::collections::vec::Vec;
|
||||
use bumpalo::Bump;
|
||||
use roc_region::all::{Located, Region};
|
||||
use roc_region::all::{Loc, Region};
|
||||
use Progress::*;
|
||||
|
||||
#[derive(Debug, PartialEq, Eq)]
|
||||
|
@ -1050,7 +1050,7 @@ where
|
|||
macro_rules! loc {
|
||||
($parser:expr) => {
|
||||
move |arena, state: $crate::state::State<'a>| {
|
||||
use roc_region::all::{Located, Region};
|
||||
use roc_region::all::{Loc, Region};
|
||||
|
||||
let start_col = state.column;
|
||||
let start_line = state.line;
|
||||
|
@ -1066,7 +1066,7 @@ macro_rules! loc {
|
|||
end_col,
|
||||
};
|
||||
|
||||
Ok((progress, Located { region, value }, state))
|
||||
Ok((progress, Loc { region, value }, state))
|
||||
}
|
||||
Err(err) => Err(err),
|
||||
}
|
||||
|
@ -1534,7 +1534,7 @@ where
|
|||
|
||||
/// For some reason, some usages won't compile unless they use this instead of the macro version
|
||||
#[inline(always)]
|
||||
pub fn loc<'a, P, Val, Error>(parser: P) -> impl Parser<'a, Located<Val>, Error>
|
||||
pub fn loc<'a, P, Val, Error>(parser: P) -> impl Parser<'a, Loc<Val>, Error>
|
||||
where
|
||||
P: Parser<'a, Val, Error>,
|
||||
Error: 'a,
|
||||
|
|
|
@ -10,7 +10,7 @@ use crate::state::State;
|
|||
use bumpalo::collections::string::String;
|
||||
use bumpalo::collections::Vec;
|
||||
use bumpalo::Bump;
|
||||
use roc_region::all::{Located, Region};
|
||||
use roc_region::all::{Loc, Region};
|
||||
|
||||
/// Different patterns are supported in different circumstances.
|
||||
/// For example, when branches can pattern match on number literals, but
|
||||
|
@ -26,7 +26,7 @@ pub enum PatternType {
|
|||
|
||||
pub fn loc_closure_param<'a>(
|
||||
min_indent: u16,
|
||||
) -> impl Parser<'a, Located<Pattern<'a>>, EPattern<'a>> {
|
||||
) -> impl Parser<'a, Loc<Pattern<'a>>, EPattern<'a>> {
|
||||
move |arena, state| parse_closure_param(arena, state, min_indent)
|
||||
}
|
||||
|
||||
|
@ -34,7 +34,7 @@ fn parse_closure_param<'a>(
|
|||
arena: &'a Bump,
|
||||
state: State<'a>,
|
||||
min_indent: u16,
|
||||
) -> ParseResult<'a, Located<Pattern<'a>>, EPattern<'a>> {
|
||||
) -> ParseResult<'a, Loc<Pattern<'a>>, EPattern<'a>> {
|
||||
one_of!(
|
||||
// An ident is the most common param, e.g. \foo -> ...
|
||||
loc_ident_pattern_help(min_indent, true),
|
||||
|
@ -54,7 +54,7 @@ fn parse_closure_param<'a>(
|
|||
|
||||
pub fn loc_pattern_help<'a>(
|
||||
min_indent: u16,
|
||||
) -> impl Parser<'a, Located<Pattern<'a>>, EPattern<'a>> {
|
||||
) -> impl Parser<'a, Loc<Pattern<'a>>, EPattern<'a>> {
|
||||
one_of!(
|
||||
specialize(EPattern::PInParens, loc_pattern_in_parens_help(min_indent)),
|
||||
loc!(underscore_pattern_help()),
|
||||
|
@ -70,11 +70,11 @@ pub fn loc_pattern_help<'a>(
|
|||
|
||||
fn loc_tag_pattern_args_help<'a>(
|
||||
min_indent: u16,
|
||||
) -> impl Parser<'a, Vec<'a, Located<Pattern<'a>>>, EPattern<'a>> {
|
||||
) -> impl Parser<'a, Vec<'a, Loc<Pattern<'a>>>, EPattern<'a>> {
|
||||
zero_or_more!(loc_tag_pattern_arg(min_indent))
|
||||
}
|
||||
|
||||
fn loc_tag_pattern_arg<'a>(min_indent: u16) -> impl Parser<'a, Located<Pattern<'a>>, EPattern<'a>> {
|
||||
fn loc_tag_pattern_arg<'a>(min_indent: u16) -> impl Parser<'a, Loc<Pattern<'a>>, EPattern<'a>> {
|
||||
// Don't parse operators, because they have a higher precedence than function application.
|
||||
// If we encounter one, we're done parsing function args!
|
||||
move |arena, state| {
|
||||
|
@ -84,14 +84,14 @@ fn loc_tag_pattern_arg<'a>(min_indent: u16) -> impl Parser<'a, Located<Pattern<'
|
|||
|
||||
let (_, loc_pat, state) = loc_parse_tag_pattern_arg(min_indent, arena, state)?;
|
||||
|
||||
let Located { region, value } = loc_pat;
|
||||
let Loc { region, value } = loc_pat;
|
||||
|
||||
Ok((
|
||||
MadeProgress,
|
||||
if spaces.is_empty() {
|
||||
Located::at(region, value)
|
||||
Loc::at(region, value)
|
||||
} else {
|
||||
Located::at(region, Pattern::SpaceBefore(arena.alloc(value), spaces))
|
||||
Loc::at(region, Pattern::SpaceBefore(arena.alloc(value), spaces))
|
||||
},
|
||||
state,
|
||||
))
|
||||
|
@ -102,7 +102,7 @@ fn loc_parse_tag_pattern_arg<'a>(
|
|||
min_indent: u16,
|
||||
arena: &'a Bump,
|
||||
state: State<'a>,
|
||||
) -> ParseResult<'a, Located<Pattern<'a>>, EPattern<'a>> {
|
||||
) -> ParseResult<'a, Loc<Pattern<'a>>, EPattern<'a>> {
|
||||
one_of!(
|
||||
specialize(EPattern::PInParens, loc_pattern_in_parens_help(min_indent)),
|
||||
loc!(underscore_pattern_help()),
|
||||
|
@ -120,7 +120,7 @@ fn loc_parse_tag_pattern_arg<'a>(
|
|||
|
||||
fn loc_pattern_in_parens_help<'a>(
|
||||
min_indent: u16,
|
||||
) -> impl Parser<'a, Located<Pattern<'a>>, PInParens<'a>> {
|
||||
) -> impl Parser<'a, Loc<Pattern<'a>>, PInParens<'a>> {
|
||||
between!(
|
||||
word1(b'(', PInParens::Open),
|
||||
space0_around_ee(
|
||||
|
@ -168,7 +168,7 @@ fn string_pattern_help<'a>() -> impl Parser<'a, Pattern<'a>, EPattern<'a>> {
|
|||
fn loc_ident_pattern_help<'a>(
|
||||
min_indent: u16,
|
||||
can_have_arguments: bool,
|
||||
) -> impl Parser<'a, Located<Pattern<'a>>, EPattern<'a>> {
|
||||
) -> impl Parser<'a, Loc<Pattern<'a>>, EPattern<'a>> {
|
||||
move |arena: &'a Bump, state: State<'a>| {
|
||||
let original_state = state.clone();
|
||||
|
||||
|
@ -177,7 +177,7 @@ fn loc_ident_pattern_help<'a>(
|
|||
|
||||
match loc_ident.value {
|
||||
Ident::GlobalTag(tag) => {
|
||||
let loc_tag = Located {
|
||||
let loc_tag = Loc {
|
||||
region: loc_ident.region,
|
||||
value: Pattern::GlobalTag(tag),
|
||||
};
|
||||
|
@ -197,14 +197,14 @@ fn loc_ident_pattern_help<'a>(
|
|||
let value =
|
||||
Pattern::Apply(&*arena.alloc(loc_tag), loc_args.into_bump_slice());
|
||||
|
||||
Ok((MadeProgress, Located { region, value }, state))
|
||||
Ok((MadeProgress, Loc { region, value }, state))
|
||||
}
|
||||
} else {
|
||||
Ok((MadeProgress, loc_tag, state))
|
||||
}
|
||||
}
|
||||
Ident::PrivateTag(tag) => {
|
||||
let loc_tag = Located {
|
||||
let loc_tag = Loc {
|
||||
region: loc_ident.region,
|
||||
value: Pattern::PrivateTag(tag),
|
||||
};
|
||||
|
@ -224,7 +224,7 @@ fn loc_ident_pattern_help<'a>(
|
|||
let value =
|
||||
Pattern::Apply(&*arena.alloc(loc_tag), loc_args.into_bump_slice());
|
||||
|
||||
Ok((MadeProgress, Located { region, value }, state))
|
||||
Ok((MadeProgress, Loc { region, value }, state))
|
||||
}
|
||||
} else {
|
||||
Ok((MadeProgress, loc_tag, state))
|
||||
|
@ -242,7 +242,7 @@ fn loc_ident_pattern_help<'a>(
|
|||
} else if module_name.is_empty() && parts.len() == 1 {
|
||||
Ok((
|
||||
MadeProgress,
|
||||
Located {
|
||||
Loc {
|
||||
region: loc_ident.region,
|
||||
value: Pattern::Identifier(parts[0]),
|
||||
},
|
||||
|
@ -256,7 +256,7 @@ fn loc_ident_pattern_help<'a>(
|
|||
};
|
||||
Ok((
|
||||
MadeProgress,
|
||||
Located {
|
||||
Loc {
|
||||
region: loc_ident.region,
|
||||
value: Pattern::Malformed(
|
||||
String::from_str_in(&malformed_str, arena).into_bump_str(),
|
||||
|
@ -268,7 +268,7 @@ fn loc_ident_pattern_help<'a>(
|
|||
}
|
||||
Ident::AccessorFunction(string) => Ok((
|
||||
MadeProgress,
|
||||
Located {
|
||||
Loc {
|
||||
region: loc_ident.region,
|
||||
value: Pattern::Malformed(string),
|
||||
},
|
||||
|
@ -279,7 +279,7 @@ fn loc_ident_pattern_help<'a>(
|
|||
|
||||
Ok((
|
||||
MadeProgress,
|
||||
Located {
|
||||
Loc {
|
||||
region: loc_ident.region,
|
||||
value: Pattern::MalformedIdent(malformed, problem),
|
||||
},
|
||||
|
@ -338,7 +338,7 @@ fn record_pattern_help<'a>(min_indent: u16) -> impl Parser<'a, Pattern<'a>, PRec
|
|||
}
|
||||
}
|
||||
|
||||
fn record_pattern_field<'a>(min_indent: u16) -> impl Parser<'a, Located<Pattern<'a>>, PRecord<'a>> {
|
||||
fn record_pattern_field<'a>(min_indent: u16) -> impl Parser<'a, Loc<Pattern<'a>>, PRecord<'a>> {
|
||||
use crate::parser::Either::*;
|
||||
|
||||
move |arena, state: State<'a>| {
|
||||
|
@ -371,7 +371,7 @@ fn record_pattern_field<'a>(min_indent: u16) -> impl Parser<'a, Located<Pattern<
|
|||
space0_before_e(val_parser, min_indent, PRecord::Space, PRecord::IndentColon)
|
||||
.parse(arena, state)?;
|
||||
|
||||
let Located {
|
||||
let Loc {
|
||||
value: label,
|
||||
region,
|
||||
} = loc_label;
|
||||
|
@ -380,7 +380,7 @@ fn record_pattern_field<'a>(min_indent: u16) -> impl Parser<'a, Located<Pattern<
|
|||
|
||||
Ok((
|
||||
MadeProgress,
|
||||
Located::at(
|
||||
Loc::at(
|
||||
region,
|
||||
Pattern::RequiredField(
|
||||
label,
|
||||
|
@ -401,7 +401,7 @@ fn record_pattern_field<'a>(min_indent: u16) -> impl Parser<'a, Located<Pattern<
|
|||
space0_before_e(val_parser, min_indent, PRecord::Space, PRecord::IndentColon)
|
||||
.parse(arena, state)?;
|
||||
|
||||
let Located {
|
||||
let Loc {
|
||||
value: label,
|
||||
region,
|
||||
} = loc_label;
|
||||
|
@ -410,7 +410,7 @@ fn record_pattern_field<'a>(min_indent: u16) -> impl Parser<'a, Located<Pattern<
|
|||
|
||||
Ok((
|
||||
MadeProgress,
|
||||
Located::at(
|
||||
Loc::at(
|
||||
region,
|
||||
Pattern::OptionalField(
|
||||
label,
|
||||
|
@ -425,14 +425,14 @@ fn record_pattern_field<'a>(min_indent: u16) -> impl Parser<'a, Located<Pattern<
|
|||
// If no value was provided, record it as a Var.
|
||||
// Canonicalize will know what to do with a Var later.
|
||||
None => {
|
||||
let Located { value, region } = loc_label;
|
||||
let Loc { value, region } = loc_label;
|
||||
let value = if !spaces.is_empty() {
|
||||
Pattern::SpaceAfter(arena.alloc(Pattern::Identifier(value)), spaces)
|
||||
} else {
|
||||
Pattern::Identifier(value)
|
||||
};
|
||||
|
||||
Ok((MadeProgress, Located::at(region, value), state))
|
||||
Ok((MadeProgress, Loc::at(region, value), state))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -6,7 +6,7 @@ use crate::parser::SyntaxError;
|
|||
use crate::state::State;
|
||||
use bumpalo::collections::Vec as BumpVec;
|
||||
use bumpalo::Bump;
|
||||
use roc_region::all::Located;
|
||||
use roc_region::all::Loc;
|
||||
|
||||
pub fn parse_expr_with<'a>(
|
||||
arena: &'a Bump,
|
||||
|
@ -19,7 +19,7 @@ pub fn parse_expr_with<'a>(
|
|||
pub fn parse_loc_with<'a>(
|
||||
arena: &'a Bump,
|
||||
input: &'a str,
|
||||
) -> Result<Located<ast::Expr<'a>>, SyntaxError<'a>> {
|
||||
) -> Result<Loc<ast::Expr<'a>>, SyntaxError<'a>> {
|
||||
let state = State::new(input.trim().as_bytes());
|
||||
|
||||
match crate::expr::test_parse_expr(0, arena, state) {
|
||||
|
@ -31,7 +31,7 @@ pub fn parse_loc_with<'a>(
|
|||
pub fn parse_defs_with<'a>(
|
||||
arena: &'a Bump,
|
||||
input: &'a str,
|
||||
) -> Result<BumpVec<'a, Located<ast::Def<'a>>>, SyntaxError<'a>> {
|
||||
) -> Result<BumpVec<'a, Loc<ast::Def<'a>>>, SyntaxError<'a>> {
|
||||
let state = State::new(input.trim().as_bytes());
|
||||
|
||||
match module_defs().parse(arena, state) {
|
||||
|
|
|
@ -9,12 +9,12 @@ use crate::parser::{
|
|||
use crate::state::State;
|
||||
use bumpalo::collections::vec::Vec;
|
||||
use bumpalo::Bump;
|
||||
use roc_region::all::{Located, Region};
|
||||
use roc_region::all::{Loc, Region};
|
||||
|
||||
pub fn located_help<'a>(
|
||||
min_indent: u16,
|
||||
is_trailing_comma_valid: bool,
|
||||
) -> impl Parser<'a, Located<TypeAnnotation<'a>>, EType<'a>> {
|
||||
) -> impl Parser<'a, Loc<TypeAnnotation<'a>>, EType<'a>> {
|
||||
expression(min_indent, is_trailing_comma_valid)
|
||||
}
|
||||
|
||||
|
@ -51,7 +51,7 @@ fn fail_type_start<'a, T: 'a>() -> impl Parser<'a, T, EType<'a>> {
|
|||
|_arena, state: State<'a>| Err((NoProgress, EType::TStart(state.line, state.column), state))
|
||||
}
|
||||
|
||||
fn term<'a>(min_indent: u16) -> impl Parser<'a, Located<TypeAnnotation<'a>>, EType<'a>> {
|
||||
fn term<'a>(min_indent: u16) -> impl Parser<'a, Loc<TypeAnnotation<'a>>, EType<'a>> {
|
||||
map_with_arena!(
|
||||
and!(
|
||||
one_of!(
|
||||
|
@ -86,8 +86,8 @@ fn term<'a>(min_indent: u16) -> impl Parser<'a, Located<TypeAnnotation<'a>>, ETy
|
|||
),
|
||||
|arena: &'a Bump,
|
||||
(loc_ann, opt_as): (
|
||||
Located<TypeAnnotation<'a>>,
|
||||
Option<(&'a [_], Located<TypeAnnotation<'a>>)>
|
||||
Loc<TypeAnnotation<'a>>,
|
||||
Option<(&'a [_], Loc<TypeAnnotation<'a>>)>
|
||||
)| {
|
||||
match opt_as {
|
||||
Some((spaces, loc_as)) => {
|
||||
|
@ -95,7 +95,7 @@ fn term<'a>(min_indent: u16) -> impl Parser<'a, Located<TypeAnnotation<'a>>, ETy
|
|||
let value =
|
||||
TypeAnnotation::As(arena.alloc(loc_ann), spaces, arena.alloc(loc_as));
|
||||
|
||||
Located { region, value }
|
||||
Loc { region, value }
|
||||
}
|
||||
|
||||
None => loc_ann,
|
||||
|
@ -106,8 +106,8 @@ fn term<'a>(min_indent: u16) -> impl Parser<'a, Located<TypeAnnotation<'a>>, ETy
|
|||
}
|
||||
|
||||
/// The `*` type variable, e.g. in (List *) Wildcard,
|
||||
fn loc_wildcard<'a>() -> impl Parser<'a, Located<TypeAnnotation<'a>>, EType<'a>> {
|
||||
map!(loc!(word1(b'*', EType::TWildcard)), |loc_val: Located<
|
||||
fn loc_wildcard<'a>() -> impl Parser<'a, Loc<TypeAnnotation<'a>>, EType<'a>> {
|
||||
map!(loc!(word1(b'*', EType::TWildcard)), |loc_val: Loc<
|
||||
(),
|
||||
>| {
|
||||
loc_val.map(|_| TypeAnnotation::Wildcard)
|
||||
|
@ -115,15 +115,15 @@ fn loc_wildcard<'a>() -> impl Parser<'a, Located<TypeAnnotation<'a>>, EType<'a>>
|
|||
}
|
||||
|
||||
/// The `_` indicating an inferred type, e.g. in (List _)
|
||||
fn loc_inferred<'a>() -> impl Parser<'a, Located<TypeAnnotation<'a>>, EType<'a>> {
|
||||
map!(loc!(word1(b'_', EType::TInferred)), |loc_val: Located<
|
||||
fn loc_inferred<'a>() -> impl Parser<'a, Loc<TypeAnnotation<'a>>, EType<'a>> {
|
||||
map!(loc!(word1(b'_', EType::TInferred)), |loc_val: Loc<
|
||||
(),
|
||||
>| {
|
||||
loc_val.map(|_| TypeAnnotation::Inferred)
|
||||
})
|
||||
}
|
||||
|
||||
fn loc_applied_arg<'a>(min_indent: u16) -> impl Parser<'a, Located<TypeAnnotation<'a>>, EType<'a>> {
|
||||
fn loc_applied_arg<'a>(min_indent: u16) -> impl Parser<'a, Loc<TypeAnnotation<'a>>, EType<'a>> {
|
||||
use crate::ast::Spaceable;
|
||||
|
||||
map_with_arena!(
|
||||
|
@ -139,11 +139,11 @@ fn loc_applied_arg<'a>(min_indent: u16) -> impl Parser<'a, Located<TypeAnnotatio
|
|||
loc!(parse_type_variable)
|
||||
)
|
||||
),
|
||||
|arena: &'a Bump, (spaces, argument): (&'a [_], Located<TypeAnnotation<'a>>)| {
|
||||
|arena: &'a Bump, (spaces, argument): (&'a [_], Loc<TypeAnnotation<'a>>)| {
|
||||
if spaces.is_empty() {
|
||||
argument
|
||||
} else {
|
||||
let Located { region, value } = argument;
|
||||
let Loc { region, value } = argument;
|
||||
arena.alloc(value).with_spaces_before(spaces, region)
|
||||
}
|
||||
}
|
||||
|
@ -152,7 +152,7 @@ fn loc_applied_arg<'a>(min_indent: u16) -> impl Parser<'a, Located<TypeAnnotatio
|
|||
|
||||
fn loc_type_in_parens<'a>(
|
||||
min_indent: u16,
|
||||
) -> impl Parser<'a, Located<TypeAnnotation<'a>>, ETypeInParens<'a>> {
|
||||
) -> impl Parser<'a, Loc<TypeAnnotation<'a>>, ETypeInParens<'a>> {
|
||||
between!(
|
||||
word1(b'(', ETypeInParens::Open),
|
||||
space0_around_ee(
|
||||
|
@ -320,7 +320,7 @@ fn applied_type<'a>(min_indent: u16) -> impl Parser<'a, TypeAnnotation<'a>, ETyp
|
|||
// e.g. `Str Float` in `Map Str Float`
|
||||
loc_applied_args_e(min_indent)
|
||||
),
|
||||
|(ctor, args): (TypeAnnotation<'a>, Vec<'a, Located<TypeAnnotation<'a>>>)| {
|
||||
|(ctor, args): (TypeAnnotation<'a>, Vec<'a, Loc<TypeAnnotation<'a>>>)| {
|
||||
match &ctor {
|
||||
TypeAnnotation::Apply(module_name, name, _) => {
|
||||
if args.is_empty() {
|
||||
|
@ -340,14 +340,14 @@ fn applied_type<'a>(min_indent: u16) -> impl Parser<'a, TypeAnnotation<'a>, ETyp
|
|||
|
||||
fn loc_applied_args_e<'a>(
|
||||
min_indent: u16,
|
||||
) -> impl Parser<'a, Vec<'a, Located<TypeAnnotation<'a>>>, EType<'a>> {
|
||||
) -> impl Parser<'a, Vec<'a, Loc<TypeAnnotation<'a>>>, EType<'a>> {
|
||||
zero_or_more!(loc_applied_arg(min_indent))
|
||||
}
|
||||
|
||||
fn expression<'a>(
|
||||
min_indent: u16,
|
||||
is_trailing_comma_valid: bool,
|
||||
) -> impl Parser<'a, Located<TypeAnnotation<'a>>, EType<'a>> {
|
||||
) -> impl Parser<'a, Loc<TypeAnnotation<'a>>, EType<'a>> {
|
||||
(move |arena, state: State<'a>| {
|
||||
let (p1, first, state) = space0_before_e(
|
||||
term(min_indent),
|
||||
|
@ -402,7 +402,7 @@ fn expression<'a>(
|
|||
arguments.extend(rest);
|
||||
let output = arena.alloc(arguments);
|
||||
|
||||
let result = Located {
|
||||
let result = Loc {
|
||||
region: return_type.region,
|
||||
value: TypeAnnotation::Function(output, arena.alloc(return_type)),
|
||||
};
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue