git.delta.rocks / jrsonnet / refs/commits / b9857aed17e5

difftreelog

style rename ast file_name to source

Yaroslav Bolyukin2022-11-09parent: #87a7e44.patch.diff
in: master

4 files changed

modifiedcrates/jrsonnet-evaluator/src/lib.rsdiffbeforeafterboth
--- a/crates/jrsonnet-evaluator/src/lib.rs
+++ b/crates/jrsonnet-evaluator/src/lib.rs
@@ -63,16 +63,15 @@
 use std::{
 	any::Any,
 	cell::{Ref, RefCell, RefMut},
-	collections::HashMap,
 	fmt::{self, Debug},
 	path::Path,
 };
 
 pub use ctx::*;
 pub use dynamic::*;
-use error::{Error::*, LocError, Result, ResultExt};
+pub use error::{Error::*, LocError, Result, ResultExt};
 pub use evaluate::*;
-use function::{CallLocation, TlaArg};
+use function::CallLocation;
 use gc::{GcHashMap, TraceBox};
 use hashbrown::hash_map::RawEntryMut;
 pub use import::*;
@@ -305,7 +304,7 @@
 				jrsonnet_parser::parse(
 					code,
 					&ParserSettings {
-						file_name: file_name.clone(),
+						source: file_name.clone(),
 					},
 				)
 				.map_err(|e| ImportSyntaxError {
@@ -411,7 +410,7 @@
 		let parsed = jrsonnet_parser::parse(
 			&code,
 			&ParserSettings {
-				file_name: source.clone(),
+				source: source.clone(),
 			},
 		)
 		.map_err(|e| ImportSyntaxError {
modifiedcrates/jrsonnet-parser/src/lib.rsdiffbeforeafterboth
--- a/crates/jrsonnet-parser/src/lib.rs
+++ b/crates/jrsonnet-parser/src/lib.rs
@@ -14,7 +14,7 @@
 pub use source::{Source, SourceDirectory, SourceFile, SourcePath, SourcePathT, SourceVirtual};
 
 pub struct ParserSettings {
-	pub file_name: Source,
+	pub source: Source,
 }
 
 macro_rules! expr_bin {
@@ -230,7 +230,7 @@
 		pub rule var_expr(s: &ParserSettings) -> Expr
 			= n:id() { expr::Expr::Var(n) }
 		pub rule id_loc(s: &ParserSettings) -> LocExpr
-			= a:position!() n:id() b:position!() { LocExpr(Rc::new(expr::Expr::Str(n)), ExprLocation(s.file_name.clone(), a as u32,b as u32)) }
+			= a:position!() n:id() b:position!() { LocExpr(Rc::new(expr::Expr::Str(n)), ExprLocation(s.source.clone(), a as u32,b as u32)) }
 		pub rule if_then_else_expr(s: &ParserSettings) -> Expr
 			= cond:ifspec(s) _ keyword("then") _ cond_then:expr(s) cond_else:(_ keyword("else") _ e:expr(s) {e})? {Expr::IfElse{
 				cond,
@@ -293,7 +293,7 @@
 		use UnaryOpType::*;
 		rule expr(s: &ParserSettings) -> LocExpr
 			= precedence! {
-				start:position!() v:@ end:position!() { LocExpr(Rc::new(v), ExprLocation(s.file_name.clone(), start as u32, end as u32)) }
+				start:position!() v:@ end:position!() { LocExpr(Rc::new(v), ExprLocation(s.source.clone(), start as u32, end as u32)) }
 				--
 				a:(@) _ binop(<"||">) _ b:@ {expr_bin!(a Or b)}
 				--
@@ -351,7 +351,7 @@
 	let len = str.len();
 	LocExpr(
 		Rc::new(Expr::Str(str)),
-		ExprLocation(settings.file_name.clone(), 0, len as u32),
+		ExprLocation(settings.source.clone(), 0, len as u32),
 	)
 }
 
@@ -368,7 +368,7 @@
 			parse(
 				$s,
 				&ParserSettings {
-					file_name: Source::new_virtual("<test>".into(), IStr::empty()),
+					source: Source::new_virtual("<test>".into(), IStr::empty()),
 				},
 			)
 			.unwrap()
@@ -719,7 +719,7 @@
 		let file_name = Source::new_virtual("<test>".into(), IStr::empty());
 		let expr = parse(
 			"{} { local x = 1, x: x } + {}",
-			&ParserSettings { file_name },
+			&ParserSettings { source: file_name },
 		)
 		.unwrap();
 		assert_eq!(
modifiedcrates/jrsonnet-stdlib/build.rsdiffbeforeafterboth
before · crates/jrsonnet-stdlib/build.rs
1use std::{env, fs::File, io::Write, path::Path};23use jrsonnet_parser::{parse, ParserSettings, Source};4use structdump::CodegenResult;56fn main() {7	let parsed = parse(8		include_str!("./src/std.jsonnet"),9		&ParserSettings {10			file_name: Source::new_virtual(11				"<std>".into(),12				include_str!("./src/std.jsonnet").into(),13			),14		},15	)16	.expect("parse");1718	let mut out = CodegenResult::default();1920	let v = out.codegen(&parsed, true);2122	{23		let out_dir = env::var("OUT_DIR").unwrap();24		let dest_path = Path::new(&out_dir).join("stdlib.rs");25		let mut f = File::create(&dest_path).unwrap();26		f.write_all(27			("#[allow(clippy::redundant_clone)]".to_owned() + &v.to_string())28				.replace(';', ";\n")29				.as_bytes(),30		)31		.unwrap();32	}33}
after · crates/jrsonnet-stdlib/build.rs
1use std::{env, fs::File, io::Write, path::Path};23use jrsonnet_parser::{parse, ParserSettings, Source};4use structdump::CodegenResult;56fn main() {7	let parsed = parse(8		include_str!("./src/std.jsonnet"),9		&ParserSettings {10			source: Source::new_virtual("<std>".into(), include_str!("./src/std.jsonnet").into()),11		},12	)13	.expect("parse");1415	let mut out = CodegenResult::default();1617	let v = out.codegen(&parsed, true);1819	{20		let out_dir = env::var("OUT_DIR").unwrap();21		let dest_path = Path::new(&out_dir).join("stdlib.rs");22		let mut f = File::create(&dest_path).unwrap();23		f.write_all(24			("#[allow(clippy::redundant_clone)]".to_owned() + &v.to_string())25				.replace(';', ";\n")26				.as_bytes(),27		)28		.unwrap();29	}30}
modifiedcrates/jrsonnet-stdlib/src/lib.rsdiffbeforeafterboth
--- a/crates/jrsonnet-stdlib/src/lib.rs
+++ b/crates/jrsonnet-stdlib/src/lib.rs
@@ -215,7 +215,7 @@
 	pub path_resolver: PathResolver,
 }
 
-pub fn extvar_source(name: &str, code: impl Into<IStr>) -> Source {
+fn extvar_source(name: &str, code: impl Into<IStr>) -> Source {
 	let source_name = format!("<extvar:{}>", name);
 	Source::new_virtual(source_name.into(), code.into())
 }
@@ -277,7 +277,7 @@
 		let parsed = jrsonnet_parser::parse(
 			&code,
 			&jrsonnet_parser::ParserSettings {
-				file_name: source.clone(),
+				source: source.clone(),
 			},
 		)
 		.map_err(|e| ImportSyntaxError {