omoikani #2124(2007/08/13 18:09 GMT) [ StandardML ] Rating0/0=0.00
SML#のScriptingライブラリは正規表現がawk互換なのでツラい。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
fun remove_comment (line) = let open Script val h = find "/\\*" line val t = find "\\*/" line fun remove_comment' (SOME (l, _), SOME (r, i)) = substring (line, 0, l) ^ substring (line, r + i, (size (line)) - (r + i)) | remove_comment' (SOME (l, _), NONE) = substring (line, 0, l) | remove_comment' (NONE, _) = line in remove_comment' (h, t) end; print (remove_comment ("AAA") ^ "\n"); print (remove_comment ("AAA/*BBB*/") ^ "\n"); print (remove_comment ("AAA/*BBB") ^ "\n"); print (remove_comment ("AAA/*BBB*/CCC") ^ "\n"); print (remove_comment ("AAA/*BBB/*CCC*/DDD*/EEE") ^ "\n"); print (remove_comment ("AAA/a//*BB*B**/CCC") ^ "\n")
Rating0/0=0.00-0+
[ reply ]
omoikani
#2124()
[
StandardML
]
Rating0/0=0.00
fun remove_comment (line) = let open Script val h = find "/\\*" line val t = find "\\*/" line fun remove_comment' (SOME (l, _), SOME (r, i)) = substring (line, 0, l) ^ substring (line, r + i, (size (line)) - (r + i)) | remove_comment' (SOME (l, _), NONE) = substring (line, 0, l) | remove_comment' (NONE, _) = line in remove_comment' (h, t) end; print (remove_comment ("AAA") ^ "\n"); print (remove_comment ("AAA/*BBB*/") ^ "\n"); print (remove_comment ("AAA/*BBB") ^ "\n"); print (remove_comment ("AAA/*BBB*/CCC") ^ "\n"); print (remove_comment ("AAA/*BBB/*CCC*/DDD*/EEE") ^ "\n"); print (remove_comment ("AAA/a//*BB*B**/CCC") ^ "\n")Rating0/0=0.00-0+
[ reply ]