mirror of
https://github.com/roc-lang/roc.git
synced 2025-09-19 18:19:46 +00:00
Merge branch 'to' into packages
This commit is contained in:
commit
ec9cf4efe2
14 changed files with 70 additions and 68 deletions
|
@ -2,7 +2,7 @@ use crate::ast::{Collection, CommentOrNewline, Spaced, Spaces, StrLiteral, TypeA
|
|||
use crate::blankspace::space0_e;
|
||||
use crate::ident::{lowercase_ident, UppercaseIdent};
|
||||
use crate::parser::{optional, then};
|
||||
use crate::parser::{specialize, word1, EPackageEntry, EPackageName, Parser};
|
||||
use crate::parser::{specialize, word1, EPackageEntry, EPackagePath, Parser};
|
||||
use crate::string_literal;
|
||||
use roc_module::symbol::{ModuleId, Symbol};
|
||||
use roc_region::all::Loc;
|
||||
|
@ -58,9 +58,9 @@ pub enum VersionComparison {
|
|||
}
|
||||
|
||||
#[derive(Copy, Clone, PartialEq, Eq, Debug)]
|
||||
pub struct PackageName<'a>(&'a str);
|
||||
pub struct PackagePath<'a>(&'a str);
|
||||
|
||||
impl<'a> PackageName<'a> {
|
||||
impl<'a> PackagePath<'a> {
|
||||
pub fn to_str(self) -> &'a str {
|
||||
self.0
|
||||
}
|
||||
|
@ -70,13 +70,13 @@ impl<'a> PackageName<'a> {
|
|||
}
|
||||
}
|
||||
|
||||
impl<'a> From<PackageName<'a>> for &'a str {
|
||||
fn from(name: PackageName<'a>) -> &'a str {
|
||||
impl<'a> From<PackagePath<'a>> for &'a str {
|
||||
fn from(name: PackagePath<'a>) -> &'a str {
|
||||
name.0
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> From<&'a str> for PackageName<'a> {
|
||||
impl<'a> From<&'a str> for PackagePath<'a> {
|
||||
fn from(string: &'a str) -> Self {
|
||||
Self(string)
|
||||
}
|
||||
|
@ -180,7 +180,7 @@ pub struct HostedHeader<'a> {
|
|||
#[derive(Copy, Clone, Debug, PartialEq, Eq)]
|
||||
pub enum To<'a> {
|
||||
ExistingPackage(&'a str),
|
||||
NewPackage(PackageName<'a>), // TODO is this obsolete? Seems like it should be deleted!
|
||||
NewPackage(PackagePath<'a>),
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, PartialEq)]
|
||||
|
@ -208,7 +208,7 @@ pub struct ProvidesTo<'a> {
|
|||
#[derive(Clone, Debug, PartialEq)]
|
||||
pub struct PackageHeader<'a> {
|
||||
pub before_name: &'a [CommentOrNewline<'a>],
|
||||
pub name: Loc<PackageName<'a>>,
|
||||
pub name: Loc<PackagePath<'a>>,
|
||||
|
||||
pub exposes: KeywordItem<'a, ExposesKeyword, Collection<'a, Loc<Spaced<'a, ModuleName<'a>>>>>,
|
||||
pub packages:
|
||||
|
@ -224,7 +224,7 @@ pub struct PlatformRequires<'a> {
|
|||
#[derive(Clone, Debug, PartialEq)]
|
||||
pub struct PlatformHeader<'a> {
|
||||
pub before_name: &'a [CommentOrNewline<'a>],
|
||||
pub name: Loc<PackageName<'a>>,
|
||||
pub name: Loc<PackagePath<'a>>,
|
||||
|
||||
pub requires: KeywordItem<'a, RequiresKeyword, PlatformRequires<'a>>,
|
||||
pub exposes: KeywordItem<'a, ExposesKeyword, Collection<'a, Loc<Spaced<'a, ModuleName<'a>>>>>,
|
||||
|
@ -265,7 +265,7 @@ pub struct TypedIdent<'a> {
|
|||
pub struct PackageEntry<'a> {
|
||||
pub shorthand: &'a str,
|
||||
pub spaces_after_shorthand: &'a [CommentOrNewline<'a>],
|
||||
pub package_name: Loc<PackageName<'a>>,
|
||||
pub package_path: Loc<PackagePath<'a>>,
|
||||
}
|
||||
|
||||
pub fn package_entry<'a>() -> impl Parser<'a, Spaced<'a, PackageEntry<'a>>, EPackageEntry<'a>> {
|
||||
|
@ -282,19 +282,19 @@ pub fn package_entry<'a>() -> impl Parser<'a, Spaced<'a, PackageEntry<'a>>, EPac
|
|||
),
|
||||
space0_e(EPackageEntry::IndentPackage)
|
||||
)),
|
||||
loc!(specialize(EPackageEntry::BadPackage, package_name()))
|
||||
loc!(specialize(EPackageEntry::BadPackage, package_path()))
|
||||
),
|
||||
move |(opt_shorthand, package_or_path)| {
|
||||
let entry = match opt_shorthand {
|
||||
Some((shorthand, spaces_after_shorthand)) => PackageEntry {
|
||||
shorthand,
|
||||
spaces_after_shorthand,
|
||||
package_name: package_or_path,
|
||||
package_path: package_or_path,
|
||||
},
|
||||
None => PackageEntry {
|
||||
shorthand: "",
|
||||
spaces_after_shorthand: &[],
|
||||
package_name: package_or_path,
|
||||
package_path: package_or_path,
|
||||
},
|
||||
};
|
||||
|
||||
|
@ -303,13 +303,13 @@ pub fn package_entry<'a>() -> impl Parser<'a, Spaced<'a, PackageEntry<'a>>, EPac
|
|||
)
|
||||
}
|
||||
|
||||
pub fn package_name<'a>() -> impl Parser<'a, PackageName<'a>, EPackageName<'a>> {
|
||||
pub fn package_path<'a>() -> impl Parser<'a, PackagePath<'a>, EPackagePath<'a>> {
|
||||
then(
|
||||
loc!(specialize(EPackageName::BadPath, string_literal::parse())),
|
||||
loc!(specialize(EPackagePath::BadPath, string_literal::parse())),
|
||||
move |_arena, state, progress, text| match text.value {
|
||||
StrLiteral::PlainLine(text) => Ok((progress, PackageName(text), state)),
|
||||
StrLiteral::Line(_) => Err((progress, EPackageName::Escapes(text.region.start()))),
|
||||
StrLiteral::Block(_) => Err((progress, EPackageName::Multiline(text.region.start()))),
|
||||
StrLiteral::PlainLine(text) => Ok((progress, PackagePath(text), state)),
|
||||
StrLiteral::Line(_) => Err((progress, EPackagePath::Escapes(text.region.start()))),
|
||||
StrLiteral::Block(_) => Err((progress, EPackagePath::Multiline(text.region.start()))),
|
||||
},
|
||||
)
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue