Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
75
Task/Strip-block-comments/Julia/strip-block-comments.julia
Normal file
75
Task/Strip-block-comments/Julia/strip-block-comments.julia
Normal file
|
|
@ -0,0 +1,75 @@
|
|||
function _stripcomments(txt::AbstractString, dlm::Tuple{String,String})
|
||||
"Strips first nest of block comments"
|
||||
|
||||
dlml, dlmr = dlm
|
||||
indx = searchindex(txt, dlml)
|
||||
if indx > 0
|
||||
out = IOBuffer()
|
||||
write(out, txt[1:indx-1])
|
||||
txt = txt[indx+length(dlml):end]
|
||||
txt = _stripcomments(txt, dlm)
|
||||
indx = searchindex(txt, dlmr)
|
||||
@assert(indx > 0, "cannot find a closer delimiter \"$dlmr\" in $txt")
|
||||
write(out, txt[indx+length(dlmr):end])
|
||||
else
|
||||
out = txt
|
||||
end
|
||||
return String(out)
|
||||
end
|
||||
|
||||
function stripcomments(txt::AbstractString, dlm::Tuple{String,String}=("/*", "*/"))
|
||||
"Strips nests of block comments"
|
||||
|
||||
dlml, dlmr = dlm
|
||||
while contains(txt, dlml)
|
||||
txt = _stripcomments(txt, dlm)
|
||||
end
|
||||
|
||||
return txt
|
||||
end
|
||||
|
||||
function main()
|
||||
println("\nNON-NESTED BLOCK COMMENT EXAMPLE:")
|
||||
smpl = """
|
||||
/**
|
||||
* Some comments
|
||||
* longer comments here that we can parse.
|
||||
*
|
||||
* Rahoo
|
||||
*/
|
||||
function subroutine() {
|
||||
a = /* inline comment */ b + c ;
|
||||
}
|
||||
/*/ <-- tricky comments */
|
||||
|
||||
/**
|
||||
* Another comment.
|
||||
*/
|
||||
function something() {
|
||||
}
|
||||
"""
|
||||
println(stripcomments(smpl))
|
||||
|
||||
println("\nNESTED BLOCK COMMENT EXAMPLE:")
|
||||
smpl = """
|
||||
/**
|
||||
* Some comments
|
||||
* longer comments here that we can parse.
|
||||
*
|
||||
* Rahoo
|
||||
*//*
|
||||
function subroutine() {
|
||||
a = /* inline comment */ b + c ;
|
||||
}
|
||||
/*/ <-- tricky comments */
|
||||
*/
|
||||
/**
|
||||
* Another comment.
|
||||
*/
|
||||
function something() {
|
||||
}
|
||||
"""
|
||||
println(stripcomments(smpl))
|
||||
end
|
||||
|
||||
main()
|
||||
Loading…
Add table
Add a link
Reference in a new issue