mirror of
https://github.com/roc-lang/roc.git
synced 2025-09-28 22:34:45 +00:00
Attach location to alias header name
This commit is contained in:
parent
11da888c07
commit
597a1cef3b
5 changed files with 18 additions and 22 deletions
|
@ -461,7 +461,7 @@ pub fn to_type2<'a>(
|
||||||
) => {
|
) => {
|
||||||
// e.g. `{ x : Int, y : Int } as Point`
|
// e.g. `{ x : Int, y : Int } as Point`
|
||||||
let symbol = match scope.introduce(
|
let symbol = match scope.introduce(
|
||||||
(*name).into(),
|
name.value.into(),
|
||||||
&env.exposed_ident_ids,
|
&env.exposed_ident_ids,
|
||||||
&mut env.ident_ids,
|
&mut env.ident_ids,
|
||||||
region,
|
region,
|
||||||
|
|
|
@ -383,7 +383,7 @@ fn can_annotation_help(
|
||||||
},
|
},
|
||||||
) => {
|
) => {
|
||||||
let symbol = match scope.introduce(
|
let symbol = match scope.introduce(
|
||||||
(*name).into(),
|
name.value.into(),
|
||||||
&env.exposed_ident_ids,
|
&env.exposed_ident_ids,
|
||||||
&mut env.ident_ids,
|
&mut env.ident_ids,
|
||||||
region,
|
region,
|
||||||
|
|
|
@ -251,7 +251,7 @@ impl<'a> Formattable for TypeAnnotation<'a> {
|
||||||
buf.spaces(1);
|
buf.spaces(1);
|
||||||
buf.push_str("as");
|
buf.push_str("as");
|
||||||
buf.spaces(1);
|
buf.spaces(1);
|
||||||
buf.push_str(name);
|
buf.push_str(name.value);
|
||||||
for var in *vars {
|
for var in *vars {
|
||||||
buf.spaces(1);
|
buf.spaces(1);
|
||||||
buf.push_str(var.value);
|
buf.push_str(var.value);
|
||||||
|
|
|
@ -227,7 +227,7 @@ pub struct PrecedenceConflict<'a> {
|
||||||
|
|
||||||
#[derive(Debug, Clone, Copy, PartialEq)]
|
#[derive(Debug, Clone, Copy, PartialEq)]
|
||||||
pub struct AliasHeader<'a> {
|
pub struct AliasHeader<'a> {
|
||||||
pub name: &'a str,
|
pub name: Loc<&'a str>,
|
||||||
pub vars: &'a [Loc<&'a str>],
|
pub vars: &'a [Loc<&'a str>],
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -9,7 +9,7 @@ use crate::parser::{
|
||||||
use crate::state::State;
|
use crate::state::State;
|
||||||
use bumpalo::collections::vec::Vec;
|
use bumpalo::collections::vec::Vec;
|
||||||
use bumpalo::Bump;
|
use bumpalo::Bump;
|
||||||
use roc_region::all::{Loc, Position};
|
use roc_region::all::{Loc, Position, Region};
|
||||||
|
|
||||||
pub fn located_help<'a>(
|
pub fn located_help<'a>(
|
||||||
min_indent: u16,
|
min_indent: u16,
|
||||||
|
@ -50,7 +50,7 @@ fn tag_union_type<'a>(min_indent: u16) -> impl Parser<'a, TypeAnnotation<'a>, ET
|
||||||
fn check_type_alias(
|
fn check_type_alias(
|
||||||
p: Progress,
|
p: Progress,
|
||||||
annot: Loc<TypeAnnotation>,
|
annot: Loc<TypeAnnotation>,
|
||||||
) -> impl Parser<Loc<AliasHeader>, ETypeInlineAlias> {
|
) -> impl Parser<AliasHeader, ETypeInlineAlias> {
|
||||||
move |arena, state| match annot.value {
|
move |arena, state| match annot.value {
|
||||||
TypeAnnotation::Apply("", tag_name, vars) => {
|
TypeAnnotation::Apply("", tag_name, vars) => {
|
||||||
let mut var_names = Vec::new_in(arena);
|
let mut var_names = Vec::new_in(arena);
|
||||||
|
@ -67,12 +67,16 @@ fn check_type_alias(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let name_start = annot.region.start();
|
||||||
|
let name_region =
|
||||||
|
Region::between(name_start, name_start.bump_column(tag_name.len() as u16));
|
||||||
|
|
||||||
let header = AliasHeader {
|
let header = AliasHeader {
|
||||||
name: tag_name,
|
name: Loc::at(name_region, tag_name),
|
||||||
vars: var_names.into_bump_slice(),
|
vars: var_names.into_bump_slice(),
|
||||||
};
|
};
|
||||||
|
|
||||||
Ok((p, Loc::at(annot.region, header), state))
|
Ok((p, header, state))
|
||||||
}
|
}
|
||||||
TypeAnnotation::Apply(_, _, _) => {
|
TypeAnnotation::Apply(_, _, _) => {
|
||||||
Err((p, ETypeInlineAlias::Qualified(annot.region.start()), state))
|
Err((p, ETypeInlineAlias::Qualified(annot.region.start()), state))
|
||||||
|
@ -81,9 +85,7 @@ fn check_type_alias(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn parse_type_alias_after_as<'a>(
|
fn parse_type_alias_after_as<'a>(min_indent: u16) -> impl Parser<'a, AliasHeader<'a>, EType<'a>> {
|
||||||
min_indent: u16,
|
|
||||||
) -> impl Parser<'a, Loc<AliasHeader<'a>>, EType<'a>> {
|
|
||||||
move |arena, state| {
|
move |arena, state| {
|
||||||
space0_before_e(
|
space0_before_e(
|
||||||
term(min_indent),
|
term(min_indent),
|
||||||
|
@ -131,18 +133,12 @@ fn term<'a>(min_indent: u16) -> impl Parser<'a, Loc<TypeAnnotation<'a>>, EType<'
|
||||||
]
|
]
|
||||||
),
|
),
|
||||||
|arena: &'a Bump,
|
|arena: &'a Bump,
|
||||||
(loc_ann, opt_as): (
|
(loc_ann, opt_as): (Loc<TypeAnnotation<'a>>, Option<(&'a [_], AliasHeader<'a>)>)| {
|
||||||
Loc<TypeAnnotation<'a>>,
|
|
||||||
Option<(&'a [_], Loc<AliasHeader<'a>>)>
|
|
||||||
)| {
|
|
||||||
match opt_as {
|
match opt_as {
|
||||||
Some((
|
Some((spaces, alias)) => {
|
||||||
spaces,
|
let alias_vars_region =
|
||||||
Loc {
|
Region::across_all(alias.vars.into_iter().map(|v| &v.region));
|
||||||
region,
|
let region = Region::span_across(&loc_ann.region, &alias_vars_region);
|
||||||
value: alias,
|
|
||||||
},
|
|
||||||
)) => {
|
|
||||||
let value = TypeAnnotation::As(arena.alloc(loc_ann), spaces, alias);
|
let value = TypeAnnotation::As(arena.alloc(loc_ann), spaces, alias);
|
||||||
|
|
||||||
Loc { region, value }
|
Loc { region, value }
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue