-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2 from ricglz/proposal_feedback
proposal feedback
- Loading branch information
Showing
14 changed files
with
166 additions
and
79 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
# Raoul | ||
|
||
Imperative language done as compilers class final project | ||
|
||
## How to run it? | ||
|
||
``` | ||
cargo run -- examples/filename.ra | ||
``` | ||
|
||
### Flags | ||
|
||
- `-d` or `--debug`. Shows debugging message for the developer of the language |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,25 @@ | ||
use clap::{Arg, Command, ArgMatches}; | ||
use clap::{Arg, ArgMatches, Command}; | ||
|
||
pub fn parse_args() -> ArgMatches { | ||
Command::new("raoul") | ||
.version("1.0") | ||
.author("ricglz") | ||
.about("My cool programming language") | ||
.arg(Arg::new("file") | ||
.value_name("FILE") | ||
.help("Sets a file to parse") | ||
.required(true)) | ||
.arg(Arg::new("verbose") | ||
.short('v') | ||
.long("verbose") | ||
.value_name("VERBOSE") | ||
.help("Makes it verbose") | ||
.default_value("false") | ||
.takes_value(false) | ||
.required(false)) | ||
.arg( | ||
Arg::new("file") | ||
.value_name("FILE") | ||
.help("Sets a file to parse") | ||
.required(true), | ||
) | ||
.arg( | ||
Arg::new("verbose") | ||
.short('d') | ||
.long("debug") | ||
.value_name("DEBUG") | ||
.help("Displays debugging prints throughout the process") | ||
.default_value("false") | ||
.takes_value(false) | ||
.required(false), | ||
) | ||
.get_matches() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,26 @@ | ||
mod args; | ||
mod enums; | ||
mod parser; | ||
mod test_parser; | ||
#[macro_use] | ||
extern crate pest_derive; | ||
|
||
use std::process::exit; | ||
|
||
use crate::parser::parse; | ||
use crate::args::parse_args; | ||
use args::parse_args; | ||
use test_parser::parse_file; | ||
|
||
fn main() { | ||
let matches = parse_args(); | ||
let filename = matches.value_of("file").expect("required"); | ||
let verbose = matches.is_present("verbose"); | ||
if verbose { | ||
let debug = matches.is_present("debug"); | ||
if debug { | ||
println!("Starting parsing"); | ||
} | ||
if let Err(error) = parse(filename, verbose) { | ||
if let Err(error) = parse_file(filename, debug) { | ||
println!("Parsing error {}", error.to_string()); | ||
exit(1); | ||
} | ||
if verbose { | ||
if debug { | ||
println!("Parsing ended sucessfully"); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
use pest::error::Error; | ||
use pest::Parser; | ||
|
||
#[derive(Parser)] | ||
#[grammar = "parser/grammar.pest"] // relative to src | ||
struct MyParser; | ||
|
||
fn parse(source: &str) -> Result<(), Error<Rule>> { | ||
if let Err(err) = MyParser::parse(Rule::program, &source) { | ||
Err(err) | ||
} else { | ||
Ok(()) | ||
} | ||
} | ||
|
||
pub fn parse_file(filename: &str, debug: bool) -> Result<(), Error<Rule>> { | ||
let program = std::fs::read_to_string(filename).expect(filename); | ||
if debug { | ||
println!("Testing {:?}", filename); | ||
} | ||
parse(&program) | ||
} | ||
|
||
#[cfg(test)] | ||
mod tests { | ||
use std::fs::read_dir; | ||
|
||
use super::*; | ||
|
||
#[test] | ||
fn example_files() { | ||
let paths = read_dir("examples").unwrap(); | ||
for path in paths { | ||
let file_path = path.expect("File must exist").path(); | ||
let file = file_path.to_str().unwrap(); | ||
assert!(parse_file(file, true).is_ok()); | ||
} | ||
} | ||
} |