summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--pygments/lexers/shell.py27
-rw-r--r--tests/examplefiles/Get-CommandDefinitionHtml.ps166
2 files changed, 76 insertions, 17 deletions
diff --git a/pygments/lexers/shell.py b/pygments/lexers/shell.py
index bc084b4c..d117fd86 100644
--- a/pygments/lexers/shell.py
+++ b/pygments/lexers/shell.py
@@ -342,7 +342,7 @@ class PowerShellLexer(RegexLexer):
'dynamicparam do default continue cmdletbinding break begin alias \\? '
'% #script #private #local #global mandatory parametersetname position '
'valuefrompipeline valuefrompipelinebypropertyname '
- 'valuefromremainingarguments helpmessage try catch').split()
+ 'valuefromremainingarguments helpmessage try catch throw').split()
operators = (
'and as band bnot bor bxor casesensitive ccontains ceq cge cgt cle '
@@ -368,13 +368,17 @@ class PowerShellLexer(RegexLexer):
tokens = {
'root': [
+ # we need to count pairs of parentheses for correct highlight
+ # of '$(...)' blocks in strings
+ (r'\(', Punctuation, '#push'),
+ (r'\)', Punctuation, '#pop'),
(r'\s+', Text),
(r'^(\s*#[#\s]*)(\.(?:%s))([^\n]*$)' % '|'.join(commenthelp),
bygroups(Comment, String.Doc, Comment)),
(r'#[^\n]*?$', Comment),
(r'(&lt;|<)#', Comment.Multiline, 'multline'),
(r'@"\n', String.Heredoc, 'heredoc-double'),
- (r"@'\n", String.Heredoc, 'heredoc-single'),
+ (r"@'\n.*?\n'@", String.Heredoc),
# escaped syntax
(r'`[\'"$@-]', Punctuation),
(r'"', String.Double, 'string'),
@@ -387,7 +391,7 @@ class PowerShellLexer(RegexLexer):
(r'\[[a-z_\[][a-z0-9_. `,\[\]]*\]', Name.Constant), # .net [type]s
(r'-[a-z_][a-z0-9_]*', Name),
(r'\w+', Name),
- (r'([.,;@{}\[\]$()=+*/\\&%!~?^`|<>-]|::)', Punctuation),
+ (r'[.,;@{}\[\]$()=+*/\\&%!~?^`|<>-]|::', Punctuation),
],
'multline': [
(r'[^#&.]+', Comment.Multiline),
@@ -398,26 +402,15 @@ class PowerShellLexer(RegexLexer):
'string': [
(r"`[0abfnrtv'\"\$]", String.Escape),
(r'[^$`"]+', String.Double),
- (r'\$\(', String.Interpol, 'interpol'),
+ (r'\$\(', Punctuation, 'root'),
(r'""', String.Double),
(r'[`$]', String.Double),
(r'"', String.Double, '#pop'),
],
'heredoc-double': [
- (r'@"\n', String.Heredoc, '#push'),
- (r"@'\n", String.Heredoc, 'heredoc-single'),
(r'\n"@', String.Heredoc, '#pop'),
+ (r'\$\(', Punctuation, 'root'),
+ (r'[^@\n]+"]', String.Heredoc),
(r".", String.Heredoc),
- ],
- 'heredoc-single': [
- (r'@"\n', String.Heredoc, 'heredoc-double'),
- (r"@'\n", String.Heredoc, '#push'),
- (r"\n'@", String.Heredoc, '#pop'),
- (r".", String.Heredoc),
- ],
- 'interpol': [
- (r'[^$)]+', String.Interpol),
- (r'\$\(', String.Interpol, '#push'),
- (r'\)', String.Interpol, '#pop'),
]
}
diff --git a/tests/examplefiles/Get-CommandDefinitionHtml.ps1 b/tests/examplefiles/Get-CommandDefinitionHtml.ps1
new file mode 100644
index 00000000..b181955f
--- /dev/null
+++ b/tests/examplefiles/Get-CommandDefinitionHtml.ps1
@@ -0,0 +1,66 @@
+
+function Get-CommandDefinitionHtml {
+
+ # this tells powershell to allow advanced features,
+ # like the [validatenotnullorempty()] attribute below.
+ [CmdletBinding()]
+ param(
+ [ValidateNotNullOrEmpty()]
+ [string]$name
+ )
+
+ $command = get-command $name
+
+ # Look mom! I'm a cmdlet!
+ $PSCmdlet.WriteVerbose("Dumping HTML for " + $command)
+
+@"
+ <html>
+ <head>
+ <title>$($command.name)</title>
+ </head>
+ <body>
+ <table border="1">
+$(
+ $command.parametersets | % {
+@"
+
+ <tr>
+ <td>$($_.name)</td>
+ <td>
+ <table border="1">
+ <tr>
+ <th colspan="8">Parameters</th>
+
+$(
+ $count = 0
+ $_.parameters | % {
+ if (0 -eq ($count % 8)) {
+@'
+ </tr>
+ <tr>
+'@
+ }
+@"
+ <td>$($_.name)</td>
+"@
+ $count++
+ }
+)
+ </tr>
+ </table>
+ </td>
+ </tr>
+"@
+ }
+)
+ </table>
+ </body>
+ </html>
+"@
+}
+
+Get-CommandDefinitionHtml get-item > out.html
+
+# show in browser
+invoke-item out.html