14
Challenge:
Some ascii-art is a pain to make, but makes code comments easier to read, especially when the code is dense. The challenge is to make a simple tool that converts comments to simple ascii-art with arrows. The comments to modify are delimited by empty comments.
For example, supposing Haskell comment syntax, convert this:
--
-- Here's a thing
-- Here's another thing
-- The most important thing
-- * * *
--
f x=x+1*x*1*1*0
To this:
-- /------------< Here's a thing
-- | /-------< Here's another thing
-- | | /-< The most important thing
-- | | |
-- v v v
f x=x+1*x*1*1*0
Rules:
- Your answer may be either a function or full program
- You may pick the language this is made to work with, replacing the "--" with two or more characters that delimit a comment in some language
- If using another comment format that requires beginning and ending delimiters, each line of the reformatted sections must be a proper comment
- The sections to be reformatted are delimited by the empty comment "\n--\n"
- Besides adding newlines, the program must not change any of the input except the delimited sections
- A comment filled with an arbitrary number of spaces may come immediately before a properly formatted section of output
- Standard loopholes are disallowed
Additional Examples:
(input)
--
--
(output)
nothing
(input)
[Code Here]
--
-- important
-- *
--
(output)
[Code Here]
-- /-< important
-- |
-- v
(input)
--
-- Do
-- Re
-- Mi
-- Fa
-- So
-- *****
--
(output)
-- /-----< Do
-- |/----< Re
-- ||/---< Mi
-- |||/--< Fa
-- ||||/-< So
-- |||||
-- vvvvv
Scoring:
- Fewest bytes wins
- Submissions without explanations or non-trivial example input/output will not be considered (though I will leave a grace period to allow time to add such)
2What if only one character is needed to delimit a comment? – Adám – 2016-01-14T22:19:26.600
As long as it's a valid comment in the language, it's fine – Michael Klein – 2016-01-14T22:21:23.847
We can assume that each comment section which is subject to reformatting will contain exactly one line of position marker asterisks, right? Will that line be always the last one? – manatwork – 2016-01-15T11:09:40.380
Yup, exactly one and always last (comment before end delimiter) – Michael Klein – 2016-01-15T12:27:47.707
And the amount of asterisks will be equal with the number of preceding lines in that section, right? – manatwork – 2016-01-15T12:43:03.123
@manatwork excluding the delimiter, yes. So (delimiter)(N commented lines)(N asterisks commented)(delimiter). – Michael Klein – 2016-01-15T12:45:08.867
Additional example 1 - an empty comment section with 2 adjacent rows containing
--
. Must it be removed altogether? It seems the only case when there is a change to the number of the rows in output. Or could we just replace the comments with 2 empty lines? – edc65 – 2016-01-15T15:20:47.473@edc65 It may be replaced with empty lines – Michael Klein – 2016-01-15T16:13:11.900