RosettaCodeData/Task/Strip-comments-from-a-string/Bracmat/strip-comments-from-a-string.bracmat
2023-07-01 13:44:08 -04:00

21 lines
515 B
Text

( " apples, pears # and bananas
oranges, mangos ; and a durian"
: ?text
& :?newText
& ( non-blank
= %@:~(" "|\t|\r|\n)
)
& ( cleanUp
=
. @(!arg:?arg ("#"|";") ?)
& @(rev$!arg:? (!non-blank ?:?arg))
& @(rev$!arg:? (!non-blank ?:?arg))
& !arg {You could write & "[" !arg "]" to prove that the blanks are stripped.}
)
& whl
' ( @(!text:?line (\r|\n) ?text)
& !newText \n cleanUp$!line:?newText
)
& !newText \n cleanUp$!text:?newText
& out$(str$!newText)
);