You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
as_quantity(x) =error("Unexpected type evaluated: $(typeof(x))")
43
44
44
45
"""
@@ -54,7 +55,50 @@ the quantity corresponding to the speed of light multiplied by Hertz,
54
55
squared.
55
56
"""
56
57
macrou_str(s)
57
-
returnesc(Meta.parse(s))
58
+
ex = Meta.parse(s)
59
+
returnesc(map_to_scope(ex))
60
+
end
61
+
62
+
functionmap_to_scope(ex::Expr)
63
+
if ex.head ==:call
64
+
ex.args[2:end] =map(map_to_scope, ex.args[2:end])
65
+
return ex
66
+
elseif ex.head ==:tuple
67
+
ex.args[:] =map(map_to_scope, ex.args)
68
+
return ex
69
+
elseif ex.head == :.
70
+
if ex.args[1] ==:Constants
71
+
@assert ex.args[2] isa QuoteNode
72
+
returnlookup_constant(ex.args[2].value)
73
+
else
74
+
return ex
75
+
end
76
+
else
77
+
throw(ArgumentError("Unexpected expression: $ex. Only `:call`, `:tuple`, and `:.` are expected."))
78
+
return ex
79
+
end
80
+
end
81
+
functionmap_to_scope(sym::Symbol)
82
+
if sym in UNIT_SYMBOLS
83
+
returnlookup_unit(sym)
84
+
elseif sym in CONSTANT_SYMBOLS
85
+
throw(ArgumentError("Found the symbol $sym. To access constants in a unit expression, access the `Constants` module. For example, `u\"Constants.h\"`."))
86
+
return sym
87
+
else
88
+
throw(ArgumentError("Symbol $sym not found in `Units` or `Constants`."))
0 commit comments