Skip to content

Commit 20641be

Browse files
ashmindmarijnh
authored andcommitted
[powershell mode] Implement actual PowerShell syntax.
1 parent 14639cc commit 20641be

File tree

2 files changed

+464
-229
lines changed

2 files changed

+464
-229
lines changed

mode/powershell/index.html

Lines changed: 156 additions & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -3,105 +3,186 @@
33
<head>
44
<meta charset="utf-8">
55
<title>CodeMirror: Powershell mode</title>
6-
<link rel="stylesheet" href="../../lib/codemirror.css">
7-
<script src="../../lib/codemirror.js"></script>
8-
<script src="../../addon/edit/matchbrackets.js"></script>
9-
<script src="../../addon/comment/comment.js"></script>
6+
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/codemirror/4.3.0/codemirror.css">
7+
<link rel="stylesheet" href="tests.css">
8+
<script src="https://cdnjs.cloudflare.com/ajax/libs/codemirror/4.3.0/codemirror.js"></script>
109
<script src="powershell.js"></script>
11-
<link rel="stylesheet" href="../../doc/docs.css">
12-
<style type="text/css">.CodeMirror {border-top: 1px solid black; border-bottom: 1px solid black;}</style>
1310
</head>
1411
<body>
1512
<h1>CodeMirror: Powershell mode</h1>
16-
17-
<div><textarea id="code" name="code">
18-
# Literals
19-
1234
20-
0.0e101
21-
.123
22-
0b01010011100
23-
0o01234567
24-
0x0987654321abcdef
25-
7
26-
2147483647
27-
3L
28-
79228162514264337593543950336L
29-
0x100000000L
30-
79228162514264337593543950336
31-
0xdeadbeef
32-
3.14j
33-
10.j
34-
10j
35-
.001j
36-
1e100j
37-
3.14e-10j
3813

14+
<div><textarea id="code" name="code">
15+
# Number Literals
16+
0 12345
17+
12kb 12mb 12gB 12Tb 12PB 12L 12D 12lkb 12dtb
18+
1.234 1.234e56 1. 1.e2 .2 .2e34
19+
1.2MB 1.kb .1dTb 1.e1gb
20+
0x1 0xabcdef 0x3tb 0xelmb
3921

4022
# String Literals
41-
'For\''
42-
"God\""
43-
"""so loved
44-
the world"""
45-
''
46-
@" Multi
47-
line
48-
string "@
23+
'Literal escaping'''
24+
'Literal $variable'
25+
"Escaping 1`""
26+
"Escaping 2"""
27+
"Escaped `$variable"
28+
"Text, $variable and more text"
29+
"Text, ${variable with spaces} and more text."
30+
"Text, $($expression + 3) and more text."
31+
"Text, $("interpolation $("inception")") and more text."
4932

50-
# Identifiers
51-
$Variable = value
52-
${Variable with spaces in it} = value
33+
@"
34+
Multiline
35+
string
36+
"@
37+
# --
38+
@"
39+
Multiline
40+
string with quotes "'
41+
"@
42+
# --
43+
@'
44+
Multiline literal
45+
string with quotes "'
46+
'@
5347

54-
# Operators
55-
+ - * / % & | ^ ~ < >
56-
== != <= >= <> << >> // **
57-
and or not in is
48+
# Array and Hash literals
49+
@( 'a','b','c' )
50+
@{ 'key': 'value' }
5851

59-
# Delimiters
60-
() [] {} , : ` = ; @ . # Note that @ and . require the proper context.
61-
+= -= *= /= %= &= |= ^=
62-
//= >>= <<= **=
63-
64-
# Keywords
65-
as assert break class continue def del elif else except
66-
finally for from global if import lambda pass raise
67-
return try while with yield
52+
# Variables
53+
$Variable = 5
54+
$global:variable = 5
55+
${Variable with spaces} = 5
6856

69-
# Types
70-
bool classmethod complex dict enumerate float frozenset int list object
71-
property reversed set slice staticmethod str super tuple type
72-
73-
# Some Example code
74-
import os
75-
from package import ParentClass
57+
# Operators
58+
= += -= *= /= %=
59+
++ -- .. -f * / % + -
60+
-not ! -bnot
61+
-split -isplit -csplit
62+
-join
63+
-is -isnot -as
64+
-eq -ieq -ceq -ne -ine -cne
65+
-gt -igt -cgt -ge -ige -cge
66+
-lt -ilt -clt -le -ile -cle
67+
-like -ilike -clike -notlike -inotlike -cnotlike
68+
-match -imatch -cmatch -notmatch -inotmatch -cnotmatch
69+
-contains -icontains -ccontains -notcontains -inotcontains -cnotcontains
70+
-replace -ireplace -creplace
71+
-band -bor -bxor
72+
-and -or -xor
7673

77-
@nonsenseDecorator
78-
def doesNothing():
79-
pass
74+
# Punctuation
75+
() [] {} , : ` = ; .
8076

