Skip to content

Commit c3d3d53

Browse files
author
Christopher Doris
committed
py_macro supports large integer literals
1 parent be06802 commit c3d3d53

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

src/py_macro.jl

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@
33
# - class definition (e.g. `struct User <: BaseModel; id::int=0; name::str=""; end`)
44
# - property syntax (e.g. `classmethod |> function foo(cls); cls(); end`)
55
# - with syntax (`@with`)
6+
# - bytes literals (`b"..."`)
7+
# - raw string literals (`r"..."` or raw"..."?)
8+
# - regex literals (`re"..."` or `r"..."`?)
9+
# - formatted string literals (`f"..."`)
610

711
const PY_MACRO_UNOPS = Dict(
812
# operators
@@ -121,6 +125,27 @@ function py_macro_lower(st, body, ans, ex; flavour=:expr)
121125
py_macro_assign(body, ans, x)
122126
return false
123127

128+
# Int128 literals
129+
elseif isexpr(ex, :macrocall) && ex.args[1] === GlobalRef(Core, Symbol("@int128_str"))
130+
value = parse(Int128, ex.args[3])
131+
x = get!(pynew, st.consts, value)
132+
py_macro_assign(body, ans, x)
133+
return false
134+
135+
# UInt128 literals
136+
elseif isexpr(ex, :macrocall) && ex.args[1] === GlobalRef(Core, Symbol("@uint128_str"))
137+
value = parse(UInt128, ex.args[3])
138+
x = get!(pynew, st.consts, value)
139+
py_macro_assign(body, ans, x)
140+
return false
141+
142+
# big integer literals
143+
elseif isexpr(ex, :macrocall) && ex.args[1] === GlobalRef(Core, Symbol("@big_str"))
144+
value = parse(BigInt, ex.args[3])
145+
x = get!(pynew, st.consts, value)
146+
py_macro_assign(body, ans, x)
147+
return false
148+
124149
# __file__
125150
elseif ex === :__file__
126151
return py_macro_lower(st, body, ans, string(st.src.file))

0 commit comments

Comments
 (0)