-
-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathMultilineComment.regex.ps1
93 lines (84 loc) · 2.27 KB
/
MultilineComment.regex.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
<#
.Synopsis
Matches Multiline Comments
.Description
Matches Multline Comments from a variety of languages.
Currently supported: PowerShell, C#, C++, JavaScript, Ruby, HTML, and XML
When this generator is used with a piped in file, the extension will autodetect the format.
If the format could not be autodetected, the match will always fail.
#>
param(
[ValidateSet('PowerShell', 'C#', 'C++', 'C', 'JavaScript', 'JSON', 'Java', 'Ruby', 'HTML', 'XML','PHP','CSHTML', 'OpenScad', '')]
[string]
$Language = 'C'
)
if ($inputObject -and $inputObject -is [IO.FileInfo]) {
$Language =
if ('.h', '.cpp', '.c', '.cs', '.js', '.java','.json', '.scad' -contains $inputObject.Extension) {
'C'
} elseif ('.ps1', '.psm1', '.psd1' -contains $inputObject.Extension) {
'PowerShell'
} elseif ('.htm', '.html', '.xml', '.pswt', '.xaml' -contains $inputObject.Extension -or
$inputObject.Extension -like '.*xml') {
'XML'
} elseif ('.php', '.cshtml' -contains $inputObject.Extension) {
$inputObject.Extension.TrimStart('.').ToUpper()
}
}
if ($inputObject -and $inputObject -is [Management.Automation.CommandInfo] -or $inputObject -is [ScriptBlock]) {
$Language = 'PowerShell'
}
if (-not $PSBoundParameters.Language -and -not $Language) {
return
}
$cStyleBlockComment = @'
/\* # The open comment
(?<Block>
(?:.|\s)+?(?=\z|\*/)
)\*/
'@
$markupLanguageComment = @'
<\!--
(?<Block>(?:.|\s)+?(?=\z|-->))
-->
'@
switch ($Language) {
PowerShell {
@'
\<\# # The opening tag
(?<Block>
(?:.|\s)+?(?=\z|\#>) # anything until the closing tag
)
\#\> # the closing tag
'@
}
{$_ -match '(C\#)|(C\+\+)|(C)|(JavaScript)|(OpenScad)'} {
@'
/\* # The open comment
(?<Block>
(?:.|\s)+?(?=\z|\*/)
)\*/
'@
}
Ruby {
@'
^=begin # begin line
(?<Block>(?.|\s)+?(?=\z|\=end)) # anything that's not =end
=end # end line
'@
}
{ $_ -match 'HTML|XML' } {
@'
<\!--
(?<Block>(?:.|\s)+?(?=\z|-->))
-->
'@
}
{ $_ -match 'PHP|CSHTML'} {
"(?:
$cStyleBlockComment
|
$markupLanguageComment
)"
}
}