81-
class ExampleClass(ParentClass):
82-
@staticmethod
83-
def example(inputStr):
84-
a = list(inputStr)
85-
a.reverse()
86-
return ''.join(a)
77+
# Keywords
78+
elseif begin function for foreach return else trap while do data dynamicparam
79+
until end break if throw param continue finally in switch exit filter from try
80+
process catch
8781

88-
def __init__(self, mixin = 'Hello'):
89-
self.mixin = mixin
82+
# Built-in variables
83+
$$ $? $^ $_
84+
$args $ConfirmPreference $ConsoleFileName $DebugPreference $Error
85+
$ErrorActionPreference $ErrorView $ExecutionContext $false $FormatEnumerationLimit
86+
$HOME $Host $input $MaximumAliasCount $MaximumDriveCount $MaximumErrorCount
87+
$MaximumFunctionCount $MaximumHistoryCount $MaximumVariableCount $MyInvocation
88+
$NestedPromptLevel $null $OutputEncoding $PID $PROFILE $ProgressPreference
89+
$PSBoundParameters $PSCommandPath $PSCulture $PSDefaultParameterValues
90+
$PSEmailServer $PSHOME $PSScriptRoot $PSSessionApplicationName
91+
$PSSessionConfigurationName $PSSessionOption $PSUICulture $PSVersionTable $PWD
92+
$ShellId $StackTrace $true $VerbosePreference $WarningPreference $WhatIfPreference
93+
$true $false $null
9094

