Add tasks for all the new languages
This commit is contained in:
parent
9dc3c2bb62
commit
bba7bfd280
13208 changed files with 134745 additions and 0 deletions
48
Task/Strip-block-comments/Nim/strip-block-comments.nim
Normal file
48
Task/Strip-block-comments/Nim/strip-block-comments.nim
Normal file
|
|
@ -0,0 +1,48 @@
|
|||
import strutils
|
||||
|
||||
proc commentStripper(txt; 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])
|
||||
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() {
|
||||
}""")
|
||||
34
Task/Strip-block-comments/Phix/strip-block-comments.phix
Normal file
34
Task/Strip-block-comments/Phix/strip-block-comments.phix
Normal file
|
|
@ -0,0 +1,34 @@
|
|||
constant test = """
|
||||
/**
|
||||
* Some comments
|
||||
* longer comments here that we can parse.
|
||||
*
|
||||
* Rahoo
|
||||
*/
|
||||
function subroutine() {
|
||||
a = /* inline comment */ b + c ;
|
||||
}
|
||||
/*/ <-- tricky comments */
|
||||
|
||||
/**
|
||||
* Another comment.
|
||||
*/
|
||||
function something() {
|
||||
}
|
||||
"""
|
||||
|
||||
function strip_comments(string text, startc="/*", endc="*/")
|
||||
while 1 do
|
||||
integer startp = match(startc,text)
|
||||
if startp=0 then exit end if
|
||||
integer endp = match(endc,text,startp+length(startc))
|
||||
if endp=0 then
|
||||
puts(1,"error, aborting...")
|
||||
abort(0)
|
||||
end if
|
||||
text[startp..endp+length(endc)-1] = ""
|
||||
end while
|
||||
return text
|
||||
end function
|
||||
|
||||
puts(1,strip_comments(test))
|
||||
13
Task/Strip-block-comments/Ring/strip-block-comments.ring
Normal file
13
Task/Strip-block-comments/Ring/strip-block-comments.ring
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
example = "123/*456*/abc/*def*/789"
|
||||
|
||||
example2 = example
|
||||
nr = 1
|
||||
while nr = 1
|
||||
n1 = substr(example2,"/*")
|
||||
n2 = substr(example2,"*/")
|
||||
if n1 > 0 and n2 > 0
|
||||
example3 = substr(example2,n1,n2-n1+2)
|
||||
example2 = substr(example2,example3,"")
|
||||
else nr = 0 ok
|
||||
end
|
||||
see example2 + nl
|
||||
|
|
@ -0,0 +1,6 @@
|
|||
func strip_block_comments(code, beg='/*', end='*/') {
|
||||
var re = Regex.new(beg.escape + '.*?' + end.escape, 's');
|
||||
code.gsub(re, '');
|
||||
}
|
||||
|
||||
say strip_block_comments(ARGF.slurp);
|
||||
9
Task/Strip-block-comments/jq/strip-block-comments.jq
Normal file
9
Task/Strip-block-comments/jq/strip-block-comments.jq
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
def strip_block_comments(open; close):
|
||||
def deregex:
|
||||
reduce ("\\\\", "\\*", "\\^", "\\?", "\\+", "\\.",
|
||||
"\\!", "\\{", "\\}", "\\[", "\\]", "\\$", "\\|" ) as $c
|
||||
(.; gsub($c; $c));
|
||||
# "?" => reluctant, "m" => multiline
|
||||
gsub( (open|deregex) + ".*?" + (close|deregex); ""; "m") ;
|
||||
|
||||
strip_block_comments("/*"; "*/")
|
||||
Loading…
Add table
Add a link
Reference in a new issue