Strip comments from Julia code to produce a minified file

Viewed 76

I have a Julia code that I want to put in somewhere else. The problem is that I need to remove all comments/unnecessary stuff from the code. How can I do this in Julia?

Example:

"""
    example(hello::String, world::Int)::Nothing

Prints something.
"""
function example(hello::String, world::Int)::Nothing
    # Hey!
    println("$hello = $world"); # Print something
end

I want to open this file in Julia and remove all comments and save this new file:

function example(hello::String, world::Int)::Nothing
    println("$hello = $world");
end

Or at least this (keeping inline comments is ok for me, as it would be hard to catch cases like print("#")):

function example(hello::String, world::Int)::Nothing
    println("$hello = $world"); # Print something
end

For one-line comments, I can split the code by lines, and filter the lines that startswith # after strip(). But I have no idea about multi line comments.

0 Answers
Related