mirror of
https://github.com/roc-lang/roc.git
synced 2025-09-28 22:34:45 +00:00
change provides ... to
This commit is contained in:
parent
905301bf96
commit
784e3ddac4
2 changed files with 39 additions and 38 deletions
|
@ -3,14 +3,13 @@ use crate::blankspace::{space0, space0_around, space0_before, space0_e, space1};
|
||||||
use crate::expr::def;
|
use crate::expr::def;
|
||||||
use crate::header::{
|
use crate::header::{
|
||||||
package_entry, package_or_path, AppHeader, Effects, ExposesEntry, ImportsEntry,
|
package_entry, package_or_path, AppHeader, Effects, ExposesEntry, ImportsEntry,
|
||||||
InterfaceHeader, ModuleName, PackageEntry, PackageName, PackageOrPath, PlatformHeader, To,
|
InterfaceHeader, ModuleName, PackageEntry, PackageName, PlatformHeader, To, TypedIdent,
|
||||||
TypedIdent,
|
|
||||||
};
|
};
|
||||||
use crate::ident::{lowercase_ident, unqualified_ident, uppercase_ident};
|
use crate::ident::{lowercase_ident, unqualified_ident, uppercase_ident};
|
||||||
use crate::parser::Progress::{self, *};
|
use crate::parser::Progress::{self, *};
|
||||||
use crate::parser::{
|
use crate::parser::{
|
||||||
self, ascii_char, ascii_string, backtrackable, end_of_file, loc, optional, peek_utf8_char,
|
self, ascii_char, ascii_string, backtrackable, end_of_file, loc, optional, peek_utf8_char,
|
||||||
peek_utf8_char_at, specialize, unexpected, unexpected_eof, word1, EHeader, EProvides, Either,
|
peek_utf8_char_at, specialize, unexpected, unexpected_eof, word1, EHeader, EProvides,
|
||||||
ParseResult, Parser, State, SyntaxError,
|
ParseResult, Parser, State, SyntaxError,
|
||||||
};
|
};
|
||||||
use crate::string_literal;
|
use crate::string_literal;
|
||||||
|
@ -322,46 +321,44 @@ struct ProvidesTo<'a> {
|
||||||
|
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
fn provides_to<'a>() -> impl Parser<'a, ProvidesTo<'a>, SyntaxError<'a>> {
|
fn provides_to<'a>() -> impl Parser<'a, ProvidesTo<'a>, SyntaxError<'a>> {
|
||||||
|
specialize(
|
||||||
|
|e, r, c| SyntaxError::Header(EHeader::Provides(e, r, c)),
|
||||||
|
provides_to_help(),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
fn provides_to_package<'a>() -> impl Parser<'a, To<'a>, SyntaxError<'a>> {
|
||||||
|
one_of![
|
||||||
|
map!(lowercase_ident(), To::ExistingPackage),
|
||||||
|
map!(package_or_path(), To::NewPackage)
|
||||||
|
]
|
||||||
|
}
|
||||||
|
|
||||||
|
#[inline(always)]
|
||||||
|
fn provides_to_help<'a>() -> impl Parser<'a, ProvidesTo<'a>, EProvides> {
|
||||||
|
let min_indent = 1;
|
||||||
|
|
||||||
map!(
|
map!(
|
||||||
and!(
|
and!(
|
||||||
|
provides_without_to_help(),
|
||||||
and!(
|
and!(
|
||||||
skip_second!(backtrackable(space1(1)), ascii_string("provides")),
|
space0_e(min_indent, EProvides::Space, EProvides::IndentTo),
|
||||||
space1(1)
|
|
||||||
),
|
|
||||||
and!(
|
|
||||||
collection!(
|
|
||||||
ascii_char(b'['),
|
|
||||||
loc!(map!(unqualified_ident(), ExposesEntry::Exposed)),
|
|
||||||
ascii_char(b','),
|
|
||||||
ascii_char(b']'),
|
|
||||||
1
|
|
||||||
),
|
|
||||||
and!(
|
|
||||||
space1(1),
|
|
||||||
skip_first!(
|
skip_first!(
|
||||||
ascii_string("to"),
|
crate::parser::keyword_e("to", EProvides::To),
|
||||||
and!(
|
and!(
|
||||||
space1(1),
|
space0_e(min_indent, EProvides::Space, EProvides::IndentPackage),
|
||||||
loc!(either!(lowercase_ident(), package_or_path()))
|
loc!(specialize(
|
||||||
)
|
|_, r, c| EProvides::Package(r, c),
|
||||||
|
provides_to_package()
|
||||||
|
))
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
),
|
),
|
||||||
|(
|
|(
|
||||||
(before_provides_keyword, after_provides_keyword),
|
((before_provides_keyword, after_provides_keyword), entries),
|
||||||
(entries, (before_to_keyword, (after_to_keyword, loc_to))),
|
(before_to_keyword, (after_to_keyword, to)),
|
||||||
)| {
|
)| {
|
||||||
let loc_to: Located<Either<&'a str, PackageOrPath<'a>>> = loc_to;
|
|
||||||
let to_val = match loc_to.value {
|
|
||||||
Either::First(pkg) => To::ExistingPackage(pkg),
|
|
||||||
Either::Second(pkg) => To::NewPackage(pkg),
|
|
||||||
};
|
|
||||||
let to = Located {
|
|
||||||
value: to_val,
|
|
||||||
region: loc_to.region,
|
|
||||||
};
|
|
||||||
|
|
||||||
ProvidesTo {
|
ProvidesTo {
|
||||||
entries,
|
entries,
|
||||||
to,
|
to,
|
||||||
|
@ -402,8 +399,8 @@ fn provides_without_to_help<'a>() -> impl Parser<
|
||||||
and!(
|
and!(
|
||||||
and!(
|
and!(
|
||||||
skip_second!(
|
skip_second!(
|
||||||
space0_e(min_indent, EProvides::Space, EProvides::IndentKeyword),
|
space0_e(min_indent, EProvides::Space, EProvides::IndentProvides),
|
||||||
crate::parser::keyword_e("provides", EProvides::Keyword)
|
crate::parser::keyword_e("provides", EProvides::Provides)
|
||||||
),
|
),
|
||||||
space0_e(min_indent, EProvides::Space, EProvides::IndentListStart)
|
space0_e(min_indent, EProvides::Space, EProvides::IndentListStart)
|
||||||
),
|
),
|
||||||
|
|
|
@ -345,13 +345,17 @@ pub enum EHeader {
|
||||||
|
|
||||||
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
||||||
pub enum EProvides {
|
pub enum EProvides {
|
||||||
Keyword(Row, Col),
|
Provides(Row, Col),
|
||||||
IndentKeyword(Row, Col),
|
To(Row, Col),
|
||||||
|
IndentProvides(Row, Col),
|
||||||
|
IndentTo(Row, Col),
|
||||||
IndentListStart(Row, Col),
|
IndentListStart(Row, Col),
|
||||||
IndentListEnd(Row, Col),
|
IndentListEnd(Row, Col),
|
||||||
|
IndentPackage(Row, Col),
|
||||||
ListStart(Row, Col),
|
ListStart(Row, Col),
|
||||||
ListEnd(Row, Col),
|
ListEnd(Row, Col),
|
||||||
Identifier(Row, Col),
|
Identifier(Row, Col),
|
||||||
|
Package(Row, Col),
|
||||||
Space(BadInputError, Row, Col),
|
Space(BadInputError, Row, Col),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue