Skip to content

Commit

Permalink
refactor: switch to nom-based parser
Browse files Browse the repository at this point in the history
  • Loading branch information
CertainLach committed Jul 5, 2024
1 parent 74ea504 commit eb83abb
Show file tree
Hide file tree
Showing 33 changed files with 3,033 additions and 814 deletions.
78 changes: 44 additions & 34 deletions Cargo.lock

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

7 changes: 2 additions & 5 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ sha3 = "0.10.8"
# Source code parsing.
# Jrsonnet has two parsers for jsonnet - one is for execution, and another is for better parsing diagnostics/lints/LSP.
# First (and fast one) is based on peg, second is based on rowan.
peg = "0.8.3"
nom = "7.1.3"
logos = "0.14.0"
ungrammar = "1.16.1"
rowan = "0.15.15"
Expand All @@ -69,7 +69,7 @@ tempfile = "3.10"
pathdiff = "0.2.1"
hashbrown = "0.14.5"
static_assertions = "1.1"
rustc-hash = "1.1"
rustc-hash = "2.0"
num-bigint = "0.4.5"
derivative = "2.2.0"
strsim = "0.11.0"
Expand All @@ -82,9 +82,6 @@ indexmap = "2.2.3"
itertools = "0.13.0"
xshell = "0.2.6"

lsp-server = "0.7.6"
lsp-types = "0.96.0"

regex = "1.10"
lru = "0.12.3"

Expand Down
23 changes: 22 additions & 1 deletion cmds/jrsonnet/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
// #![cfg(feature = "nightly", feature(unix_sigpipe))]

use std::{
fs::{create_dir_all, File},
io::{Read, Write},
path::PathBuf,
};

use clap::{CommandFactory, Parser};
Expand All @@ -11,6 +14,7 @@ use jrsonnet_evaluator::{
error::{Error as JrError, ErrorKind},
ResultExt, State, Val,
};
use jrsonnet_parser::Source;

#[cfg(feature = "mimalloc")]
#[global_allocator]
Expand All @@ -23,6 +27,11 @@ enum SubOpts {
/// Target shell name
shell: Shell,
},
Analyze {
#[command(flatten)]
stdlib: StdOpts,
file: PathBuf,
},
}

#[derive(Parser)]
Expand Down Expand Up @@ -87,7 +96,9 @@ struct Opts {
debug: DebugOpts,
}

// TODO: Add unix_sigpipe = "sig_dfl"
// // Do not panic on pipe failure: https://github.com/rust-lang/rust/issues/97889
// #[cfg(feature = "nightly", unix_sigpipe = "sig_dfl")]
// Feature was replaced with compiler flag, which can't be feature-gated, thus recommended, but only enabled in nix flake based builds.
fn main() {
let opts: Opts = Opts::parse();

Expand All @@ -105,6 +116,16 @@ fn main() {
generate(shell, app, "jrsonnet", buf);
std::process::exit(0)
}
SubOpts::Analyze { file, stdlib } => {
let content = std::fs::read_to_string(file).expect("read file failed");
let source = Source::new_virtual("name".into(), (&content).into());
let ast =
jrsonnet_parser::parse(&content, &jrsonnet_parser::ParserSettings { source })
.expect("parsed");
let ctx = stdlib.context_initializer().expect("ctx");
jrsonnet_evaluator::analyze_root(State::default(), &ast, ctx);
std::process::exit(0)
}
}
}

Expand Down
2 changes: 2 additions & 0 deletions crates/jrsonnet-evaluator/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -61,3 +61,5 @@ hi-doc = { workspace = true, optional = true }
num-bigint = { workspace = true, features = ["serde"], optional = true }
derivative.workspace = true
stacker = "0.1.15"
smallvec = "1.13.2"
drop_bomb.workspace = true
Loading

0 comments on commit eb83abb

Please sign in to comment.