Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
43
Task/Strip-block-comments/F-Sharp/strip-block-comments.fs
Normal file
43
Task/Strip-block-comments/F-Sharp/strip-block-comments.fs
Normal file
|
|
@ -0,0 +1,43 @@
|
|||
open System
|
||||
open System.Text.RegularExpressions
|
||||
|
||||
let balancedComments opening closing =
|
||||
new Regex(
|
||||
String.Format("""
|
||||
{0} # An outer opening delimiter
|
||||
(?> # efficiency: no backtracking here
|
||||
{0} (?<LEVEL>) # An opening delimiter, one level down
|
||||
|
|
||||
{1} (?<-LEVEL>) # A closing delimiter, one level up
|
||||
|
|
||||
(?! {0} | {1} ) . # With negative lookahead: Anything but delimiters
|
||||
)* # As many times as we see these
|
||||
(?(LEVEL)(?!)) # Fail, unless on level 0 here
|
||||
{1} # Outer closing delimiter
|
||||
""", Regex.Escape(opening), Regex.Escape(closing)),
|
||||
RegexOptions.IgnorePatternWhitespace ||| RegexOptions.Singleline)
|
||||
|
||||
[<EntryPoint>]
|
||||
let main args =
|
||||
let sample = """
|
||||
/**
|
||||
* Some comments
|
||||
* longer comments here that we can parse.
|
||||
*
|
||||
* Rahoo
|
||||
*/
|
||||
function subroutine() {
|
||||
a = /* inline comment */ b + c ;
|
||||
}
|
||||
/*/ <-- tricky comments */
|
||||
|
||||
/**
|
||||
* Another comment.
|
||||
* /* nested balanced
|
||||
*/ */
|
||||
function something() {
|
||||
}
|
||||
"""
|
||||
let balancedC = balancedComments "/*" "*/"
|
||||
printfn "%s" (balancedC.Replace(sample, ""))
|
||||
0
|
||||
Loading…
Add table
Add a link
Reference in a new issue