Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
47
Task/Strip-block-comments/Nim/strip-block-comments.nim
Normal file
47
Task/Strip-block-comments/Nim/strip-block-comments.nim
Normal file
|
|
@ -0,0 +1,47 @@
|
|||
import strutils
|
||||
|
||||
proc commentStripper(txt: string; delim: tuple[l, r: string] = ("/*", "*/")): string =
|
||||
let i = txt.find(delim.l)
|
||||
if i < 0: return txt
|
||||
|
||||
result = if i > 0: txt[0 ..< i] else: ""
|
||||
let tmp = commentStripper(txt[i+delim.l.len .. txt.high], delim)
|
||||
let j = tmp.find(delim.r)
|
||||
assert j >= 0
|
||||
result &= tmp[j+delim.r.len .. tmp.high]
|
||||
|
||||
echo "NON-NESTED BLOCK COMMENT EXAMPLE:"
|
||||
echo commentStripper("""/**
|
||||
* Some comments
|
||||
* longer comments here that we can parse.
|
||||
*
|
||||
* Rahoo
|
||||
*/
|
||||
function subroutine() {
|
||||
a = /* inline comment */ b + c ;
|
||||
}
|
||||
/*/ <-- tricky comments */
|
||||
|
||||
/**
|
||||
* Another comment.
|
||||
*/
|
||||
function something() {
|
||||
}""")
|
||||
|
||||
echo "\nNESTED BLOCK COMMENT EXAMPLE:"
|
||||
echo commentStripper(""" /**
|
||||
* Some comments
|
||||
* longer comments here that we can parse.
|
||||
*
|
||||
* Rahoo
|
||||
*//*
|
||||
function subroutine() {
|
||||
a = /* inline comment */ b + c ;
|
||||
}
|
||||
/*/ <-- tricky comments */
|
||||
*/
|
||||
/**
|
||||
* Another comment.
|
||||
*/
|
||||
function something() {
|
||||
}""")
|
||||
Loading…
Add table
Add a link
Reference in a new issue