File tree Expand file tree Collapse file tree 3 files changed +33
-0
lines changed Expand file tree Collapse file tree 3 files changed +33
-0
lines changed Original file line number Diff line number Diff line change @@ -8,6 +8,7 @@ export VarName,
8
8
subsumes,
9
9
subsumedby,
10
10
varname,
11
+ varname_from_str,
11
12
vsym,
12
13
@varname ,
13
14
@vsym
Original file line number Diff line number Diff line change @@ -663,6 +663,8 @@ function drop_escape(expr::Expr)
663
663
return Expr (expr. head, map (x -> drop_escape (x), expr. args)... )
664
664
end
665
665
666
+ varname_from_str (str:: AbstractString ) = eval (drop_escape (varname (Meta. parse (str))))
667
+
666
668
function _parse_obj_optic (ex)
667
669
obj, optics = _parse_obj_optics (ex)
668
670
optic = Expr (:call , Accessors. opticcompose, optics... )
Original file line number Diff line number Diff line change 137
137
@inferred get (c, @varname (b. a[1 ]))
138
138
@inferred Accessors. set (c, @varname (b. a[1 ]), 10 )
139
139
end
140
+
141
+ @testset " roundtrip conversion to/from string" begin
142
+ # Static optics
143
+ vns = [
144
+ @varname (x),
145
+ @varname (x. a),
146
+ @varname (x[1 ]),
147
+ @varname (x[1 : 10 ]),
148
+ @varname (x[1 , 2 ]),
149
+ @varname (x[1 , 2 : 5 ]),
150
+ @varname (x[:]),
151
+ @varname (x. a[1 ]),
152
+ @varname (x. a[1 : 10 ]),
153
+ @varname (x[1 ]. a),
154
+ ]
155
+ for vn in vns
156
+ @test varname_from_str (repr (vn)) == vn
157
+ end
158
+
159
+ # Post-concretisation
160
+ x = ones (10 )
161
+ vn = @varname (x[begin : end ])
162
+ @test varname_from_str (repr (vn)) == vn
163
+
164
+ # When forcing concretisation
165
+ vn = @varname (x[:], true )
166
+ @test_broken varname_from_str (repr (vn)) == vn
167
+ dump (varname_from_str (repr (vn)))
168
+ dump (vn)
169
+ end
140
170
end
You can’t perform that action at this time.
0 commit comments