Timeline for Remove C and C++ comments using Python?
Current License: CC BY-SA 3.0
15 events
| when toggle format | what | by | license | comment | |
|---|---|---|---|---|---|
| May 13, 2020 at 10:38 | comment | added | Markus Jarderot |
@AmanDeep You could add [^\S\r\n]*\r?\n? after \*/ to include whitespace up until and including the following newline, if any.
|
|
| May 12, 2020 at 14:24 | comment | added | Aman Deep | It leaves a newline after removing a multi line comment. any fix for this? | |
| Mar 8, 2018 at 14:20 | comment | added | Mark Smith |
This fails for me (python2 and python3) on the simple string blah "blah" with error TypeError: sequence item 1: expected string, module found.
|
|
| S May 19, 2014 at 17:45 | history | suggested | Scis | CC BY-SA 3.0 |
Fix the case where `int/**/x=5;` will become an illeagal line where it should in fact be legal. The singe space replacing the emtystring worked for me.
|
| May 19, 2014 at 17:40 | review | Suggested edits | |||
| S May 19, 2014 at 17:45 | |||||
| May 8, 2013 at 5:39 | comment | added | Markus Jarderot |
@robocat It does handle escapes, but not pre-processor statements. Neither does it handle Digraphs and trigraphs, but that is normally not a problem. For pre-processor statements, you could add |#[^\r\n]*(?:\\\r?\n[^\r\n]*)* at the end of the regex.
|
|
| May 8, 2013 at 4:42 | comment | added | robocat | @markus-jarderot - Good point! I forgot it was C because I was looking for an ECMAScript solution! With C the regex can also fail on preprocessor statements (removing lines beginning with # is probably an easy fix for that issue though) so as it stands it doesn't solve "properly handles awkward cases". Also doesn't C have multiline strings using \ and does this handle those? | |
| Apr 26, 2013 at 6:12 | comment | added | Markus Jarderot |
@robocat True. But Regex literals are not part of the C language. If you wish to parse code with Regex literals, you could add this at the end of the Regex: |/(?:\\.|[^\\/])+/. The condition in the replacer() function would also have to be tweaked.
|
|
| Apr 26, 2013 at 6:00 | comment | added | robocat |
So I think it would fail on various RegExp strings (e.g. /\// or /\/*/ or /'/; //blah) and multiline strings (davidwalsh.name/multiline-javascript-strings). i.e. usable for simple code, but probably not for larger production codebases. If I had to use Python I would look for solutions using pynoceros or pynarcissus. If you can use node.js then UglifyJS2 is a good base for munging JavaScript code.
|
|
| Feb 3, 2010 at 6:27 | comment | added | atikat | Also you can preserve line numbering relative to the input file by changing the first return to: return "" + "\n" * s.count('\n') I needed to do this in my situation. | |
| May 22, 2009 at 23:51 | history | edited | Markus Jarderot | CC BY-SA 2.5 |
deleted 1 characters in body
|
| Oct 29, 2008 at 19:37 | comment | added | Markus Jarderot |
Yes it does. \\. will match any escaped char, including \".
|
|
| Oct 29, 2008 at 12:45 | comment | added | Brian | This doesn't handle escaped " chars in strings. eg: char some_punctuation_chars=".\"/"; /* comment */ | |
| Oct 27, 2008 at 22:11 | history | edited | Markus Jarderot | CC BY-SA 2.5 |
added 138 characters in body
|
| Oct 27, 2008 at 21:48 | history | answered | Markus Jarderot | CC BY-SA 2.5 |