...

Source file src/github.com/alecthomas/chroma/lexers/p/powershell.go

Documentation: github.com/alecthomas/chroma/lexers/p

     1  package p
     2  
     3  import (
     4  	. "github.com/alecthomas/chroma" // nolint
     5  	"github.com/alecthomas/chroma/lexers/internal"
     6  )
     7  
     8  // Powershell lexer.
     9  var Powershell = internal.Register(MustNewLazyLexer(
    10  	&Config{
    11  		Name:            "PowerShell",
    12  		Aliases:         []string{"powershell", "posh", "ps1", "psm1", "psd1"},
    13  		Filenames:       []string{"*.ps1", "*.psm1", "*.psd1"},
    14  		MimeTypes:       []string{"text/x-powershell"},
    15  		DotAll:          true,
    16  		CaseInsensitive: true,
    17  	},
    18  	powershellRules,
    19  ))
    20  
    21  func powershellRules() Rules {
    22  	return Rules{
    23  		"root": {
    24  			{`\(`, Punctuation, Push("child")},
    25  			{`\s+`, Text, nil},
    26  			{`^(\s*#[#\s]*)(\.(?:component|description|example|externalhelp|forwardhelpcategory|forwardhelptargetname|functionality|inputs|link|notes|outputs|parameter|remotehelprunspace|role|synopsis))([^\n]*$)`, ByGroups(Comment, LiteralStringDoc, Comment), nil},
    27  			{`#[^\n]*?$`, Comment, nil},
    28  			{`(&lt;|<)#`, CommentMultiline, Push("multline")},
    29  			{`(?i)([A-Z]:)`, Name, nil},
    30  			{`@"\n`, LiteralStringHeredoc, Push("heredoc-double")},
    31  			{`@'\n.*?\n'@`, LiteralStringHeredoc, nil},
    32  			{"`[\\'\"$@-]", Punctuation, nil},
    33  			{`"`, LiteralStringDouble, Push("string")},
    34  			{`'([^']|'')*'`, LiteralStringSingle, nil},
    35  			{`(\$|@@|@)((global|script|private|env):)?\w+`, NameVariable, nil},
    36  			{`[a-z]\w*-[a-z]\w*\b`, NameBuiltin, nil},
    37  			{`(while|validateset|validaterange|validatepattern|validatelength|validatecount|until|trap|switch|return|ref|process|param|parameter|in|if|global:|function|foreach|for|finally|filter|end|elseif|else|dynamicparam|do|default|continue|cmdletbinding|break|begin|alias|\?|%|#script|#private|#local|#global|mandatory|parametersetname|position|valuefrompipeline|valuefrompipelinebypropertyname|valuefromremainingarguments|helpmessage|try|catch|throw)\b`, Keyword, nil},
    38  			{`-(and|as|band|bnot|bor|bxor|casesensitive|ccontains|ceq|cge|cgt|cle|clike|clt|cmatch|cne|cnotcontains|cnotlike|cnotmatch|contains|creplace|eq|exact|f|file|ge|gt|icontains|ieq|ige|igt|ile|ilike|ilt|imatch|ine|inotcontains|inotlike|inotmatch|ireplace|is|isnot|le|like|lt|match|ne|not|notcontains|notlike|notmatch|or|regex|replace|wildcard)\b`, Operator, nil},
    39  			{`(ac|asnp|cat|cd|cfs|chdir|clc|clear|clhy|cli|clp|cls|clv|cnsn|compare|copy|cp|cpi|cpp|curl|cvpa|dbp|del|diff|dir|dnsn|ebp|echo|epal|epcsv|epsn|erase|etsn|exsn|fc|fhx|fl|foreach|ft|fw|gal|gbp|gc|gci|gcm|gcs|gdr|ghy|gi|gjb|gl|gm|gmo|gp|gps|gpv|group|gsn|gsnp|gsv|gu|gv|gwmi|h|history|icm|iex|ihy|ii|ipal|ipcsv|ipmo|ipsn|irm|ise|iwmi|iwr|kill|lp|ls|man|md|measure|mi|mount|move|mp|mv|nal|ndr|ni|nmo|npssc|nsn|nv|ogv|oh|popd|ps|pushd|pwd|r|rbp|rcjb|rcsn|rd|rdr|ren|ri|rjb|rm|rmdir|rmo|rni|rnp|rp|rsn|rsnp|rujb|rv|rvpa|rwmi|sajb|sal|saps|sasv|sbp|sc|select|set|shcm|si|sl|sleep|sls|sort|sp|spjb|spps|spsv|start|sujb|sv|swmi|tee|trcm|type|wget|where|wjb|write)\s`, NameBuiltin, nil},
    40  			{"\\[[a-z_\\[][\\w. `,\\[\\]]*\\]", NameConstant, nil},
    41  			{`-[a-z_]\w*`, Name, nil},
    42  			{`\w+`, Name, nil},
    43  			{"[.,;@{}\\[\\]$()=+*/\\\\&%!~?^`|<>-]|::", Punctuation, nil},
    44  		},
    45  		"child": {
    46  			{`\)`, Punctuation, Pop(1)},
    47  			Include("root"),
    48  		},
    49  		"multline": {
    50  			{`[^#&.]+`, CommentMultiline, nil},
    51  			{`#(>|&gt;)`, CommentMultiline, Pop(1)},
    52  			{`\.(component|description|example|externalhelp|forwardhelpcategory|forwardhelptargetname|functionality|inputs|link|notes|outputs|parameter|remotehelprunspace|role|synopsis)`, LiteralStringDoc, nil},
    53  			{`[#&.]`, CommentMultiline, nil},
    54  		},
    55  		"string": {
    56  			{"`[0abfnrtv'\\\"$`]", LiteralStringEscape, nil},
    57  			{"[^$`\"]+", LiteralStringDouble, nil},
    58  			{`\$\(`, Punctuation, Push("child")},
    59  			{`""`, LiteralStringDouble, nil},
    60  			{"[`$]", LiteralStringDouble, nil},
    61  			{`"`, LiteralStringDouble, Pop(1)},
    62  		},
    63  		"heredoc-double": {
    64  			{`\n"@`, LiteralStringHeredoc, Pop(1)},
    65  			{`\$\(`, Punctuation, Push("child")},
    66  			{`[^@\n]+"]`, LiteralStringHeredoc, nil},
    67  			{`.`, LiteralStringHeredoc, nil},
    68  		},
    69  	}
    70  }
    71  

View as plain text