mirror of
https://github.com/roc-lang/roc.git
synced 2024-09-22 08:17:40 +03:00
Parse a : before each effects entry
This commit is contained in:
parent
51b838010c
commit
c8b28b96fa
@ -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, _) => {
|
||||
|
@ -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>>,
|
||||
},
|
||||
|
||||
|
@ -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>> {
|
||||
// e.g.
|
||||
//
|
||||
// printLine : Str -> Effect {}
|
||||
map!(
|
||||
and!(loc(unqualified_ident()), type_annotation::located(0)),
|
||||
|(ident, ann)| { EffectsEntry::Effect { ident, ann } }
|
||||
)
|
||||
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 {}
|
||||
|
||||
Ok((
|
||||
EffectsEntry::Effect {
|
||||
ident,
|
||||
spaces_before_colon,
|
||||
ann,
|
||||
},
|
||||
state,
|
||||
))
|
||||
}
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
|
@ -3,4 +3,4 @@ platform folkertdev/foo
|
||||
requires [ main ]
|
||||
imports []
|
||||
effects
|
||||
{ putChar Int -> Effect {}, putLine Str -> Effect {} }
|
||||
{ putChar : Int -> Effect {}, putLine : Str -> Effect {} }
|
||||
|
Loading…
Reference in New Issue
Block a user