@@ -211,9 +211,8 @@ function qparse(str::String, reg::AbstractDict{Symbol,U}) where {U<:AbstractUnit
211211end
212212
213213# Expression parsing (for dynamic and macros) ==============================================================
214- function uparse_expr (str0:: String , reg:: AbstractDict{Symbol, U} ) where U <: AbstractUnitLike
215- str = _expr_preprocessing (str0)
216- parsed = Meta. parse (str)
214+ function uparse_expr (str:: String , reg:: AbstractDict{Symbol, U} ) where U <: AbstractUnitLike
215+ parsed = Meta. parse (_expr_preprocessing (str))
217216
218217 if ! (parsed isa PARSE_CASES)
219218 throw (ArgumentError (" Unexpected expression: String input \" $(str) \" was not parsed as $(PARSE_CASES) " ))
@@ -223,9 +222,8 @@ function uparse_expr(str0::String, reg::AbstractDict{Symbol, U}) where U <: Abst
223222 end
224223end
225224
226- function qparse_expr (str0:: String , reg:: AbstractDict{Symbol, U} ) where U <: AbstractUnitLike
227- str = _expr_preprocessing (str0)
228- parsed = Meta. parse (str)
225+ function qparse_expr (str:: String , reg:: AbstractDict{Symbol, U} ) where U <: AbstractUnitLike
226+ parsed = Meta. parse (_expr_preprocessing (str))
229227
230228 if ! (parsed isa PARSE_CASES)
231229 throw (ArgumentError (" Unexpected expression: String input \" $(str) \" was not parsed as $(PARSE_CASES) " ))
@@ -288,7 +286,12 @@ function change_symbol(u::U, s::Symbol) where U<:AbstractAffineUnits
288286 return constructorof (U)(scale= uscale (u), offset= uoffset (u), dims= dimension (u), symbol= s)
289287end
290288
291- _expr_preprocessing (str:: String ) = replace (str, " " => " " , " %" => " percent" )
289+ function _expr_preprocessing (str1:: AbstractString )
290+ space2mult = r" ([\%\w ]) +([\%\w ])" => s "\1 *\2 "
291+ str2 = replace (str1, space2mult) # Spaces between words are multiplications
292+ str3 = replace (str2, space2mult) # Spaces between words are multiplications
293+ return replace (str3, " " => " " , " %" => " percent" ) # Eliminates extra spaces
294+ end
292295
293296end
294297
0 commit comments