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

difftreelog

refactor split literals and trivials

nyvtyzzzYaroslav Bolyukin2026-05-08parent: #d543e94.patch.diff
in: master

39 files changed

modifiedcrates/jrsonnet-ir-parser/src/lib.rsdiffbeforeafterboth
1use jrsonnet_gcmodule::Acyclic;1use jrsonnet_gcmodule::Acyclic;
2use jrsonnet_ir::{2use jrsonnet_ir::{
3 ArgsDesc, AssertExpr, AssertStmt, BinaryOp, BinaryOpType, BindSpec, CompSpec, Destruct, Expr,3 ArgsDesc, AssertExpr, AssertStmt, BinaryOp, BinaryOpType, BindSpec, CompSpec, Destruct, Expr,
4 ExprParam, ExprParams, FieldMember, FieldName, ForSpecData, IStr, IfElse, IfSpecData,4 ExprParam, ExprParams, FieldMember, FieldName, ForSpecData, IStr, IdentityKind, IfElse,
5 ImportKind, IndexPart, LiteralType, Member, NumValue, ObjBody, ObjComp, ObjMembers, Slice,5 IfSpecData, ImportKind, IndexPart, Member, NumValue, ObjBody, ObjComp, ObjMembers, Slice,
6 SliceDesc, Source, Span, Spanned, UnaryOpType, Visibility, unescape,6 SliceDesc, Source, Span, Spanned, TrivialVal, UnaryOpType, Visibility, unescape,
7};7};
8use jrsonnet_lexer::{Lexeme, Lexer, Span as LexSpan, SyntaxKind, T, collect_lexed_str_block};8use jrsonnet_lexer::{Lexeme, Lexer, Span as LexSpan, SyntaxKind, T, collect_lexed_str_block};
99
247 Ok(IStr::from(text))247 Ok(IStr::from(text))
248}248}
249249
250fn literal(p: &mut Parser<'_>) -> Option<(Span, LiteralType)> {
251 let t = match p.peek() {
252 T![self] => LiteralType::This,
253 T![super] => LiteralType::Super,
254 T!['$'] => LiteralType::Dollar,
255 T![null] => LiteralType::Null,
256 T![true] => LiteralType::True,
257 T![false] => LiteralType::False,
258 _ => return None,
259 };
260 Some((p.eat_any_spanned(), t))
261}
262
263fn assert_stmt(p: &mut Parser<'_>) -> Result<AssertStmt> {250fn assert_stmt(p: &mut Parser<'_>) -> Result<AssertStmt> {
264 p.eat(T![assert])?;251 p.eat(T![assert])?;
265 let assertion = spanned(p, expr)?;252 let assertion = spanned(p, expr)?;
688675
689#[allow(clippy::too_many_lines)]676#[allow(clippy::too_many_lines)]
690fn expr_basic(p: &mut Parser<'_>) -> Result<Expr> {677fn expr_basic(p: &mut Parser<'_>) -> Result<Expr> {
691 if let Some((span, lit)) = literal(p) {678 match p.peek() {
679 T![self] => Ok(Expr::Identity(p.eat_any_spanned(), IdentityKind::This)),
680 T![super] => Ok(Expr::Identity(p.eat_any_spanned(), IdentityKind::Super)),
692 return Ok(Expr::Literal(span, lit));681 T!['$'] => Ok(Expr::Identity(p.eat_any_spanned(), IdentityKind::Dollar)),
682 T![null] => {
683 p.eat_any();
684 Ok(Expr::Trivial(TrivialVal::Null))
685 }
686 T![true] => {
687 p.eat_any();
688 Ok(Expr::Trivial(TrivialVal::Bool(true)))
689 }
690 T![false] => {
691 p.eat_any();
692 Ok(Expr::Trivial(TrivialVal::Bool(false)))
693 }693 }
694694
695 match p.peek() {
696 SyntaxKind::STRING_DOUBLE695 SyntaxKind::STRING_DOUBLE
697 | SyntaxKind::STRING_SINGLE696 | SyntaxKind::STRING_SINGLE
698 | SyntaxKind::STRING_DOUBLE_VERBATIM697 | SyntaxKind::STRING_DOUBLE_VERBATIM
699 | SyntaxKind::STRING_SINGLE_VERBATIM698 | SyntaxKind::STRING_SINGLE_VERBATIM
700 | SyntaxKind::STRING_BLOCK => Ok(Expr::Str(parse_string_content(p)?)),699 | SyntaxKind::STRING_BLOCK => Ok(Expr::Trivial(TrivialVal::Str(parse_string_content(p)?))),
701700
702 SyntaxKind::FLOAT => Ok(Expr::Num(parse_number(p)?)),701 SyntaxKind::FLOAT => Ok(Expr::Trivial(TrivialVal::Num(parse_number(p)?))),
703702
704 T!['('] => {703 T!['('] => {
705 p.eat(T!['('])?;704 p.eat(T!['('])?;
832 if parts.is_empty() {831 if parts.is_empty() {
833 return;832 return;
834 }833 }
835 let old = std::mem::replace(e, Expr::Str(IStr::empty()));834 let old = std::mem::replace(e, Expr::Trivial(TrivialVal::Null));
836 *e = Expr::Index {835 *e = Expr::Index {
837 indexable: Box::new(old),836 indexable: Box::new(old),
838 parts: std::mem::take(parts),837 parts: std::mem::take(parts),
863 });862 });
864 } else {863 } else {
865 // ?.field864 // ?.field
866 let id_spanned = spanned(p, |p| Ok(Expr::Str(ident(p)?)))?;865 let id_spanned = spanned(p, |p| Ok(Expr::Trivial(TrivialVal::Str(ident(p)?))))?;
867 parts.push(IndexPart {866 parts.push(IndexPart {
868 span: id_spanned.span,867 span: id_spanned.span,
869 value: id_spanned.value,868 value: id_spanned.value,
878877
879 if p.at(T![.]) {878 if p.at(T![.]) {
880 p.eat(T![.])?;879 p.eat(T![.])?;
881 let id_spanned = spanned(p, |p| Ok(Expr::Str(ident(p)?)))?;880 let id_spanned = spanned(p, |p| Ok(Expr::Trivial(TrivialVal::Str(ident(p)?))))?;
882 parts.push(IndexPart {881 parts.push(IndexPart {
883 span: id_spanned.span,882 span: id_spanned.span,
884 value: id_spanned.value,883 value: id_spanned.value,
1058pub fn string_to_expr(s: IStr, settings: &ParserSettings) -> Spanned<Expr> {1057pub fn string_to_expr(s: IStr, settings: &ParserSettings) -> Spanned<Expr> {
1059 let len = u32::try_from(s.len()).expect("code size is limited by 4gb");1058 let len = u32::try_from(s.len()).expect("code size is limited by 4gb");
10601059
1061 Spanned::new(Expr::Str(s), Span(settings.source.clone(), 0, len))1060 Spanned::new(
1061 Expr::Trivial(TrivialVal::Str(s)),
1062 Span(settings.source.clone(), 0, len),
1063 )
1062}1064}
10631065
1064#[cfg(test)]1066#[cfg(test)]
modifiedcrates/jrsonnet-ir-parser/src/snapshots/jrsonnet_ir_parser__tests__basic_math.snapdiffbeforeafterboth
1---1---
2source: crates/jrsonnet-ir-parser/src/lib.rs2source: crates/jrsonnet-ir-parser/src/lib.rs
3assertion_line: 1094
3expression: "format!(\"{v:#?}\")"4expression: "format!(\"{v:#?}\")"
4---5---
5BinaryOp(6BinaryOp(
6 BinaryOp {7 BinaryOp {
7 lhs: Num(8 lhs: Trivial(
9 Num(
8 2.0,10 2.0,
11 ),
9 ),12 ),
10 op: Add,13 op: Add,
11 rhs: BinaryOp(14 rhs: BinaryOp(
12 BinaryOp {15 BinaryOp {
13 lhs: Num(16 lhs: Trivial(
17 Num(
14 2.0,18 2.0,
19 ),
15 ),20 ),
16 op: Mul,21 op: Mul,
17 rhs: Num(22 rhs: Trivial(
23 Num(
18 2.0,24 2.0,
25 ),
19 ),26 ),
20 },27 },
21 ),28 ),
modifiedcrates/jrsonnet-ir-parser/src/snapshots/jrsonnet_ir_parser__tests__basic_test.snapdiffbeforeafterboth
1---1---
2source: crates/jrsonnet-ir-parser/src/lib.rs2source: crates/jrsonnet-ir-parser/src/lib.rs
3assertion_line: 1082
3expression: "format!(\"{v:#?}\")"4expression: "format!(\"{v:#?}\")"
4---5---
5AssertExpr(6AssertExpr(
6 AssertExpr {7 AssertExpr {
7 assert: AssertStmt {8 assert: AssertStmt {
8 assertion: Index {9 assertion: Index {
9 indexable: Literal(10 indexable: Trivial(
10 virtual:<test>:7-11,11 Bool(
12 true,
11 True,13 ),
12 ),14 ),
13 parts: [15 parts: [
14 IndexPart {16 IndexPart {
15 span: virtual:<test>:12-17,17 span: virtual:<test>:12-17,
16 value: Literal(18 value: Trivial(
17 virtual:<test>:12-17,19 Bool(
20 false,
18 False,21 ),
19 ),22 ),
20 },23 },
21 ],24 ],
22 } from virtual:<test>:7-18,25 } from virtual:<test>:7-18,
23 message: Some(26 message: Some(
24 Literal(27 Trivial(
25 virtual:<test>:21-26,28 Bool(
29 false,
26 False,30 ),
27 ),31 ),
28 ),32 ),
29 },33 },
30 rest: Literal(34 rest: Trivial(
31 virtual:<test>:29-33,35 Bool(
36 true,
32 True,37 ),
33 ),38 ),
34 },39 },
35)40)
modifiedcrates/jrsonnet-ir-parser/src/snapshots/jrsonnet_ir_parser__tests__error_expr.snapdiffbeforeafterboth
1---1---
2source: crates/jrsonnet-ir-parser/src/lib.rs2source: crates/jrsonnet-ir-parser/src/lib.rs
3assertion_line: 1161
3expression: "format!(\"{v:#?}\")"4expression: "format!(\"{v:#?}\")"
4---5---
5ErrorStmt(6ErrorStmt(
6 virtual:<test>:0-5,7 virtual:<test>:0-5,
7 Str(8 Trivial(
9 Str(
8 "bad",10 "bad",
11 ),
9 ),12 ),
10)13)
1114
modifiedcrates/jrsonnet-ir-parser/src/snapshots/jrsonnet_ir_parser__tests__function_and_call.snapdiffbeforeafterboth
1---1---
2source: crates/jrsonnet-ir-parser/src/lib.rs2source: crates/jrsonnet-ir-parser/src/lib.rs
3assertion_line: 1118
3expression: "format!(\"{v:#?}\")"4expression: "format!(\"{v:#?}\")"
4---5---
5LocalExpr(6LocalExpr(
19 "y" from virtual:<test>:11-12,20 "y" from virtual:<test>:11-12,
20 ),21 ),
21 default: Some(22 default: Some(
22 Num(23 Trivial(
24 Num(
23 1.0,25 1.0,
26 ),
24 ),27 ),
25 ),28 ),
26 },29 },
62 ),65 ),
63 ArgsDesc {66 ArgsDesc {
64 unnamed: [67 unnamed: [
65 Num(68 Trivial(
69 Num(
66 2.0,70 2.0,
71 ),
67 ),72 ),
68 ],73 ],
69 names: [74 names: [
70 "y",75 "y",
71 ],76 ],
72 values: [77 values: [
73 Num(78 Trivial(
79 Num(
74 3.0,80 3.0,
81 ),
75 ),82 ),
76 ],83 ],
77 } from virtual:<test>:26-34,84 } from virtual:<test>:26-34,
modifiedcrates/jrsonnet-ir-parser/src/snapshots/jrsonnet_ir_parser__tests__if_then_else.snapdiffbeforeafterboth
1---1---
2source: crates/jrsonnet-ir-parser/src/lib.rs2source: crates/jrsonnet-ir-parser/src/lib.rs
3assertion_line: 1124
3expression: "format!(\"{v:#?}\")"4expression: "format!(\"{v:#?}\")"
4---5---
5IfElse(6IfElse(
6 IfElse {7 IfElse {
7 cond: IfSpecData {8 cond: IfSpecData {
8 span: virtual:<test>:0-2,9 span: virtual:<test>:0-2,
9 cond: Literal(10 cond: Trivial(
10 virtual:<test>:3-7,11 Bool(
12 true,
11 True,13 ),
12 ),14 ),
13 },15 },
14 cond_then: Num(16 cond_then: Trivial(
17 Num(
15 1.0,18 1.0,
19 ),
16 ),20 ),
17 cond_else: Some(21 cond_else: Some(
18 Num(22 Trivial(
23 Num(
19 2.0,24 2.0,
25 ),
20 ),26 ),
21 ),27 ),
22 },28 },
modifiedcrates/jrsonnet-ir-parser/src/snapshots/jrsonnet_ir_parser__tests__imports.snapdiffbeforeafterboth
1---1---
2source: crates/jrsonnet-ir-parser/src/lib.rs2source: crates/jrsonnet-ir-parser/src/lib.rs
3assertion_line: 1130
3expression: "format!(\"{v:#?}\")"4expression: "format!(\"{v:#?}\")"
4---5---
5Arr(6Arr(
6 [7 [
7 Import(8 Import(
8 Normal from virtual:<test>:1-7,9 Normal from virtual:<test>:1-7,
9 Str(10 Trivial(
11 Str(
10 "a",12 "a",
13 ),
11 ),14 ),
12 ),15 ),
13 Import(16 Import(
14 Str from virtual:<test>:13-22,17 Str from virtual:<test>:13-22,
15 Str(18 Trivial(
19 Str(
16 "b",20 "b",
21 ),
17 ),22 ),
18 ),23 ),
19 Import(24 Import(
20 Bin from virtual:<test>:28-37,25 Bin from virtual:<test>:28-37,
21 Str(26 Trivial(
27 Str(
22 "c",28 "c",
29 ),
23 ),30 ),
24 ),31 ),
25 ],32 ],
modifiedcrates/jrsonnet-ir-parser/src/snapshots/jrsonnet_ir_parser__tests__index_and_suffix.snapdiffbeforeafterboth
1---1---
2source: crates/jrsonnet-ir-parser/src/lib.rs2source: crates/jrsonnet-ir-parser/src/lib.rs
3assertion_line: 1143
3expression: "format!(\"{v:#?}\")"4expression: "format!(\"{v:#?}\")"
4---5---
5Index {6Index {
11 parts: [12 parts: [
12 IndexPart {13 IndexPart {
13 span: virtual:<test>:4-8,14 span: virtual:<test>:4-8,
14 value: Str(15 value: Trivial(
16 Str(
15 "test",17 "test",
18 ),
16 ),19 ),
17 },20 },
18 ],21 ],
19 },22 },
20 ArgsDesc {23 ArgsDesc {
21 unnamed: [24 unnamed: [
22 Num(25 Trivial(
26 Num(
23 2.0,27 2.0,
28 ),
24 ),29 ),
25 ],30 ],
26 names: [],31 names: [],
31 parts: [36 parts: [
32 IndexPart {37 IndexPart {
33 span: virtual:<test>:12-17,38 span: virtual:<test>:12-17,
34 value: Str(39 value: Trivial(
40 Str(
35 "field",41 "field",
42 ),
36 ),43 ),
37 },44 },
38 IndexPart {45 IndexPart {
39 span: virtual:<test>:18-19,46 span: virtual:<test>:18-19,
40 value: Num(47 value: Trivial(
48 Num(
41 0.0,49 0.0,
50 ),
42 ),51 ),
43 },52 },
44 ],53 ],
modifiedcrates/jrsonnet-ir-parser/src/snapshots/jrsonnet_ir_parser__tests__literals.snapdiffbeforeafterboth
1---1---
2source: crates/jrsonnet-ir-parser/src/lib.rs2source: crates/jrsonnet-ir-parser/src/lib.rs
3assertion_line: 1088
3expression: "format!(\"{v:#?}\")"4expression: "format!(\"{v:#?}\")"
4---5---
5Arr(6Arr(
6 [7 [
7 Literal(8 Trivial(
8 virtual:<test>:1-5,
9 Null,9 Null,
10 ),10 ),
11 Literal(11 Trivial(
12 virtual:<test>:7-11,12 Bool(
13 true,
13 True,14 ),
14 ),15 ),
15 Literal(16 Trivial(
16 virtual:<test>:13-18,17 Bool(
18 false,
17 False,19 ),
18 ),20 ),
19 Literal(21 Identity(
20 virtual:<test>:20-24,22 virtual:<test>:20-24,
21 This,23 This,
22 ),24 ),
23 Literal(25 Identity(
24 virtual:<test>:26-31,26 virtual:<test>:26-31,
25 Super,27 Super,
26 ),28 ),
27 Literal(29 Identity(
28 virtual:<test>:33-34,30 virtual:<test>:33-34,
29 Dollar,31 Dollar,
30 ),32 ),
modifiedcrates/jrsonnet-ir-parser/src/snapshots/jrsonnet_ir_parser__tests__obj_extend.snapdiffbeforeafterboth
1---1---
2source: crates/jrsonnet-ir-parser/src/lib.rs2source: crates/jrsonnet-ir-parser/src/lib.rs
3assertion_line: 1149
3expression: "format!(\"{v:#?}\")"4expression: "format!(\"{v:#?}\")"
4---5---
5ObjExtend(6ObjExtend(
24 plus: false,25 plus: false,
25 params: None,26 params: None,
26 visibility: Normal,27 visibility: Normal,
27 value: Num(28 value: Trivial(
29 Num(
28 1.0,30 1.0,
31 ),
29 ),32 ),
30 },33 },
31 ],34 ],
modifiedcrates/jrsonnet-ir-parser/src/snapshots/jrsonnet_ir_parser__tests__object.snapdiffbeforeafterboth
1---1---
2source: crates/jrsonnet-ir-parser/src/lib.rs2source: crates/jrsonnet-ir-parser/src/lib.rs
3assertion_line: 1112
3expression: "format!(\"{v:#?}\")"4expression: "format!(\"{v:#?}\")"
4---5---
5Obj(6Obj(
15 plus: false,16 plus: false,
16 params: None,17 params: None,
17 visibility: Normal,18 visibility: Normal,
18 value: Num(19 value: Trivial(
20 Num(
19 1.0,21 1.0,
22 ),
20 ),23 ),
21 },24 },
22 FieldMember {25 FieldMember {
26 plus: false,29 plus: false,
27 params: None,30 params: None,
28 visibility: Hidden,31 visibility: Hidden,
29 value: Num(32 value: Trivial(
33 Num(
30 2.0,34 2.0,
35 ),
31 ),36 ),
32 },37 },
33 FieldMember {38 FieldMember {
37 plus: false,42 plus: false,
38 params: None,43 params: None,
39 visibility: Unhide,44 visibility: Unhide,
40 value: Num(45 value: Trivial(
46 Num(
41 3.0,47 3.0,
48 ),
42 ),49 ),
43 },50 },
44 ],51 ],
modifiedcrates/jrsonnet-ir-parser/src/snapshots/jrsonnet_ir_parser__tests__peg_snapshots@array_comp.jsonnet.snapdiffbeforeafterboth
1---1---
2source: crates/jrsonnet-ir-parser/src/lib.rs2source: crates/jrsonnet-ir-parser/src/lib.rs
3assertion_line: 1184
3expression: v4expression: v
4input_file: crates/jrsonnet-peg-parser/src/tests/array_comp.jsonnet5input_file: crates/jrsonnet-peg-parser/src/tests/array_comp.jsonnet
5---6---
14 parts: [15 parts: [
15 IndexPart {16 IndexPart {
16 span: virtual:<test>:7-15,17 span: virtual:<test>:7-15,
17 value: Str(18 value: Trivial(
19 Str(
18 "deepJoin",20 "deepJoin",
21 ),
19 ),22 ),
20 },23 },
21 ],24 ],
modifiedcrates/jrsonnet-ir-parser/src/snapshots/jrsonnet_ir_parser__tests__peg_snapshots@basic_math.jsonnet.snapdiffbeforeafterboth
1---1---
2source: crates/jrsonnet-ir-parser/src/lib.rs2source: crates/jrsonnet-ir-parser/src/lib.rs
3assertion_line: 1184
3expression: v4expression: v
4input_file: crates/jrsonnet-peg-parser/src/tests/basic_math.jsonnet5input_file: crates/jrsonnet-peg-parser/src/tests/basic_math.jsonnet
5---6---
6Arr(7Arr(
7 [8 [
8 BinaryOp(9 BinaryOp(
9 BinaryOp {10 BinaryOp {
10 lhs: Num(11 lhs: Trivial(
12 Num(
11 2.0,13 2.0,
14 ),
12 ),15 ),
13 op: Add,16 op: Add,
14 rhs: BinaryOp(17 rhs: BinaryOp(
15 BinaryOp {18 BinaryOp {
16 lhs: Num(19 lhs: Trivial(
20 Num(
17 2.0,21 2.0,
22 ),
18 ),23 ),
19 op: Mul,24 op: Mul,
20 rhs: Num(25 rhs: Trivial(
26 Num(
21 2.0,27 2.0,
28 ),
22 ),29 ),
23 },30 },
24 ),31 ),
25 },32 },
26 ),33 ),
27 BinaryOp(34 BinaryOp(
28 BinaryOp {35 BinaryOp {
29 lhs: Num(36 lhs: Trivial(
37 Num(
30 2.0,38 2.0,
39 ),
31 ),40 ),
32 op: Add,41 op: Add,
33 rhs: BinaryOp(42 rhs: BinaryOp(
34 BinaryOp {43 BinaryOp {
35 lhs: Num(44 lhs: Trivial(
45 Num(
36 2.0,46 2.0,
47 ),
37 ),48 ),
38 op: Mul,49 op: Mul,
39 rhs: Num(50 rhs: Trivial(
51 Num(
40 2.0,52 2.0,
53 ),
41 ),54 ),
42 },55 },
43 ),56 ),
47 BinaryOp {60 BinaryOp {
48 lhs: BinaryOp(61 lhs: BinaryOp(
49 BinaryOp {62 BinaryOp {
50 lhs: Num(63 lhs: Trivial(
64 Num(
51 2.0,65 2.0,
66 ),
52 ),67 ),
53 op: Add,68 op: Add,
54 rhs: Num(69 rhs: Trivial(
70 Num(
55 2.0,71 2.0,
72 ),
56 ),73 ),
57 },74 },
58 ),75 ),
59 op: Add,76 op: Add,
60 rhs: BinaryOp(77 rhs: BinaryOp(
61 BinaryOp {78 BinaryOp {
62 lhs: Num(79 lhs: Trivial(
80 Num(
63 2.0,81 2.0,
82 ),
64 ),83 ),
65 op: Mul,84 op: Mul,
66 rhs: Num(85 rhs: Trivial(
86 Num(
67 2.0,87 2.0,
88 ),
68 ),89 ),
69 },90 },
70 ),91 ),
71 },92 },
72 ),93 ),
73 BinaryOp(94 BinaryOp(
74 BinaryOp {95 BinaryOp {
75 lhs: Num(96 lhs: Trivial(
97 Num(
76 2.0,98 2.0,
99 ),
77 ),100 ),
78 op: Add,101 op: Add,
79 rhs: BinaryOp(102 rhs: BinaryOp(
80 BinaryOp {103 BinaryOp {
81 lhs: Num(104 lhs: Trivial(
105 Num(
82 2.0,106 2.0,
107 ),
83 ),108 ),
84 op: Add,109 op: Add,
85 rhs: BinaryOp(110 rhs: BinaryOp(
86 BinaryOp {111 BinaryOp {
87 lhs: Num(112 lhs: Trivial(
113 Num(
88 2.0,114 2.0,
115 ),
89 ),116 ),
90 op: Mul,117 op: Mul,
91 rhs: Num(118 rhs: Trivial(
119 Num(
92 2.0,120 2.0,
121 ),
93 ),122 ),
94 },123 },
95 ),124 ),
99 ),128 ),
100 BinaryOp(129 BinaryOp(
101 BinaryOp {130 BinaryOp {
102 lhs: Num(131 lhs: Trivial(
132 Num(
103 2.0,133 2.0,
134 ),
104 ),135 ),
105 op: Add,136 op: Add,
106 rhs: BinaryOp(137 rhs: BinaryOp(
107 BinaryOp {138 BinaryOp {
108 lhs: Num(139 lhs: Trivial(
140 Num(
109 3.0,141 3.0,
142 ),
110 ),143 ),
111 op: Mul,144 op: Mul,
112 rhs: Num(145 rhs: Trivial(
146 Num(
113 4.0,147 4.0,
148 ),
114 ),149 ),
115 },150 },
116 ),151 ),
modifiedcrates/jrsonnet-ir-parser/src/snapshots/jrsonnet_ir_parser__tests__peg_snapshots@comment_eof.jsonnet.snapdiffbeforeafterboth
1---1---
2source: crates/jrsonnet-ir-parser/src/lib.rs2source: crates/jrsonnet-ir-parser/src/lib.rs
3assertion_line: 1184
3expression: v4expression: v
4input_file: crates/jrsonnet-peg-parser/src/tests/comment_eof.jsonnet5input_file: crates/jrsonnet-peg-parser/src/tests/comment_eof.jsonnet
5---6---
16 plus: false,17 plus: false,
17 params: None,18 params: None,
18 visibility: Normal,19 visibility: Normal,
19 value: Num(20 value: Trivial(
21 Num(
20 1.0,22 1.0,
23 ),
21 ),24 ),
22 },25 },
23 ],26 ],
modifiedcrates/jrsonnet-ir-parser/src/snapshots/jrsonnet_ir_parser__tests__peg_snapshots@default_nondefault.jsonnet.snapdiffbeforeafterboth
1---1---
2source: crates/jrsonnet-ir-parser/src/lib.rs2source: crates/jrsonnet-ir-parser/src/lib.rs
3assertion_line: 1184
3expression: v4expression: v
4input_file: crates/jrsonnet-peg-parser/src/tests/default_nondefault.jsonnet5input_file: crates/jrsonnet-peg-parser/src/tests/default_nondefault.jsonnet
5---6---
14 "foo" from virtual:<test>:8-11,15 "foo" from virtual:<test>:8-11,
15 ),16 ),
16 default: Some(17 default: Some(
17 Str(18 Trivial(
19 Str(
18 "foo",20 "foo",
21 ),
19 ),22 ),
20 ),23 ),
21 },24 },
44 ),47 ),
45 binds_len: 2,48 binds_len: 2,
46 },49 },
47 value: Literal(50 value: Trivial(
48 virtual:<test>:28-32,
49 Null,51 Null,
50 ),52 ),
51 },53 },
52 ],54 ],
53 Literal(55 Trivial(
54 virtual:<test>:34-38,
55 Null,56 Null,
56 ),57 ),
57)58)
modifiedcrates/jrsonnet-ir-parser/src/snapshots/jrsonnet_ir_parser__tests__peg_snapshots@imports.jsonnet.snapdiffbeforeafterboth
1---1---
2source: crates/jrsonnet-ir-parser/src/lib.rs2source: crates/jrsonnet-ir-parser/src/lib.rs
3assertion_line: 1184
3expression: v4expression: v
4input_file: crates/jrsonnet-peg-parser/src/tests/imports.jsonnet5input_file: crates/jrsonnet-peg-parser/src/tests/imports.jsonnet
5---6---
6Arr(7Arr(
7 [8 [
8 Import(9 Import(
9 Normal from virtual:<test>:2-8,10 Normal from virtual:<test>:2-8,
10 Str(11 Trivial(
12 Str(
11 "hello",13 "hello",
14 ),
12 ),15 ),
13 ),16 ),
14 Import(17 Import(
15 Str from virtual:<test>:18-27,18 Str from virtual:<test>:18-27,
16 Str(19 Trivial(
20 Str(
17 "garnish.txt",21 "garnish.txt",
22 ),
18 ),23 ),
19 ),24 ),
20 Import(25 Import(
21 Bin from virtual:<test>:43-52,26 Bin from virtual:<test>:43-52,
22 Str(27 Trivial(
28 Str(
23 "garnish.bin",29 "garnish.bin",
30 ),
24 ),31 ),
25 ),32 ),
26 ],33 ],
modifiedcrates/jrsonnet-ir-parser/src/snapshots/jrsonnet_ir_parser__tests__peg_snapshots@multiline.jsonnet.snapdiffbeforeafterboth
1---1---
2source: crates/jrsonnet-ir-parser/src/lib.rs2source: crates/jrsonnet-ir-parser/src/lib.rs
3assertion_line: 1184
3expression: v4expression: v
4input_file: crates/jrsonnet-peg-parser/src/tests/multiline.jsonnet5input_file: crates/jrsonnet-peg-parser/src/tests/multiline.jsonnet
5---6---
6Arr(7Arr(
7 [8 [
8 Str(9 Trivial(
10 Str(
9 "Hello world!\na\n",11 "Hello world!\na\n",
12 ),
10 ),13 ),
11 Str(14 Trivial(
15 Str(
12 "Hello world!\na\n",16 "Hello world!\na\n",
17 ),
13 ),18 ),
14 Str(19 Trivial(
20 Str(
15 "Hello world!\n\ta\n",21 "Hello world!\n\ta\n",
22 ),
16 ),23 ),
17 Str(24 Trivial(
25 Str(
18 "Hello world!\n a\n",26 "Hello world!\n a\n",
27 ),
19 ),28 ),
20 ],29 ],
21)30)
modifiedcrates/jrsonnet-ir-parser/src/snapshots/jrsonnet_ir_parser__tests__peg_snapshots@reserved.jsonnet.snapdiffbeforeafterboth
1---1---
2source: crates/jrsonnet-ir-parser/src/lib.rs2source: crates/jrsonnet-ir-parser/src/lib.rs
3assertion_line: 1184
3expression: v4expression: v
4input_file: crates/jrsonnet-peg-parser/src/tests/reserved.jsonnet5input_file: crates/jrsonnet-peg-parser/src/tests/reserved.jsonnet
5---6---
6Arr(7Arr(
7 [8 [
8 Literal(9 Trivial(
9 virtual:<test>:2-6,
10 Null,10 Null,
11 ),11 ),
12 Var(12 Var(
modifiedcrates/jrsonnet-ir-parser/src/snapshots/jrsonnet_ir_parser__tests__peg_snapshots@slice.jsonnet.snapdiffbeforeafterboth
1---1---
2source: crates/jrsonnet-ir-parser/src/lib.rs2source: crates/jrsonnet-ir-parser/src/lib.rs
3assertion_line: 1184
3expression: v4expression: v
4input_file: crates/jrsonnet-peg-parser/src/tests/slice.jsonnet5input_file: crates/jrsonnet-peg-parser/src/tests/slice.jsonnet
5---6---
12 ),13 ),
13 slice: SliceDesc {14 slice: SliceDesc {
14 start: Some(15 start: Some(
15 Num(16 Trivial(
17 Num(
16 1.0,18 1.0,
19 ),
17 ) from virtual:<test>:4-5,20 ) from virtual:<test>:4-5,
18 ),21 ),
19 end: None,22 end: None,
28 ),31 ),
29 slice: SliceDesc {32 slice: SliceDesc {
30 start: Some(33 start: Some(
31 Num(34 Trivial(
35 Num(
32 1.0,36 1.0,
37 ),
33 ) from virtual:<test>:11-12,38 ) from virtual:<test>:11-12,
34 ),39 ),
35 end: None,40 end: None,
45 slice: SliceDesc {50 slice: SliceDesc {
46 start: None,51 start: None,
47 end: Some(52 end: Some(
48 Num(53 Trivial(
54 Num(
49 1.0,55 1.0,
56 ),
50 ) from virtual:<test>:20-21,57 ) from virtual:<test>:20-21,
51 ),58 ),
52 step: None,59 step: None,
62 start: None,69 start: None,
63 end: None,70 end: None,
64 step: Some(71 step: Some(
65 Num(72 Trivial(
73 Num(
66 1.0,74 1.0,
75 ),
67 ) from virtual:<test>:29-30,76 ) from virtual:<test>:29-30,
68 ),77 ),
69 },78 },
83 "len" from virtual:<test>:38-41,92 "len" from virtual:<test>:38-41,
84 ),93 ),
85 op: Sub,94 op: Sub,
86 rhs: Num(95 rhs: Trivial(
96 Num(
87 1.0,97 1.0,
98 ),
88 ),99 ),
89 },100 },
90 ) from virtual:<test>:38-45,101 ) from virtual:<test>:38-45,
modifiedcrates/jrsonnet-ir-parser/src/snapshots/jrsonnet_ir_parser__tests__peg_snapshots@string_escaping.jsonnet.snapdiffbeforeafterboth
1---1---
2source: crates/jrsonnet-ir-parser/src/lib.rs2source: crates/jrsonnet-ir-parser/src/lib.rs
3assertion_line: 1184
3expression: v4expression: v
4input_file: crates/jrsonnet-peg-parser/src/tests/string_escaping.jsonnet5input_file: crates/jrsonnet-peg-parser/src/tests/string_escaping.jsonnet
5---6---
6Arr(7Arr(
7 [8 [
8 Str(9 Trivial(
10 Str(
9 "Hello, \"world\"!",11 "Hello, \"world\"!",
12 ),
10 ),13 ),
11 Str(14 Trivial(
15 Str(
12 "Hello 'world'!",16 "Hello 'world'!",
17 ),
13 ),18 ),
14 Str(19 Trivial(
20 Str(
15 "\\\\",21 "\\\\",
22 ),
16 ),23 ),
17 Str(24 Trivial(
25 Str(
18 "Hello\nWorld",26 "Hello\nWorld",
27 ),
19 ),28 ),
20 Str(29 Trivial(
30 Str(
21 "Hello\\n\"World\"",31 "Hello\\n\"World\"",
32 ),
22 ),33 ),
23 ],34 ],
24)35)
modifiedcrates/jrsonnet-ir-parser/src/snapshots/jrsonnet_ir_parser__tests__peg_snapshots@subexp.jsonnet.snapdiffbeforeafterboth
1---1---
2source: crates/jrsonnet-ir-parser/src/lib.rs2source: crates/jrsonnet-ir-parser/src/lib.rs
3assertion_line: 1184
3expression: v4expression: v
4input_file: crates/jrsonnet-peg-parser/src/tests/subexp.jsonnet5input_file: crates/jrsonnet-peg-parser/src/tests/subexp.jsonnet
5---6---
22 into: Full(23 into: Full(
23 "x" from virtual:<test>:11-12,24 "x" from virtual:<test>:11-12,
24 ),25 ),
25 value: Num(26 value: Trivial(
27 Num(
26 1.0,28 1.0,
29 ),
27 ),30 ),
28 },31 },
29 ],32 ],
modifiedcrates/jrsonnet-ir-parser/src/snapshots/jrsonnet_ir_parser__tests__peg_snapshots@suffix.jsonnet.snapdiffbeforeafterboth
1---1---
2source: crates/jrsonnet-ir-parser/src/lib.rs2source: crates/jrsonnet-ir-parser/src/lib.rs
3assertion_line: 1184
3expression: v4expression: v
4input_file: crates/jrsonnet-peg-parser/src/tests/suffix.jsonnet5input_file: crates/jrsonnet-peg-parser/src/tests/suffix.jsonnet
5---6---
12 parts: [13 parts: [
13 IndexPart {14 IndexPart {
14 span: virtual:<test>:6-10,15 span: virtual:<test>:6-10,
15 value: Str(16 value: Trivial(
17 Str(
16 "test",18 "test",
19 ),
17 ),20 ),
18 },21 },
19 ],22 ],
24 ),27 ),
25 ArgsDesc {28 ArgsDesc {
26 unnamed: [29 unnamed: [
27 Num(30 Trivial(
31 Num(
28 2.0,32 2.0,
33 ),
29 ),34 ),
30 ],35 ],
31 names: [],36 names: [],
41 parts: [46 parts: [
42 IndexPart {47 IndexPart {
43 span: virtual:<test>:24-28,48 span: virtual:<test>:24-28,
44 value: Str(49 value: Trivial(
50 Str(
45 "test",51 "test",
52 ),
46 ),53 ),
47 },54 },
48 ],55 ],
49 },56 },
50 ArgsDesc {57 ArgsDesc {
51 unnamed: [58 unnamed: [
52 Num(59 Trivial(
60 Num(
53 2.0,61 2.0,
62 ),
54 ),63 ),
55 ],64 ],
56 names: [],65 names: [],
modifiedcrates/jrsonnet-ir-parser/src/snapshots/jrsonnet_ir_parser__tests__slice.snapdiffbeforeafterboth
1---1---
2source: crates/jrsonnet-ir-parser/src/lib.rs2source: crates/jrsonnet-ir-parser/src/lib.rs
3assertion_line: 1167
3expression: "format!(\"{v:#?}\")"4expression: "format!(\"{v:#?}\")"
4---5---
5Arr(6Arr(
11 ),12 ),
12 slice: SliceDesc {13 slice: SliceDesc {
13 start: Some(14 start: Some(
14 Num(15 Trivial(
16 Num(
15 1.0,17 1.0,
18 ),
16 ) from virtual:<test>:3-4,19 ) from virtual:<test>:3-4,
17 ),20 ),
18 end: None,21 end: None,
27 ),30 ),
28 slice: SliceDesc {31 slice: SliceDesc {
29 start: Some(32 start: Some(
30 Num(33 Trivial(
34 Num(
31 1.0,35 1.0,
36 ),
32 ) from virtual:<test>:10-11,37 ) from virtual:<test>:10-11,
33 ),38 ),
34 end: None,39 end: None,
44 slice: SliceDesc {49 slice: SliceDesc {
45 start: None,50 start: None,
46 end: Some(51 end: Some(
47 Num(52 Trivial(
53 Num(
48 1.0,54 1.0,
55 ),
49 ) from virtual:<test>:19-20,56 ) from virtual:<test>:19-20,
50 ),57 ),
51 step: None,58 step: None,
61 start: None,68 start: None,
62 end: None,69 end: None,
63 step: Some(70 step: Some(
64 Num(71 Trivial(
72 Num(
65 1.0,73 1.0,
74 ),
66 ) from virtual:<test>:28-29,75 ) from virtual:<test>:28-29,
67 ),76 ),
68 },77 },
modifiedcrates/jrsonnet-ir-parser/src/snapshots/jrsonnet_ir_parser__tests__strings.snapdiffbeforeafterboth
1---1---
2source: crates/jrsonnet-ir-parser/src/lib.rs2source: crates/jrsonnet-ir-parser/src/lib.rs
3assertion_line: 1106
3expression: "format!(\"{v:#?}\")"4expression: "format!(\"{v:#?}\")"
4---5---
5Arr(6Arr(
6 [7 [
7 Str(8 Trivial(
9 Str(
8 "hello",10 "hello",
11 ),
9 ),12 ),
10 Str(13 Trivial(
14 Str(
11 "world",15 "world",
16 ),
12 ),17 ),
13 Str(18 Trivial(
19 Str(
14 "raw\"str",20 "raw\"str",
21 ),
15 ),22 ),
16 Str(23 Trivial(
24 Str(
17 "raw'str",25 "raw'str",
26 ),
18 ),27 ),
19 ],28 ],
20)29)
modifiedcrates/jrsonnet-ir-parser/src/snapshots/jrsonnet_ir_parser__tests__underscore_numbers.snapdiffbeforeafterboth
1---1---
2source: crates/jrsonnet-ir-parser/src/lib.rs2source: crates/jrsonnet-ir-parser/src/lib.rs
3assertion_line: 1100
3expression: "format!(\"{v:#?}\")"4expression: "format!(\"{v:#?}\")"
4---5---
5Arr(6Arr(
6 [7 [
7 Num(8 Trivial(
9 Num(
8 1000.0,10 1000.0,
11 ),
9 ),12 ),
10 Num(13 Trivial(
14 Num(
11 1000.0001,15 1000.0001,
16 ),
12 ),17 ),
13 Num(18 Trivial(
19 Num(
14 100000000000.0,20 100000000000.0,
21 ),
15 ),22 ),
16 ],23 ],
17)24)
modifiedcrates/jrsonnet-ir/src/expr.rsdiffbeforeafterboth
31 Unhide,31 Unhide,
32}32}
33
34#[derive(Debug, Clone, PartialEq, Acyclic)]
35pub enum TrivialVal {
36 Null,
37 Bool(bool),
38 Num(NumValue),
39 Str(IStr),
40}
3341
34impl Visibility {42impl Visibility {
35 pub fn is_visible(&self) -> bool {43 pub fn is_visible(&self) -> bool {
351 ObjComp(ObjComp),359 ObjComp(ObjComp),
352}360}
353361
362/// Object identity reference: `self`, `super`, or `$`.#[derive(Debug, PartialEq, Eq, Clone, Copy, Acyclic)]
354#[derive(Debug, PartialEq, Eq, Clone, Copy, Acyclic)]363#[derive(Debug, PartialEq, Acyclic)]
355pub enum LiteralType {364pub enum IdentityKind {
356 This,365 This,
357 Super,366 Super,
358 Dollar,367 Dollar,
359 Null,
360 True,
361 False,
362}368}
363369
364#[derive(Debug, PartialEq, Acyclic)]370#[derive(Debug, PartialEq, Acyclic)]
404/// Syntax base410/// Syntax base
405#[derive(Debug, PartialEq, Acyclic)]411#[derive(Debug, PartialEq, Acyclic)]
406pub enum Expr {412pub enum Expr {
413 /// Object-identity reference: `self`, `super`, `$`.
407 Literal(Span, LiteralType),414 Identity(Span, IdentityKind),
408415
409 /// String value: "hello"416 /// Trivial value literal
410 Str(IStr),417 Trivial(TrivialVal),
411 /// Number: 1, 2.0, 2e+20418
412 Num(NumValue),
413 /// Variable name: test419 /// Variable name: test
414 Var(Spanned<IStr>),420 Var(Spanned<IStr>),
415421
modifiedcrates/jrsonnet-ir/src/visit.rsdiffbeforeafterboth
5use crate::{5use crate::{
6 ArgsDesc, AssertExpr, AssertStmt, BinaryOp, BindSpec, CompSpec, Destruct, Expr, ExprParam,6 ArgsDesc, AssertExpr, AssertStmt, BinaryOp, BindSpec, CompSpec, Destruct, Expr, ExprParam,
7 ExprParams, FieldMember, FieldName, ForSpecData, IfElse, IfSpecData, ImportKind, IndexPart,7 ExprParams, FieldMember, FieldName, ForSpecData, IfElse, IfSpecData, ImportKind, IndexPart,
8 ObjBody, ObjComp, ObjMembers, Slice, SliceDesc,8 ObjBody, ObjComp, ObjMembers, Slice, SliceDesc, TrivialVal,
9};9};
1010
11pub trait Visitor: Sized {11pub trait Visitor: Sized {
178}178}
179pub fn visit_expr<V: Visitor>(v: &mut V, e: &Expr) {179pub fn visit_expr<V: Visitor>(v: &mut V, e: &Expr) {
180 match e {180 match e {
181 Expr::Literal(_span, _literal_type) => {}181 Expr::Identity(_span, _identity_kind) => {}
182 Expr::Str(_istr) => {}182 Expr::Trivial(_) => {}
183 Expr::Num(_num) => {}
184 Expr::Var(_spanned) => {}183 Expr::Var(_spanned) => {}
185 Expr::Arr(exprs) => {184 Expr::Arr(exprs) => {
186 for e in &**exprs {185 for e in &**exprs {
220 Expr::Import(kind, expr) => {219 Expr::Import(kind, expr) => {
221 v.visit_expr(expr);220 v.visit_expr(expr);
222221
223 if let Expr::Str(expr) = &**expr {222 if let Expr::Trivial(TrivialVal::Str(expr)) = &**expr {
224 v.visit_import(matches!(**kind, ImportKind::Normal), expr.clone());223 v.visit_import(matches!(**kind, ImportKind::Normal), expr.clone());
225 }224 }
226 }225 }
modifiedcrates/jrsonnet-peg-parser/src/lib.rsdiffbeforeafterboth
1use jrsonnet_gcmodule::Acyclic;1use jrsonnet_gcmodule::Acyclic;
2use jrsonnet_ir::{2use jrsonnet_ir::{
3 ArgsDesc, AssertExpr, AssertStmt, BinaryOp, BindSpec, CompSpec, Destruct, DestructRest, Expr,3 ArgsDesc, AssertExpr, AssertStmt, BinaryOp, BindSpec, CompSpec, Destruct, DestructRest, Expr,
4 ExprParam, ExprParams, FieldMember, FieldName, ForSpecData, IStr, IfElse, IfSpecData,4 ExprParam, ExprParams, FieldMember, FieldName, ForSpecData, IStr, IdentityKind, IfElse,
5 ImportKind, IndexPart, LiteralType, Member, NumValue, ObjBody, ObjComp, ObjMembers, Slice,5 IfSpecData, ImportKind, IndexPart, Member, NumValue, ObjBody, ObjComp, ObjMembers, Slice,
6 SliceDesc, Source, Span, Spanned, Visibility, unescape,6 SliceDesc, Source, Span, Spanned, TrivialVal, Visibility, unescape,
7};7};
8use peg::parser;8use peg::parser;
99
263 pub rule local_expr(s: &ParserSettings) -> Expr263 pub rule local_expr(s: &ParserSettings) -> Expr
264 = keyword("local") _ binds:bind(s) ** comma() (_ ",")? _ ";" _ expr:expr(s) { Expr::LocalExpr(binds, Box::new(expr)) }264 = keyword("local") _ binds:bind(s) ** comma() (_ ",")? _ ";" _ expr:expr(s) { Expr::LocalExpr(binds, Box::new(expr)) }
265 pub rule string_expr(s: &ParserSettings) -> Expr265 pub rule string_expr(s: &ParserSettings) -> Expr
266 = s:string() {Expr::Str(s.into())}266 = s:string() {Expr::Trivial(TrivialVal::Str(s.into()))}
267 pub rule obj_expr(s: &ParserSettings) -> Expr267 pub rule obj_expr(s: &ParserSettings) -> Expr
268 = "{" _ body:objinside(s) _ "}" {Expr::Obj(body)}268 = "{" _ body:objinside(s) _ "}" {Expr::Obj(body)}
269 pub rule array_expr(s: &ParserSettings) -> Expr269 pub rule array_expr(s: &ParserSettings) -> Expr
273 Expr::ArrComp(Box::new(expr), specs)273 Expr::ArrComp(Box::new(expr), specs)
274 }274 }
275 pub rule number_expr(s: &ParserSettings) -> Expr275 pub rule number_expr(s: &ParserSettings) -> Expr
276 = n:number() {? NumValue::new(n).map_or_else(|| Err("!!!numbers are finite"), |n| Ok(Expr::Num(n)))}276 = n:number() {? NumValue::new(n).map_or_else(|| Err("!!!numbers are finite"), |n| Ok(Expr::Trivial(TrivialVal::Num(n))))}
277277
278 rule spanned<T: Acyclic>(x: rule<T>, s: &ParserSettings) -> Spanned<T>278 rule spanned<T: Acyclic>(x: rule<T>, s: &ParserSettings) -> Spanned<T>
279 = a:position!() n:x() b:position!() { Spanned::new(n, Span(s.source.clone(), codeidx(a), codeidx(b))) }279 = a:position!() n:x() b:position!() { Spanned::new(n, Span(s.source.clone(), codeidx(a), codeidx(b))) }
280280
281 pub rule var_expr(s: &ParserSettings) -> Expr281 pub rule var_expr(s: &ParserSettings) -> Expr
282 = n:spanned(<id()>, s) { Expr::Var(n) }282 = n:spanned(<id()>, s) { Expr::Var(n) }
283 pub rule id_loc(s: &ParserSettings) -> Spanned<Expr>283 pub rule id_loc(s: &ParserSettings) -> Spanned<Expr>
284 = a:position!() n:id() b:position!() { Spanned::new(Expr::Str(n), Span(s.source.clone(), codeidx(a), codeidx(b))) }284 = a:position!() n:id() b:position!() { Spanned::new(Expr::Trivial(TrivialVal::Str(n)), Span(s.source.clone(), codeidx(a), codeidx(b))) }
285 pub rule if_then_else_expr(s: &ParserSettings) -> Expr285 pub rule if_then_else_expr(s: &ParserSettings) -> Expr
286 = cond:ifspec(s) _ keyword("then") _ cond_then:expr(s) cond_else:(_ keyword("else") _ e:expr(s) {e})? {Expr::IfElse(Box::new(IfElse{286 = cond:ifspec(s) _ keyword("then") _ cond_then:expr(s) cond_else:(_ keyword("else") _ e:expr(s) {e})? {Expr::IfElse(Box::new(IfElse{
287 cond,287 cond,
290 }))}290 }))}
291291
292 pub rule literal(s: &ParserSettings) -> Expr292 pub rule literal(s: &ParserSettings) -> Expr
293 = a:position!() v:(293 = keyword("null") { Expr::Trivial(TrivialVal::Null) }
294 keyword("null") {LiteralType::Null}
295 / keyword("true") {LiteralType::True}294 / keyword("true") { Expr::Trivial(TrivialVal::Bool(true)) }
296 / keyword("false") {LiteralType::False}295 / keyword("false") { Expr::Trivial(TrivialVal::Bool(false)) }
297 / keyword("self") {LiteralType::This}296 / a:position!() v:(
297 keyword("self") {IdentityKind::This}
298 / keyword("$") {LiteralType::Dollar}298 / keyword("$") {IdentityKind::Dollar}
299 / keyword("super") {LiteralType::Super}299 / keyword("super") {IdentityKind::Super}
300 ) b:position!() {Expr::Literal(Span(s.source.clone(), codeidx(a), codeidx(b)), v)}300 ) b:position!() { Expr::Identity(Span(s.source.clone(), codeidx(a), codeidx(b)), v) }
301301
302 rule import_kind() -> ImportKind302 rule import_kind() -> ImportKind
303 = keyword("importstr") { ImportKind::Str }303 = keyword("importstr") { ImportKind::Str }
429pub fn string_to_expr(str: IStr, settings: &ParserSettings) -> Spanned<Expr> {429pub fn string_to_expr(str: IStr, settings: &ParserSettings) -> Spanned<Expr> {
430 let len = str.len();430 let len = str.len();
431 Spanned::new(431 Spanned::new(
432 Expr::Str(str),432 Expr::Trivial(TrivialVal::Str(str)),
433 Span(settings.source.clone(), 0, codeidx(len)),433 Span(settings.source.clone(), 0, codeidx(len)),
434 )434 )
435}435}
modifiedcrates/jrsonnet-peg-parser/src/snapshots/jrsonnet_peg_parser__tests__snapshots@array_comp.jsonnet.snapdiffbeforeafterboth
1---1---
2source: crates/jrsonnet-peg-parser/src/lib.rs2source: crates/jrsonnet-peg-parser/src/lib.rs
3assertion_line: 459
3expression: v4expression: v
4input_file: crates/jrsonnet-peg-parser/src/tests/array_comp.jsonnet5input_file: crates/jrsonnet-peg-parser/src/tests/array_comp.jsonnet
5---6---
14 parts: [15 parts: [
15 IndexPart {16 IndexPart {
16 span: virtual:<test>:7-15,17 span: virtual:<test>:7-15,
17 value: Str(18 value: Trivial(
19 Str(
18 "deepJoin",20 "deepJoin",
21 ),
19 ),22 ),
20 },23 },
21 ],24 ],
modifiedcrates/jrsonnet-peg-parser/src/snapshots/jrsonnet_peg_parser__tests__snapshots@basic_math.jsonnet.snapdiffbeforeafterboth
1---1---
2source: crates/jrsonnet-peg-parser/src/lib.rs2source: crates/jrsonnet-peg-parser/src/lib.rs
3assertion_line: 459
3expression: v4expression: v
4input_file: crates/jrsonnet-peg-parser/src/tests/basic_math.jsonnet5input_file: crates/jrsonnet-peg-parser/src/tests/basic_math.jsonnet
5---6---
6Arr(7Arr(
7 [8 [
8 BinaryOp(9 BinaryOp(
9 BinaryOp {10 BinaryOp {
10 lhs: Num(11 lhs: Trivial(
12 Num(
11 2.0,13 2.0,
14 ),
12 ),15 ),
13 op: Add,16 op: Add,
14 rhs: BinaryOp(17 rhs: BinaryOp(
15 BinaryOp {18 BinaryOp {
16 lhs: Num(19 lhs: Trivial(
20 Num(
17 2.0,21 2.0,
22 ),
18 ),23 ),
19 op: Mul,24 op: Mul,
20 rhs: Num(25 rhs: Trivial(
26 Num(
21 2.0,27 2.0,
28 ),
22 ),29 ),
23 },30 },
24 ),31 ),
25 },32 },
26 ),33 ),
27 BinaryOp(34 BinaryOp(
28 BinaryOp {35 BinaryOp {
29 lhs: Num(36 lhs: Trivial(
37 Num(
30 2.0,38 2.0,
39 ),
31 ),40 ),
32 op: Add,41 op: Add,
33 rhs: BinaryOp(42 rhs: BinaryOp(
34 BinaryOp {43 BinaryOp {
35 lhs: Num(44 lhs: Trivial(
45 Num(
36 2.0,46 2.0,
47 ),
37 ),48 ),
38 op: Mul,49 op: Mul,
39 rhs: Num(50 rhs: Trivial(
51 Num(
40 2.0,52 2.0,
53 ),
41 ),54 ),
42 },55 },
43 ),56 ),
47 BinaryOp {60 BinaryOp {
48 lhs: BinaryOp(61 lhs: BinaryOp(
49 BinaryOp {62 BinaryOp {
50 lhs: Num(63 lhs: Trivial(
64 Num(
51 2.0,65 2.0,
66 ),
52 ),67 ),
53 op: Add,68 op: Add,
54 rhs: Num(69 rhs: Trivial(
70 Num(
55 2.0,71 2.0,
72 ),
56 ),73 ),
57 },74 },
58 ),75 ),
59 op: Add,76 op: Add,
60 rhs: BinaryOp(77 rhs: BinaryOp(
61 BinaryOp {78 BinaryOp {
62 lhs: Num(79 lhs: Trivial(
80 Num(
63 2.0,81 2.0,
82 ),
64 ),83 ),
65 op: Mul,84 op: Mul,
66 rhs: Num(85 rhs: Trivial(
86 Num(
67 2.0,87 2.0,
88 ),
68 ),89 ),
69 },90 },
70 ),91 ),
71 },92 },
72 ),93 ),
73 BinaryOp(94 BinaryOp(
74 BinaryOp {95 BinaryOp {
75 lhs: Num(96 lhs: Trivial(
97 Num(
76 2.0,98 2.0,
99 ),
77 ),100 ),
78 op: Add,101 op: Add,
79 rhs: BinaryOp(102 rhs: BinaryOp(
80 BinaryOp {103 BinaryOp {
81 lhs: Num(104 lhs: Trivial(
105 Num(
82 2.0,106 2.0,
107 ),
83 ),108 ),
84 op: Add,109 op: Add,
85 rhs: BinaryOp(110 rhs: BinaryOp(
86 BinaryOp {111 BinaryOp {
87 lhs: Num(112 lhs: Trivial(
113 Num(
88 2.0,114 2.0,
115 ),
89 ),116 ),
90 op: Mul,117 op: Mul,
91 rhs: Num(118 rhs: Trivial(
119 Num(
92 2.0,120 2.0,
121 ),
93 ),122 ),
94 },123 },
95 ),124 ),
99 ),128 ),
100 BinaryOp(129 BinaryOp(
101 BinaryOp {130 BinaryOp {
102 lhs: Num(131 lhs: Trivial(
132 Num(
103 2.0,133 2.0,
134 ),
104 ),135 ),
105 op: Add,136 op: Add,
106 rhs: BinaryOp(137 rhs: BinaryOp(
107 BinaryOp {138 BinaryOp {
108 lhs: Num(139 lhs: Trivial(
140 Num(
109 3.0,141 3.0,
142 ),
110 ),143 ),
111 op: Mul,144 op: Mul,
112 rhs: Num(145 rhs: Trivial(
146 Num(
113 4.0,147 4.0,
148 ),
114 ),149 ),
115 },150 },
116 ),151 ),
modifiedcrates/jrsonnet-peg-parser/src/snapshots/jrsonnet_peg_parser__tests__snapshots@comment_eof.jsonnet.snapdiffbeforeafterboth
1---1---
2source: crates/jrsonnet-peg-parser/src/lib.rs2source: crates/jrsonnet-peg-parser/src/lib.rs
3assertion_line: 459
3expression: v4expression: v
4input_file: crates/jrsonnet-peg-parser/src/tests/comment_eof.jsonnet5input_file: crates/jrsonnet-peg-parser/src/tests/comment_eof.jsonnet
5---6---
16 plus: false,17 plus: false,
17 params: None,18 params: None,
18 visibility: Normal,19 visibility: Normal,
19 value: Num(20 value: Trivial(
21 Num(
20 1.0,22 1.0,
23 ),
21 ),24 ),
22 },25 },
23 ],26 ],
modifiedcrates/jrsonnet-peg-parser/src/snapshots/jrsonnet_peg_parser__tests__snapshots@default_nondefault.jsonnet.snapdiffbeforeafterboth
1---1---
2source: crates/jrsonnet-peg-parser/src/lib.rs2source: crates/jrsonnet-peg-parser/src/lib.rs
3assertion_line: 459
3expression: v4expression: v
4input_file: crates/jrsonnet-peg-parser/src/tests/default_nondefault.jsonnet5input_file: crates/jrsonnet-peg-parser/src/tests/default_nondefault.jsonnet
5---6---
14 "foo" from virtual:<test>:8-11,15 "foo" from virtual:<test>:8-11,
15 ),16 ),
16 default: Some(17 default: Some(
17 Str(18 Trivial(
19 Str(
18 "foo",20 "foo",
21 ),
19 ),22 ),
20 ),23 ),
21 },24 },
44 ),47 ),
45 binds_len: 2,48 binds_len: 2,
46 },49 },
47 value: Literal(50 value: Trivial(
48 virtual:<test>:28-32,
49 Null,51 Null,
50 ),52 ),
51 },53 },
52 ],54 ],
53 Literal(55 Trivial(
54 virtual:<test>:34-38,
55 Null,56 Null,
56 ),57 ),
57)58)
modifiedcrates/jrsonnet-peg-parser/src/snapshots/jrsonnet_peg_parser__tests__snapshots@imports.jsonnet.snapdiffbeforeafterboth
1---1---
2source: crates/jrsonnet-peg-parser/src/lib.rs2source: crates/jrsonnet-peg-parser/src/lib.rs
3assertion_line: 459
3expression: v4expression: v
4input_file: crates/jrsonnet-peg-parser/src/tests/imports.jsonnet5input_file: crates/jrsonnet-peg-parser/src/tests/imports.jsonnet
5---6---
6Arr(7Arr(
7 [8 [
8 Import(9 Import(
9 Normal from virtual:<test>:2-8,10 Normal from virtual:<test>:2-8,
10 Str(11 Trivial(
12 Str(
11 "hello",13 "hello",
14 ),
12 ),15 ),
13 ),16 ),
14 Import(17 Import(
15 Str from virtual:<test>:18-27,18 Str from virtual:<test>:18-27,
16 Str(19 Trivial(
20 Str(
17 "garnish.txt",21 "garnish.txt",
22 ),
18 ),23 ),
19 ),24 ),
20 Import(25 Import(
21 Bin from virtual:<test>:43-52,26 Bin from virtual:<test>:43-52,
22 Str(27 Trivial(
28 Str(
23 "garnish.bin",29 "garnish.bin",
30 ),
24 ),31 ),
25 ),32 ),
26 ],33 ],
modifiedcrates/jrsonnet-peg-parser/src/snapshots/jrsonnet_peg_parser__tests__snapshots@multiline.jsonnet.snapdiffbeforeafterboth
1---1---
2source: crates/jrsonnet-peg-parser/src/lib.rs2source: crates/jrsonnet-peg-parser/src/lib.rs
3assertion_line: 459
3expression: v4expression: v
4input_file: crates/jrsonnet-peg-parser/src/tests/multiline.jsonnet5input_file: crates/jrsonnet-peg-parser/src/tests/multiline.jsonnet
5---6---
6Arr(7Arr(
7 [8 [
8 Str(9 Trivial(
10 Str(
9 "Hello world!\na\n",11 "Hello world!\na\n",
12 ),
10 ),13 ),
11 Str(14 Trivial(
15 Str(
12 "Hello world!\na\n",16 "Hello world!\na\n",
17 ),
13 ),18 ),
14 Str(19 Trivial(
20 Str(
15 "Hello world!\n\ta\n",21 "Hello world!\n\ta\n",
22 ),
16 ),23 ),
17 Str(24 Trivial(
25 Str(
18 "Hello world!\n a\n",26 "Hello world!\n a\n",
27 ),
19 ),28 ),
20 ],29 ],
21)30)
modifiedcrates/jrsonnet-peg-parser/src/snapshots/jrsonnet_peg_parser__tests__snapshots@reserved.jsonnet.snapdiffbeforeafterboth
1---1---
2source: crates/jrsonnet-peg-parser/src/lib.rs2source: crates/jrsonnet-peg-parser/src/lib.rs
3assertion_line: 459
3expression: v4expression: v
4input_file: crates/jrsonnet-peg-parser/src/tests/reserved.jsonnet5input_file: crates/jrsonnet-peg-parser/src/tests/reserved.jsonnet
5---6---
6Arr(7Arr(
7 [8 [
8 Literal(9 Trivial(
9 virtual:<test>:2-6,
10 Null,10 Null,
11 ),11 ),
12 Var(12 Var(
modifiedcrates/jrsonnet-peg-parser/src/snapshots/jrsonnet_peg_parser__tests__snapshots@slice.jsonnet.snapdiffbeforeafterboth
1---1---
2source: crates/jrsonnet-peg-parser/src/lib.rs2source: crates/jrsonnet-peg-parser/src/lib.rs
3assertion_line: 459
3expression: v4expression: v
4input_file: crates/jrsonnet-peg-parser/src/tests/slice.jsonnet5input_file: crates/jrsonnet-peg-parser/src/tests/slice.jsonnet
5---6---
12 ),13 ),
13 slice: SliceDesc {14 slice: SliceDesc {
14 start: Some(15 start: Some(
15 Num(16 Trivial(
17 Num(
16 1.0,18 1.0,
19 ),
17 ) from virtual:<test>:4-5,20 ) from virtual:<test>:4-5,
18 ),21 ),
19 end: None,22 end: None,
28 ),31 ),
29 slice: SliceDesc {32 slice: SliceDesc {
30 start: Some(33 start: Some(
31 Num(34 Trivial(
35 Num(
32 1.0,36 1.0,
37 ),
33 ) from virtual:<test>:11-12,38 ) from virtual:<test>:11-12,
34 ),39 ),
35 end: None,40 end: None,
45 slice: SliceDesc {50 slice: SliceDesc {
46 start: None,51 start: None,
47 end: Some(52 end: Some(
48 Num(53 Trivial(
54 Num(
49 1.0,55 1.0,
56 ),
50 ) from virtual:<test>:20-21,57 ) from virtual:<test>:20-21,
51 ),58 ),
52 step: None,59 step: None,
62 start: None,69 start: None,
63 end: None,70 end: None,
64 step: Some(71 step: Some(
65 Num(72 Trivial(
73 Num(
66 1.0,74 1.0,
75 ),
67 ) from virtual:<test>:29-30,76 ) from virtual:<test>:29-30,
68 ),77 ),
69 },78 },
83 "len" from virtual:<test>:38-41,92 "len" from virtual:<test>:38-41,
84 ),93 ),
85 op: Sub,94 op: Sub,
86 rhs: Num(95 rhs: Trivial(
96 Num(
87 1.0,97 1.0,
98 ),
88 ),99 ),
89 },100 },
90 ) from virtual:<test>:38-45,101 ) from virtual:<test>:38-45,
modifiedcrates/jrsonnet-peg-parser/src/snapshots/jrsonnet_peg_parser__tests__snapshots@string_escaping.jsonnet.snapdiffbeforeafterboth
1---1---
2source: crates/jrsonnet-peg-parser/src/lib.rs2source: crates/jrsonnet-peg-parser/src/lib.rs
3assertion_line: 459
3expression: v4expression: v
4input_file: crates/jrsonnet-peg-parser/src/tests/string_escaping.jsonnet5input_file: crates/jrsonnet-peg-parser/src/tests/string_escaping.jsonnet
5---6---
6Arr(7Arr(
7 [8 [
8 Str(9 Trivial(
10 Str(
9 "Hello, \"world\"!",11 "Hello, \"world\"!",
12 ),
10 ),13 ),
11 Str(14 Trivial(
15 Str(
12 "Hello 'world'!",16 "Hello 'world'!",
17 ),
13 ),18 ),
14 Str(19 Trivial(
20 Str(
15 "\\\\",21 "\\\\",
22 ),
16 ),23 ),
17 Str(24 Trivial(
25 Str(
18 "Hello\nWorld",26 "Hello\nWorld",
27 ),
19 ),28 ),
20 Str(29 Trivial(
30 Str(
21 "Hello\\n\"World\"",31 "Hello\\n\"World\"",
32 ),
22 ),33 ),
23 ],34 ],
24)35)
modifiedcrates/jrsonnet-peg-parser/src/snapshots/jrsonnet_peg_parser__tests__snapshots@subexp.jsonnet.snapdiffbeforeafterboth
1---1---
2source: crates/jrsonnet-peg-parser/src/lib.rs2source: crates/jrsonnet-peg-parser/src/lib.rs
3assertion_line: 459
3expression: v4expression: v
4input_file: crates/jrsonnet-peg-parser/src/tests/subexp.jsonnet5input_file: crates/jrsonnet-peg-parser/src/tests/subexp.jsonnet
5---6---
22 into: Full(23 into: Full(
23 "x" from virtual:<test>:11-12,24 "x" from virtual:<test>:11-12,
24 ),25 ),
25 value: Num(26 value: Trivial(
27 Num(
26 1.0,28 1.0,
29 ),
27 ),30 ),
28 },31 },
29 ],32 ],
modifiedcrates/jrsonnet-peg-parser/src/snapshots/jrsonnet_peg_parser__tests__snapshots@suffix.jsonnet.snapdiffbeforeafterboth
1---1---
2source: crates/jrsonnet-peg-parser/src/lib.rs2source: crates/jrsonnet-peg-parser/src/lib.rs
3assertion_line: 459
3expression: v4expression: v
4input_file: crates/jrsonnet-peg-parser/src/tests/suffix.jsonnet5input_file: crates/jrsonnet-peg-parser/src/tests/suffix.jsonnet
5---6---
12 parts: [13 parts: [
13 IndexPart {14 IndexPart {
14 span: virtual:<test>:6-10,15 span: virtual:<test>:6-10,
15 value: Str(16 value: Trivial(
17 Str(
16 "test",18 "test",
19 ),
17 ),20 ),
18 },21 },
19 ],22 ],
24 ),27 ),
25 ArgsDesc {28 ArgsDesc {
26 unnamed: [29 unnamed: [
27 Num(30 Trivial(
31 Num(
28 2.0,32 2.0,
33 ),
29 ),34 ),
30 ],35 ],
31 names: [],36 names: [],
41 parts: [46 parts: [
42 IndexPart {47 IndexPart {
43 span: virtual:<test>:24-28,48 span: virtual:<test>:24-28,
44 value: Str(49 value: Trivial(
50 Str(
45 "test",51 "test",
52 ),
46 ),53 ),
47 },54 },
48 ],55 ],
49 },56 },
50 ArgsDesc {57 ArgsDesc {
51 unnamed: [58 unnamed: [
52 Num(59 Trivial(
60 Num(
53 2.0,61 2.0,
62 ),
54 ),63 ),
55 ],64 ],
56 names: [],65 names: [],