Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
120 changes: 120 additions & 0 deletions Cargo.lock

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

3 changes: 3 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ categories = ["command-line-utilities", "development-tools", "compilers", "text-
log = "0.4.21"
pretty_env_logger = "0.5.0"

# For CLI argument parsing.
clap = { version = "4.5.0", features = ["derive"] }

# For custom errors.
thiserror = "2.0.0"

Expand Down
9 changes: 4 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,19 +18,18 @@ Monkey has a C-like syntax, supports **variable bindings**, **prefix** and **inf

## Content
* [Usage](#usage)
+ [Usage - Logging](#usage-logging)
* [Compiling](#compiling)
* [Unit Testing](#unit-testing)
* [Issues/Feature Requests](#issuesfeature-requests)


## Usage
Run the interpreter via

```sh
monkey_interpreter
```

### Usage - Logging
The crates `pretty_env_logger` and `log` are used to provide logging.
The environment variable `RUST_LOG` can be used to set the logging level.
See [https://crates.io/crates/pretty_env_logger](https://crates.io/crates/pretty_env_logger) for more detailed documentation.


## Compiling
Expand Down
11 changes: 11 additions & 0 deletions src/cli/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
use clap::Parser;

#[derive(Parser, Debug)]
#[command(version, about, long_about = None)]
pub(crate) struct Arguments {
#[arg(
long,
help = "Enable verbose output, respects RUST_LOG environment variable if set."
)]
pub(crate) verbose: bool,
}
13 changes: 12 additions & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,29 @@ extern crate pretty_env_logger;
use std::io::{stdin, stdout, Write};

use anyhow::{Context, Result};
use clap::Parser;

use crate::cli::Arguments;
use crate::evaluator::Evaluator;
use crate::lexical_analysis::LexicalAnalysis;
use crate::syntax_analysis::SyntaxAnalysis;

mod cli;
mod evaluator;
mod lexical_analysis;
mod syntax_analysis;

fn main() {
info!("Version {}.", env!("CARGO_PKG_VERSION"));
let arguments = Arguments::parse();
debug!("The command line arguments provided are {arguments:?}.");

// Set up logging: if verbose is true and RUST_LOG is not set, default to info level
if arguments.verbose && std::env::var("RUST_LOG").is_err() {
std::env::set_var("RUST_LOG", "info");
}

pretty_env_logger::init();
trace!("Version {}.", env!("CARGO_PKG_VERSION"));
let mut evaluator = crate::evaluator::Evaluator::new();

loop {
Expand Down