Skip to content
This repository has been archived by the owner on Jun 11, 2023. It is now read-only.

Commit

Permalink
Merge pull request #65 from udohjeremiah/metaprogramming
Browse files Browse the repository at this point in the history
add task to done section
  • Loading branch information
udohjeremiah authored May 1, 2023
2 parents ff3a8f6 + 4d3992c commit 4551ab1
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 47 deletions.
6 changes: 2 additions & 4 deletions TODO.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,10 +68,6 @@ To see what's happening in a section, click on the arrow symbol (▶).
## In Progress...

<details><summary></summary>

- [ ] Create the `_23_metaprogramming.jl` file:
[`metaprogramming`](https://github.com/udohjeremiah/REPLference.jl/tree/metaprogramming)
[@udohjeremiah](https://github.com/udohjeremiah)
</details>

## Done ✓
Expand All @@ -84,4 +80,6 @@ To see what's happening in a section, click on the arrow symbol (▶).
- [x] Create the `.JuliaFormatter.jl` file and use `BlueStyle`:
[`#60`](https://github.com/udohjeremiah/REPLference.jl/pull/60)
[@udohjeremiah](https://github.com/udohjeremiah)
- [x] Create the `_23_metaprogramming.jl` file:
[`#64`](https://github.com/udohjeremiah/REPLference.jl/pull/64)
</details>
91 changes: 49 additions & 42 deletions src/REPLference.jl
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ include("_19_module.jl")
include("_20_regex.jl")
include("_21_date.jl")
include("_22_random.jl")
include("_23_metaprogramming.jl")

import Dates: AbstractTime
import .Docs: doc
Expand Down Expand Up @@ -76,136 +77,142 @@ function subtree end
function man(obj::Symbol)
str = string(obj)
# keywords
if match(r"^(?:keyword|reserved)"i, str) != nothing
if match(r"^(?:keyword|reserved)"i, str) !== nothing
doc(keywords)
# variables
elseif match(r"^variable"i, str) != nothing
elseif match(r"^variable"i, str) !== nothing
doc(variables)
# operators
elseif match(r"^operat(?:or|ion)"i, str) != nothing
elseif match(r"^operat(?:or|ion)"i, str) !== nothing
doc(operators)
# integers
elseif match(r"^integer"i, str) != nothing
elseif match(r"^integer"i, str) !== nothing
doc(integers)
# floating points
elseif match(r"^float"i, str) != nothing
elseif match(r"^float"i, str) !== nothing
doc(floats)
# complex numbers
elseif match(r"^complex"i, str) != nothing
elseif match(r"^complex"i, str) !== nothing
doc(complexs)
# rational numbers
elseif match(r"^rational"i, str) != nothing
elseif match(r"^rational"i, str) !== nothing
doc(rationals)
# irrationals
elseif match(r"^irrational"i, str) != nothing
elseif match(r"^irrational"i, str) !== nothing
doc(irrationals)
# characters
elseif match(r"^character"i, str) != nothing
elseif match(r"^character"i, str) !== nothing
doc(characters)
# strings
elseif match(r"^string"i, str) != nothing
elseif match(r"^string"i, str) !== nothing
doc(strings)
# ranges
elseif match(r"^range"i, str) != nothing
elseif match(r"^range"i, str) !== nothing
doc(ranges)
# arrays
elseif match(r"^array"i, str) != nothing
elseif match(r"^array"i, str) !== nothing
doc(arrays)
# tuples
elseif match(r"^(?:tuple|named(.)?tuple)"i, str) != nothing
elseif match(r"^(?:tuple|named(.)?tuple)"i, str) !== nothing
doc(tuples)
# dictionaries
elseif match(r"^dict"i, str) != nothing
elseif match(r"^dict"i, str) !== nothing
doc(dicts)
# sets
elseif match(r"^set"i, str) != nothing
elseif match(r"^set"i, str) !== nothing
doc(sets)
# types
elseif match(r"^(?:type|datatype)"i, str) != nothing
elseif match(r"^(?:type|datatype)"i, str) !== nothing
doc(types)
# function
elseif match(r"^(?:function|method|procedure)"i, str) != nothing
elseif match(r"^(?:function|method|procedure)"i, str) !== nothing
doc(functions)
# files
elseif match(r"^(?:file|io|stream)"i, str) != nothing
elseif match(r"^(?:file|io|stream)"i, str) !== nothing
doc(files)
# modules
elseif match(r"^(?:module|package)"i, str) != nothing
elseif match(r"^(?:module|package)"i, str) !== nothing
doc(modules)
# regexes
elseif match(r"^reg(?:ex|ular)"i, str) != nothing
elseif match(r"^reg(?:ex|ular)"i, str) !== nothing
doc(regexes)
# time and date
elseif match(r"^(?:time|date)"i, str) != nothing
elseif match(r"^(?:time|date)"i, str) !== nothing
doc(datetime)
# random numbers
elseif match(r"^rand"i, str) != nothing
elseif match(r"^rand"i, str) !== nothing
doc(randoms)
# metaprogramming
elseif match(r"^meta"i, str) !== nothing
doc(metaprogramming)
end
end

function fun(obj::Symbol; extmod=false)
str = string(obj)
# operators
if match(r"operat(?:or|ion)"i, str) != nothing
if match(r"operat(?:or|ion)"i, str) !== nothing
operators(; extmod=extmod)
# integers
elseif match(r"^integer"i, str) != nothing
elseif match(r"^integer"i, str) !== nothing
integers(; extmod=extmod)
# floating points
elseif match(r"^float"i, str) != nothing
elseif match(r"^float"i, str) !== nothing
floats(; extmod=extmod)
# complex numbers
elseif match(r"^complex"i, str) != nothing
elseif match(r"^complex"i, str) !== nothing
complexs(; extmod=extmod)
# rational numbers
elseif match(r"^rational"i, str) != nothing
elseif match(r"^rational"i, str) !== nothing
rationals(; extmod=extmod)
# irrationals
elseif match(r"^irrational"i, str) != nothing
elseif match(r"^irrational"i, str) !== nothing
irrationals(; extmod=extmod)
# characters
elseif match(r"^character"i, str) != nothing
elseif match(r"^character"i, str) !== nothing
characters(; extmod=extmod)
# strings
elseif match(r"^string"i, str) != nothing
elseif match(r"^string"i, str) !== nothing
strings(; extmod=extmod)
# ranges
elseif match(r"^range"i, str) != nothing
elseif match(r"^range"i, str) !== nothing
ranges(; extmod=extmod)
# arrays
elseif match(r"^array"i, str) != nothing
elseif match(r"^array"i, str) !== nothing
arrays(; extmod=extmod)
# tuples
elseif match(r"^(?:tuple|named(.)?tuple)"i, str) != nothing
elseif match(r"^(?:tuple|named(.)?tuple)"i, str) !== nothing
tuples(; extmod=extmod)
# dictionaries
elseif match(r"^dict"i, str) != nothing
elseif match(r"^dict"i, str) !== nothing
dicts(; extmod=extmod)
# sets
elseif match(r"^set"i, str) != nothing
elseif match(r"^set"i, str) !== nothing
sets(; extmod=extmod)
# types
elseif match(r"^(?:type|datatype)"i, str) != nothing
elseif match(r"^(?:type|datatype)"i, str) !== nothing
types()
# function
elseif match(r"^(?:function|method|procedure)"i, str) != nothing
elseif match(r"^(?:function|method|procedure)"i, str) !== nothing
functions(; extmod=extmod)
# files
elseif match(r"^(?:file|io|stream)"i, str) != nothing
elseif match(r"^(?:file|io|stream)"i, str) !== nothing
files(; extmod=extmod)
# modules
elseif match(r"^(?:module|package)"i, str) != nothing
elseif match(r"^(?:module|package)"i, str) !== nothing
modules(; extmod=extmod)
# regexes
elseif match(r"^re(?:gex|gular)"i, str) != nothing
elseif match(r"^re(?:gex|gular)"i, str) !== nothing
regexes(; extmod=extmod)
# time and date
elseif match(r"^(?:time|date)"i, str) != nothing
elseif match(r"^(?:time|date)"i, str) !== nothing
datetime(; extmod=extmod)
# random numbers
elseif match(r"^rand"i, str) != nothing
elseif match(r"^rand"i, str) !== nothing
randoms(; extmod=extmod)
# metaprogramming
elseif match(r"^meta"i, str) !== nothing
metaprogramming(; extmod=extmod)
end
end

Expand Down
2 changes: 1 addition & 1 deletion src/_23_metaprogramming.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1740,7 +1740,7 @@ function metaprogramming(; extmod=false)
]
types = ["Types" => ["DataType", "Expr", "Meta.ParseErrorˣ", "QuoteNode", "Symbol"]]
operators = ["Operators" => [":"]]
stdlib => ["Stdlib" => ["Printf.@printf", "Printf.@sprintf"]]
stdlib = ["Stdlib" => ["Printf.@printf", "Printf.@sprintf"]]
_print_names(macros, methods, types, operators)
if extmod == true
_print_names(stdlib)
Expand Down
3 changes: 3 additions & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ using Test
@test typeof(man(:regex)) === Markdown.MD
@test typeof(man(:time)) === Markdown.MD
@test typeof(man(:random)) === Markdown.MD
@test typeof(man(:meta)) === Markdown.MD

@test man(:keywords) == man(:reserved)
@test man(:operators) == man(:operations)
Expand Down Expand Up @@ -72,6 +73,7 @@ using Test
@test fun(:files) === nothing
@test fun(:modules) === nothing
@test fun(:regex) === nothing
@test fun(:meta) === nothing

@test fun(:keywords) == fun(:reserved)
@test fun(:operators) == fun(:operations)
Expand Down Expand Up @@ -104,6 +106,7 @@ using Test
@test fun(:files; extmod=true) === nothing
@test fun(:modules; extmod=true) === nothing
@test fun(:regex; extmod=true) === nothing
@test fun(:meta; extmod=true) === nothing

@test subtree(Number) === nothing
@test subtree(Vector) === nothing
Expand Down

0 comments on commit 4551ab1

Please sign in to comment.