33 lines
610 B
Text
33 lines
610 B
Text
F strip_comments(s, b_delim = ‘/*’, e_delim = ‘*/’)
|
||
V r = ‘’
|
||
V i = 0
|
||
L
|
||
V? p = s.find(b_delim, i)
|
||
I p == N
|
||
L.break
|
||
r ‘’= s[i .< p]
|
||
V? e = s.find(e_delim, p + b_delim.len)
|
||
assert(e != N)
|
||
i = e + e_delim.len
|
||
r ‘’= s[i..]
|
||
R r
|
||
|
||
V text = ‘
|
||
/**
|
||
* Some comments
|
||
* longer comments here that we can parse.
|
||
*
|
||
* Rahoo
|
||
*/
|
||
function subroutine() {
|
||
a = /* inline comment */ b + c ;
|
||
}
|
||
/*/ <-- tricky comments */
|
||
|
||
/**
|
||
* Another comment.
|
||
*/
|
||
function something() {
|
||
}’
|
||
|
||
print(strip_comments(text))
|