Skip to content

Instantly share code, notes, and snippets.

@hayd
Last active August 29, 2015 14:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hayd/a9afa3e3049786d7c5a2 to your computer and use it in GitHub Desktop.
Save hayd/a9afa3e3049786d7c5a2 to your computer and use it in GitHub Desktop.
lexicon test build script
using LightGraphs
macro file(args...) buildfile(args...) end
buildfile(t, s::AbstractString) = buildfile(t, Expr(:string, s))
buildfile(target, source::Expr) = quote
open(joinpath(dirname(@__FILE__), $(esc(target))), "w") do file
println(" - '$($(esc(target)))'")
println(file, "<!-- AUTOGENERATED. See 'docs/build.jl' for source. -->")
$(Expr(:block, [buildwriter(arg) for arg in source.args]...))
end
end
buildwriter(ex::Expr) = :(print(file, $(esc(ex))))
buildwriter(t::AbstractString) = Expr(:block,
[buildwriter(p, iseven(n)) for (n, p) in enumerate(split(t, r"{{|}}"))]...
)
buildwriter(part, isdef) = isdef ?
begin
#parts = Expr(:vect, [:(@doc($(parse(p)))) for p in split(part, r"\s*,\s*")]...)
parts = Expr(:vect, [:(($(parse(p))), @doc($(parse(p)))) for p in split(part, r"\s*,\s*")]...)
#methods = Expr(:vect, [:($(parse(p)) for p in split(part, r"\s*,\s*")]
quote
for (f, docstring) in $(esc(parts))
println(file)
md_methodtable(file, f)
writemime(file, "text/plain", docstring)
end
end
end :
:(print(file, $(esc(part))))
function md_methodtable(io, f)
println(io, "```")
for m in methods(f)
md_method(io, m)
end
println(io, "```")
end
function md_method(io, m)
print(io, m.func.code.name)
tv, decls, file, line = Base.arg_decl_parts(m)
if !isempty(tv)
show_delim_array(io, tv, '{', ',', '}', false)
end
print(io, "(")
print_joined(io, [isempty(d[2]) ? "$(d[1])" : "$(d[1])::$(d[2])" for d in decls],
", ", ", ")
print(io, ")")
println(io)
end
@file "foo.md" "{{add_vertex!,degree}}"
add_vertex!(g::Union{LightGraphs.Graph,LightGraphs.DiGraph})

Add a new vertex to the graph g.

degree(g::LightGraphs.DiGraph, v::Int64)
degree(g::LightGraphs.Graph, v::Int64)
degree(g::Union{LightGraphs.Graph,LightGraphs.DiGraph})
degree(g::Union{LightGraphs.Graph,LightGraphs.DiGraph}, v::AbstractArray{Int64,1})

Return the number of edges (both ingoing and outgoing) from the vertex v.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment