Skip to content

Commit

Permalink
parse some more syntax (#8)
Browse files Browse the repository at this point in the history
* fix chumsky integration bugs; support multiple statements, places, ranges, whitespace

* parse aliases

* parse enums

* parse strings

* parse comments
  • Loading branch information
jyn514 authored Oct 19, 2024
1 parent 50bda37 commit d42dbb2
Show file tree
Hide file tree
Showing 20 changed files with 711 additions and 128 deletions.
162 changes: 134 additions & 28 deletions lang/Cargo.lock

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

6 changes: 4 additions & 2 deletions lang/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,10 @@ version = "0.1.0"
edition = "2021"

[dependencies]
chumsky = { version = "1.0.0-alpha.7", features = ["extension"] }
rowan = "0.15.16"
# chumsky = { version = "1.0.0-alpha.7", features = ["extension"] }
chumsky = { git = "https://github.com/jyn514/chumsky", rev = "8baf2151f0e8e5904847056b7bde0d06a2be8dee", version = "1.0.0-alpha.7", features = ["extension"] }
# rowan = "0.15.16"
cstree = { git = "https://github.com/jyn514/cstree", rev = "6116e41806e7fce57e1cc078c19d117c3e0b5075", version = "0.12" }

[dev-dependencies]
ctrlc = "3.4.5"
Expand Down
20 changes: 6 additions & 14 deletions lang/src/bin/raw_dump.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,22 +15,14 @@ impl From<io::Error> for Error {
fn main() -> Result<(), Error> {
let path = std::env::args().nth(1).unwrap();
let input = std::fs::read_to_string(path)?;
let output = lang::parse(&input);
if output.errors.is_empty() {
dbg(output.red_tree(), 0);
let mut output = lang::parse(&input);
// steal these errors so they don't get printed in the debug output
let errs = std::mem::take(&mut output.errors);
print!("{output:?}");
if errs.is_empty() {
Ok(())
} else {
eprintln!("{:#?}", output.errors);
eprintln!("{:#?}", errs);
Err(Error::Parse)
}
}

fn dbg(node: lang::SyntaxNode, indent: usize) {
println!("{}{:?}", " ".repeat(indent * 2), node);
for child in node.children_with_tokens() {
match child {
rowan::NodeOrToken::Node(n) => dbg(n, indent + 1),
rowan::NodeOrToken::Token(t) => println!("{}{:?}", " ".repeat((indent + 1) * 2), t),
}
}
}
Loading

0 comments on commit d42dbb2

Please sign in to comment.