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() { while let Some(effects_entry) = stack.pop() {
match effects_entry { match effects_entry {
EffectsEntry::Effect { ident, ann } => { EffectsEntry::Effect {
ident,
spaces_before_colon: _,
ann,
} => {
output.push((ident, ann)); output.push((ident, ann));
} }
EffectsEntry::SpaceAfter(nested, _) | EffectsEntry::SpaceBefore(nested, _) => { EffectsEntry::SpaceAfter(nested, _) | EffectsEntry::SpaceBefore(nested, _) => {

View File

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

View File

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

View File

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