91-
</textarea></div>
95+
# Built-in functions
96+
A:
97+
Add-Computer Add-Content Add-History Add-Member Add-PSSnapin Add-Type
98+
B:
99+
C:
100+
Checkpoint-Computer Clear-Content Clear-EventLog Clear-History Clear-Host Clear-Item
101+
Clear-ItemProperty Clear-Variable Compare-Object Complete-Transaction Connect-PSSession
102+
ConvertFrom-Csv ConvertFrom-Json ConvertFrom-SecureString ConvertFrom-StringData
103+
Convert-Path ConvertTo-Csv ConvertTo-Html ConvertTo-Json ConvertTo-SecureString
104+
ConvertTo-Xml Copy-Item Copy-ItemProperty
105+
D:
106+
Debug-Process Disable-ComputerRestore Disable-PSBreakpoint Disable-PSRemoting
107+
Disable-PSSessionConfiguration Disconnect-PSSession
108+
E:
109+
Enable-ComputerRestore Enable-PSBreakpoint Enable-PSRemoting Enable-PSSessionConfiguration
110+
Enter-PSSession Exit-PSSession Export-Alias Export-Clixml Export-Console Export-Counter
111+
Export-Csv Export-FormatData Export-ModuleMember Export-PSSession
112+
F:
113+
ForEach-Object Format-Custom Format-List Format-Table Format-Wide
114+
G:
115+
Get-Acl Get-Alias Get-AuthenticodeSignature Get-ChildItem Get-Command Get-ComputerRestorePoint
116+
Get-Content Get-ControlPanelItem Get-Counter Get-Credential Get-Culture Get-Date
117+
Get-Event Get-EventLog Get-EventSubscriber Get-ExecutionPolicy Get-FormatData Get-Help
118+
Get-History Get-Host Get-HotFix Get-Item Get-ItemProperty Get-Job Get-Location Get-Member
119+
Get-Module Get-PfxCertificate Get-Process Get-PSBreakpoint Get-PSCallStack Get-PSDrive
120+
Get-PSProvider Get-PSSession Get-PSSessionConfiguration Get-PSSnapin Get-Random Get-Service
121+
Get-TraceSource Get-Transaction Get-TypeData Get-UICulture Get-Unique Get-Variable Get-Verb
122+
Get-WinEvent Get-WmiObject Group-Object
123+
H:
124+
help
125+
I:
126+
Import-Alias Import-Clixml Import-Counter Import-Csv Import-LocalizedData Import-Module
127+
Import-PSSession ImportSystemModules Invoke-Command Invoke-Expression Invoke-History
128+
Invoke-Item Invoke-RestMethod Invoke-WebRequest Invoke-WmiMethod
129+
J:
130+
Join-Path
131+
K:
132+
L:
133+
Limit-EventLog
134+
M:
135+
Measure-Command Measure-Object mkdir more Move-Item Move-ItemProperty
136+
N:
137+
New-Alias New-Event New-EventLog New-Item New-ItemProperty New-Module New-ModuleManifest
138+
New-Object New-PSDrive New-PSSession New-PSSessionConfigurationFile New-PSSessionOption
139+
New-PSTransportOption New-Service New-TimeSpan New-Variable New-WebServiceProxy
140+
New-WinEvent
141+
O:
142+
oss Out-Default Out-File Out-GridView Out-Host Out-Null Out-Printer Out-String
143+
P:
144+
Pause Pop-Location prompt Push-Location
145+
Q:
146+
R:
147+
Read-Host Receive-Job Receive-PSSession Register-EngineEvent Register-ObjectEvent
148+
Register-PSSessionConfiguration Register-WmiEvent Remove-Computer Remove-Event
149+
Remove-EventLog Remove-Item Remove-ItemProperty Remove-Job Remove-Module
150+
Remove-PSBreakpoint Remove-PSDrive Remove-PSSession Remove-PSSnapin Remove-TypeData
151+
Remove-Variable Remove-WmiObject Rename-Computer Rename-Item Rename-ItemProperty
152+
Reset-ComputerMachinePassword Resolve-Path Restart-Computer Restart-Service
153+
Restore-Computer Resume-Job Resume-Service
154+
S:
155+
Save-Help Select-Object Select-String Select-Xml Send-MailMessage Set-Acl Set-Alias
156+
Set-AuthenticodeSignature Set-Content Set-Date Set-ExecutionPolicy Set-Item
157+
Set-ItemProperty Set-Location Set-PSBreakpoint Set-PSDebug
158+
Set-PSSessionConfiguration Set-Service Set-StrictMode Set-TraceSource Set-Variable
159+
Set-WmiInstance Show-Command Show-ControlPanelItem Show-EventLog Sort-Object
160+
Split-Path Start-Job Start-Process Start-Service Start-Sleep Start-Transaction
161+
Start-Transcript Stop-Computer Stop-Job Stop-Process Stop-Service Stop-Transcript
162+
Suspend-Job Suspend-Service
163+
T:
164+
TabExpansion2 Tee-Object Test-ComputerSecureChannel Test-Connection
165+
Test-ModuleManifest Test-Path Test-PSSessionConfigurationFile Trace-Command
166+
U:
167+
Unblock-File Undo-Transaction Unregister-Event Unregister-PSSessionConfiguration
168+
Update-FormatData Update-Help Update-List Update-TypeData Use-Transaction
169+
V:
170+
W:
171+
Wait-Event Wait-Job Wait-Process Where-Object Write-Debug Write-Error Write-EventLog
172+
Write-Host Write-Output Write-Progress Write-Verbose Write-Warning
173+
X:
174+
Y:
175+
Z:</textarea></div>
92176
<script>
93177
var editor = CodeMirror.fromTextArea(document.getElementById("code"), {
94-
mode: {name: "powershell",
95-
version: 2,
96-
singleLineStringErrors: false},
178+
mode: "powershell",
97179
lineNumbers: true,
98180
indentUnit: 4,
99181
tabMode: "shift",
100182
matchBrackets: true
101183
});
102184
</script>
103185

104-
105186
<p><strong>MIME types defined:</strong> <code>text/x-powershell</code>.</p>
106187
</body>
107188
</html>

0 commit comments

Comments
 (0)