Parse a : before each effects entry

This commit is contained in:
Richard Feldman 2020-11-07 11:42:55 -05:00
parent 51b838010c
commit c8b28b96fa
4 changed files with 34 additions and 11 deletions

View File

@ -2454,7 +2454,11 @@ fn unpack_exposes_entries<'a>(
while let Some(effects_entry) = stack.pop() {
match effects_entry {
EffectsEntry::Effect { ident, ann } => {
EffectsEntry::Effect {
ident,
spaces_before_colon: _,
ann,
} => {
output.push((ident, ann));
}
EffectsEntry::SpaceAfter(nested, _) | EffectsEntry::SpaceBefore(nested, _) => {

View File

@ -75,6 +75,7 @@ pub enum EffectsEntry<'a> {
/// printLine : Str -> Effect {}
Effect {
ident: Loc<&'a str>,
spaces_before_colon: &'a [CommentOrNewline<'a>],
ann: Loc<TypeAnnotation<'a>>,
},

View File

@ -2,10 +2,10 @@ use crate::ast::{
AppHeader, Attempting, CommentOrNewline, Def, EffectsEntry, ExposesEntry, ImportsEntry,
InterfaceHeader, Module, PlatformHeader,
};
use crate::blankspace::{space0_around, space1};
use crate::blankspace::{space0, space0_around, space0_before, space1};
use crate::expr::def;
use crate::header::{ModuleName, PackageName};
use crate::ident::unqualified_ident;
use crate::ident::{lowercase_ident, unqualified_ident};
use crate::parser::{
self, ascii_char, ascii_string, loc, optional, peek_utf8_char, peek_utf8_char_at, unexpected,
unexpected_eof, ParseResult, Parser, State,
@ -350,13 +350,31 @@ fn effects<'a>() -> impl Parser<
#[inline(always)]
fn effects_entry<'a>() -> impl Parser<'a, EffectsEntry<'a>> {
move |arena, state| {
// You must have a field name, e.g. "email"
let (ident, state) = loc!(lowercase_ident()).parse(arena, state)?;
let (spaces_before_colon, state) = space0(0).parse(arena, state)?;
let (ann, state) = skip_first!(
ascii_char(':'),
space0_before(type_annotation::located(0), 0)
)
.parse(arena, state)?;
// e.g.
//
// printLine : Str -> Effect {}
map!(
and!(loc(unqualified_ident()), type_annotation::located(0)),
|(ident, ann)| { EffectsEntry::Effect { ident, ann } }
)
Ok((
EffectsEntry::Effect {
ident,
spaces_before_colon,
ann,
},
state,
))
}
}
#[inline(always)]

View File

@ -3,4 +3,4 @@ platform folkertdev/foo
requires [ main ]
imports []
effects
{ putChar Int -> Effect {}, putLine Str -> Effect {} }
{ putChar : Int -> Effect {}, putLine : Str -> Effect {} }