diff --git a/.gitignore b/.gitignore index eea47b7..88b0f28 100644 --- a/.gitignore +++ b/.gitignore @@ -2,3 +2,5 @@ */*.png */*.schem */*.litematic +*/*.csv +*/*.txt diff --git a/Cargo.lock b/Cargo.lock index 64fcc6c..110453b 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -311,7 +311,7 @@ checksum = "f1bddf1187be692e79c5ffeab891132dfb0f236ed36a43c7ed39f1165ee20191" [[package]] name = "voxelmap" -version = "0.1.1" +version = "0.2.0" dependencies = [ "clap", "lodepng", diff --git a/Cargo.toml b/Cargo.toml index b966c25..822f5c7 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "voxelmap" -version = "0.1.1" +version = "0.2.0" authors = ["raffitz "] edition = "2018" description = "Converts mathematical descriptions of objects to voxel maps" diff --git a/examples/error_incomplete.solid b/examples/error_incomplete.solid new file mode 100644 index 0000000..8422b9c --- /dev/null +++ b/examples/error_incomplete.solid @@ -0,0 +1,6 @@ +# circle with radius s +-s ≤ x ≤ s +-s ≤ y ≤ s +0 ≤ z ≤ 0 + +ρ ≤ s + \ No newline at end of file diff --git a/examples/error_line_end.solid b/examples/error_line_end.solid new file mode 100644 index 0000000..44b1026 --- /dev/null +++ b/examples/error_line_end.solid @@ -0,0 +1,6 @@ +# circle with radius s +-s ≤ x ≤ s +-s ≤ y ≤ s +0 ≤ z ≤ 0 + +ρ ≤ s + diff --git a/examples/error_parser.solid b/examples/error_parser.solid new file mode 100644 index 0000000..f9af9f6 --- /dev/null +++ b/examples/error_parser.solid @@ -0,0 +1,6 @@ +# circle with radius s +-s ≤ x ≤ s +-s ≤ y ≤ s +0 ≤ z ≤ 0 + +ρ ≤ ≤ s diff --git a/examples/error_tokenizer.solid b/examples/error_tokenizer.solid new file mode 100644 index 0000000..48aded1 --- /dev/null +++ b/examples/error_tokenizer.solid @@ -0,0 +1,6 @@ +# circle with radius s +-s ≤ x ≤ s +-s ≤ y ≤ s +0 ≤ z ≤ 0 + +ρ ç s diff --git a/src/main.rs b/src/main.rs index acdd903..55a5ceb 100644 --- a/src/main.rs +++ b/src/main.rs @@ -368,11 +368,15 @@ fn main() -> Result<(), error::Error> { let mut line_ends = false; - for token in lex { + let mut reason = "parsing"; + + for (token, span) in lex.spanned() { if debug { println!("{:?}", token); } - if token == parser::Token::LineEnd { + if token == parser::Token::Error { + reason = "tokenizing"; + } else if token == parser::Token::LineEnd { if line_ends { continue; } else { @@ -381,10 +385,45 @@ fn main() -> Result<(), error::Error> { } else { line_ends = false; } - p.parse(token)?; + if p.parse(token).is_err() { + let mut line = 1; + let mut col = 1; + for (index, _) in data.match_indices('\n') { + if index > span.start { + break; + } + line += 1; + col = span.start - index; + } + let token_val = if line_ends { + r"\n" + } else { + data.get(span).unwrap() + }; + eprintln!( + "{}:{}:{}: Error {} \"{}\"", + matches.value_of("FILE").unwrap(), + line, + col, + reason, + token_val + ); + fs::remove_dir(matches.value_of("OUTPUT_DIR").unwrap())?; + return Err(Error::ParserError); + } } - let (assigns, limits, tree) = p.end_of_input()?; + let (assigns, limits, tree) = match p.end_of_input() { + Ok(result) => Ok(result), + Err(_) => { + eprintln!( + "{}: Unexpected end of file", + matches.value_of("FILE").unwrap() + ); + fs::remove_dir(matches.value_of("OUTPUT_DIR").unwrap())?; + Err(Error::ParserError) + } + }?; let idents = assigns.unwrap_or_default(); let ident_arg = Some(&idents);