Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 9 additions & 9 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "technique"
version = "0.4.0"
version = "0.4.1"
edition = "2021"
description = "A domain specific language for procedures."
authors = [ "Andrew Cowie" ]
Expand Down
61 changes: 48 additions & 13 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -160,16 +160,26 @@ fn main() {
std::process::exit(1);
}
};

let technique = match parsing::parse(&filename, &content) {
Ok(document) => document,
Err(error) => {
eprintln!(
"{}",
problem::full_parsing_error(&error, &filename, &content, &Terminal)
);
Err(errors) => {
for (i, error) in errors
.iter()
.enumerate()
{
if i > 0 {
eprintln!();
}
eprintln!(
"{}",
problem::full_parsing_error(&error, &filename, &content, &Terminal)
);
}
std::process::exit(1);
}
};

// TODO continue with validation of the returned technique

eprintln!("{}", "ok".bright_green());
Expand Down Expand Up @@ -205,12 +215,26 @@ fn main() {
std::process::exit(1);
}
};

let technique = match parsing::parse(&filename, &content) {
Ok(document) => document,
Err(error) => {
Err(errors) => {
for (i, error) in errors
.iter()
.enumerate()
{
if i > 0 {
eprintln!();
}
eprintln!(
"{}",
problem::concise_parsing_error(&error, &filename, &content, &Terminal)
);
}

eprintln!(
"{}",
problem::concise_parsing_error(&error, &filename, &content, &Terminal)
"\nUnable to parse input file. Try `technique check {}` for details.",
&filename.to_string_lossy()
);
std::process::exit(1);
}
Expand Down Expand Up @@ -251,16 +275,27 @@ fn main() {
std::process::exit(1);
}
};

let technique = match parsing::parse(&filename, &content) {
Ok(document) => document,
Err(error) => {
Err(errors) => {
// It is possible that we will want to render the error
// into the PDF document rather than crashing here. We'll
// see in the future.
eprintln!(
"{}",
problem::full_parsing_error(&error, &filename, &content, &Terminal)
);

for (i, error) in errors
.iter()
.enumerate()
{
if i > 0 {
eprintln!();
}

eprintln!(
"{}",
problem::concise_parsing_error(&error, &filename, &content, &Terminal)
);
}
std::process::exit(1);
}
};
Expand Down
13 changes: 7 additions & 6 deletions src/parsing/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,10 @@ pub fn load(filename: &Path) -> Result<String, LoadingError> {
}
}

/// Parse text into a Technique object, or error out.
pub fn parse<'i>(filename: &'i Path, content: &'i str) -> Result<Document<'i>, ParsingError<'i>> {
let result = parser::parse_via_taking(filename, content);
/// Parse text into a Document object, or return the list of errors
/// encountered.
pub fn parse<'i>(filename: &'i Path, content: &'i str) -> Result<Document<'i>, Vec<ParsingError>> {
let result = parser::parse_with_recovery(filename, content);

match result {
Ok(document) => {
Expand Down Expand Up @@ -66,9 +67,9 @@ pub fn parse<'i>(filename: &'i Path, content: &'i str) -> Result<Document<'i>, P
}
Ok(document)
}
Err(error) => {
debug!("error: {:?}", error);
Err(error)
Err(errors) => {
debug!("errors: {}", errors.len());
Err(errors)
}
}
}
Loading