Browse Source

Improve error handling

Add error examples
Improve .gitignore to exclude csvs and txts
Bump version
main
raffitz 2 years ago
parent
commit
80474bc838
Signed by: raffitz
GPG Key ID: BB3596BD0A31252D
  1. 2
      .gitignore
  2. 2
      Cargo.lock
  3. 2
      Cargo.toml
  4. 6
      examples/error_incomplete.solid
  5. 6
      examples/error_line_end.solid
  6. 6
      examples/error_parser.solid
  7. 6
      examples/error_tokenizer.solid
  8. 47
      src/main.rs

2
.gitignore vendored

@ -2,3 +2,5 @@ @@ -2,3 +2,5 @@
*/*.png
*/*.schem
*/*.litematic
*/*.csv
*/*.txt

2
Cargo.lock generated

@ -311,7 +311,7 @@ checksum = "f1bddf1187be692e79c5ffeab891132dfb0f236ed36a43c7ed39f1165ee20191" @@ -311,7 +311,7 @@ checksum = "f1bddf1187be692e79c5ffeab891132dfb0f236ed36a43c7ed39f1165ee20191"
[[package]]
name = "voxelmap"
version = "0.1.1"
version = "0.2.0"
dependencies = [
"clap",
"lodepng",

2
Cargo.toml

@ -1,6 +1,6 @@ @@ -1,6 +1,6 @@
[package]
name = "voxelmap"
version = "0.1.1"
version = "0.2.0"
authors = ["raffitz <raf.a.m.c.gon@gmail.com>"]
edition = "2018"
description = "Converts mathematical descriptions of objects to voxel maps"

6
examples/error_incomplete.solid

@ -0,0 +1,6 @@ @@ -0,0 +1,6 @@
# circle with radius s
-s ≤ x ≤ s
-s ≤ y ≤ s
0 ≤ z ≤ 0
ρ ≤ s +

6
examples/error_line_end.solid

@ -0,0 +1,6 @@ @@ -0,0 +1,6 @@
# circle with radius s
-s ≤ x ≤ s
-s ≤ y ≤ s
0 ≤ z ≤ 0
ρ ≤ s +

6
examples/error_parser.solid

@ -0,0 +1,6 @@ @@ -0,0 +1,6 @@
# circle with radius s
-s ≤ x ≤ s
-s ≤ y ≤ s
0 ≤ z ≤ 0
ρ ≤ ≤ s

6
examples/error_tokenizer.solid

@ -0,0 +1,6 @@ @@ -0,0 +1,6 @@
# circle with radius s
-s ≤ x ≤ s
-s ≤ y ≤ s
0 ≤ z ≤ 0
ρ ç s

47
src/main.rs

@ -368,11 +368,15 @@ fn main() -> Result<(), error::Error> { @@ -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> { @@ -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);

Loading…
Cancel
Save