mirror of
https://github.com/roc-lang/roc.git
synced 2025-08-03 03:42:17 +00:00
Merge pull request #7335 from faldor20/add-lsp-range-info-for-file-load-errors-
Add lsp range info for file load errors
This commit is contained in:
commit
27b36a8f1f
17 changed files with 784 additions and 51 deletions
|
@ -702,7 +702,7 @@ pub fn handle_error_module(
|
|||
|
||||
pub fn handle_loading_problem(problem: LoadingProblem) -> std::io::Result<i32> {
|
||||
match problem {
|
||||
LoadingProblem::FormattedReport(report) => {
|
||||
LoadingProblem::FormattedReport(report, _) => {
|
||||
print!("{report}");
|
||||
Ok(1)
|
||||
}
|
||||
|
|
|
@ -88,7 +88,7 @@ fn write_types_for_module_real(module_id: ModuleId, filename: &str, output_path:
|
|||
|
||||
let mut module = match res_module {
|
||||
Ok(v) => v,
|
||||
Err(LoadingProblem::FormattedReport(report)) => {
|
||||
Err(LoadingProblem::FormattedReport(report, _)) => {
|
||||
internal_error!("{}", report);
|
||||
}
|
||||
Err(other) => {
|
||||
|
|
|
@ -187,7 +187,7 @@ mod test_reporting {
|
|||
let mut buf = String::new();
|
||||
|
||||
match infer_expr_help_new(subdir, arena, src) {
|
||||
Err(LoadingProblem::FormattedReport(fail)) => fail,
|
||||
Err(LoadingProblem::FormattedReport(fail, _)) => fail,
|
||||
Ok((module_src, type_problems, can_problems, home, interns)) => {
|
||||
let lines = LineInfo::new(&module_src);
|
||||
let src_lines: Vec<&str> = module_src.split('\n').collect();
|
||||
|
|
|
@ -998,13 +998,52 @@ pub enum LoadingProblem<'a> {
|
|||
TriedToImportAppModule,
|
||||
|
||||
/// a formatted report
|
||||
FormattedReport(String),
|
||||
FormattedReport(String, Option<Region>),
|
||||
|
||||
ImportCycle(PathBuf, Vec<ModuleId>),
|
||||
IncorrectModuleName(FileError<'a, IncorrectModuleName<'a>>),
|
||||
CouldNotFindCacheDir,
|
||||
ChannelProblem(ChannelProblem),
|
||||
}
|
||||
impl<'a> LoadingProblem<'a> {
|
||||
pub fn get_region(&self) -> Option<Region> {
|
||||
match self {
|
||||
LoadingProblem::ParsingFailed(err) => err.problem.problem.get_region(),
|
||||
LoadingProblem::MultiplePlatformPackages {
|
||||
filename: _,
|
||||
module_id: _,
|
||||
source: _,
|
||||
region,
|
||||
} => Some(*region),
|
||||
LoadingProblem::NoPlatformPackage {
|
||||
filename: _,
|
||||
module_id: _,
|
||||
source: _,
|
||||
region,
|
||||
} => Some(*region),
|
||||
LoadingProblem::UnrecognizedPackageShorthand {
|
||||
filename: _,
|
||||
module_id: _,
|
||||
source: _,
|
||||
region,
|
||||
shorthand: _,
|
||||
available: _,
|
||||
} => Some(*region),
|
||||
LoadingProblem::FileProblem {
|
||||
filename: _,
|
||||
error: _,
|
||||
} => None,
|
||||
LoadingProblem::UnexpectedHeader(_) => None,
|
||||
LoadingProblem::ErrJoiningWorkerThreads => None,
|
||||
LoadingProblem::TriedToImportAppModule => None,
|
||||
LoadingProblem::FormattedReport(_, region) => *region,
|
||||
LoadingProblem::ImportCycle(_, _) => None,
|
||||
LoadingProblem::IncorrectModuleName(_) => None,
|
||||
LoadingProblem::CouldNotFindCacheDir => None,
|
||||
LoadingProblem::ChannelProblem(_) => None,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
pub enum AvailableShorthands<'a> {
|
||||
|
@ -1179,12 +1218,12 @@ impl<'a> LoadStart<'a> {
|
|||
})
|
||||
.into_inner()
|
||||
.into_module_ids();
|
||||
|
||||
let region = problem.get_region();
|
||||
let report = report_loading_problem(problem, module_ids, render, palette);
|
||||
|
||||
// TODO try to gracefully recover and continue
|
||||
// instead of changing the control flow to exit.
|
||||
return Err(LoadingProblem::FormattedReport(report));
|
||||
return Err(LoadingProblem::FormattedReport(report, region));
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -1672,10 +1711,11 @@ fn state_thread_step<'a>(
|
|||
}
|
||||
Msg::FailedToReadFile { filename, error } => {
|
||||
let buf = to_file_problem_report_string(filename, error, true);
|
||||
Err(LoadingProblem::FormattedReport(buf))
|
||||
Err(LoadingProblem::FormattedReport(buf, None))
|
||||
}
|
||||
|
||||
Msg::FailedToParse(problem) => {
|
||||
let region = problem.problem.problem.get_region();
|
||||
let module_ids = (*state.arc_modules).lock().clone().into_module_ids();
|
||||
let buf = to_parse_problem_report(
|
||||
problem,
|
||||
|
@ -1684,14 +1724,14 @@ fn state_thread_step<'a>(
|
|||
state.render,
|
||||
state.palette,
|
||||
);
|
||||
Err(LoadingProblem::FormattedReport(buf))
|
||||
Err(LoadingProblem::FormattedReport(buf, region))
|
||||
}
|
||||
Msg::IncorrectModuleName(FileError {
|
||||
problem: SourceError { problem, bytes },
|
||||
filename,
|
||||
}) => {
|
||||
let module_ids = (*state.arc_modules).lock().clone().into_module_ids();
|
||||
let buf = to_incorrect_module_name_report(
|
||||
let (buf, region) = to_incorrect_module_name_report(
|
||||
module_ids,
|
||||
state.constrained_ident_ids,
|
||||
problem,
|
||||
|
@ -1699,7 +1739,7 @@ fn state_thread_step<'a>(
|
|||
bytes,
|
||||
state.render,
|
||||
);
|
||||
Err(LoadingProblem::FormattedReport(buf))
|
||||
Err(LoadingProblem::FormattedReport(buf, Some(region)))
|
||||
}
|
||||
msg => {
|
||||
// This is where most of the main thread's work gets done.
|
||||
|
@ -1716,6 +1756,7 @@ fn state_thread_step<'a>(
|
|||
match res_state {
|
||||
Ok(new_state) => Ok(ControlFlow::Continue(new_state)),
|
||||
Err(LoadingProblem::ParsingFailed(problem)) => {
|
||||
let region = problem.problem.problem.get_region();
|
||||
let module_ids = Arc::try_unwrap(arc_modules)
|
||||
.unwrap_or_else(|_| {
|
||||
panic!(
|
||||
|
@ -1734,7 +1775,7 @@ fn state_thread_step<'a>(
|
|||
render,
|
||||
palette,
|
||||
);
|
||||
Err(LoadingProblem::FormattedReport(buf))
|
||||
Err(LoadingProblem::FormattedReport(buf, region))
|
||||
}
|
||||
Err(LoadingProblem::ImportCycle(filename, cycle)) => {
|
||||
let module_ids = arc_modules.lock().clone().into_module_ids();
|
||||
|
@ -1747,7 +1788,7 @@ fn state_thread_step<'a>(
|
|||
filename,
|
||||
render,
|
||||
);
|
||||
return Err(LoadingProblem::FormattedReport(buf));
|
||||
return Err(LoadingProblem::FormattedReport(buf, None));
|
||||
}
|
||||
Err(LoadingProblem::IncorrectModuleName(FileError {
|
||||
problem: SourceError { problem, bytes },
|
||||
|
@ -1756,7 +1797,7 @@ fn state_thread_step<'a>(
|
|||
let module_ids = arc_modules.lock().clone().into_module_ids();
|
||||
|
||||
let root_exposed_ident_ids = IdentIds::exposed_builtins(0);
|
||||
let buf = to_incorrect_module_name_report(
|
||||
let (buf, region) = to_incorrect_module_name_report(
|
||||
module_ids,
|
||||
root_exposed_ident_ids,
|
||||
problem,
|
||||
|
@ -1764,7 +1805,7 @@ fn state_thread_step<'a>(
|
|||
bytes,
|
||||
render,
|
||||
);
|
||||
return Err(LoadingProblem::FormattedReport(buf));
|
||||
return Err(LoadingProblem::FormattedReport(buf, Some(region)));
|
||||
}
|
||||
Err(LoadingProblem::UnrecognizedPackageShorthand {
|
||||
filename,
|
||||
|
@ -1788,7 +1829,7 @@ fn state_thread_step<'a>(
|
|||
available,
|
||||
render,
|
||||
);
|
||||
return Err(LoadingProblem::FormattedReport(buf));
|
||||
return Err(LoadingProblem::FormattedReport(buf, Some(region)));
|
||||
}
|
||||
Err(e) => Err(e),
|
||||
}
|
||||
|
@ -1836,8 +1877,9 @@ pub fn report_loading_problem(
|
|||
bytes,
|
||||
render,
|
||||
)
|
||||
.0
|
||||
}
|
||||
LoadingProblem::FormattedReport(report) => report,
|
||||
LoadingProblem::FormattedReport(report, _region) => report,
|
||||
LoadingProblem::FileProblem { filename, error } => {
|
||||
to_file_problem_report_string(filename, error, true)
|
||||
}
|
||||
|
@ -2085,7 +2127,7 @@ fn load_multi_threaded<'a>(
|
|||
"command can sometimes give a more helpful error report than other commands.\n\n"
|
||||
)
|
||||
.to_string(),
|
||||
))
|
||||
None))
|
||||
})
|
||||
}
|
||||
}
|
||||
|
@ -3046,7 +3088,7 @@ fn register_package_shorthands<'a>(
|
|||
Problem::InvalidUrl(url_err),
|
||||
module_path.to_path_buf(),
|
||||
);
|
||||
return Err(LoadingProblem::FormattedReport(buf));
|
||||
return Err(LoadingProblem::FormattedReport(buf, None));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -3164,7 +3206,7 @@ fn finish_specialization<'a>(
|
|||
Valid(To::NewPackage(p_or_p)) => PathBuf::from(p_or_p.as_str()),
|
||||
other => {
|
||||
let buf = report_cannot_run(state.root_id, state.root_path, other);
|
||||
return Err(LoadingProblem::FormattedReport(buf));
|
||||
return Err(LoadingProblem::FormattedReport(buf, None));
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -4129,7 +4171,9 @@ fn load_packages<'a>(
|
|||
Err(problem) => {
|
||||
let buf = to_https_problem_report_string(src, problem, filename);
|
||||
|
||||
load_messages.push(Msg::FailedToLoad(LoadingProblem::FormattedReport(buf)));
|
||||
load_messages.push(Msg::FailedToLoad(LoadingProblem::FormattedReport(
|
||||
buf, None,
|
||||
)));
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
@ -6447,7 +6491,7 @@ fn to_incorrect_module_name_report<'a>(
|
|||
filename: PathBuf,
|
||||
src: &'a [u8],
|
||||
render: RenderTarget,
|
||||
) -> String {
|
||||
) -> (String, Region) {
|
||||
use roc_reporting::report::{Report, RocDocAllocator, DEFAULT_PALETTE};
|
||||
use ven_pretty::DocAllocator;
|
||||
|
||||
|
@ -6488,7 +6532,7 @@ fn to_incorrect_module_name_report<'a>(
|
|||
let mut buf = String::new();
|
||||
let palette = DEFAULT_PALETTE;
|
||||
report.render(render, &mut buf, &alloc, &palette);
|
||||
buf
|
||||
(buf, found.region)
|
||||
}
|
||||
|
||||
fn to_no_platform_package_report(
|
||||
|
|
|
@ -141,7 +141,7 @@ fn multiple_modules(subdir: &str, files: Vec<(&str, &str)>) -> Result<LoadedModu
|
|||
|
||||
match multiple_modules_help(subdir, arena, files) {
|
||||
Err(io_error) => panic!("IO trouble: {io_error:?}"),
|
||||
Ok(Err(LoadingProblem::FormattedReport(buf))) => Err(buf),
|
||||
Ok(Err(LoadingProblem::FormattedReport(buf, _))) => Err(buf),
|
||||
Ok(Err(loading_problem)) => Err(format!("{loading_problem:?}")),
|
||||
Ok(Ok(mut loaded_module)) => {
|
||||
let home = loaded_module.module_id;
|
||||
|
@ -247,7 +247,7 @@ fn load_fixture(
|
|||
);
|
||||
let mut loaded_module = match loaded {
|
||||
Ok(x) => x,
|
||||
Err(roc_load_internal::file::LoadingProblem::FormattedReport(report)) => {
|
||||
Err(roc_load_internal::file::LoadingProblem::FormattedReport(report, _)) => {
|
||||
println!("{report}");
|
||||
panic!("{}", report);
|
||||
}
|
||||
|
|
|
@ -63,6 +63,27 @@ pub enum SyntaxError<'a> {
|
|||
Space(BadInputError),
|
||||
NotEndOfFile(Position),
|
||||
}
|
||||
impl<'a> SyntaxError<'a> {
|
||||
pub fn get_region(&self) -> Option<Region> {
|
||||
match self {
|
||||
SyntaxError::Unexpected(r) => Some(*r),
|
||||
SyntaxError::Eof(r) => Some(*r),
|
||||
SyntaxError::ReservedKeyword(r) => Some(*r),
|
||||
SyntaxError::ArgumentsBeforeEquals(r) => Some(*r),
|
||||
SyntaxError::Type(e_type) => Some(e_type.get_region()),
|
||||
SyntaxError::Pattern(e_pattern) => Some(e_pattern.get_region()),
|
||||
SyntaxError::NotEndOfFile(pos) => Some(Region::from_pos(*pos)),
|
||||
SyntaxError::Expr(e_expr, _) => Some(e_expr.get_region()),
|
||||
SyntaxError::Header(e_header) => Some(e_header.get_region()),
|
||||
SyntaxError::NotYetImplemented(_) => None,
|
||||
SyntaxError::OutdentedTooFar => None,
|
||||
SyntaxError::Todo => None,
|
||||
SyntaxError::InvalidPattern => None,
|
||||
SyntaxError::BadUtf8 => None,
|
||||
SyntaxError::Space(_bad_input) => None,
|
||||
}
|
||||
}
|
||||
}
|
||||
pub trait SpaceProblem: std::fmt::Debug {
|
||||
fn space_problem(e: BadInputError, pos: Position) -> Self;
|
||||
}
|
||||
|
@ -133,6 +154,27 @@ pub enum EHeader<'a> {
|
|||
InconsistentModuleName(Region),
|
||||
}
|
||||
|
||||
impl<'a> EHeader<'a> {
|
||||
pub fn get_region(&self) -> Region {
|
||||
match self {
|
||||
EHeader::Provides(provides, _pos) => provides.get_region(),
|
||||
EHeader::Params(params, _pos) => params.get_region(),
|
||||
EHeader::Exposes(_, pos) => Region::from_pos(*pos),
|
||||
EHeader::Imports(_, pos) => Region::from_pos(*pos),
|
||||
EHeader::Requires(requires, _pos) => requires.get_region(),
|
||||
EHeader::Packages(packages, _pos) => packages.get_region(),
|
||||
EHeader::Space(_, pos) => Region::from_pos(*pos),
|
||||
EHeader::Start(pos) => Region::from_pos(*pos),
|
||||
EHeader::ModuleName(pos) => Region::from_pos(*pos),
|
||||
EHeader::AppName(app_name, _pos) => app_name.get_region(),
|
||||
EHeader::PackageName(package_name, _pos) => package_name.get_region(),
|
||||
EHeader::PlatformName(platform_name, _pos) => platform_name.get_region(),
|
||||
EHeader::IndentStart(pos) => Region::from_pos(*pos),
|
||||
EHeader::InconsistentModuleName(region) => *region,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Eq)]
|
||||
pub enum EProvides<'a> {
|
||||
Provides(Position),
|
||||
|
@ -149,6 +191,26 @@ pub enum EProvides<'a> {
|
|||
Space(BadInputError, Position),
|
||||
}
|
||||
|
||||
impl<'a> EProvides<'a> {
|
||||
pub fn get_region(&self) -> Region {
|
||||
let pos = match self {
|
||||
EProvides::Provides(p)
|
||||
| EProvides::Open(p)
|
||||
| EProvides::To(p)
|
||||
| EProvides::IndentProvides(p)
|
||||
| EProvides::IndentTo(p)
|
||||
| EProvides::IndentListStart(p)
|
||||
| EProvides::IndentPackage(p)
|
||||
| EProvides::ListStart(p)
|
||||
| EProvides::ListEnd(p)
|
||||
| EProvides::Identifier(p)
|
||||
| EProvides::Package(_, p)
|
||||
| EProvides::Space(_, p) => p,
|
||||
};
|
||||
Region::from_pos(*pos)
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Eq)]
|
||||
pub enum EParams<'a> {
|
||||
Pattern(PRecord<'a>, Position),
|
||||
|
@ -158,6 +220,19 @@ pub enum EParams<'a> {
|
|||
Space(BadInputError, Position),
|
||||
}
|
||||
|
||||
impl<'a> EParams<'a> {
|
||||
pub fn get_region(&self) -> Region {
|
||||
let pos = match self {
|
||||
EParams::Pattern(_, p)
|
||||
| EParams::BeforeArrow(p)
|
||||
| EParams::Arrow(p)
|
||||
| EParams::AfterArrow(p)
|
||||
| EParams::Space(_, p) => p,
|
||||
};
|
||||
Region::from_pos(*pos)
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
||||
pub enum EExposes {
|
||||
Exposes(Position),
|
||||
|
@ -170,6 +245,22 @@ pub enum EExposes {
|
|||
Space(BadInputError, Position),
|
||||
}
|
||||
|
||||
impl EExposes {
|
||||
pub fn get_region(&self) -> Region {
|
||||
let pos = match self {
|
||||
EExposes::Exposes(p)
|
||||
| EExposes::Open(p)
|
||||
| EExposes::IndentExposes(p)
|
||||
| EExposes::IndentListStart(p)
|
||||
| EExposes::ListStart(p)
|
||||
| EExposes::ListEnd(p)
|
||||
| EExposes::Identifier(p)
|
||||
| EExposes::Space(_, p) => p,
|
||||
};
|
||||
Region::from_pos(*pos)
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Eq)]
|
||||
pub enum ERequires<'a> {
|
||||
Requires(Position),
|
||||
|
@ -183,6 +274,23 @@ pub enum ERequires<'a> {
|
|||
Space(BadInputError, Position),
|
||||
}
|
||||
|
||||
impl<'a> ERequires<'a> {
|
||||
pub fn get_region(&self) -> Region {
|
||||
let pos = match self {
|
||||
ERequires::Requires(p)
|
||||
| ERequires::Open(p)
|
||||
| ERequires::IndentRequires(p)
|
||||
| ERequires::IndentListStart(p)
|
||||
| ERequires::ListStart(p)
|
||||
| ERequires::ListEnd(p)
|
||||
| ERequires::TypedIdent(_, p)
|
||||
| ERequires::Rigid(p)
|
||||
| ERequires::Space(_, p) => p,
|
||||
};
|
||||
Region::from_pos(*pos)
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Eq)]
|
||||
pub enum ETypedIdent<'a> {
|
||||
Space(BadInputError, Position),
|
||||
|
@ -194,6 +302,21 @@ pub enum ETypedIdent<'a> {
|
|||
Identifier(Position),
|
||||
}
|
||||
|
||||
impl<'a> ETypedIdent<'a> {
|
||||
pub fn get_region(&self) -> Region {
|
||||
let pos = match self {
|
||||
ETypedIdent::Space(_, p)
|
||||
| ETypedIdent::HasType(p)
|
||||
| ETypedIdent::IndentHasType(p)
|
||||
| ETypedIdent::Name(p)
|
||||
| ETypedIdent::Type(_, p)
|
||||
| ETypedIdent::IndentType(p)
|
||||
| ETypedIdent::Identifier(p) => p,
|
||||
};
|
||||
Region::from_pos(*pos)
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Eq)]
|
||||
pub enum EPackages<'a> {
|
||||
Open(Position),
|
||||
|
@ -207,6 +330,23 @@ pub enum EPackages<'a> {
|
|||
PackageEntry(EPackageEntry<'a>, Position),
|
||||
}
|
||||
|
||||
impl<'a> EPackages<'a> {
|
||||
pub fn get_region(&self) -> Region {
|
||||
let pos = match self {
|
||||
EPackages::Open(p)
|
||||
| EPackages::Space(_, p)
|
||||
| EPackages::Packages(p)
|
||||
| EPackages::IndentPackages(p)
|
||||
| EPackages::ListStart(p)
|
||||
| EPackages::ListEnd(p)
|
||||
| EPackages::IndentListStart(p)
|
||||
| EPackages::IndentListEnd(p)
|
||||
| EPackages::PackageEntry(_, p) => p,
|
||||
};
|
||||
Region::from_pos(*pos)
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Eq)]
|
||||
pub enum EPackageName<'a> {
|
||||
BadPath(EString<'a>, Position),
|
||||
|
@ -214,6 +354,17 @@ pub enum EPackageName<'a> {
|
|||
Multiline(Position),
|
||||
}
|
||||
|
||||
impl<'a> EPackageName<'a> {
|
||||
pub fn get_region(&self) -> Region {
|
||||
let pos = match self {
|
||||
EPackageName::BadPath(_, p) | EPackageName::Escapes(p) | EPackageName::Multiline(p) => {
|
||||
p
|
||||
}
|
||||
};
|
||||
Region::from_pos(*pos)
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Eq)]
|
||||
pub enum EPackageEntry<'a> {
|
||||
BadPackage(EPackageName<'a>, Position),
|
||||
|
@ -225,6 +376,21 @@ pub enum EPackageEntry<'a> {
|
|||
Space(BadInputError, Position),
|
||||
}
|
||||
|
||||
impl<'a> EPackageEntry<'a> {
|
||||
pub fn get_region(&self) -> Region {
|
||||
let pos = match self {
|
||||
EPackageEntry::BadPackage(_, p)
|
||||
| EPackageEntry::Shorthand(p)
|
||||
| EPackageEntry::Colon(p)
|
||||
| EPackageEntry::IndentPackage(p)
|
||||
| EPackageEntry::IndentPlatform(p)
|
||||
| EPackageEntry::Platform(p)
|
||||
| EPackageEntry::Space(_, p) => p,
|
||||
};
|
||||
Region::from_pos(*pos)
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
||||
pub enum EImports {
|
||||
Open(Position),
|
||||
|
@ -248,6 +414,33 @@ pub enum EImports {
|
|||
StrLiteral(Position),
|
||||
}
|
||||
|
||||
impl EImports {
|
||||
pub fn get_region(&self) -> Region {
|
||||
let pos = match self {
|
||||
EImports::Open(p)
|
||||
| EImports::Imports(p)
|
||||
| EImports::IndentImports(p)
|
||||
| EImports::IndentListStart(p)
|
||||
| EImports::IndentListEnd(p)
|
||||
| EImports::ListStart(p)
|
||||
| EImports::ListEnd(p)
|
||||
| EImports::Identifier(p)
|
||||
| EImports::ExposingDot(p)
|
||||
| EImports::ShorthandDot(p)
|
||||
| EImports::Shorthand(p)
|
||||
| EImports::ModuleName(p)
|
||||
| EImports::Space(_, p)
|
||||
| EImports::IndentSetStart(p)
|
||||
| EImports::SetStart(p)
|
||||
| EImports::SetEnd(p)
|
||||
| EImports::TypedIdent(p)
|
||||
| EImports::AsKeyword(p)
|
||||
| EImports::StrLiteral(p) => p,
|
||||
};
|
||||
Region::from_pos(*pos)
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
||||
pub enum BadInputError {
|
||||
HasTab,
|
||||
|
@ -363,6 +556,69 @@ pub enum EExpr<'a> {
|
|||
UnexpectedTopLevelExpr(Position),
|
||||
}
|
||||
|
||||
impl<'a> EExpr<'a> {
|
||||
pub fn get_region(&self) -> Region {
|
||||
match self {
|
||||
// Cases with child nodes that have get_region()
|
||||
EExpr::Type(e_type, _) => e_type.get_region(),
|
||||
EExpr::Pattern(e_pattern, _) => e_pattern.get_region(),
|
||||
EExpr::Ability(e_ability, _) => e_ability.get_region(),
|
||||
EExpr::When(e_when, _) => e_when.get_region(),
|
||||
EExpr::If(e_if, _) => e_if.get_region(),
|
||||
EExpr::Expect(e_expect, _) => e_expect.get_region(),
|
||||
EExpr::Dbg(e_expect, _) => e_expect.get_region(),
|
||||
EExpr::Import(e_import, _) => e_import.get_region(),
|
||||
EExpr::Return(e_return, _) => e_return.get_region(),
|
||||
EExpr::Closure(e_closure, _) => e_closure.get_region(),
|
||||
EExpr::InParens(e_in_parens, _) => e_in_parens.get_region(),
|
||||
EExpr::Record(e_record, _) => e_record.get_region(),
|
||||
EExpr::Str(e_string, _) => e_string.get_region(),
|
||||
EExpr::List(e_list, _) => e_list.get_region(),
|
||||
|
||||
// Cases with direct Region values
|
||||
EExpr::RecordUpdateOldBuilderField(r)
|
||||
| EExpr::RecordUpdateIgnoredField(r)
|
||||
| EExpr::RecordBuilderOldBuilderField(r) => *r,
|
||||
|
||||
// Cases with Position values
|
||||
EExpr::TrailingOperator(p)
|
||||
| EExpr::Start(p)
|
||||
| EExpr::End(p)
|
||||
| EExpr::BadExprEnd(p)
|
||||
| EExpr::Space(_, p)
|
||||
| EExpr::Dot(p)
|
||||
| EExpr::Access(p)
|
||||
| EExpr::UnaryNot(p)
|
||||
| EExpr::UnaryNegate(p)
|
||||
| EExpr::BadOperator(_, p)
|
||||
| EExpr::DefMissingFinalExpr(p)
|
||||
| EExpr::DefMissingFinalExpr2(_, p)
|
||||
| EExpr::IndentDefBody(p)
|
||||
| EExpr::IndentEquals(p)
|
||||
| EExpr::IndentAnnotation(p)
|
||||
| EExpr::Equals(p)
|
||||
| EExpr::Colon(p)
|
||||
| EExpr::DoubleColon(p)
|
||||
| EExpr::Ident(p)
|
||||
| EExpr::ElmStyleFunction(_, p)
|
||||
| EExpr::MalformedPattern(p)
|
||||
| EExpr::QualifiedTag(p)
|
||||
| EExpr::BackpassComma(p)
|
||||
| EExpr::BackpassArrow(p)
|
||||
| EExpr::BackpassContinue(p)
|
||||
| EExpr::DbgContinue(p)
|
||||
| EExpr::Underscore(p)
|
||||
| EExpr::Crash(p)
|
||||
| EExpr::Try(p)
|
||||
| EExpr::Number(_, p)
|
||||
| EExpr::IndentStart(p)
|
||||
| EExpr::IndentEnd(p)
|
||||
| EExpr::UnexpectedComma(p)
|
||||
| EExpr::UnexpectedTopLevelExpr(p) => Region::from_pos(*p),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Eq)]
|
||||
pub enum ENumber {
|
||||
End,
|
||||
|
@ -388,6 +644,29 @@ pub enum EString<'a> {
|
|||
ExpectedDoubleQuoteGotSingleQuote(Position),
|
||||
}
|
||||
|
||||
impl<'a> EString<'a> {
|
||||
pub fn get_region(&self) -> Region {
|
||||
match self {
|
||||
// Case with child node that has get_region()
|
||||
EString::Format(expr, _) => expr.get_region(),
|
||||
|
||||
// Cases with Position values
|
||||
EString::Open(p)
|
||||
| EString::CodePtOpen(p)
|
||||
| EString::CodePtEnd(p)
|
||||
| EString::InvalidSingleQuote(_, p)
|
||||
| EString::Space(_, p)
|
||||
| EString::EndlessSingleLine(p)
|
||||
| EString::EndlessMultiLine(p)
|
||||
| EString::EndlessSingleQuote(p)
|
||||
| EString::UnknownEscape(p)
|
||||
| EString::FormatEnd(p)
|
||||
| EString::MultilineInsufficientIndent(p)
|
||||
| EString::ExpectedDoubleQuoteGotSingleQuote(p) => Region::from_pos(*p),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
||||
pub enum ESingleQuote {
|
||||
Empty,
|
||||
|
@ -414,6 +693,27 @@ pub enum ERecord<'a> {
|
|||
Space(BadInputError, Position),
|
||||
}
|
||||
|
||||
impl<'a> ERecord<'a> {
|
||||
pub fn get_region(&self) -> Region {
|
||||
match self {
|
||||
// Cases with child node that has get_region()
|
||||
ERecord::Expr(expr, _) => expr.get_region(),
|
||||
|
||||
// Cases with Position values
|
||||
ERecord::End(p)
|
||||
| ERecord::Open(p)
|
||||
| ERecord::Prefix(p)
|
||||
| ERecord::Field(p)
|
||||
| ERecord::UnderscoreField(p)
|
||||
| ERecord::Colon(p)
|
||||
| ERecord::QuestionMark(p)
|
||||
| ERecord::Arrow(p)
|
||||
| ERecord::Ampersand(p)
|
||||
| ERecord::Space(_, p) => Region::from_pos(*p),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Eq)]
|
||||
pub enum EInParens<'a> {
|
||||
End(Position),
|
||||
|
@ -429,6 +729,21 @@ pub enum EInParens<'a> {
|
|||
Space(BadInputError, Position),
|
||||
}
|
||||
|
||||
impl<'a> EInParens<'a> {
|
||||
pub fn get_region(&self) -> Region {
|
||||
match self {
|
||||
// Cases with child node that has get_region()
|
||||
EInParens::Expr(expr, _) => expr.get_region(),
|
||||
|
||||
// Cases with Position values
|
||||
EInParens::End(p)
|
||||
| EInParens::Open(p)
|
||||
| EInParens::Empty(p)
|
||||
| EInParens::Space(_, p) => Region::from_pos(*p),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Eq)]
|
||||
pub enum EClosure<'a> {
|
||||
Space(BadInputError, Position),
|
||||
|
@ -444,6 +759,26 @@ pub enum EClosure<'a> {
|
|||
IndentArg(Position),
|
||||
}
|
||||
|
||||
impl<'a> EClosure<'a> {
|
||||
pub fn get_region(&self) -> Region {
|
||||
match self {
|
||||
// Cases with child nodes that have get_region()
|
||||
EClosure::Pattern(pattern, _) => pattern.get_region(),
|
||||
EClosure::Body(expr, _) => expr.get_region(),
|
||||
|
||||
// Cases with Position values
|
||||
EClosure::Space(_, p)
|
||||
| EClosure::Start(p)
|
||||
| EClosure::Arrow(p)
|
||||
| EClosure::Comma(p)
|
||||
| EClosure::Arg(p)
|
||||
| EClosure::IndentArrow(p)
|
||||
| EClosure::IndentBody(p)
|
||||
| EClosure::IndentArg(p) => Region::from_pos(*p),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Eq)]
|
||||
pub enum EList<'a> {
|
||||
Open(Position),
|
||||
|
@ -453,6 +788,18 @@ pub enum EList<'a> {
|
|||
Expr(&'a EExpr<'a>, Position),
|
||||
}
|
||||
|
||||
impl<'a> EList<'a> {
|
||||
pub fn get_region(&self) -> Region {
|
||||
match self {
|
||||
// Case with child node that has get_region()
|
||||
EList::Expr(expr, _) => expr.get_region(),
|
||||
|
||||
// Cases with Position values
|
||||
EList::Open(p) | EList::End(p) | EList::Space(_, p) => Region::from_pos(*p),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Eq)]
|
||||
pub enum EWhen<'a> {
|
||||
Space(BadInputError, Position),
|
||||
|
@ -476,6 +823,32 @@ pub enum EWhen<'a> {
|
|||
PatternAlignment(u32, Position),
|
||||
}
|
||||
|
||||
impl<'a> EWhen<'a> {
|
||||
pub fn get_region(&self) -> Region {
|
||||
match self {
|
||||
// Cases with child nodes that have get_region()
|
||||
EWhen::Pattern(pattern, _) => pattern.get_region(),
|
||||
EWhen::IfGuard(expr, _) => expr.get_region(),
|
||||
EWhen::Condition(expr, _) => expr.get_region(),
|
||||
EWhen::Branch(expr, _) => expr.get_region(),
|
||||
|
||||
// Cases with Position values
|
||||
EWhen::Space(_, p)
|
||||
| EWhen::When(p)
|
||||
| EWhen::Is(p)
|
||||
| EWhen::Arrow(p)
|
||||
| EWhen::Bar(p)
|
||||
| EWhen::IfToken(p)
|
||||
| EWhen::IndentCondition(p)
|
||||
| EWhen::IndentPattern(p)
|
||||
| EWhen::IndentArrow(p)
|
||||
| EWhen::IndentBranch(p)
|
||||
| EWhen::IndentIfGuard(p)
|
||||
| EWhen::PatternAlignment(_, p) => Region::from_pos(*p),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Eq)]
|
||||
pub enum EAbility<'a> {
|
||||
Space(BadInputError, Position),
|
||||
|
@ -486,6 +859,21 @@ pub enum EAbility<'a> {
|
|||
DemandColon(Position),
|
||||
}
|
||||
|
||||
impl<'a> EAbility<'a> {
|
||||
pub fn get_region(&self) -> Region {
|
||||
match self {
|
||||
// Case with child node that has get_region()
|
||||
EAbility::Type(e_type, _) => e_type.get_region(),
|
||||
|
||||
// Cases with Position values
|
||||
EAbility::Space(_, p)
|
||||
| EAbility::DemandAlignment(_, p)
|
||||
| EAbility::DemandName(p)
|
||||
| EAbility::DemandColon(p) => Region::from_pos(*p),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Eq)]
|
||||
pub enum EIf<'a> {
|
||||
Space(BadInputError, Position),
|
||||
|
@ -505,6 +893,26 @@ pub enum EIf<'a> {
|
|||
IndentElseBranch(Position),
|
||||
}
|
||||
|
||||
impl<'a> EIf<'a> {
|
||||
pub fn get_region(&self) -> Region {
|
||||
match self {
|
||||
EIf::Condition(expr, _) | EIf::ThenBranch(expr, _) | EIf::ElseBranch(expr, _) => {
|
||||
expr.get_region()
|
||||
}
|
||||
EIf::Space(_, p)
|
||||
| EIf::If(p)
|
||||
| EIf::Then(p)
|
||||
| EIf::Else(p)
|
||||
| EIf::IndentCondition(p)
|
||||
| EIf::IndentIf(p)
|
||||
| EIf::IndentThenToken(p)
|
||||
| EIf::IndentElseToken(p)
|
||||
| EIf::IndentThenBranch(p)
|
||||
| EIf::IndentElseBranch(p) => Region::from_pos(*p),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Eq)]
|
||||
pub enum EExpect<'a> {
|
||||
Space(BadInputError, Position),
|
||||
|
@ -515,6 +923,18 @@ pub enum EExpect<'a> {
|
|||
IndentCondition(Position),
|
||||
}
|
||||
|
||||
impl<'a> EExpect<'a> {
|
||||
pub fn get_region(&self) -> Region {
|
||||
match self {
|
||||
EExpect::Condition(expr, _) | EExpect::Continuation(expr, _) => expr.get_region(),
|
||||
EExpect::Space(_, p)
|
||||
| EExpect::Dbg(p)
|
||||
| EExpect::Expect(p)
|
||||
| EExpect::IndentCondition(p) => Region::from_pos(*p),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Eq)]
|
||||
pub enum EReturn<'a> {
|
||||
Space(BadInputError, Position),
|
||||
|
@ -522,6 +942,16 @@ pub enum EReturn<'a> {
|
|||
ReturnValue(&'a EExpr<'a>, Position),
|
||||
IndentReturnValue(Position),
|
||||
}
|
||||
impl<'a> EReturn<'a> {
|
||||
pub fn get_region(&self) -> Region {
|
||||
match self {
|
||||
EReturn::ReturnValue(expr, _) => expr.get_region(),
|
||||
EReturn::Space(_, p) | EReturn::Return(p) | EReturn::IndentReturnValue(p) => {
|
||||
Region::from_pos(*p)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Eq)]
|
||||
pub enum EImport<'a> {
|
||||
|
@ -553,6 +983,44 @@ pub enum EImport<'a> {
|
|||
EndNewline(Position),
|
||||
}
|
||||
|
||||
impl<'a> EImport<'a> {
|
||||
pub fn get_region(&self) -> Region {
|
||||
match self {
|
||||
// Cases with child nodes that have get_region()
|
||||
EImport::Params(params, _) => params.get_region(),
|
||||
EImport::Annotation(e_type, _) => e_type.get_region(),
|
||||
|
||||
// Case with direct Region value
|
||||
EImport::LowercaseAlias(r) => *r,
|
||||
|
||||
// Cases with Position values
|
||||
EImport::Import(p)
|
||||
| EImport::IndentStart(p)
|
||||
| EImport::PackageShorthand(p)
|
||||
| EImport::PackageShorthandDot(p)
|
||||
| EImport::ModuleName(p)
|
||||
| EImport::IndentAs(p)
|
||||
| EImport::As(p)
|
||||
| EImport::IndentAlias(p)
|
||||
| EImport::Alias(p)
|
||||
| EImport::IndentExposing(p)
|
||||
| EImport::Exposing(p)
|
||||
| EImport::ExposingListStart(p)
|
||||
| EImport::ExposedName(p)
|
||||
| EImport::ExposingListEnd(p)
|
||||
| EImport::IndentIngestedPath(p)
|
||||
| EImport::IngestedPath(p)
|
||||
| EImport::IndentIngestedName(p)
|
||||
| EImport::IngestedName(p)
|
||||
| EImport::IndentColon(p)
|
||||
| EImport::Colon(p)
|
||||
| EImport::IndentAnnotation(p)
|
||||
| EImport::Space(_, p)
|
||||
| EImport::EndNewline(p) => Region::from_pos(*p),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Eq)]
|
||||
pub enum EImportParams<'a> {
|
||||
Indent(Position),
|
||||
|
@ -563,6 +1031,19 @@ pub enum EImportParams<'a> {
|
|||
Space(BadInputError, Position),
|
||||
}
|
||||
|
||||
impl<'a> EImportParams<'a> {
|
||||
pub fn get_region(&self) -> Region {
|
||||
match self {
|
||||
EImportParams::Indent(p) | EImportParams::Record(_, p) | EImportParams::Space(_, p) => {
|
||||
Region::from_pos(*p)
|
||||
}
|
||||
EImportParams::RecordUpdateFound(r)
|
||||
| EImportParams::RecordBuilderFound(r)
|
||||
| EImportParams::RecordIgnoredFieldFound(r) => *r,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Eq)]
|
||||
pub enum EPattern<'a> {
|
||||
Record(PRecord<'a>, Position),
|
||||
|
@ -587,6 +1068,32 @@ pub enum EPattern<'a> {
|
|||
RecordUpdaterFunction(Position),
|
||||
}
|
||||
|
||||
impl<'a> EPattern<'a> {
|
||||
pub fn get_region(&self) -> Region {
|
||||
match self {
|
||||
// Cases with child nodes that have get_region()
|
||||
EPattern::Record(expr, _) => expr.get_region(),
|
||||
EPattern::List(expr, _) => expr.get_region(),
|
||||
EPattern::PInParens(expr, _) => expr.get_region(),
|
||||
|
||||
// Cases with Position values
|
||||
EPattern::AsKeyword(position)
|
||||
| EPattern::AsIdentifier(position)
|
||||
| EPattern::Underscore(position)
|
||||
| EPattern::NotAPattern(position)
|
||||
| EPattern::Start(position)
|
||||
| EPattern::End(position)
|
||||
| EPattern::Space(_, position)
|
||||
| EPattern::NumLiteral(_, position)
|
||||
| EPattern::IndentStart(position)
|
||||
| EPattern::IndentEnd(position)
|
||||
| EPattern::AsIndentStart(position)
|
||||
| EPattern::AccessorFunction(position)
|
||||
| EPattern::RecordUpdaterFunction(position) => Region::from_pos(*position),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Eq)]
|
||||
pub enum PRecord<'a> {
|
||||
End(Position),
|
||||
|
@ -602,6 +1109,24 @@ pub enum PRecord<'a> {
|
|||
Space(BadInputError, Position),
|
||||
}
|
||||
|
||||
impl<'a> PRecord<'a> {
|
||||
pub fn get_region(&self) -> Region {
|
||||
match self {
|
||||
// Cases with child nodes that have get_region()
|
||||
PRecord::Pattern(pattern, _) => pattern.get_region(),
|
||||
PRecord::Expr(expr, _) => expr.get_region(),
|
||||
|
||||
// Cases with Position values
|
||||
PRecord::End(p)
|
||||
| PRecord::Open(p)
|
||||
| PRecord::Field(p)
|
||||
| PRecord::Colon(p)
|
||||
| PRecord::Optional(p)
|
||||
| PRecord::Space(_, p) => Region::from_pos(*p),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Eq)]
|
||||
pub enum PList<'a> {
|
||||
End(Position),
|
||||
|
@ -613,6 +1138,20 @@ pub enum PList<'a> {
|
|||
Space(BadInputError, Position),
|
||||
}
|
||||
|
||||
impl<'a> PList<'a> {
|
||||
pub fn get_region(&self) -> Region {
|
||||
match self {
|
||||
// Case with child node that has get_region()
|
||||
PList::Pattern(pattern, _) => pattern.get_region(),
|
||||
|
||||
// Cases with Position values
|
||||
PList::End(p) | PList::Open(p) | PList::Rest(p) | PList::Space(_, p) => {
|
||||
Region::from_pos(*p)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Eq)]
|
||||
pub enum PInParens<'a> {
|
||||
Empty(Position),
|
||||
|
@ -623,6 +1162,21 @@ pub enum PInParens<'a> {
|
|||
Space(BadInputError, Position),
|
||||
}
|
||||
|
||||
impl<'a> PInParens<'a> {
|
||||
pub fn get_region(&self) -> Region {
|
||||
match self {
|
||||
// Case with child node that has get_region()
|
||||
PInParens::Pattern(pattern, _) => pattern.get_region(),
|
||||
|
||||
// Cases with Position values
|
||||
PInParens::Empty(p)
|
||||
| PInParens::End(p)
|
||||
| PInParens::Open(p)
|
||||
| PInParens::Space(_, p) => Region::from_pos(*p),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Eq)]
|
||||
pub enum EType<'a> {
|
||||
Space(BadInputError, Position),
|
||||
|
@ -648,6 +1202,34 @@ pub enum EType<'a> {
|
|||
TIndentEnd(Position),
|
||||
TAsIndentStart(Position),
|
||||
}
|
||||
impl<'a> EType<'a> {
|
||||
pub fn get_region(&self) -> Region {
|
||||
match self {
|
||||
// Cases with child nodes that have get_region()
|
||||
EType::TRecord(expr, _) => expr.get_region(),
|
||||
EType::TTagUnion(expr, _) => expr.get_region(),
|
||||
EType::TInParens(expr, _) => expr.get_region(),
|
||||
EType::TApply(eapply, _) => eapply.get_region(),
|
||||
EType::TInlineAlias(einline, _) => einline.get_region(),
|
||||
EType::TAbilityImpl(eability, _) => eability.get_region(),
|
||||
|
||||
// Cases with Position values
|
||||
EType::Space(_, p)
|
||||
| EType::UnderscoreSpacing(p)
|
||||
| EType::TBadTypeVariable(p)
|
||||
| EType::TWildcard(p)
|
||||
| EType::TInferred(p)
|
||||
| EType::TStart(p)
|
||||
| EType::TEnd(p)
|
||||
| EType::TFunctionArgument(p)
|
||||
| EType::TWhereBar(p)
|
||||
| EType::TImplementsClause(p)
|
||||
| EType::TIndentStart(p)
|
||||
| EType::TIndentEnd(p)
|
||||
| EType::TAsIndentStart(p) => Region::from_pos(*p),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Eq)]
|
||||
pub enum ETypeRecord<'a> {
|
||||
|
@ -667,6 +1249,27 @@ pub enum ETypeRecord<'a> {
|
|||
IndentEnd(Position),
|
||||
}
|
||||
|
||||
impl<'a> ETypeRecord<'a> {
|
||||
pub fn get_region(&self) -> Region {
|
||||
match self {
|
||||
// Case with child node that has get_region()
|
||||
ETypeRecord::Type(type_expr, _) => type_expr.get_region(),
|
||||
|
||||
// Cases with Position values
|
||||
ETypeRecord::End(p)
|
||||
| ETypeRecord::Open(p)
|
||||
| ETypeRecord::Field(p)
|
||||
| ETypeRecord::Colon(p)
|
||||
| ETypeRecord::Optional(p)
|
||||
| ETypeRecord::Space(_, p)
|
||||
| ETypeRecord::IndentOpen(p)
|
||||
| ETypeRecord::IndentColon(p)
|
||||
| ETypeRecord::IndentOptional(p)
|
||||
| ETypeRecord::IndentEnd(p) => Region::from_pos(*p),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Eq)]
|
||||
pub enum ETypeTagUnion<'a> {
|
||||
End(Position),
|
||||
|
@ -677,6 +1280,20 @@ pub enum ETypeTagUnion<'a> {
|
|||
Space(BadInputError, Position),
|
||||
}
|
||||
|
||||
impl<'a> ETypeTagUnion<'a> {
|
||||
pub fn get_region(&self) -> Region {
|
||||
match self {
|
||||
// Case with child node that has get_region()
|
||||
ETypeTagUnion::Type(type_expr, _) => type_expr.get_region(),
|
||||
|
||||
// Cases with Position values
|
||||
ETypeTagUnion::End(p) | ETypeTagUnion::Open(p) | ETypeTagUnion::Space(_, p) => {
|
||||
Region::from_pos(*p)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Eq)]
|
||||
pub enum ETypeInParens<'a> {
|
||||
/// e.g. (), which isn't a valid type
|
||||
|
@ -694,6 +1311,23 @@ pub enum ETypeInParens<'a> {
|
|||
IndentEnd(Position),
|
||||
}
|
||||
|
||||
impl<'a> ETypeInParens<'a> {
|
||||
pub fn get_region(&self) -> Region {
|
||||
match self {
|
||||
// Cases with child nodes that have get_region()
|
||||
ETypeInParens::Type(type_expr, _) => type_expr.get_region(),
|
||||
|
||||
// Cases with Position values
|
||||
ETypeInParens::Empty(p)
|
||||
| ETypeInParens::End(p)
|
||||
| ETypeInParens::Open(p)
|
||||
| ETypeInParens::Space(_, p)
|
||||
| ETypeInParens::IndentOpen(p)
|
||||
| ETypeInParens::IndentEnd(p) => Region::from_pos(*p),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Eq)]
|
||||
pub enum ETypeApply {
|
||||
///
|
||||
|
@ -706,6 +1340,20 @@ pub enum ETypeApply {
|
|||
StartIsNumber(Position),
|
||||
}
|
||||
|
||||
impl ETypeApply {
|
||||
pub fn get_region(&self) -> Region {
|
||||
let pos = match self {
|
||||
ETypeApply::StartNotUppercase(p)
|
||||
| ETypeApply::End(p)
|
||||
| ETypeApply::Space(_, p)
|
||||
| ETypeApply::DoubleDot(p)
|
||||
| ETypeApply::TrailingDot(p)
|
||||
| ETypeApply::StartIsNumber(p) => p,
|
||||
};
|
||||
Region::from_pos(*pos)
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Eq)]
|
||||
pub enum ETypeInlineAlias {
|
||||
NotAnAlias(Position),
|
||||
|
@ -713,6 +1361,17 @@ pub enum ETypeInlineAlias {
|
|||
ArgumentNotLowercase(Position),
|
||||
}
|
||||
|
||||
impl ETypeInlineAlias {
|
||||
pub fn get_region(&self) -> Region {
|
||||
let pos = match self {
|
||||
ETypeInlineAlias::NotAnAlias(p)
|
||||
| ETypeInlineAlias::Qualified(p)
|
||||
| ETypeInlineAlias::ArgumentNotLowercase(p) => p,
|
||||
};
|
||||
Region::from_pos(*pos)
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Eq)]
|
||||
pub enum ETypeAbilityImpl<'a> {
|
||||
End(Position),
|
||||
|
@ -734,6 +1393,29 @@ pub enum ETypeAbilityImpl<'a> {
|
|||
IndentBar(Position),
|
||||
IndentAmpersand(Position),
|
||||
}
|
||||
impl<'a> ETypeAbilityImpl<'a> {
|
||||
pub fn get_region(&self) -> Region {
|
||||
match self {
|
||||
// Case with child node that has get_region()
|
||||
ETypeAbilityImpl::Type(type_expr, _) => type_expr.get_region(),
|
||||
ETypeAbilityImpl::Expr(expr, _) => expr.get_region(),
|
||||
// Cases with Position values
|
||||
ETypeAbilityImpl::End(p)
|
||||
| ETypeAbilityImpl::Open(p)
|
||||
| ETypeAbilityImpl::Field(p)
|
||||
| ETypeAbilityImpl::UnderscoreField(p)
|
||||
| ETypeAbilityImpl::Colon(p)
|
||||
| ETypeAbilityImpl::Arrow(p)
|
||||
| ETypeAbilityImpl::Optional(p)
|
||||
| ETypeAbilityImpl::Space(_, p)
|
||||
| ETypeAbilityImpl::Prefix(p)
|
||||
| ETypeAbilityImpl::QuestionMark(p)
|
||||
| ETypeAbilityImpl::Ampersand(p)
|
||||
| ETypeAbilityImpl::IndentBar(p)
|
||||
| ETypeAbilityImpl::IndentAmpersand(p) => Region::from_pos(*p),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> From<ERecord<'a>> for ETypeAbilityImpl<'a> {
|
||||
fn from(e: ERecord<'a>) -> Self {
|
||||
|
|
|
@ -91,6 +91,7 @@ fn create_llvm_module<'a>(
|
|||
Ok(x) => x,
|
||||
Err(LoadMonomorphizedError::LoadingProblem(roc_load::LoadingProblem::FormattedReport(
|
||||
report,
|
||||
_,
|
||||
))) => {
|
||||
println!("{report}");
|
||||
panic!();
|
||||
|
|
|
@ -173,6 +173,7 @@ fn compiles_to_ir(test_name: &str, src: &str, mode: &str, allow_type_errors: boo
|
|||
Ok(x) => x,
|
||||
Err(LoadMonomorphizedError::LoadingProblem(roc_load::LoadingProblem::FormattedReport(
|
||||
report,
|
||||
_,
|
||||
))) => {
|
||||
println!("{report}");
|
||||
panic!();
|
||||
|
|
|
@ -64,6 +64,7 @@ pub(crate) fn write_compiled_ir<'a>(
|
|||
Ok(x) => x,
|
||||
Err(LoadMonomorphizedError::LoadingProblem(roc_load::LoadingProblem::FormattedReport(
|
||||
report,
|
||||
_,
|
||||
))) => {
|
||||
println!("{report}");
|
||||
panic!();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue