Skip to content

Commit

Permalink
generated from Expronicon
Browse files Browse the repository at this point in the history
  • Loading branch information
Roger-luo committed Apr 12, 2023
1 parent 35c2e4d commit 4f040c3
Show file tree
Hide file tree
Showing 7 changed files with 71 additions and 52 deletions.
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "ExproniconLite"
uuid = "55351af7-c7e9-48d6-89ff-24e801d99491"
authors = ["Roger-luo <[email protected]> and contributors"]
version = "0.10.1"
version = "0.10.2"

[deps]
Pkg = "44cfe95a-1eb2-52ea-b672-e2afdf69b78f"
Expand Down
2 changes: 1 addition & 1 deletion src/ExproniconLite.jl
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
end
end
end
export NoDefault, JLExpr, JLFor, JLIfElse, JLFunction, JLField, JLKwField, JLStruct, JLKwStruct, @expr, @test_expr, compare_expr, AnalysisError, is_function, is_kw_function, is_struct, is_tuple, is_splat, is_ifelse, is_for, is_field, is_field_default, is_datatype_expr, is_matrix_expr, split_function, split_function_head, split_struct, split_struct_name, split_ifelse, uninferrable_typevars, has_symbol, is_literal, is_gensym, alias_gensym, has_kwfn_constructor, has_plain_constructor, guess_type, guess_module, guess_value, Substitute, no_default, prettify, rm_lineinfo, flatten_blocks, name_only, annotations_only, rm_annotations, rm_single_block, rm_nothing, substitute, eval_interp, eval_literal, renumber_gensym, expr_map, nexprs, codegen_ast, codegen_ast_kwfn, codegen_ast_kwfn_plain, codegen_ast_kwfn_infer, codegen_ast_struct, codegen_ast_struct_head, codegen_ast_struct_body, struct_name_plain, struct_name_without_inferable, xtuple, xnamedtuple, xcall, xpush, xgetindex, xfirst, xlast, xprint, xprintln, xmap, xmapreduce, xiterate, print_inline, print_expr, sprint_expr
export NoDefault, JLExpr, JLFor, JLIfElse, JLFunction, JLField, JLKwField, JLStruct, JLKwStruct, @expr, @test_expr, compare_expr, AnalysisError, SyntaxError, is_function, is_kw_function, is_struct, is_tuple, is_splat, is_ifelse, is_for, is_field, is_field_default, is_datatype_expr, is_matrix_expr, split_function, split_function_head, split_struct, split_struct_name, split_ifelse, uninferrable_typevars, has_symbol, is_literal, is_gensym, alias_gensym, has_kwfn_constructor, has_plain_constructor, guess_type, guess_module, guess_value, Substitute, no_default, prettify, rm_lineinfo, flatten_blocks, name_only, annotations_only, rm_annotations, rm_single_block, rm_nothing, substitute, eval_interp, eval_literal, renumber_gensym, expr_map, nexprs, codegen_ast, codegen_ast_kwfn, codegen_ast_kwfn_plain, codegen_ast_kwfn_infer, codegen_ast_struct, codegen_ast_struct_head, codegen_ast_struct_body, struct_name_plain, struct_name_without_inferable, xtuple, xnamedtuple, xcall, xpush, xgetindex, xfirst, xlast, xprint, xprintln, xmap, xmapreduce, xiterate, print_inline, print_expr, sprint_expr
#= none:60 =# @static if !(#= none:60 =# @isdefined(eachsplit))
eachsplit(s, pat) = begin
split(s, pat)
Expand Down
26 changes: 13 additions & 13 deletions src/analysis/compare.jl
Original file line number Diff line number Diff line change
Expand Up @@ -95,46 +95,46 @@
$(Expr(:symbolicgoto, Symbol("####final#386#436")))
end
end
if var"##387" isa Tuple{LineNumberNode, LineNumberNode}
if var"##387" isa Tuple{TypeVar, TypeVar}
if begin
var"##390" = var"##387"[1]
var"##390" isa LineNumberNode
var"##390" isa TypeVar
end && begin
var"##391" = var"##387"[2]
var"##391" isa LineNumberNode
var"##391" isa TypeVar
end
var"##return#385" = begin
compare_expr(m, lhs.lb, rhs.lb) || return false
compare_expr(m, lhs.ub, rhs.ub) || return false
return true
end
$(Expr(:symbolicgoto, Symbol("####final#386#436")))
end
end
if var"##387" isa Tuple{GlobalRef, GlobalRef}
if var"##387" isa Tuple{LineNumberNode, LineNumberNode}
if begin
var"##392" = var"##387"[1]
var"##392" isa GlobalRef
var"##392" isa LineNumberNode
end && begin
var"##393" = var"##387"[2]
var"##393" isa GlobalRef
var"##393" isa LineNumberNode
end
var"##return#385" = begin
return lhs === rhs
return true
end
$(Expr(:symbolicgoto, Symbol("####final#386#436")))
end
end
if var"##387" isa Tuple{TypeVar, TypeVar}
if var"##387" isa Tuple{GlobalRef, GlobalRef}
if begin
var"##394" = var"##387"[1]
var"##394" isa TypeVar
var"##394" isa GlobalRef
end && begin
var"##395" = var"##387"[2]
var"##395" isa TypeVar
var"##395" isa GlobalRef
end
var"##return#385" = begin
compare_expr(m, lhs.lb, rhs.lb) || return false
compare_expr(m, lhs.ub, rhs.ub) || return false
return true
return lhs === rhs
end
$(Expr(:symbolicgoto, Symbol("####final#386#436")))
end
Expand Down
49 changes: 29 additions & 20 deletions src/analysis/cons.jl
Original file line number Diff line number Diff line change
@@ -1,25 +1,31 @@

