Browse Source

Simplify format_node by removing legacy code

pull/19/head
Fredrik Ekre 1 year ago
parent
commit
2eca8e7bdc
No known key found for this signature in database
GPG Key ID: DE82E6D5E364C0A2
  1. 173
      src/Runic.jl

173
src/Runic.jl

@ -303,177 +303,14 @@ function format_node!(ctx::Context, node::Node)::Union{Node, Nothing, NullNode}
@return_something four_space_indent(ctx, node) @return_something four_space_indent(ctx, node)
ctx.call_depth -= 1 ctx.call_depth -= 1
# If the node is unchanged at this point, just keep going. # If none of the transformations above changed the node (and thus returned back up one
if ( # level before recursing down here again) we i) accept it if it is a leaf or ii) recurse
node_kind === K"block" || # one level depeer.
node_kind === K"braces" || if is_leaf(node)
node_kind === K"bracescat" || # {a; b}
node_kind === K"call" ||
node_kind === K"cartesian_iterator" ||
node_kind === K"char" ||
node_kind === K"cmdstring" ||
node_kind === K"comparison" ||
node_kind === K"comprehension" ||
node_kind === K"core_@cmd" ||
node_kind === K"curly" ||
node_kind === K"dotcall" ||
node_kind === K"filter" ||
node_kind === K"generator" ||
node_kind === K"hcat" ||
node_kind === K"importpath" ||
node_kind === K"inert" ||
node_kind === K"juxtapose" ||
node_kind === K"macrocall" ||
node_kind === K"ncat" ||
node_kind === K"nrow" ||
node_kind === K"parens" ||
node_kind === K"ref" ||
node_kind === K"row" ||
node_kind === K"string" ||
node_kind === K"toplevel" ||
node_kind === K"typed_comprehension" ||
node_kind === K"typed_hcat" ||
node_kind === K"typed_ncat" ||
node_kind === K"typed_vcat" ||
node_kind === K"vcat" ||
node_kind === K"vect"
)
# Nodes that always recurse!
@assert !JuliaSyntax.is_trivia(node)
node′ = format_node_with_kids!(ctx, node)
@assert node′ !== nullnode
return node′
elseif !JuliaSyntax.is_trivia(node) && (
node_kind === K"abstract" ||
node_kind === K"as" ||
node_kind === K"break" ||
node_kind === K"catch" ||
node_kind === K"const" ||
node_kind === K"continue" ||
node_kind === K"do" ||
node_kind === K"doc" ||
node_kind === K"elseif" ||
node_kind === K"export" ||
node_kind === K"finally" ||
node_kind === K"for" ||
node_kind === K"function" ||
node_kind === K"global" ||
node_kind === K"if" ||
node_kind === K"import" ||
node_kind === K"let" ||
node_kind === K"local" ||
node_kind === K"macro" ||
node_kind === K"module" ||
node_kind === K"outer" ||
node_kind === K"parameters" ||
node_kind === K"primitive" ||
node_kind === K"quote" ||
node_kind === K"return" ||
node_kind === K"struct" ||
node_kind === K"try" ||
node_kind === K"tuple" ||
node_kind === K"using" ||
node_kind === K"var" ||
node_kind === K"where" ||
node_kind === K"while"
)
# Nodes that recurse! if not trivia
@assert !JuliaSyntax.is_trivia(node)
node′ = format_node_with_kids!(ctx, node)
@assert node′ !== nullnode
return node′
elseif !is_leaf(node) && (
JuliaSyntax.is_operator(node) ||
node_kind === K"else" # try-(catch|finally)-else
)
# Nodes that should recurse if they have kids (all??)
node′ = format_node_with_kids!(ctx, node)
@assert node′ !== nullnode
return node′
elseif node_kind === K"Whitespace" ||
node_kind === K"NewlineWs" ||
node_kind === K"Comment"
# Whitespace and comments emitted verbatim for now
accept_node!(ctx, node)
return nothing
elseif (
node_kind === K"(" ||
node_kind === K")" ||
node_kind === K"," ||
node_kind === K"::" ||
node_kind === K";" ||
node_kind === K"<:" ||
node_kind === K"@" ||
node_kind === K"BinInt" ||
node_kind === K"Char" ||
node_kind === K"CmdMacroName" ||
node_kind === K"CmdString" ||
node_kind === K"Float" ||
node_kind === K"Float32" ||
node_kind === K"HexInt" ||
node_kind === K"Identifier" ||
node_kind === K"Integer" ||
node_kind === K"MacroName" ||
node_kind === K"OctInt" ||
node_kind === K"String" ||
node_kind === K"StringMacroName" ||
node_kind === K"false" ||
node_kind === K"true" ||
node_kind === K"type" ||
JuliaSyntax.is_operator(node) ||
JuliaSyntax.is_trivia(node) && (
node_kind === K"$" ||
node_kind === K"=" ||
node_kind === K"[" ||
node_kind === K"\"" ||
node_kind === K"\"\"\"" ||
node_kind === K"]" ||
node_kind === K"`" ||
node_kind === K"```" ||
node_kind === K"abstract" ||
node_kind === K"as" ||
node_kind === K"baremodule" ||
node_kind === K"begin" ||
node_kind === K"break" ||
node_kind === K"catch" ||
node_kind === K"const" ||
node_kind === K"continue" ||
node_kind === K"do" ||
node_kind === K"else" ||
node_kind === K"elseif" ||
node_kind === K"end" ||
node_kind === K"export" ||
node_kind === K"finally" ||
node_kind === K"for" ||
node_kind === K"function" ||
node_kind === K"global" ||
node_kind === K"if" ||
node_kind === K"import" ||
node_kind === K"in" ||
node_kind === K"let" ||
node_kind === K"local" ||
node_kind === K"macro" ||
node_kind === K"module" ||
node_kind === K"mutable" ||
node_kind === K"outer" ||
node_kind === K"primitive" ||
node_kind === K"quote" ||
node_kind === K"return" ||
node_kind === K"struct" ||
node_kind === K"try" ||
node_kind === K"using" ||
node_kind === K"var" ||
node_kind === K"while" ||
node_kind === K"{" ||
node_kind === K"}"
)
)
# Nodes that always emit like the source code
accept_node!(ctx, node) accept_node!(ctx, node)
return nothing return nothing
else else
msg = "unhandled node of type $(node_kind), current text:\n" * String(take!(ctx.fmt_io)) return format_node_with_kids!(ctx, node)
throw(ErrorException(msg))
end end
end end

Loading…
Cancel
Save