store the final comments in the AST for record & tag union annotations

This commit is contained in:
Sébastien Besnier 2020-11-18 15:41:17 +01:00
parent c692319fb9
commit 52bace2c25
3 changed files with 29 additions and 10 deletions

View file

@ -322,6 +322,7 @@ pub enum TypeAnnotation<'a> {
/// The row type variable in an open record, e.g. the `r` in `{ name: Str }r`.
/// This is None if it's a closed record annotation like `{ name: Str }`.
ext: Option<&'a Loc<TypeAnnotation<'a>>>,
final_comments: &'a [CommentOrNewline<'a>],
},
/// A tag union, e.g. `[
@ -330,6 +331,7 @@ pub enum TypeAnnotation<'a> {
/// The row type variable in an open tag union, e.g. the `a` in `[ Foo, Bar ]a`.
/// This is None if it's a closed tag union like `[ Foo, Bar]`.
ext: Option<&'a Loc<TypeAnnotation<'a>>>,
final_comments: &'a [CommentOrNewline<'a>],
},
/// The `*` type variable, e.g. in (List *)

View file

@ -21,7 +21,7 @@ macro_rules! tag_union {
($min_indent:expr) => {
map!(
and!(
collection!(
collection_trailing_sep!(
ascii_char(b'['),
loc!(tag_type($min_indent)),
ascii_char(b','),
@ -33,12 +33,13 @@ macro_rules! tag_union {
move |arena, state| allocated(term($min_indent)).parse(arena, state)
)
),
|(tags, ext): (
Vec<'a, Located<Tag<'a>>>,
|((tags, final_comments), ext): (
(Vec<'a, Located<Tag<'a>>>, &'a [CommentOrNewline<'a>]),
Option<&'a Located<TypeAnnotation<'a>>>,
)| TypeAnnotation::TagUnion {
tags: tags.into_bump_slice(),
ext,
final_comments
}
)
};
@ -168,13 +169,14 @@ fn record_type<'a>(min_indent: u16) -> impl Parser<'a, TypeAnnotation<'a>> {
|((fields, final_comments), ext): (
(
Vec<'a, Located<AssignedField<'a, TypeAnnotation<'a>>>>,
&[CommentOrNewline<'a>]
&'a [CommentOrNewline<'a>]
),
Option<&'a Located<TypeAnnotation<'a>>>,
)| {
Record {
fields: fields.into_bump_slice(),
ext,
final_comments,
}
}
)