I am processing some Julia code with regexes, to convert the colorschemes in Colorschemes.jl to
go objects. I want to remove the comments before feeding the Julia code to my
zsh script. What are the options?
PS: For the record, this code set is small enough that I can hardcode the problem away, but I’m curious for future reference.
In the general case, you’ll have to parse the file - simple regexes can grow very complicated once you try to take care of text that looks like a comment inside a string literal.
Rather than using regexes, you might consider simply using Julia’s parser, which gives you a syntax tree that you can walk to output anything you want. This will be a lot more robust than processing code as strings.
In case you want to export them all from Julia, it might be simpler to just do this:
for cs in ColorSchemes.colorschemes
for color in last(cs).colors
but parsing Julia code is obviously more fun!