mirror of
https://github.com/roc-lang/roc.git
synced 2025-09-26 13:29:12 +00:00
add very rough framework of how the parse might need to change
This commit is contained in:
parent
1059c81d33
commit
99547086ee
6 changed files with 91 additions and 37 deletions
|
@ -507,5 +507,11 @@ fn fmt_imports_entry<'a, 'buf>(buf: &mut Buf<'buf>, entry: &ImportsEntry<'a>, in
|
||||||
fmt_collection(buf, indent, Braces::Curly, *entries, Newlines::No)
|
fmt_collection(buf, indent, Braces::Curly, *entries, Newlines::No)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
IngestedFile(file_name, typed_ident) => {
|
||||||
|
fmt_str_literal(buf, *file_name, indent);
|
||||||
|
buf.push_str(" as ");
|
||||||
|
typed_ident.format(buf, 0);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -420,6 +420,9 @@ impl<'a> RemoveSpaces<'a> for ImportsEntry<'a> {
|
||||||
match *self {
|
match *self {
|
||||||
ImportsEntry::Module(a, b) => ImportsEntry::Module(a, b.remove_spaces(arena)),
|
ImportsEntry::Module(a, b) => ImportsEntry::Module(a, b.remove_spaces(arena)),
|
||||||
ImportsEntry::Package(a, b, c) => ImportsEntry::Package(a, b, c.remove_spaces(arena)),
|
ImportsEntry::Package(a, b, c) => ImportsEntry::Package(a, b, c.remove_spaces(arena)),
|
||||||
|
ImportsEntry::IngestedFile(a, b) => {
|
||||||
|
ImportsEntry::IngestedFile(a, b.remove_spaces(arena))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -4490,7 +4490,8 @@ fn build_header<'a>(
|
||||||
let mut scope_size = 0;
|
let mut scope_size = 0;
|
||||||
|
|
||||||
for loc_entry in imports {
|
for loc_entry in imports {
|
||||||
let (qualified_module_name, exposed) = exposed_from_import(&loc_entry.value);
|
let (qualified_module_name, exposed) =
|
||||||
|
exposed_from_import(&loc_entry.value, &declared_name);
|
||||||
|
|
||||||
scope_size += num_exposes;
|
scope_size += num_exposes;
|
||||||
|
|
||||||
|
@ -5620,7 +5621,10 @@ fn parse<'a>(arena: &'a Bump, header: ModuleHeader<'a>) -> Result<Msg<'a>, Loadi
|
||||||
Ok(Msg::Parsed(parsed))
|
Ok(Msg::Parsed(parsed))
|
||||||
}
|
}
|
||||||
|
|
||||||
fn exposed_from_import<'a>(entry: &ImportsEntry<'a>) -> (QualifiedModuleName<'a>, Vec<Loc<Ident>>) {
|
fn exposed_from_import<'a>(
|
||||||
|
entry: &ImportsEntry<'a>,
|
||||||
|
current_module: &ModuleName,
|
||||||
|
) -> (QualifiedModuleName<'a>, Vec<Loc<Ident>>) {
|
||||||
use roc_parse::header::ImportsEntry::*;
|
use roc_parse::header::ImportsEntry::*;
|
||||||
|
|
||||||
match entry {
|
match entry {
|
||||||
|
@ -5653,6 +5657,21 @@ fn exposed_from_import<'a>(entry: &ImportsEntry<'a>) -> (QualifiedModuleName<'a>
|
||||||
|
|
||||||
(qualified_module_name, exposed)
|
(qualified_module_name, exposed)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
IngestedFile(_, typed_ident) => {
|
||||||
|
let exposed = vec![typed_ident
|
||||||
|
.extract_spaces()
|
||||||
|
.item
|
||||||
|
.ident
|
||||||
|
.map(|&ident_str| Ident(ident_str.into()))];
|
||||||
|
|
||||||
|
let qualified_module_name = QualifiedModuleName {
|
||||||
|
opt_package: None,
|
||||||
|
module: current_module.to_owned(),
|
||||||
|
};
|
||||||
|
|
||||||
|
(qualified_module_name, exposed)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -277,6 +277,9 @@ pub enum ImportsEntry<'a> {
|
||||||
ModuleName<'a>,
|
ModuleName<'a>,
|
||||||
Collection<'a, Loc<Spaced<'a, ExposedName<'a>>>>,
|
Collection<'a, Loc<Spaced<'a, ExposedName<'a>>>>,
|
||||||
),
|
),
|
||||||
|
|
||||||
|
/// e.g "path/to/my/file.txt" as myFile : Str
|
||||||
|
IngestedFile(StrLiteral<'a>, Spaced<'a, TypedIdent<'a>>),
|
||||||
}
|
}
|
||||||
|
|
||||||
/// e.g.
|
/// e.g.
|
||||||
|
|
|
@ -9,12 +9,12 @@ use crate::header::{
|
||||||
use crate::ident::{self, lowercase_ident, unqualified_ident, uppercase, UppercaseIdent};
|
use crate::ident::{self, lowercase_ident, unqualified_ident, uppercase, UppercaseIdent};
|
||||||
use crate::parser::Progress::{self, *};
|
use crate::parser::Progress::{self, *};
|
||||||
use crate::parser::{
|
use crate::parser::{
|
||||||
backtrackable, increment_min_indent, optional, reset_min_indent, specialize, word1, EExposes,
|
backtrackable, increment_min_indent, optional, reset_min_indent, specialize, word1, word2,
|
||||||
EGenerates, EGeneratesWith, EHeader, EImports, EPackages, EProvides, ERequires, ETypedIdent,
|
EExposes, EGenerates, EGeneratesWith, EHeader, EImports, EPackages, EProvides, ERequires,
|
||||||
Parser, SourceError, SpaceProblem, SyntaxError,
|
ETypedIdent, Parser, SourceError, SpaceProblem, SyntaxError,
|
||||||
};
|
};
|
||||||
use crate::state::State;
|
use crate::state::State;
|
||||||
use crate::string_literal;
|
use crate::string_literal::{self, parse_str_literal};
|
||||||
use crate::type_annotation;
|
use crate::type_annotation;
|
||||||
use roc_region::all::{Loc, Position};
|
use roc_region::all::{Loc, Position};
|
||||||
|
|
||||||
|
@ -606,40 +606,60 @@ fn imports_entry<'a>() -> impl Parser<'a, Spaced<'a, ImportsEntry<'a>>, EImports
|
||||||
Option<Collection<'a, Loc<Spaced<'a, ExposedName<'a>>>>>,
|
Option<Collection<'a, Loc<Spaced<'a, ExposedName<'a>>>>>,
|
||||||
);
|
);
|
||||||
|
|
||||||
map_with_arena!(
|
one_of!(
|
||||||
and!(
|
map!(
|
||||||
and!(
|
and!(
|
||||||
// e.g. `pf.`
|
and!(
|
||||||
optional(backtrackable(skip_second!(
|
// e.g. `pf.`
|
||||||
shortname(),
|
optional(backtrackable(skip_second!(
|
||||||
word1(b'.', EImports::ShorthandDot)
|
shortname(),
|
||||||
))),
|
word1(b'.', EImports::ShorthandDot)
|
||||||
// e.g. `Task`
|
))),
|
||||||
module_name_help(EImports::ModuleName)
|
// e.g. `Task`
|
||||||
|
module_name_help(EImports::ModuleName)
|
||||||
|
),
|
||||||
|
// e.g. `.{ Task, after}`
|
||||||
|
optional(skip_first!(
|
||||||
|
word1(b'.', EImports::ExposingDot),
|
||||||
|
collection_trailing_sep_e!(
|
||||||
|
word1(b'{', EImports::SetStart),
|
||||||
|
exposes_entry(EImports::Identifier),
|
||||||
|
word1(b',', EImports::SetEnd),
|
||||||
|
word1(b'}', EImports::SetEnd),
|
||||||
|
Spaced::SpaceBefore
|
||||||
|
)
|
||||||
|
))
|
||||||
),
|
),
|
||||||
// e.g. `.{ Task, after}`
|
|((opt_shortname, module_name), opt_values): Temp<'a>| {
|
||||||
optional(skip_first!(
|
let exposed_values = opt_values.unwrap_or_else(Collection::empty);
|
||||||
word1(b'.', EImports::ExposingDot),
|
|
||||||
collection_trailing_sep_e!(
|
let entry = match opt_shortname {
|
||||||
word1(b'{', EImports::SetStart),
|
Some(shortname) => {
|
||||||
exposes_entry(EImports::Identifier),
|
ImportsEntry::Package(shortname, module_name, exposed_values)
|
||||||
word1(b',', EImports::SetEnd),
|
}
|
||||||
word1(b'}', EImports::SetEnd),
|
|
||||||
Spaced::SpaceBefore
|
None => ImportsEntry::Module(module_name, exposed_values),
|
||||||
)
|
};
|
||||||
))
|
|
||||||
|
Spaced::Item(entry)
|
||||||
|
}
|
||||||
),
|
),
|
||||||
|_arena, ((opt_shortname, module_name), opt_values): Temp<'a>| {
|
map!(
|
||||||
let exposed_values = opt_values.unwrap_or_else(Collection::empty);
|
and!(
|
||||||
|
and!(
|
||||||
let entry = match opt_shortname {
|
// e.g. "filename"
|
||||||
Some(shortname) => ImportsEntry::Package(shortname, module_name, exposed_values),
|
// TODO: str literal allows for multiline strings. We probably don't want that for file names.
|
||||||
|
specialize(|_, pos| EImports::StrLiteral(pos), parse_str_literal()),
|
||||||
None => ImportsEntry::Module(module_name, exposed_values),
|
// e.g. as
|
||||||
};
|
word2(b'a', b's', EImports::AsKeyword)
|
||||||
|
),
|
||||||
Spaced::Item(entry)
|
// e.g. file : Str
|
||||||
}
|
specialize(|_, pos| EImports::TypedIdent(pos), typed_ident())
|
||||||
|
),
|
||||||
|
|((file_name, _), typed_ident)| {
|
||||||
|
Spaced::Item(ImportsEntry::IngestedFile(file_name, typed_ident))
|
||||||
|
}
|
||||||
|
)
|
||||||
)
|
)
|
||||||
.trace("imports_entry")
|
.trace("imports_entry")
|
||||||
}
|
}
|
||||||
|
|
|
@ -232,6 +232,9 @@ pub enum EImports {
|
||||||
IndentSetStart(Position),
|
IndentSetStart(Position),
|
||||||
SetStart(Position),
|
SetStart(Position),
|
||||||
SetEnd(Position),
|
SetEnd(Position),
|
||||||
|
TypedIdent(Position),
|
||||||
|
AsKeyword(Position),
|
||||||
|
StrLiteral(Position),
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue