diff --git a/src/Runic.jl b/src/Runic.jl index ca5aa47..cb1a5be 100644 --- a/src/Runic.jl +++ b/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) ctx.call_depth -= 1 - # If the node is unchanged at this point, just keep going. - if ( - node_kind === K"block" || - node_kind === K"braces" || - 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 + # If none of the transformations above changed the node (and thus returned back up one + # level before recursing down here again) we i) accept it if it is a leaf or ii) recurse + # one level depeer. + if is_leaf(node) accept_node!(ctx, node) return nothing else - msg = "unhandled node of type $(node_kind), current text:\n" * String(take!(ctx.fmt_io)) - throw(ErrorException(msg)) + return format_node_with_kids!(ctx, node) end end