Initial data commit
This commit is contained in:
parent
72d218235f
commit
f23f22d71c
199087 changed files with 3378941 additions and 0 deletions
24
Task/Strip-block-comments/Python/strip-block-comments-1.py
Normal file
24
Task/Strip-block-comments/Python/strip-block-comments-1.py
Normal file
|
|
@ -0,0 +1,24 @@
|
|||
def _commentstripper(txt, delim):
|
||||
'Strips first nest of block comments'
|
||||
|
||||
deliml, delimr = delim
|
||||
out = ''
|
||||
if deliml in txt:
|
||||
indx = txt.index(deliml)
|
||||
out += txt[:indx]
|
||||
txt = txt[indx+len(deliml):]
|
||||
txt = _commentstripper(txt, delim)
|
||||
assert delimr in txt, 'Cannot find closing comment delimiter in ' + txt
|
||||
indx = txt.index(delimr)
|
||||
out += txt[(indx+len(delimr)):]
|
||||
else:
|
||||
out = txt
|
||||
return out
|
||||
|
||||
def commentstripper(txt, delim=('/*', '*/')):
|
||||
'Strips nests of block comments'
|
||||
|
||||
deliml, delimr = delim
|
||||
while deliml in txt:
|
||||
txt = _commentstripper(txt, delim)
|
||||
return txt
|
||||
41
Task/Strip-block-comments/Python/strip-block-comments-2.py
Normal file
41
Task/Strip-block-comments/Python/strip-block-comments-2.py
Normal file
|
|
@ -0,0 +1,41 @@
|
|||
def test():
|
||||
print('\nNON-NESTED BLOCK COMMENT EXAMPLE:')
|
||||
sample = ''' /**
|
||||
* Some comments
|
||||
* longer comments here that we can parse.
|
||||
*
|
||||
* Rahoo
|
||||
*/
|
||||
function subroutine() {
|
||||
a = /* inline comment */ b + c ;
|
||||
}
|
||||
/*/ <-- tricky comments */
|
||||
|
||||
/**
|
||||
* Another comment.
|
||||
*/
|
||||
function something() {
|
||||
}'''
|
||||
print(commentstripper(sample))
|
||||
|
||||
print('\nNESTED BLOCK COMMENT EXAMPLE:')
|
||||
sample = ''' /**
|
||||
* Some comments
|
||||
* longer comments here that we can parse.
|
||||
*
|
||||
* Rahoo
|
||||
*//*
|
||||
function subroutine() {
|
||||
a = /* inline comment */ b + c ;
|
||||
}
|
||||
/*/ <-- tricky comments */
|
||||
*/
|
||||
/**
|
||||
* Another comment.
|
||||
*/
|
||||
function something() {
|
||||
}'''
|
||||
print(commentstripper(sample))
|
||||
|
||||
if __name__ == '__main__':
|
||||
test()
|
||||
Loading…
Add table
Add a link
Reference in a new issue