Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bootstrap emojify on WatchJuliaBurn and reorganize structure #39

Merged
merged 15 commits into from
Dec 15, 2023
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ jobs:
with:
version: 1
- run: |
julia -e 'using Pkg; Pkg.add("Latexify"); Pkg.develop(path="."); include("src/create_README.jl")'
julia -e 'using Pkg; Pkg.add("Latexify"); Pkg.develop(path="."); include("📜/👢🎀.jl")'
theogf marked this conversation as resolved.
Show resolved Hide resolved
echo $(git diff)
- uses: EndBug/add-and-commit@v7
with:
Expand Down
81 changes: 9 additions & 72 deletions src/WatchJuliaBurn.jl
Original file line number Diff line number Diff line change
@@ -1,11 +1,17 @@
module WatchJuliaBurn

export @🐒
export @🥩_str
export @new_emoji
export emojify
using Base: print

using LinearAlgebra
using Statistics

# Needed for the first global constant.
const 📖 = Dict

const emoji_to_func = Dict{Any, Any}()

"""
Expand Down Expand Up @@ -34,74 +40,7 @@ macro new_emoji(emoji, func, julia_version)
end)
end

## Contains mapping from functions to func_to_emojis
## Each function (treated as a Symbol) maps to a Tuple of Symbols and Tuple{Symbol,Float64} for
## emojis needing a specific version
const func_to_emojis = Dict(
## Base
:throw => (:(c╯°□°ↄ╯), :(🤮), :(🚮),),
:map => (:(🗺),),
:broadcast => (:(📡),),
:Dict => (:(📖),),
:true => (:(✅), :(👍), :(👌),),
:false => (:👎,),
:delete! => (:(🔥),),
:print => (:(🖨️),),
:nothing => (:(⬛),),
:findall => (:(🕵️),),
:show => (:(☝️),),
:peek => ((:(⛰️), 1.5),),
:chop => ((Symbol(Char(0x0001f333) * Char(0x0001fa93)), 1.2),), # 🌳🪓
:ArgumentError => (:(💬🚨),),
:join => (:(🚪🚶),),
:foldr => (:(🗂), :(📁),),
:first => (:(🥇),),
:findfirst => (:(🔎🥇),),
:keys => (:(🔑), :(🗝),),
:rand => (:(🎰),:(🎲),),
:kill => (:(⚰️),),
:run => (:(🏃),),
:error => (:(💣),),
:cd => (:(💿),),
:zip => (:(🤐),),
## Arrays
:cat => (:(😻), :(😹), :(🐈),),
:vcat => (:(⬇️😻), :(⬇️😹), :(⬇️🐈),),
:hcat => (:(➡️😻), :(➡️😹), :(➡️🐈),),
:Matrix => (:(🔢),),
:collect => (:(🧺),),
:axes => ((Symbol(Char(0x1fa93)^2), 1.2),), # 🪓🪓
:fill => (:(🚰),),
## Math
:pi => (:(🥧), :(🍰),),
:tan => (:(🧑🏻➡️🧑🏽), :(👩🏻➡️👩🏽),),
:log => ((Symbol(Char(0x1fab5)), 1.5),), # 🪵
:clamp => (:(🗜️),),
:mod => (:(🛵🔧),),
:inv => (:(↔),),
:imag => (:(🔮),),
:round => (:(🎠), :(🔵),),
:time => (:(🕛),),
:cot => (:(🧥), :(🥼)),
:count => (:(🧮),),
:count_ones => (:(🧮1️⃣1️⃣),),
:count_zeros => (:(🧮0️⃣0️⃣),),
:findnext => ((:🔎⏭),),
:isreal => ((:🛸❓),),
:float => ((:⛵️),),
:sign => ((Symbol(Char(0x1faa7)), 1.5),(Symbol(Char(0x1f68f)), 1.5),), # 🪧, 🚏
:abs => ((:👔💪),(:🎽💪),),
:view => (:(👀), (:👁️),),
:write => (:(🖊️), :(✍️), :(🖋️),),
:Threads => (:(🧵),),
:time => (:(⏱️), :(⌛), :(⏲️),),
:string => (:(🎻),),
:download => (:(📥),),
:sleep => (:(😴), :(💤),),
:exit => (:(🚪),),
:pop! => (:(🍾), :(🏹🎈)),
:(mean ∘ skipmissing) => (:(😠),),
)
include("📖.jl")

for func in keys(func_to_emojis)
for symbol_info in func_to_emojis[func]
Expand All @@ -115,12 +54,10 @@ end

## Additional features (does not pass with @new_emoji)
@eval $(Symbol("@🥩_str")) = $(getfield(Main, Symbol("@raw_str")))
export @🥩_str
func_to_emojis[:(raw)] = (:(🥩),)
emoji_to_func[:(🥩"")] = (:(raw""), "")

include("emojify.jl")
include("monkeycatch.jl")
export @🐒
include("😃→🗿.jl")
include("🙈🙊🙉.jl")

end
81 changes: 0 additions & 81 deletions src/create_README.jl

This file was deleted.

68 changes: 68 additions & 0 deletions src/📖.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
## Contains mapping from functions to func_to_emojis
## Each function (treated as a Symbol) maps to a Tuple of Symbols and Tuple{Symbol,Float64} for
## emojis needing a specific version
const func_to_emojis = Dict(
theogf marked this conversation as resolved.
Show resolved Hide resolved
## Base
:throw => (:(c╯°□°ↄ╯), :(🤮), :(🚮),),
:map => (:(🗺),),
:broadcast => (:(📡),),
:Dict => (:(📖),),
:true => (:(✅), :(👍), :(👌),),
:false => (:👎,),
:delete! => (:(🔥),),
:print => (:(🖨️),),
:nothing => (:(⬛),),
:findall => (:(🕵️),),
:show => (:(☝️),),
:peek => ((:(⛰️), 1.5),),
:chop => ((Symbol(Char(0x0001f333) * Char(0x0001fa93)), 1.2),), # 🌳🪓
:ArgumentError => (:(💬🚨),),
:join => (:(🚪🚶),),
:foldr => (:(🗂), :(📁),),
:first => (:(🥇),),
:findfirst => (:(🔎🥇),),
:keys => (:(🔑), :(🗝),),
:rand => (:(🎰),:(🎲),),
:kill => (:(⚰️),),
:run => (:(🏃),),
:error => (:(💣),),
:cd => (:(💿),),
:zip => (:(🤐),),
## Arrays
:cat => (:(😻), :(😹), :(🐈),),
:vcat => (:(⬇️😻), :(⬇️😹), :(⬇️🐈),),
:hcat => (:(➡️😻), :(➡️😹), :(➡️🐈),),
:Matrix => (:(🔢),),
:collect => (:(🧺),),
:axes => ((Symbol(Char(0x1fa93)^2), 1.2),), # 🪓🪓
:fill => (:(🚰),),
## Math
:pi => (:(🥧), :(🍰),),
:tan => (:(🧑🏻➡️🧑🏽), :(👩🏻➡️👩🏽),),
:log => ((Symbol(Char(0x1fab5)), 1.5),), # 🪵
:clamp => (:(🗜️),),
:mod => (:(🛵🔧),),
:inv => (:(↔),),
:imag => (:(🔮),),
:round => (:(🎠), :(🔵),),
:time => (:(🕛),),
:cot => (:(🧥), :(🥼)),
:count => (:(🧮),),
:count_ones => (:(🧮1️⃣1️⃣),),
:count_zeros => (:(🧮0️⃣0️⃣),),
:findnext => ((:🔎⏭),),
:isreal => ((:🛸❓),),
:float => ((:⛵️),),
:sign => ((Symbol(Char(0x1faa7)), 1.5),(Symbol(Char(0x1f68f)), 1.5),), # 🪧, 🚏
:abs => ((:👔💪),(:🎽💪),),
:view => (:(👀), (:👁️),),
:write => (:(🖊️), :(✍️), :(🖋️),),
:Threads => (:(🧵),),
:time => (:(⏱️), :(⌛), :(⏲️),),
:string => (:(🎻),),
:download => (:(📥),),
:sleep => (:(😴), :(💤),),
:exit => (:(🚪),),
:pop! => (:(🍾), :(🏹🎈)),
:(mean ∘ skipmissing) => (:(😠),),
)
10 changes: 5 additions & 5 deletions src/emojify.jl → src/😃→🗿.jl
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ function emojify_file(filepath::String; overwrite=👍)
str = String(read(filepath))
str = emojify_string(str)
if overwrite
write(filepath, str)
🖊️(filepath, str)
return ⬛
else
return str
Expand All @@ -28,20 +28,20 @@ end

function emojify_string(str::String)
for func in 🔑(func_to_emojis)
str = replace(str, Regex("\\b" * string(func) * "\\b") => RandString(to_string.(func_to_emojis[func])))
str = replace(str, Regex("\\b" * 🎻(func) * "\\b") => RandString(to_string.(func_to_emojis[func])))
end
return str
end

function to_string(emoji::Symbol)
string(emoji)
🎻(emoji)
end

function to_string(emoji::Tuple)
return string(emoji[1])
return 🎻(emoji[1])
end

## Allow to get a random string every time it's printed
## Allow to get a random 🎻 every ⏲️ it's printed
struct RandString{TS}
strings::TS
end
Expand Down
18 changes: 9 additions & 9 deletions src/monkeycatch.jl → src/🙈🙊🙉.jl
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ finally
baz()
end
```
you can now write the far more legible:
you can now ✍️ the far more legible:
```julia
💣 = foo
😥 = bar
Expand All @@ -30,12 +30,12 @@ you can now write the far more legible:
```
"""
macro 🐒(monkeyexpression::Expr)
monkeyexpression.head == :block || error("You have to wrap this in a begin...end block, sorry!")
monkeyexpression.head == :block || 💣("You have to wrap this in a begin...end block, sorry!")
newexpr = Expr(:block)
tryblock = Expr(:block)
catchme = false
catchblock = false
finallyblock = nothing
catchme = 👎
catchblock = 👎
finallyblock =
state = :start # where are we in the expression
for sub in monkeyexpression.args
if state == :start
Expand All @@ -44,7 +44,7 @@ macro 🐒(monkeyexpression::Expr)
elseif sub isa LineNumberNode
push!(newexpr.args, sub)
else
error("Missing 🙈")
💣("Missing 🙈")
end
elseif state == :try
if sub isa Symbol && sub == :🙊
Expand All @@ -56,7 +56,7 @@ macro 🐒(monkeyexpression::Expr)
if length(sub.args) == 2
catchme = sub.args[2]
else
error("Can only catch a single error at once, duh!")
💣("Can only catch a single 💣 at once, duh!")
end
elseif sub isa Symbol && sub == :🙉
state = :finally
Expand All @@ -76,10 +76,10 @@ macro 🐒(monkeyexpression::Expr)
end
end
if state == :try
error("Syntax: 🙈 without 🙊 or 🙉")
💣("Syntax: 🙈 without 🙊 or 🙉")
end
tryexpr = Expr(:try, tryblock, catchme, catchblock)
if !(finallyblock === nothing)
if !(finallyblock === )
push!(tryexpr.args, finallyblock)
end
push!(newexpr.args, tryexpr)
Expand Down
2 changes: 1 addition & 1 deletion test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,6 @@ using LinearAlgebra
@test 🔮(1 + 2im) == 2

## Monkey try/catch/finally
include("monkeytests.jl")
include("🐒tests.jl")

end
File renamed without changes.
Loading