Skip to content

Commit

Permalink
Make semdemo parse to AST use oq3_source_file (#48)
Browse files Browse the repository at this point in the history
* Make semdemo parse to AST use oq3_source_file

Before this commit, QASM_PATH is respected by `semdemo semantics` but not `semdemo parse`.

This commit allows files to be found in QASM_PATH when running `semdemo parse`.
This is needed when debugging and switching between `semdemo parse` and `semdemo semantics`.

For example, the following works with QASM_PATH
cargo run --example semdemo -- parse ex.qasm

Closes #41

* Make semdemo.rs clippy compliant

I already did this once. But that commit got lost somehow.
  • Loading branch information
jlapeyre authored Jan 18, 2024
1 parent fa4a97e commit 39b5c66
Showing 1 changed file with 4 additions and 6 deletions.
10 changes: 4 additions & 6 deletions crates/oq3_semantics/examples/semdemo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,10 @@ use std::path::PathBuf;
use oq3_lexer::{tokenize, Token};
use oq3_parser::SyntaxKind;
use oq3_semantics::syntax_to_semantics;
use oq3_source_file::SourceTrait;
use oq3_syntax::{parse_text, GreenNode, SourceFile};
use rowan::NodeOrToken; // TODO: this can be accessed from a higher level

// use source_file::source_file;
//use source_file::{SourceTrait};

#[derive(Parser)]
#[command(name = "demotest")]
#[command(about = "Demo of parser that parses and prints tokens or trees to stdout.")]
Expand Down Expand Up @@ -120,13 +118,13 @@ fn main() {
// context.program().print_asg_debug_pretty();
// }
Some(Commands::Parse { file_name }) => {
let parsed_source = SourceFile::parse(&read_example_source(file_name));
let parse_tree: SourceFile = parsed_source.tree();
let parsed_source = oq3_source_file::parse_source_file(file_name);
let parse_tree = parsed_source.syntax_ast().tree();
println!(
"Found {} items",
parse_tree.items().collect::<Vec<_>>().len()
);
let syntax_errors = parsed_source.errors();
let syntax_errors = parsed_source.syntax_ast().errors();
println!(
"Found {} parse errors:\n{:?}\n",
syntax_errors.len(),
Expand Down

0 comments on commit 39b5c66

Please sign in to comment.