Talk:Strip block comments: Difference between revisions

Content added Content deleted
Line 53: Line 53:
:: You can't garantee the delimiters really marks a block of comment if they are allowed to appear inside a literal string verbatim by the language, which is almost all the languages. Think <code>print("# not comment")</code>. For any language where white space is not significant, you pretty much have to parse the source from begining and tokenize everything to be sure /* really starts a comment. Simply match-and-replace will not do, just like how everyone knows using regular expression to strip HTML tag is wrong (though everyone does it any way). --[[User:Ledrug|Ledrug]] 07:35, 12 August 2011 (UTC)
:: You can't garantee the delimiters really marks a block of comment if they are allowed to appear inside a literal string verbatim by the language, which is almost all the languages. Think <code>print("# not comment")</code>. For any language where white space is not significant, you pretty much have to parse the source from begining and tokenize everything to be sure /* really starts a comment. Simply match-and-replace will not do, just like how everyone knows using regular expression to strip HTML tag is wrong (though everyone does it any way). --[[User:Ledrug|Ledrug]] 07:35, 12 August 2011 (UTC)
::: Sure you can, and you can do so without any knowledge of string syntax. Though this task does not do that. For example, you can specify that comments extend to the end of the line and that on any line with a comment, the comment is the shortest string that matches the comment pattern. This mechanism would be similar to the concept of escape characters. It also bears resemblance to most any comment syntax which does not allow for nested comments. --[[User:Rdm|Rdm]] 11:25, 12 August 2011 (UTC)
::: Sure you can, and you can do so without any knowledge of string syntax. Though this task does not do that. For example, you can specify that comments extend to the end of the line and that on any line with a comment, the comment is the shortest string that matches the comment pattern. This mechanism would be similar to the concept of escape characters. It also bears resemblance to most any comment syntax which does not allow for nested comments. --[[User:Rdm|Rdm]] 11:25, 12 August 2011 (UTC)
:::: You lost me. So you can just strip from # to end of line in the example <code>print("# not comment")</code>? --[[User:Ledrug|Ledrug]] 19:38, 12 August 2011 (UTC)