mirror of
https://github.com/roc-lang/roc.git
synced 2025-09-27 05:49:08 +00:00
New app
header syntax
Implements the new app header syntax as discussed in Zulip [1].
app [main] {
cli: platform "../platform/main.roc",
json: "../json/main.roc"
}
Old headers still parse and are automatically upgraded to the new
syntax by the formatter.
[1] 418444862
This commit is contained in:
parent
057a18573a
commit
8dedd9f03c
90 changed files with 1044 additions and 1056 deletions
|
@ -38,7 +38,6 @@ impl<'a> HeaderType<'a> {
|
|||
#[derive(Debug)]
|
||||
pub enum HeaderType<'a> {
|
||||
App {
|
||||
output_name: StrLiteral<'a>,
|
||||
provides: &'a [Loc<ExposedName<'a>>],
|
||||
to_platform: To<'a>,
|
||||
},
|
||||
|
@ -85,11 +84,7 @@ impl<'a> HeaderType<'a> {
|
|||
Self::Module { name, .. } | Self::Builtin { name, .. } | Self::Hosted { name, .. } => {
|
||||
Some(name.into())
|
||||
}
|
||||
Self::App {
|
||||
output_name: StrLiteral::PlainLine(name),
|
||||
..
|
||||
}
|
||||
| Self::Platform {
|
||||
Self::Platform {
|
||||
config_shorthand: name,
|
||||
..
|
||||
}
|
||||
|
@ -234,6 +229,8 @@ keywords! {
|
|||
RequiresKeyword => "requires",
|
||||
ProvidesKeyword => "provides",
|
||||
ToKeyword => "to",
|
||||
PlatformKeyword => "platform",
|
||||
// Deprecated
|
||||
ImportsKeyword => "imports",
|
||||
}
|
||||
|
||||
|
@ -276,14 +273,13 @@ pub enum To<'a> {
|
|||
|
||||
#[derive(Clone, Debug, PartialEq)]
|
||||
pub struct AppHeader<'a> {
|
||||
pub before_name: &'a [CommentOrNewline<'a>],
|
||||
pub name: Loc<StrLiteral<'a>>,
|
||||
|
||||
pub packages:
|
||||
Option<KeywordItem<'a, PackagesKeyword, Collection<'a, Loc<Spaced<'a, PackageEntry<'a>>>>>>,
|
||||
pub imports:
|
||||
Option<KeywordItem<'a, ImportsKeyword, Collection<'a, Loc<Spaced<'a, ImportsEntry<'a>>>>>>,
|
||||
pub provides: ProvidesTo<'a>,
|
||||
pub before_provides: &'a [CommentOrNewline<'a>],
|
||||
pub provides: Collection<'a, Loc<Spaced<'a, ExposedName<'a>>>>,
|
||||
pub before_packages: &'a [CommentOrNewline<'a>],
|
||||
pub packages: Loc<Collection<'a, Loc<Spaced<'a, PackageEntry<'a>>>>>,
|
||||
// Old header pieces
|
||||
pub old_imports: Option<KeywordItem<'a, ImportsKeyword, ImportsCollection<'a>>>,
|
||||
pub old_provides_to_new_package: Option<PackageName<'a>>,
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, PartialEq)]
|
||||
|
@ -359,6 +355,7 @@ pub struct TypedIdent<'a> {
|
|||
pub struct PackageEntry<'a> {
|
||||
pub shorthand: &'a str,
|
||||
pub spaces_after_shorthand: &'a [CommentOrNewline<'a>],
|
||||
pub platform_marker: Option<&'a [CommentOrNewline<'a>]>,
|
||||
pub package_name: Loc<PackageName<'a>>,
|
||||
}
|
||||
|
||||
|
@ -379,9 +376,15 @@ pub fn package_entry<'a>() -> impl Parser<'a, Spaced<'a, PackageEntry<'a>>, EPac
|
|||
),
|
||||
space0_e(EPackageEntry::IndentPackage)
|
||||
)),
|
||||
loc!(specialize_err(EPackageEntry::BadPackage, package_name()))
|
||||
and!(
|
||||
optional(skip_first!(
|
||||
crate::parser::keyword(crate::keyword::PLATFORM, EPackageEntry::Platform),
|
||||
space0_e(EPackageEntry::IndentPackage)
|
||||
)),
|
||||
loc!(specialize_err(EPackageEntry::BadPackage, package_name()))
|
||||
)
|
||||
),
|
||||
move |arena, (opt_shorthand, package_or_path)| {
|
||||
move |arena, (opt_shorthand, (platform_marker, package_or_path))| {
|
||||
let entry = match opt_shorthand {
|
||||
Some(((shorthand, spaces_before_colon), spaces_after_colon)) => PackageEntry {
|
||||
shorthand,
|
||||
|
@ -390,11 +393,13 @@ pub fn package_entry<'a>() -> impl Parser<'a, Spaced<'a, PackageEntry<'a>>, EPac
|
|||
spaces_before_colon,
|
||||
spaces_after_colon,
|
||||
),
|
||||
platform_marker,
|
||||
package_name: package_or_path,
|
||||
},
|
||||
None => PackageEntry {
|
||||
shorthand: "",
|
||||
spaces_after_shorthand: &[],
|
||||
platform_marker,
|
||||
package_name: package_or_path,
|
||||
},
|
||||
};
|
||||
|
@ -442,7 +447,7 @@ impl<'a> Malformed for HostedHeader<'a> {
|
|||
|
||||
impl<'a> Malformed for AppHeader<'a> {
|
||||
fn is_malformed(&self) -> bool {
|
||||
self.name.is_malformed()
|
||||
false
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue