September 2017 Update
This commit is contained in:
parent
bba7bfd280
commit
ba8067c3b7
14570 changed files with 153136 additions and 63871 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()
|
||||
51
Task/Strip-block-comments/Kotlin/strip-block-comments.kotlin
Normal file
51
Task/Strip-block-comments/Kotlin/strip-block-comments.kotlin
Normal file
|
|
@ -0,0 +1,51 @@
|
|||
// version 1.1.4-3
|
||||
|
||||
val sample = """
|
||||
/**
|
||||
* Some comments
|
||||
* longer comments here that we can parse.
|
||||
*
|
||||
* Rahoo
|
||||
*/
|
||||
function subroutine() {
|
||||
a = /* inline comment */ b + c ;
|
||||
}
|
||||
/*/ <-- tricky comments */
|
||||
|
||||
/**
|
||||
* Another comment.
|
||||
*/
|
||||
function something() {
|
||||
}
|
||||
"""
|
||||
|
||||
val sample2 = """
|
||||
``{
|
||||
` Some comments
|
||||
` longer comments here that we can parse.
|
||||
`
|
||||
` Rahoo
|
||||
``}
|
||||
function subroutine2() {
|
||||
d = ``{ inline comment ``} e + f ;
|
||||
}
|
||||
``{ / <-- tricky comments ``}
|
||||
|
||||
``{
|
||||
` Another comment.
|
||||
``}
|
||||
function something2() {
|
||||
}
|
||||
"""
|
||||
|
||||
fun stripBlockComments(text: String, del1: String = "/*", del2: String = "*/"): String {
|
||||
val d1 = Regex.escape(del1)
|
||||
val d2 = Regex.escape(del2)
|
||||
val r = Regex("""(?s)$d1.*?$d2""")
|
||||
return text.replace(r, "")
|
||||
}
|
||||
|
||||
fun main(args: Array<String>) {
|
||||
println(stripBlockComments(sample))
|
||||
println(stripBlockComments(sample2, "``{", "``}"))
|
||||
}
|
||||
4
Task/Strip-block-comments/Zkl/strip-block-comments.zkl
Normal file
4
Task/Strip-block-comments/Zkl/strip-block-comments.zkl
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
fcn stripper(text, a="/*", b="*/"){
|
||||
while(xy:=text.span(a,b,True)){ x,y:=xy; text=text[0,x] + text[x+y,*] }
|
||||
text
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue