git.delta.rocks / jrsonnet / refs/commits / 433adfa9b8ae

difftreelog

source

crates/jrsonnet-parser/src/lib.rs17.9 KiBsourcehistory
1#![feature(box_syntax)]2#![feature(test)]34extern crate test;56use peg::parser;7use std::{path::PathBuf, rc::Rc};8mod expr;9pub use expr::*;10pub use peg;1112#[derive(Default)]13pub struct ParserSettings {14	pub loc_data: bool,15	pub file_name: Rc<PathBuf>,16}1718parser! {19	grammar jsonnet_parser() for str {20		use peg::ParseLiteral;2122		/// Standard C-like comments23		rule comment()24			= "//" (!['\n'][_])* "\n"25			/ "/*" ("\\*/" / "\\\\" / (!("*/")[_]))* "*/"26			/ "#" (!['\n'][_])* "\n"2728		rule single_whitespace() = quiet!{([' ' | '\r' | '\n' | '\t'] / comment())} / expected!("<whitespace>")29		rule _() = single_whitespace()*3031		/// For comma-delimited elements32		rule comma() = quiet!{_ "," _} / expected!("<comma>")33		rule alpha() -> char = c:$(['_' | 'a'..='z' | 'A'..='Z']) {c.chars().next().unwrap()}34		rule digit() -> char = d:$(['0'..='9']) {d.chars().next().unwrap()}35		rule end_of_ident() = !['0'..='9' | '_' | 'a'..='z' | 'A'..='Z']36		/// Sequence of digits37		rule uint() -> u64 = a:$(digit()+) { a.parse().unwrap() }38		/// Number in scientific notation format39		rule number() -> f64 = quiet!{a:$(uint() ("." uint())? (['e'|'E'] (s:['+'|'-'])? uint())?) { a.parse().unwrap() }} / expected!("<number>")4041		/// Reserved word followed by any non-alphanumberic42		rule reserved() = ("assert" / "else" / "error" / "false" / "for" / "function" / "if" / "import" / "importstr" / "in" / "local" / "null" / "tailstrict" / "then" / "self" / "super" / "true") end_of_ident()43		rule id() = quiet!{ !reserved() alpha() (alpha() / digit())*} / expected!("<identifier>")4445		rule keyword(id: &'static str)46			= ##parse_string_literal(id) end_of_ident()47		// Adds location data information to existing expression48		rule l(s: &ParserSettings, x: rule<Expr>) -> LocExpr49			= start:position!() v:x() end:position!() {loc_expr!(v, s.loc_data, (s.file_name.clone(), start, end))}5051		pub rule param(s: &ParserSettings) -> expr::Param = name:$(id()) expr:(_ "=" _ expr:expr(s){expr})? { expr::Param(name.into(), expr) }52		pub rule params(s: &ParserSettings) -> expr::ParamsDesc53			= params:param(s) ** comma() comma()? {54				let mut defaults_started = false;55				for param in &params {56					defaults_started = defaults_started || param.1.is_some();57					assert_eq!(defaults_started, param.1.is_some(), "defauld parameters should be used after all positionals");58				}59				expr::ParamsDesc(Rc::new(params))60			}61			/ { expr::ParamsDesc(Rc::new(Vec::new())) }6263		pub rule arg(s: &ParserSettings) -> expr::Arg64			= name:$(id()) _ "=" _ expr:expr(s) {expr::Arg(Some(name.into()), expr)}65			/ expr:expr(s) {expr::Arg(None, expr)}66		pub rule args(s: &ParserSettings) -> expr::ArgsDesc67			= args:arg(s) ** comma() comma()? {68				let mut named_started = false;69				for arg in &args {70					named_started = named_started || arg.0.is_some();71					assert_eq!(named_started, arg.0.is_some(), "named args should be used after all positionals");72				}73				expr::ArgsDesc(args)74			}75			/ { expr::ArgsDesc(Vec::new()) }7677		pub rule bind(s: &ParserSettings) -> expr::BindSpec78			= name:$(id()) _ "=" _ expr:expr(s) {expr::BindSpec{name:name.into(), params: None, value: expr}}79			/ name:$(id()) _ "(" _ params:params(s) _ ")" _ "=" _ expr:expr(s) {expr::BindSpec{name:name.into(), params: Some(params), value: expr}}80		pub rule assertion(s: &ParserSettings) -> expr::AssertStmt81			= keyword("assert") _ cond:expr(s) msg:(_ ":" _ e:expr(s) {e})? { expr::AssertStmt(cond, msg) }8283		pub rule whole_line() -> &'input str84			= str:$((!['\n'][_])* "\n") {str}85		pub rule string_block() -> String86			= "|||" (!['\n']single_whitespace())* "\n"87			  prefix:[' ' | '\t']+ first_line:whole_line()88			  lines:([' ' | '\t']*<{prefix.len()}> s:whole_line() {s})*89			  [' ' | '\t']*<, {prefix.len() - 1}> "|||"90			  {let mut l = first_line.to_owned(); l.extend(lines); l}91		pub rule string() -> String92			= "\"" str:$(("\\\"" / "\\\\" / (!['"'][_]))*) "\"" {unescape::unescape(str).unwrap()}93			/ "'" str:$(("\\'" / "\\\\" / (!['\''][_]))*) "'" {unescape::unescape(str).unwrap()}94			/ "@'" str:$(("''" / (!['\''][_]))*) "'" {str.replace("''", "'")}95			/ "@\"" str:$(("\"\"" / (!['"'][_]))*) "\"" {str.replace("\"\"", "\"")}96			/ string_block()9798		pub rule field_name(s: &ParserSettings) -> expr::FieldName99			= name:$(id()) {expr::FieldName::Fixed(name.into())}100			/ name:string() {expr::FieldName::Fixed(name.into())}101			/ "[" _ expr:expr(s) _ "]" {expr::FieldName::Dyn(expr)}102		pub rule visibility() -> expr::Visibility103			= ":::" {expr::Visibility::Unhide}104			/ "::" {expr::Visibility::Hidden}105			/ ":" {expr::Visibility::Normal}106		pub rule field(s: &ParserSettings) -> expr::FieldMember107			= name:field_name(s) _ plus:"+"? _ visibility:visibility() _ value:expr(s) {expr::FieldMember{108				name,109				plus: plus.is_some(),110				params: None,111				visibility,112				value,113			}}114			/ name:field_name(s) _ "(" _ params:params(s) _ ")" _ visibility:visibility() _ value:expr(s) {expr::FieldMember{115				name,116				plus: false,117				params: Some(params),118				visibility,119				value,120			}}121		pub rule obj_local(s: &ParserSettings) -> BindSpec122			= keyword("local") _ bind:bind(s) {bind}123		pub rule member(s: &ParserSettings) -> expr::Member124			= bind:obj_local(s) {expr::Member::BindStmt(bind)}125			/ assertion:assertion(s) {expr::Member::AssertStmt(assertion)}126			/ field:field(s) {expr::Member::Field(field)}127		pub rule objinside(s: &ParserSettings) -> expr::ObjBody128			= pre_locals:(b: obj_local(s) comma() {b})* "[" _ key:expr(s) _ "]" _ ":" _ value:expr(s) post_locals:(comma() b:obj_local(s) {b})* _ forspec:forspec(s) others:(_ rest:compspec(s) {rest})? {129				let mut compspecs = vec![CompSpec::ForSpec(forspec)];130				compspecs.extend(others.unwrap_or_default());131				expr::ObjBody::ObjComp(expr::ObjComp{132					pre_locals,133					key,134					value,135					post_locals,136					compspecs,137				})138			}139			/ members:(member(s) ** comma()) comma()? {expr::ObjBody::MemberList(members)}140		pub rule ifspec(s: &ParserSettings) -> IfSpecData141			= keyword("if") _ expr:expr(s) {IfSpecData(expr)}142		pub rule forspec(s: &ParserSettings) -> ForSpecData143			= keyword("for") _ id:$(id()) _ keyword("in") _ cond:expr(s) {ForSpecData(id.into(), cond)}144		pub rule compspec(s: &ParserSettings) -> Vec<expr::CompSpec>145			= s:(i:ifspec(s) { expr::CompSpec::IfSpec(i) } / f:forspec(s) {expr::CompSpec::ForSpec(f)} ) ** _ {s}146		pub rule local_expr(s: &ParserSettings) -> LocExpr147			= l(s,<keyword("local") _ binds:bind(s) ** comma() _ ";" _ expr:expr(s) { Expr::LocalExpr(binds, expr) }>)148		pub rule string_expr(s: &ParserSettings) -> LocExpr149			= l(s, <s:string() {Expr::Str(s.into())}>)150		pub rule obj_expr(s: &ParserSettings) -> LocExpr151			= l(s,<"{" _ body:objinside(s) _ "}" {Expr::Obj(body)}>)152		pub rule array_expr(s: &ParserSettings) -> LocExpr153			= l(s,<"[" _ elems:(expr(s) ** comma()) _ comma()? "]" {Expr::Arr(elems)}>)154		pub rule array_comp_expr(s: &ParserSettings) -> LocExpr155			= l(s,<"[" _ expr:expr(s) _ comma()? _ forspec:forspec(s) _ others:(others: compspec(s) _ {others})? "]" {156				let mut specs = vec![CompSpec::ForSpec(forspec)];157				specs.extend(others.unwrap_or_default());158				Expr::ArrComp(expr, specs)159			}>)160		pub rule number_expr(s: &ParserSettings) -> LocExpr161			= l(s,<n:number() { expr::Expr::Num(n) }>)162		pub rule var_expr(s: &ParserSettings) -> LocExpr163			= l(s,<n:$(id()) { expr::Expr::Var(n.into()) }>)164		pub rule if_then_else_expr(s: &ParserSettings) -> LocExpr165			= l(s,<cond:ifspec(s) _ keyword("then") _ cond_then:expr(s) cond_else:(_ keyword("else") _ e:expr(s) {e})? {Expr::IfElse{166				cond,167				cond_then,168				cond_else,169			}}>)170171		pub rule literal(s: &ParserSettings) -> LocExpr172			= l(s,<v:(173				keyword("null") {LiteralType::Null}174				/ keyword("true") {LiteralType::True}175				/ keyword("false") {LiteralType::False}176				/ keyword("self") {LiteralType::This}177				/ keyword("$") {LiteralType::Dollar}178				/ keyword("super") {LiteralType::Super}179			) {Expr::Literal(v)}>)180181		pub rule expr_basic(s: &ParserSettings) -> LocExpr182			= literal(s)183184			/ string_expr(s) / number_expr(s)185			/ array_expr(s)186			/ obj_expr(s)187			/ array_expr(s)188			/ array_comp_expr(s)189190			/ l(s,<keyword("importstr") _ path:string() {Expr::ImportStr(PathBuf::from(path))}>)191			/ l(s,<keyword("import") _ path:string() {Expr::Import(PathBuf::from(path))}>)192193			/ var_expr(s)194			/ local_expr(s)195			/ if_then_else_expr(s)196197			/ l(s,<keyword("function") _ "(" _ params:params(s) _ ")" _ expr:expr(s) {Expr::Function(params, expr)}>)198			/ l(s,<assertion:assertion(s) _ ";" _ expr:expr(s) { Expr::AssertExpr(assertion, expr) }>)199200			/ l(s,<keyword("error") _ expr:expr(s) { Expr::Error(expr) }>)201202		rule slice_part(s: &ParserSettings) -> Option<LocExpr>203			= e:(_ e:expr(s) _{e})? {e}204		pub rule slice_desc(s: &ParserSettings) -> SliceDesc205			= start:slice_part(s) ":" pair:(end:slice_part(s) step:(":" e:slice_part(s){e})? {(end, step.flatten())})? {206				let (end, step) = if let Some((end, step)) = pair {207					(end, step)208				}else{209					(None, None)210				};211212				SliceDesc { start, end, step }213			}214215		rule expr(s: &ParserSettings) -> LocExpr216			= start:position!() a:precedence! {217				a:(@) _ "||" _ b:@ {loc_expr_todo!(Expr::BinaryOp(a, BinaryOpType::Or, b))}218				--219				a:(@) _ "&&" _ b:@ {loc_expr_todo!(Expr::BinaryOp(a, BinaryOpType::And, b))}220				--221				a:(@) _ "|" _ b:@ {loc_expr_todo!(Expr::BinaryOp(a, BinaryOpType::BitOr, b))}222				--223				a:@ _ "^" _ b:(@) {loc_expr_todo!(Expr::BinaryOp(a, BinaryOpType::BitXor, b))}224				--225				a:(@) _ "&" _ b:@ {loc_expr_todo!(Expr::BinaryOp(a, BinaryOpType::BitAnd, b))}226				--227				a:(@) _ "==" _ b:@ {loc_expr_todo!(Expr::Apply(228					el!(Expr::Index(229						el!(Expr::Var("std".into())),230						el!(Expr::Str("equals".into()))231					)),232					ArgsDesc(vec![Arg(None, a), Arg(None, b)]),233					true234				))}235				a:(@) _ "!=" _ b:@ {loc_expr_todo!(Expr::UnaryOp(UnaryOpType::Not, el!(Expr::Apply(236					el!(Expr::Index(237						el!(Expr::Var("std".into())),238						el!(Expr::Str("equals".into()))239					)),240					ArgsDesc(vec![Arg(None, a), Arg(None, b)]),241					true242				))))}243				--244				a:(@) _ "<" _ b:@ {loc_expr_todo!(Expr::BinaryOp(a, BinaryOpType::Lt, b))}245				a:(@) _ ">" _ b:@ {loc_expr_todo!(Expr::BinaryOp(a, BinaryOpType::Gt, b))}246				a:(@) _ "<=" _ b:@ {loc_expr_todo!(Expr::BinaryOp(a, BinaryOpType::Lte, b))}247				a:(@) _ ">=" _ b:@ {loc_expr_todo!(Expr::BinaryOp(a, BinaryOpType::Gte, b))}248				a:(@) _ keyword("in") _ b:@ {loc_expr_todo!(Expr::Apply(249					el!(Expr::Index(250						el!(Expr::Var("std".into())),251						el!(Expr::Str("objectHasEx".into()))252					)), ArgsDesc(vec![Arg(None, b), Arg(None, a), Arg(None, el!(Expr::Literal(LiteralType::True)))]),253					true254				))}255				--256				a:(@) _ "<<" _ b:@ {loc_expr_todo!(Expr::BinaryOp(a, BinaryOpType::Lhs, b))}257				a:(@) _ ">>" _ b:@ {loc_expr_todo!(Expr::BinaryOp(a, BinaryOpType::Rhs, b))}258				--259				a:(@) _ "+" _ b:@ {loc_expr_todo!(Expr::BinaryOp(a, BinaryOpType::Add, b))}260				a:(@) _ "-" _ b:@ {loc_expr_todo!(Expr::BinaryOp(a, BinaryOpType::Sub, b))}261				--262				a:(@) _ "*" _ b:@ {loc_expr_todo!(Expr::BinaryOp(a, BinaryOpType::Mul, b))}263				a:(@) _ "/" _ b:@ {loc_expr_todo!(Expr::BinaryOp(a, BinaryOpType::Div, b))}264				a:(@) _ "%" _ b:@ {loc_expr_todo!(Expr::Apply(265					el!(Expr::Index(266						el!(Expr::Var("std".into())),267						el!(Expr::Str("mod".into()))268					)), ArgsDesc(vec![Arg(None, a), Arg(None, b)]),269					true270				))}271				--272						"-" _ b:@ {loc_expr_todo!(Expr::UnaryOp(UnaryOpType::Minus, b))}273						"!" _ b:@ {loc_expr_todo!(Expr::UnaryOp(UnaryOpType::Not, b))}274						"~" _ b:@ { loc_expr_todo!(Expr::UnaryOp(UnaryOpType::BitNot, b)) }275				--276				a:(@) _ "[" _ s:slice_desc(s) _ "]" {loc_expr_todo!(Expr::Apply(277					el!(Expr::Index(278						el!(Expr::Var("std".into())),279						el!(Expr::Str("slice".into())),280					)),281					ArgsDesc(vec![282						Arg(None, a),283						Arg(None, s.start.unwrap_or_else(||el!(Expr::Literal(LiteralType::Null)))),284						Arg(None, s.end.unwrap_or_else(||el!(Expr::Literal(LiteralType::Null)))),285						Arg(None, s.step.unwrap_or_else(||el!(Expr::Literal(LiteralType::Null)))),286					]),287					true,288				))}289				a:(@) _ "." _ s:$(id()) {loc_expr_todo!(Expr::Index(a, el!(Expr::Str(s.into()))))}290				a:(@) _ "[" _ s:expr(s) _ "]" {loc_expr_todo!(Expr::Index(a, s))}291				a:(@) _ "(" _ args:args(s) _ ")" ts:(_ keyword("tailstrict"))? {loc_expr_todo!(Expr::Apply(a, args, ts.is_some()))}292				a:(@) _ "{" _ body:objinside(s) _ "}" {loc_expr_todo!(Expr::ObjExtend(a, body))}293				--294				e:expr_basic(s) {e}295				"(" _ e:expr(s) _ ")" {loc_expr_todo!(Expr::Parened(e))}296			} end:position!() {297				let LocExpr(e, _) = a;298				LocExpr(e, if s.loc_data {299					Some(ExprLocation(s.file_name.clone(), start, end))300				} else {301					None302				})303			}304			/ e:expr_basic(s) {e}305306		pub rule jsonnet(s: &ParserSettings) -> LocExpr = _ e:expr(s) _ {e}307	}308}309310pub type ParseError = peg::error::ParseError<peg::str::LineCol>;311pub fn parse(str: &str, settings: &ParserSettings) -> Result<LocExpr, ParseError> {312	jsonnet_parser::jsonnet(str, settings)313}314315#[macro_export]316macro_rules! el {317	($expr:expr) => {318		LocExpr(std::rc::Rc::new($expr), None)319	};320}321322#[cfg(test)]323pub mod tests {324	use super::{expr::*, parse};325	use crate::ParserSettings;326	use std::path::PathBuf;327	use std::rc::Rc;328329	macro_rules! parse {330		($s:expr) => {331			parse(332				$s,333				&ParserSettings {334					loc_data: false,335					file_name: Rc::new(PathBuf::from("/test.jsonnet")),336					},337				)338			.unwrap()339		};340	}341342	mod expressions {343		use super::*;344345		pub fn basic_math() -> LocExpr {346			el!(Expr::BinaryOp(347				el!(Expr::Num(2.0)),348				BinaryOpType::Add,349				el!(Expr::BinaryOp(350					el!(Expr::Num(2.0)),351					BinaryOpType::Mul,352					el!(Expr::Num(2.0)),353				)),354			))355		}356	}357358	#[test]359	fn multiline_string() {360		assert_eq!(361			parse!("|||\n    Hello world!\n     a\n|||"),362			el!(Expr::Str("Hello world!\n a\n".into())),363		);364		assert_eq!(365			parse!("|||\n  Hello world!\n   a\n|||"),366			el!(Expr::Str("Hello world!\n a\n".into())),367		);368		assert_eq!(369			parse!("|||\n\t\tHello world!\n\t\t\ta\n|||"),370			el!(Expr::Str("Hello world!\n\ta\n".into())),371		);372		assert_eq!(373			parse!("|||\n   Hello world!\n    a\n |||"),374			el!(Expr::Str("Hello world!\n a\n".into())),375		);376	}377378	#[test]379	fn slice() {380		parse!("a[1:]");381		parse!("a[1::]");382		parse!("a[:1:]");383		parse!("a[::1]");384		parse!("str[:len - 1]");385	}386387	#[test]388	fn string_escaping() {389		assert_eq!(390			parse!(r#""Hello, \"world\"!""#),391			el!(Expr::Str(r#"Hello, "world"!"#.into())),392		);393		assert_eq!(394			parse!(r#"'Hello \'world\'!'"#),395			el!(Expr::Str("Hello 'world'!".into())),396		);397		assert_eq!(parse!(r#"'\\\\'"#), el!(Expr::Str("\\\\".into())),);398	}399400	#[test]401	fn string_unescaping() {402		assert_eq!(403			parse!(r#""Hello\nWorld""#),404			el!(Expr::Str("Hello\nWorld".into())),405		);406	}407408	#[test]409	fn string_verbantim() {410		assert_eq!(411			parse!(r#"@"Hello\n""World""""#),412			el!(Expr::Str("Hello\\n\"World\"".into())),413		);414	}415416	#[test]417	fn imports() {418		assert_eq!(419			parse!("import \"hello\""),420			el!(Expr::Import(PathBuf::from("hello"))),421		);422		assert_eq!(423			parse!("importstr \"garnish.txt\""),424			el!(Expr::ImportStr(PathBuf::from("garnish.txt")))425		);426	}427428	#[test]429	fn empty_object() {430		assert_eq!(parse!("{}"), el!(Expr::Obj(ObjBody::MemberList(vec![]))));431	}432433	#[test]434	fn basic_math() {435		assert_eq!(436			parse!("2+2*2"),437			el!(Expr::BinaryOp(438				el!(Expr::Num(2.0)),439				BinaryOpType::Add,440				el!(Expr::BinaryOp(441					el!(Expr::Num(2.0)),442					BinaryOpType::Mul,443					el!(Expr::Num(2.0))444				))445			))446		);447	}448449	#[test]450	fn basic_math_with_indents() {451		assert_eq!(parse!("2	+ 	  2	  *	2   	"), expressions::basic_math());452	}453454	#[test]455	fn basic_math_parened() {456		assert_eq!(457			parse!("2+(2+2*2)"),458			el!(Expr::BinaryOp(459				el!(Expr::Num(2.0)),460				BinaryOpType::Add,461				el!(Expr::Parened(expressions::basic_math())),462			))463		);464	}465466	/// Comments should not affect parsing467	#[test]468	fn comments() {469		assert_eq!(470			parse!("2//comment\n+//comment\n3/*test*/*/*test*/4"),471			el!(Expr::BinaryOp(472				el!(Expr::Num(2.0)),473				BinaryOpType::Add,474				el!(Expr::BinaryOp(475					el!(Expr::Num(3.0)),476					BinaryOpType::Mul,477					el!(Expr::Num(4.0))478				))479			))480		);481	}482483	/// Comments should be able to be escaped484	#[test]485	fn comment_escaping() {486		assert_eq!(487			parse!("2/*\\*/+*/ - 22"),488			el!(Expr::BinaryOp(489				el!(Expr::Num(2.0)),490				BinaryOpType::Sub,491				el!(Expr::Num(22.0))492			))493		);494	}495496	#[test]497	fn suffix() {498		// assert_eq!(parse!("std.test"), el!(Expr::Num(2.2)));499		// assert_eq!(parse!("std(2)"), el!(Expr::Num(2.2)));500		// assert_eq!(parse!("std.test(2)"), el!(Expr::Num(2.2)));501		// assert_eq!(parse!("a[b]"), el!(Expr::Num(2.2)))502	}503504	#[test]505	fn array_comp() {506		use Expr::*;507		assert_eq!(508			parse!("[std.deepJoin(x) for x in arr]"),509			el!(ArrComp(510				el!(Apply(511					el!(Index(el!(Var("std".into())), el!(Str("deepJoin".into())))),512					ArgsDesc(vec![Arg(None, el!(Var("x".into())))]),513					false,514				)),515				vec![CompSpec::ForSpec(ForSpecData(516					"x".into(),517					el!(Var("arr".into()))518				))]519			)),520		)521	}522523	#[test]524	fn reserved() {525		use Expr::*;526		assert_eq!(parse!("null"), el!(Literal(LiteralType::Null)));527		assert_eq!(parse!("nulla"), el!(Var("nulla".into())));528	}529530	#[test]531	fn multiple_args_buf() {532		parse!("a(b, null_fields)");533	}534535	#[test]536	fn infix_precedence() {537		use Expr::*;538		assert_eq!(539			parse!("!a && !b"),540			el!(BinaryOp(541				el!(UnaryOp(UnaryOpType::Not, el!(Var("a".into())))),542				BinaryOpType::And,543				el!(UnaryOp(UnaryOpType::Not, el!(Var("b".into()))))544			))545		);546	}547548	#[test]549	fn infix_precedence_division() {550		use Expr::*;551		assert_eq!(552			parse!("!a / !b"),553			el!(BinaryOp(554				el!(UnaryOp(UnaryOpType::Not, el!(Var("a".into())))),555				BinaryOpType::Div,556				el!(UnaryOp(UnaryOpType::Not, el!(Var("b".into()))))557			))558		);559	}560561	#[test]562	fn double_negation() {563		use Expr::*;564		assert_eq!(565			parse!("!!a"),566			el!(UnaryOp(567				UnaryOpType::Not,568				el!(UnaryOp(UnaryOpType::Not, el!(Var("a".into()))))569			))570		)571	}572573	#[test]574	fn array_test_error() {575		parse!("[a for a in b if c for e in f]");576		//                    ^^^^ failed code577	}578579	#[test]580	fn can_parse_stdlib() {581		parse!(jrsonnet_stdlib::STDLIB_STR);582	}583584	use test::Bencher;585586	// From source code587	#[bench]588	fn bench_parse_peg(b: &mut Bencher) {589		b.iter(|| parse!(jrsonnet_stdlib::STDLIB_STR))590	}591}