#= none:1 =# Core.@doc " JLFunction(ex::Expr)\n\nCreate a `JLFunction` object from a Julia function `Expr`.\n\n# Example\n\n```julia\njulia> JLFunction(:(f(x) = 2))\nf(x) = begin\n #= REPL[37]:1 =# \n 2 \nend\n```\n" function JLFunction(ex::Expr)
#= none:1 =# Core.@doc " JLFunction(ex::Expr)\n\nCreate a `JLFunction` object from a Julia function `Expr`.\n\n# Example\n\n```julia\njulia> JLFunction(:(f(x) = 2))\nf(x) = begin\n #= REPL[37]:1 =# \n 2 \nend\n```\n" function JLFunction(ex::Expr; source = nothing)
(line, doc, expr) = split_doc(ex)
(head, call, body) = split_function(expr)
(name, args, kw, whereparams, rettype) = split_function_head(call)
if !(isnothing(doc))
source = line
end
(head, call, body) = split_function(expr; source)
(name, args, kw, whereparams, rettype) = split_function_head(call; source)
JLFunction(head, name, args, kw, rettype, whereparams, body, line, doc)
end
#= none:23 =# Core.@doc " JLStruct(ex::Expr)\n\nCreate a `JLStruct` object from a Julia struct `Expr`.\n\n# Example\n\n```julia\njulia> JLStruct(:(struct Foo\n x::Int\n end))\nstruct Foo\n #= REPL[38]:2 =#\n x::Int\nend\n```\n" function JLStruct(ex::Expr)
#= none:27 =# Core.@doc " JLStruct(ex::Expr)\n\nCreate a `JLStruct` object from a Julia struct `Expr`.\n\n# Example\n\n```julia\njulia> JLStruct(:(struct Foo\n x::Int\n end))\nstruct Foo\n #= REPL[38]:2 =#\n x::Int\nend\n```\n" function JLStruct(ex::Expr; source = nothing)
(line, doc, expr) = split_doc(ex)
(ismutable, typename, typevars, supertype, body) = split_struct(expr)
if !(isnothing(doc))
source = line
end
(ismutable, typename, typevars, supertype, body) = split_struct(expr; source)
(fields, constructors, misc) = (JLField[], JLFunction[], [])
(field_doc, field_line) = (nothing, nothing)
(field_doc, field_source) = (nothing, source)
body = flatten_blocks(body)
for each = body.args
m = split_field_if_match(typename, each)
m = split_field_if_match(typename, each; source = field_source)
if m isa String
field_doc = m
elseif m isa LineNumberNode
field_line = m
field_source = m
elseif m isa NamedTuple
push!(fields, JLField(; m..., doc = field_doc, line = field_line))
(field_doc, field_line) = (nothing, nothing)
push!(fields, JLField(; m..., doc = field_doc, line = field_source))
(field_doc, field_source) = (nothing, nothing)
elseif m isa JLFunction
push!(constructors, m)
else
Expand All @@ -28,22 +34,25 @@
end
JLStruct(typename, ismutable, typevars, supertype, fields, constructors, line, doc, misc)
end
#= none:67 =# Core.@doc " JLKwStruct(ex::Expr, typealias=nothing)\n\nCreate a `JLKwStruct` from given Julia struct `Expr`, with an option to attach\nan alias to this type name.\n\n# Example\n\n```julia\njulia> JLKwStruct(:(struct Foo\n x::Int = 1\n end))\n#= kw =# struct Foo\n #= REPL[39]:2 =#\n x::Int = 1\nend\n```\n" function JLKwStruct(ex::Expr, typealias = nothing)
#= none:74 =# Core.@doc " JLKwStruct(ex::Expr, typealias=nothing)\n\nCreate a `JLKwStruct` from given Julia struct `Expr`, with an option to attach\nan alias to this type name.\n\n# Example\n\n```julia\njulia> JLKwStruct(:(struct Foo\n x::Int = 1\n end))\n#= kw =# struct Foo\n #= REPL[39]:2 =#\n x::Int = 1\nend\n```\n" function JLKwStruct(ex::Expr, typealias = nothing; source = nothing)
(line, doc, expr) = split_doc(ex)
(ismutable, typename, typevars, supertype, body) = split_struct(expr)
if !(isnothing(doc))
source = line
end
(ismutable, typename, typevars, supertype, body) = split_struct(expr; source)
(fields, constructors, misc) = (JLKwField[], JLFunction[], [])
(field_doc, field_line) = (nothing, nothing)
(field_doc, field_source) = (nothing, source)
body = flatten_blocks(body)
for each = body.args
m = split_field_if_match(typename, each, true)
m = split_field_if_match(typename, each, true; source = field_source)
if m isa String
field_doc = m
elseif m isa LineNumberNode
field_line = m
field_source = m
elseif m isa NamedTuple
field = JLKwField(; m..., doc = field_doc, line = field_line)
field = JLKwField(; m..., doc = field_doc, line = field_source)
push!(fields, field)
(field_doc, field_line) = (nothing, nothing)
(field_doc, field_source) = (nothing, nothing)
elseif m isa JLFunction
push!(constructors, m)
else
Expand All @@ -52,12 +61,12 @@
end
JLKwStruct(typename, typealias, ismutable, typevars, supertype, fields, constructors, line, doc, misc)
end
#= none:111 =# Core.@doc " JLIfElse(ex::Expr)\n\nCreate a `JLIfElse` from given Julia ifelse `Expr`.\n\n# Example\n\n```julia\njulia> ex = :(if foo(x)\n x = 1 + 1\n elseif goo(x)\n y = 1 + 2\n else\n error(\"abc\")\n end)\n:(if foo(x)\n #= REPL[41]:2 =#\n x = 1 + 1\n elseif #= REPL[41]:3 =# goo(x)\n #= REPL[41]:4 =#\n y = 1 + 2\n else\n #= REPL[41]:6 =#\n error(\"abc\")\n end)\n\njulia> JLIfElse(ex)\nif foo(x)\n begin\n #= REPL[41]:2 =# \n x = 1 + 1 \n end\nelseif begin\n #= REPL[41]:3 =# \n goo(x) \nend\n begin\n #= REPL[41]:4 =# \n y = 1 + 2 \n end\nelse\n begin\n #= REPL[41]:6 =# \n error(\"abc\") \n end\nend\n```\n" function JLIfElse(ex::Expr)
ex.head === :if || error("expect an if ... elseif ... else ... end expression")
#= none:121 =# Core.@doc " JLIfElse(ex::Expr)\n\nCreate a `JLIfElse` from given Julia ifelse `Expr`.\n\n# Example\n\n```julia\njulia> ex = :(if foo(x)\n x = 1 + 1\n elseif goo(x)\n y = 1 + 2\n else\n error(\"abc\")\n end)\n:(if foo(x)\n #= REPL[41]:2 =#\n x = 1 + 1\n elseif #= REPL[41]:3 =# goo(x)\n #= REPL[41]:4 =#\n y = 1 + 2\n else\n #= REPL[41]:6 =#\n error(\"abc\")\n end)\n\njulia> JLIfElse(ex)\nif foo(x)\n begin\n #= REPL[41]:2 =# \n x = 1 + 1 \n end\nelseif begin\n #= REPL[41]:3 =# \n goo(x) \nend\n begin\n #= REPL[41]:4 =# \n y = 1 + 2 \n end\nelse\n begin\n #= REPL[41]:6 =# \n error(\"abc\") \n end\nend\n```\n" function JLIfElse(ex::Expr; source = nothing)
ex.head === :if || throw(SyntaxError("expect an if ... elseif ... else ... end expression", source))
(conds, stmts, otherwise) = split_ifelse(ex)
return JLIfElse(conds, stmts, otherwise)
end
#= none:165 =# Core.@doc " JLFor(ex::Expr)\n\nCreate a `JLFor` from given Julia for loop expression.\n\n# Example\n\n```julia\njulia> ex = @expr for i in 1:10, j in 1:j\n M[i, j] += 1\n end\n:(for i = 1:10, j = 1:j\n #= REPL[3]:2 =#\n M[i, j] += 1\n end)\n\njulia> jl = JLFor(ex)\nfor i in 1 : 10,\n j in 1 : j\n #= loop body =#\n begin\n #= REPL[3]:2 =# \n M[i, j] += 1 \n end\nend\n\njulia> jl.vars\n2-element Vector{Any}:\n :i\n :j\n\njulia> jl.iterators\n2-element Vector{Any}:\n :(1:10)\n :(1:j)\n```\n" function JLFor(ex::Expr)
#= none:177 =# Core.@doc " JLFor(ex::Expr)\n\nCreate a `JLFor` from given Julia for loop expression.\n\n# Example\n\n```julia\njulia> ex = @expr for i in 1:10, j in 1:j\n M[i, j] += 1\n end\n:(for i = 1:10, j = 1:j\n #= REPL[3]:2 =#\n M[i, j] += 1\n end)\n\njulia> jl = JLFor(ex)\nfor i in 1 : 10,\n j in 1 : j\n #= loop body =#\n begin\n #= REPL[3]:2 =# \n M[i, j] += 1 \n end\nend\n\njulia> jl.vars\n2-element Vector{Any}:\n :i\n :j\n\njulia> jl.iterators\n2-element Vector{Any}:\n :(1:10)\n :(1:j)\n```\n" function JLFor(ex::Expr)
(vars, itrs, body) = split_forloop(ex)
return JLFor(vars, itrs, body)
end
10 changes: 10 additions & 0 deletions src/analysis/exception.jl
Original file line number Diff line number Diff line change
@@ -1,4 +1,14 @@

struct SyntaxError <: Exception
msg::AbstractString
source::Union{Nothing, LineNumberNode}
end
SyntaxError(msg::AbstractString; source = nothing) = begin
SyntaxError(msg, source)
end
function Base.showerror(io::IO, err::SyntaxError)
print(io, "SyntaxError: ", err.msg, " at ", err.source)
end
struct AnalysisError <: Exception
expect::String
got
Expand Down
Loading

2 comments on commit 4f040c3

@Roger-luo
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

release via ion

@JuliaRegistrator register branch=main

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Registration pull request created: JuliaRegistries/General/81500

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a v0.10.2 -m "<description of version>" 4f040c35f8c9951285408349bb420ee6c0e23861
git push origin v0.10.2

Please sign in to comment.