From 7bb4c54cfa9595560be17059e8e8de9e0339bafa Mon Sep 17 00:00:00 2001 From: G8t Guy Date: Sat, 10 Dec 2016 12:58:36 +0500 Subject: [PATCH 1/6] Add the basic powershell 5 syntax support. --- AUTHORS.en.txt | 3 ++- AUTHORS.ru.txt | 1 + src/languages/powershell.js | 6 +++--- 3 files changed, 6 insertions(+), 4 deletions(-) diff --git a/AUTHORS.en.txt b/AUTHORS.en.txt index 9147782d88..d5b95d38aa 100644 --- a/AUTHORS.en.txt +++ b/AUTHORS.en.txt @@ -231,4 +231,5 @@ Contributors: - Alexander Lichter - Nicolas Le Gall - Kenton Hamaluik -- Marvin Saignat \ No newline at end of file +- Marvin Saignat +- G8t Guy diff --git a/AUTHORS.ru.txt b/AUTHORS.ru.txt index 137240b1e2..7119e582b9 100644 --- a/AUTHORS.ru.txt +++ b/AUTHORS.ru.txt @@ -232,3 +232,4 @@ URL: https://highlightjs.org/ - Николя Ле Галль - Кентон Хамалуик - Марвин Сайнат +- Грейт Гай diff --git a/src/languages/powershell.js b/src/languages/powershell.js index 66b76353fb..aba4a8fc9f 100644 --- a/src/languages/powershell.js +++ b/src/languages/powershell.js @@ -45,7 +45,7 @@ function(hljs) { var PS_HELPTAGS = { className: 'doctag', variants: [ - /* no paramater help tags */ + /* no paramater help tags */ { begin: /\.(synopsis|description|example|inputs|outputs|notes|link|component|role|functionality)/ }, /* one parameter help tags */ { begin: /\.(parameter|forwardhelptargetname|forwardhelpcategory|remotehelprunspace|externalhelp)\s+\S+/ } @@ -70,8 +70,8 @@ function(hljs) { case_insensitive: true, keywords: { keyword: 'if else foreach return function do while until elseif begin for trap data dynamicparam end break throw param continue finally in switch exit filter try process catch', - built_in: 'Add-Computer Add-Content Add-History Add-JobTrigger Add-Member Add-PSSnapin Add-Type Checkpoint-Computer Clear-Content Clear-EventLog Clear-History Clear-Host Clear-Item Clear-ItemProperty Clear-Variable Compare-Object Complete-Transaction Connect-PSSession Connect-WSMan Convert-Path ConvertFrom-Csv ConvertFrom-Json ConvertFrom-SecureString ConvertFrom-StringData ConvertTo-Csv ConvertTo-Html ConvertTo-Json ConvertTo-SecureString ConvertTo-Xml Copy-Item Copy-ItemProperty Debug-Process Disable-ComputerRestore Disable-JobTrigger Disable-PSBreakpoint Disable-PSRemoting Disable-PSSessionConfiguration Disable-WSManCredSSP Disconnect-PSSession Disconnect-WSMan Disable-ScheduledJob Enable-ComputerRestore Enable-JobTrigger Enable-PSBreakpoint Enable-PSRemoting Enable-PSSessionConfiguration Enable-ScheduledJob Enable-WSManCredSSP Enter-PSSession Exit-PSSession Export-Alias Export-Clixml Export-Console Export-Counter Export-Csv Export-FormatData Export-ModuleMember Export-PSSession ForEach-Object Format-Custom Format-List Format-Table Format-Wide Get-Acl Get-Alias Get-AuthenticodeSignature Get-ChildItem Get-Command Get-ComputerRestorePoint Get-Content Get-ControlPanelItem Get-Counter Get-Credential Get-Culture Get-Date Get-Event Get-EventLog Get-EventSubscriber Get-ExecutionPolicy Get-FormatData Get-Host Get-HotFix Get-Help Get-History Get-IseSnippet Get-Item Get-ItemProperty Get-Job Get-JobTrigger Get-Location Get-Member Get-Module Get-PfxCertificate Get-Process Get-PSBreakpoint Get-PSCallStack Get-PSDrive Get-PSProvider Get-PSSession Get-PSSessionConfiguration Get-PSSnapin Get-Random Get-ScheduledJob Get-ScheduledJobOption Get-Service Get-TraceSource Get-Transaction Get-TypeData Get-UICulture Get-Unique Get-Variable Get-Verb Get-WinEvent Get-WmiObject Get-WSManCredSSP Get-WSManInstance Group-Object Import-Alias Import-Clixml Import-Counter Import-Csv Import-IseSnippet Import-LocalizedData Import-PSSession Import-Module Invoke-AsWorkflow Invoke-Command Invoke-Expression Invoke-History Invoke-Item Invoke-RestMethod Invoke-WebRequest Invoke-WmiMethod Invoke-WSManAction Join-Path Limit-EventLog Measure-Command Measure-Object Move-Item Move-ItemProperty New-Alias New-Event New-EventLog New-IseSnippet New-Item New-ItemProperty New-JobTrigger New-Object New-Module New-ModuleManifest New-PSDrive New-PSSession New-PSSessionConfigurationFile New-PSSessionOption New-PSTransportOption New-PSWorkflowExecutionOption New-PSWorkflowSession New-ScheduledJobOption New-Service New-TimeSpan New-Variable New-WebServiceProxy New-WinEvent New-WSManInstance New-WSManSessionOption Out-Default Out-File Out-GridView Out-Host Out-Null Out-Printer Out-String Pop-Location Push-Location Read-Host Receive-Job Register-EngineEvent Register-ObjectEvent Register-PSSessionConfiguration Register-ScheduledJob Register-WmiEvent Remove-Computer Remove-Event Remove-EventLog Remove-Item Remove-ItemProperty Remove-Job Remove-JobTrigger Remove-Module Remove-PSBreakpoint Remove-PSDrive Remove-PSSession Remove-PSSnapin Remove-TypeData Remove-Variable Remove-WmiObject Remove-WSManInstance Rename-Computer Rename-Item Rename-ItemProperty Reset-ComputerMachinePassword Resolve-Path Restart-Computer Restart-Service Restore-Computer Resume-Job Resume-Service Save-Help Select-Object Select-String Select-Xml Send-MailMessage Set-Acl Set-Alias Set-AuthenticodeSignature Set-Content Set-Date Set-ExecutionPolicy Set-Item Set-ItemProperty Set-JobTrigger Set-Location Set-PSBreakpoint Set-PSDebug Set-PSSessionConfiguration Set-ScheduledJob Set-ScheduledJobOption Set-Service Set-StrictMode Set-TraceSource Set-Variable Set-WmiInstance Set-WSManInstance Set-WSManQuickConfig Show-Command Show-ControlPanelItem Show-EventLog Sort-Object Split-Path Start-Job Start-Process Start-Service Start-Sleep Start-Transaction Start-Transcript Stop-Computer Stop-Job Stop-Process Stop-Service Stop-Transcript Suspend-Job Suspend-Service Tee-Object Test-ComputerSecureChannel Test-Connection Test-ModuleManifest Test-Path Test-PSSessionConfigurationFile Trace-Command Unblock-File Undo-Transaction Unregister-Event Unregister-PSSessionConfiguration Unregister-ScheduledJob Update-FormatData Update-Help Update-List Update-TypeData Use-Transaction Wait-Event Wait-Job Wait-Process Where-Object Write-Debug Write-Error Write-EventLog Write-Host Write-Output Write-Progress Write-Verbose Write-Warning Add-MDTPersistentDrive Disable-MDTMonitorService Enable-MDTMonitorService Get-MDTDeploymentShareStatistics Get-MDTMonitorData Get-MDTOperatingSystemCatalog Get-MDTPersistentDrive Import-MDTApplication Import-MDTDriver Import-MDTOperatingSystem Import-MDTPackage Import-MDTTaskSequence New-MDTDatabase Remove-MDTMonitorData Remove-MDTPersistentDrive Restore-MDTPersistentDrive Set-MDTMonitorData Test-MDTDeploymentShare Test-MDTMonitorData Update-MDTDatabaseSchema Update-MDTDeploymentShare Update-MDTLinkedDS Update-MDTMedia Update-MDTMedia Add-VamtProductKey Export-VamtData Find-VamtManagedMachine Get-VamtConfirmationId Get-VamtProduct Get-VamtProductKey Import-VamtData Initialize-VamtData Install-VamtConfirmationId Install-VamtProductActivation Install-VamtProductKey Update-VamtProduct', - nomarkup: '-ne -eq -lt -gt -ge -le -not -like -notlike -match -notmatch -contains -notcontains -in -notin -replace' + built_in: 'Add-Computer Add-Content Add-History Add-JobTrigger Add-Member Add-PSSnapin Add-Type Checkpoint-Computer Clear-Content Clear-EventLog Clear-History Clear-Host Clear-Item Clear-ItemProperty Clear-Variable Compare-Object Complete-Transaction Connect-PSSession Connect-WSMan Convert-Path ConvertFrom-Csv ConvertFrom-Json ConvertFrom-SecureString ConvertFrom-StringData ConvertTo-Csv ConvertTo-Html ConvertTo-Json ConvertTo-SecureString ConvertTo-Xml Copy-Item Copy-ItemProperty Debug-Process Disable-ComputerRestore Disable-JobTrigger Disable-PSBreakpoint Disable-PSRemoting Disable-PSSessionConfiguration Disable-WSManCredSSP Disconnect-PSSession Disconnect-WSMan Disable-ScheduledJob Enable-ComputerRestore Enable-JobTrigger Enable-PSBreakpoint Enable-PSRemoting Enable-PSSessionConfiguration Enable-ScheduledJob Enable-WSManCredSSP Enter-PSSession Exit-PSSession Export-Alias Export-Clixml Export-Console Export-Counter Export-Csv Export-FormatData Export-ModuleMember Export-PSSession ForEach-Object Format-Custom Format-List Format-Table Format-Wide Get-Acl Get-Alias Get-AuthenticodeSignature Get-ChildItem Get-Command Get-ComputerRestorePoint Get-Content Get-ControlPanelItem Get-Counter Get-Credential Get-Culture Get-Date Get-Event Get-EventLog Get-EventSubscriber Get-ExecutionPolicy Get-FormatData Get-Host Get-HotFix Get-Help Get-History Get-IseSnippet Get-Item Get-ItemProperty Get-Job Get-JobTrigger Get-Location Get-Member Get-Module Get-PfxCertificate Get-Process Get-PSBreakpoint Get-PSCallStack Get-PSDrive Get-PSProvider Get-PSSession Get-PSSessionConfiguration Get-PSSnapin Get-Random Get-ScheduledJob Get-ScheduledJobOption Get-Service Get-TraceSource Get-Transaction Get-TypeData Get-UICulture Get-Unique Get-Variable Get-Verb Get-WinEvent Get-WmiObject Get-WSManCredSSP Get-WSManInstance Group-Object Import-Alias Import-Clixml Import-Counter Import-Csv Import-IseSnippet Import-LocalizedData Import-PSSession Import-Module Invoke-AsWorkflow Invoke-Command Invoke-Expression Invoke-History Invoke-Item Invoke-RestMethod Invoke-WebRequest Invoke-WmiMethod Invoke-WSManAction Join-Path Limit-EventLog Measure-Command Measure-Object Move-Item Move-ItemProperty New-Alias New-Event New-EventLog New-IseSnippet New-Item New-ItemProperty New-JobTrigger New-Object New-Module New-ModuleManifest New-PSDrive New-PSSession New-PSSessionConfigurationFile New-PSSessionOption New-PSTransportOption New-PSWorkflowExecutionOption New-PSWorkflowSession New-ScheduledJobOption New-Service New-TimeSpan New-Variable New-WebServiceProxy New-WinEvent New-WSManInstance New-WSManSessionOption Out-Default Out-File Out-GridView Out-Host Out-Null Out-Printer Out-String Pop-Location Push-Location Read-Host Receive-Job Register-EngineEvent Register-ObjectEvent Register-PSSessionConfiguration Register-ScheduledJob Register-WmiEvent Remove-Computer Remove-Event Remove-EventLog Remove-Item Remove-ItemProperty Remove-Job Remove-JobTrigger Remove-Module Remove-PSBreakpoint Remove-PSDrive Remove-PSSession Remove-PSSnapin Remove-TypeData Remove-Variable Remove-WmiObject Remove-WSManInstance Rename-Computer Rename-Item Rename-ItemProperty Reset-ComputerMachinePassword Resolve-Path Restart-Computer Restart-Service Restore-Computer Resume-Job Resume-Service Save-Help Select-Object Select-String Select-Xml Send-MailMessage Set-Acl Set-Alias Set-AuthenticodeSignature Set-Content Set-Date Set-ExecutionPolicy Set-Item Set-ItemProperty Set-JobTrigger Set-Location Set-PSBreakpoint Set-PSDebug Set-PSSessionConfiguration Set-ScheduledJob Set-ScheduledJobOption Set-Service Set-StrictMode Set-TraceSource Set-Variable Set-WmiInstance Set-WSManInstance Set-WSManQuickConfig Show-Command Show-ControlPanelItem Show-EventLog Sort-Object Split-Path Start-Job Start-Process Start-Service Start-Sleep Start-Transaction Start-Transcript Stop-Computer Stop-Job Stop-Process Stop-Service Stop-Transcript Suspend-Job Suspend-Service Tee-Object Test-ComputerSecureChannel Test-Connection Test-ModuleManifest Test-Path Test-PSSessionConfigurationFile Trace-Command Unblock-File Undo-Transaction Unregister-Event Unregister-PSSessionConfiguration Unregister-ScheduledJob Update-FormatData Update-Help Update-List Update-TypeData Use-Transaction Wait-Event Wait-Job Wait-Process Where-Object Write-Debug Write-Error Write-EventLog Write-Host Write-Output Write-Progress Write-Verbose Write-Warning Add-MDTPersistentDrive Disable-MDTMonitorService Enable-MDTMonitorService Get-MDTDeploymentShareStatistics Get-MDTMonitorData Get-MDTOperatingSystemCatalog Get-MDTPersistentDrive Import-MDTApplication Import-MDTDriver Import-MDTOperatingSystem Import-MDTPackage Import-MDTTaskSequence New-MDTDatabase Remove-MDTMonitorData Remove-MDTPersistentDrive Restore-MDTPersistentDrive Set-MDTMonitorData Test-MDTDeploymentShare Test-MDTMonitorData Update-MDTDatabaseSchema Update-MDTDeploymentShare Update-MDTLinkedDS Update-MDTMedia Update-MDTMedia Add-VamtProductKey Export-VamtData Find-VamtManagedMachine Get-VamtConfirmationId Get-VamtProduct Get-VamtProductKey Import-VamtData Initialize-VamtData Install-VamtConfirmationId Install-VamtProductActivation Install-VamtProductKey Update-VamtProduct using namespace module class enum', + nomarkup: '-ne -eq -lt -gt -ge -le -not -like -notlike -match -notmatch -contains -notcontains -in -notin -replace -split -join' }, contains: [ BACKTICK_ESCAPE, From 79c25c609e94491ee18f92046f295f0826904fd2 Mon Sep 17 00:00:00 2001 From: G8t Guy Date: Sun, 11 Dec 2016 20:53:40 +0500 Subject: [PATCH 2/6] Refactoring. --- src/languages/powershell.js | 108 +++++++++++++++++++++++++++++------- 1 file changed, 88 insertions(+), 20 deletions(-) diff --git a/src/languages/powershell.js b/src/languages/powershell.js index aba4a8fc9f..8b89d2c287 100644 --- a/src/languages/powershell.js +++ b/src/languages/powershell.js @@ -1,24 +1,44 @@ -/* -Language: PowerShell -Author: David Mohundro -Contributors: Nicholas Blumhardt , Victor Zhou , Nicolas Le Gall -*/ +module.exports = function(hljs) { + + // https://msdn.microsoft.com/en-us/library/ms714428(v=vs.85).aspx + var VALID_VERBS = + 'Add|Clear|Close|Copy|Enter|Exit|Find|Format|Get|Hide|Join|Lock|' + + 'Move|New|Open|Optimize|Pop|Push|Redo|Remove|Rename|Reset|Resize|' + + 'Search|Select|Set|Show|Skip|Split|Step|Switch|Undo|Unlock|' + + 'Watch|Backup|Checkpoint|Compare|Compress|Convert|ConvertFrom|' + + 'ConvertTo|Dismount|Edit|Expand|Export|Group|Import|Initialize|' + + 'Limit|Merge|New|Out|Publish|Restore|Save|Sync|Unpublish|Update|' + + 'Approve|Assert|Complete|Confirm|Deny|Disable|Enable|Install|Invoke|Register|' + + 'Request|Restart|Resume|Start|Stop|Submit|Suspend|Uninstall|' + + 'Unregister|Wait|Debug|Measure|Ping|Repair|Resolve|Test|Trace|Connect|' + + 'Disconnect|Read|Receive|Send|Write|Block|Grant|Protect|Revoke|Unblock|' + + 'Unprotect|Use|ForEach|Sort|Tee|Where' + + var KEYWORDS = { + keyword: + 'if else foreach return do while until elseif begin for trap data dynamicparam ' + + 'end break throw param continue finally in switch exit filter try process catch ' + + 'hidden static', + + name: + '-ne -eq -lt -gt -ge -le -not -like -notlike -match -notmatch -contains '+ + '-notcontains -in -notin -replace -split -join' + } -function(hljs) { var BACKTICK_ESCAPE = { begin: '`[\\s\\S]', relevance: 0 - }; + } var VAR = { className: 'variable', variants: [ {begin: /\$[\w\d][\w\d_:]*/} ] - }; + } var LITERAL = { className: 'literal', begin: /\$(null|true|false)\b/ - }; + } var QUOTE_STRING = { className: 'string', variants: [ @@ -33,14 +53,14 @@ function(hljs) { begin: /\$[A-z]/, end: /[^A-z]/ } ] - }; + } var APOS_STRING = { className: 'string', variants: [ { begin: /'/, end: /'/ }, { begin: /@'/, end: /^'@/ } ] - }; + } var PS_HELPTAGS = { className: 'doctag', @@ -50,7 +70,7 @@ function(hljs) { /* one parameter help tags */ { begin: /\.(parameter|forwardhelptargetname|forwardhelpcategory|remotehelprunspace|externalhelp)\s+\S+/ } ] - }; + } var PS_COMMENT = hljs.inherit( hljs.COMMENT(null, null), { @@ -62,25 +82,73 @@ function(hljs) { ], contains: [PS_HELPTAGS] } - ); + ) + + var CMDLETS = { + className: 'built_in', + variants: [ + { begin: '('.concat( VALID_VERBS, ')+(-)[\\w\\d]+') }, + { className: 'name', begin: /[\w\d]+(-)[\w\d]+/ } + ] + } + var PS_CLASS = { + className: 'class', + beginKeywords: 'class enum', end: /[{]/, excludeEnd: true, + contains: [ + { beginKeywords: ':' }, + hljs.TITLE_MODE + ] + } + + var IDENT_RE = '[a-zA-Z-_]\\w*'; + + var PS_FUNCTION = { + className: 'keyword', + begin: /function\s/, end: /(\s|[^A-Z0-9-])/, + excludeEnd: true, + contains: [ + CMDLETS, + { className: 'name', begin: /[\w\d]+/ } + ] + } + + var PS_USING = { + className: 'keyword hljs-strong', + begin: /using\s/, end: /$/, + contains: [ + QUOTE_STRING, + APOS_STRING, + { className: 'type', begin: /(assembly|command|module|namespace|type)/ }, + { className: 'meta', begin: /\S+/ } + ] + } + + var PS_ARGUMENTS = { + className: 'literal hljs-strong', + variants: [ + { begin: '(-)[\\w\\d]+' }, + ] + } return { aliases: ['ps'], lexemes: /-?[A-z\.\-]+/, case_insensitive: true, - keywords: { - keyword: 'if else foreach return function do while until elseif begin for trap data dynamicparam end break throw param continue finally in switch exit filter try process catch', - built_in: 'Add-Computer Add-Content Add-History Add-JobTrigger Add-Member Add-PSSnapin Add-Type Checkpoint-Computer Clear-Content Clear-EventLog Clear-History Clear-Host Clear-Item Clear-ItemProperty Clear-Variable Compare-Object Complete-Transaction Connect-PSSession Connect-WSMan Convert-Path ConvertFrom-Csv ConvertFrom-Json ConvertFrom-SecureString ConvertFrom-StringData ConvertTo-Csv ConvertTo-Html ConvertTo-Json ConvertTo-SecureString ConvertTo-Xml Copy-Item Copy-ItemProperty Debug-Process Disable-ComputerRestore Disable-JobTrigger Disable-PSBreakpoint Disable-PSRemoting Disable-PSSessionConfiguration Disable-WSManCredSSP Disconnect-PSSession Disconnect-WSMan Disable-ScheduledJob Enable-ComputerRestore Enable-JobTrigger Enable-PSBreakpoint Enable-PSRemoting Enable-PSSessionConfiguration Enable-ScheduledJob Enable-WSManCredSSP Enter-PSSession Exit-PSSession Export-Alias Export-Clixml Export-Console Export-Counter Export-Csv Export-FormatData Export-ModuleMember Export-PSSession ForEach-Object Format-Custom Format-List Format-Table Format-Wide Get-Acl Get-Alias Get-AuthenticodeSignature Get-ChildItem Get-Command Get-ComputerRestorePoint Get-Content Get-ControlPanelItem Get-Counter Get-Credential Get-Culture Get-Date Get-Event Get-EventLog Get-EventSubscriber Get-ExecutionPolicy Get-FormatData Get-Host Get-HotFix Get-Help Get-History Get-IseSnippet Get-Item Get-ItemProperty Get-Job Get-JobTrigger Get-Location Get-Member Get-Module Get-PfxCertificate Get-Process Get-PSBreakpoint Get-PSCallStack Get-PSDrive Get-PSProvider Get-PSSession Get-PSSessionConfiguration Get-PSSnapin Get-Random Get-ScheduledJob Get-ScheduledJobOption Get-Service Get-TraceSource Get-Transaction Get-TypeData Get-UICulture Get-Unique Get-Variable Get-Verb Get-WinEvent Get-WmiObject Get-WSManCredSSP Get-WSManInstance Group-Object Import-Alias Import-Clixml Import-Counter Import-Csv Import-IseSnippet Import-LocalizedData Import-PSSession Import-Module Invoke-AsWorkflow Invoke-Command Invoke-Expression Invoke-History Invoke-Item Invoke-RestMethod Invoke-WebRequest Invoke-WmiMethod Invoke-WSManAction Join-Path Limit-EventLog Measure-Command Measure-Object Move-Item Move-ItemProperty New-Alias New-Event New-EventLog New-IseSnippet New-Item New-ItemProperty New-JobTrigger New-Object New-Module New-ModuleManifest New-PSDrive New-PSSession New-PSSessionConfigurationFile New-PSSessionOption New-PSTransportOption New-PSWorkflowExecutionOption New-PSWorkflowSession New-ScheduledJobOption New-Service New-TimeSpan New-Variable New-WebServiceProxy New-WinEvent New-WSManInstance New-WSManSessionOption Out-Default Out-File Out-GridView Out-Host Out-Null Out-Printer Out-String Pop-Location Push-Location Read-Host Receive-Job Register-EngineEvent Register-ObjectEvent Register-PSSessionConfiguration Register-ScheduledJob Register-WmiEvent Remove-Computer Remove-Event Remove-EventLog Remove-Item Remove-ItemProperty Remove-Job Remove-JobTrigger Remove-Module Remove-PSBreakpoint Remove-PSDrive Remove-PSSession Remove-PSSnapin Remove-TypeData Remove-Variable Remove-WmiObject Remove-WSManInstance Rename-Computer Rename-Item Rename-ItemProperty Reset-ComputerMachinePassword Resolve-Path Restart-Computer Restart-Service Restore-Computer Resume-Job Resume-Service Save-Help Select-Object Select-String Select-Xml Send-MailMessage Set-Acl Set-Alias Set-AuthenticodeSignature Set-Content Set-Date Set-ExecutionPolicy Set-Item Set-ItemProperty Set-JobTrigger Set-Location Set-PSBreakpoint Set-PSDebug Set-PSSessionConfiguration Set-ScheduledJob Set-ScheduledJobOption Set-Service Set-StrictMode Set-TraceSource Set-Variable Set-WmiInstance Set-WSManInstance Set-WSManQuickConfig Show-Command Show-ControlPanelItem Show-EventLog Sort-Object Split-Path Start-Job Start-Process Start-Service Start-Sleep Start-Transaction Start-Transcript Stop-Computer Stop-Job Stop-Process Stop-Service Stop-Transcript Suspend-Job Suspend-Service Tee-Object Test-ComputerSecureChannel Test-Connection Test-ModuleManifest Test-Path Test-PSSessionConfigurationFile Trace-Command Unblock-File Undo-Transaction Unregister-Event Unregister-PSSessionConfiguration Unregister-ScheduledJob Update-FormatData Update-Help Update-List Update-TypeData Use-Transaction Wait-Event Wait-Job Wait-Process Where-Object Write-Debug Write-Error Write-EventLog Write-Host Write-Output Write-Progress Write-Verbose Write-Warning Add-MDTPersistentDrive Disable-MDTMonitorService Enable-MDTMonitorService Get-MDTDeploymentShareStatistics Get-MDTMonitorData Get-MDTOperatingSystemCatalog Get-MDTPersistentDrive Import-MDTApplication Import-MDTDriver Import-MDTOperatingSystem Import-MDTPackage Import-MDTTaskSequence New-MDTDatabase Remove-MDTMonitorData Remove-MDTPersistentDrive Restore-MDTPersistentDrive Set-MDTMonitorData Test-MDTDeploymentShare Test-MDTMonitorData Update-MDTDatabaseSchema Update-MDTDeploymentShare Update-MDTLinkedDS Update-MDTMedia Update-MDTMedia Add-VamtProductKey Export-VamtData Find-VamtManagedMachine Get-VamtConfirmationId Get-VamtProduct Get-VamtProductKey Import-VamtData Initialize-VamtData Install-VamtConfirmationId Install-VamtProductActivation Install-VamtProductKey Update-VamtProduct using namespace module class enum', - nomarkup: '-ne -eq -lt -gt -ge -le -not -like -notlike -match -notmatch -contains -notcontains -in -notin -replace -split -join' - }, + keywords: KEYWORDS, contains: [ + CMDLETS, BACKTICK_ESCAPE, hljs.NUMBER_MODE, QUOTE_STRING, APOS_STRING, LITERAL, VAR, - PS_COMMENT + PS_COMMENT, + PS_CLASS, + PS_FUNCTION, + PS_USING, + PS_ARGUMENTS + ] - }; + } } From aa14df0e5e1c603d01e071c06c319d366234dcba Mon Sep 17 00:00:00 2001 From: G8t Guy Date: Mon, 12 Dec 2016 23:45:47 +0500 Subject: [PATCH 3/6] Highlight Constractors. --- src/languages/powershell.js | 113 +++++++++++++++++++++++++++++------- 1 file changed, 92 insertions(+), 21 deletions(-) diff --git a/src/languages/powershell.js b/src/languages/powershell.js index 8b89d2c287..89c38fcde3 100644 --- a/src/languages/powershell.js +++ b/src/languages/powershell.js @@ -1,5 +1,7 @@ module.exports = function(hljs) { + // var IDENT_RE = '[a-zA-Z-_]\\w*'; + // https://msdn.microsoft.com/en-us/library/ms714428(v=vs.85).aspx var VALID_VERBS = 'Add|Clear|Close|Copy|Enter|Exit|Find|Format|Get|Hide|Join|Lock|' + @@ -14,31 +16,39 @@ module.exports = function(hljs) { 'Disconnect|Read|Receive|Send|Write|Block|Grant|Protect|Revoke|Unblock|' + 'Unprotect|Use|ForEach|Sort|Tee|Where' + var COMPARISON_OPERATORS = + '-and|-as|-band|-bnot|-bor|-bxor|-casesensitive|-ccontains|-ceq|-cge|-cgt|' + + '-cle|-clike|-clt|-cmatch|-cne|-cnotcontains|-cnotlike|-cnotmatch|-contains|' + + '-creplace|-csplit|-eq|-exact|-f|-file|-ge|-gt|-icontains|-ieq|-ige|-igt|' + + '-ile|-ilike|-ilt|-imatch|-in|-ine|-inotcontains|-inotlike|-inotmatch|' + + '-ireplace|-is|-isnot|-isplit|-join|-le|-like|-lt|-match|-ne|-not|' + + '-notcontains|-notin|-notlike|-notmatch|-or|-regex|-replace|-shl|-shr|' + + '-split|-wildcard|-xor' + var KEYWORDS = { keyword: 'if else foreach return do while until elseif begin for trap data dynamicparam ' + 'end break throw param continue finally in switch exit filter try process catch ' + - 'hidden static', - - name: - '-ne -eq -lt -gt -ge -le -not -like -notlike -match -notmatch -contains '+ - '-notcontains -in -notin -replace -split -join' + 'hidden static' } var BACKTICK_ESCAPE = { begin: '`[\\s\\S]', relevance: 0 } + var VAR = { className: 'variable', variants: [ {begin: /\$[\w\d][\w\d_:]*/} ] } + var LITERAL = { className: 'literal', begin: /\$(null|true|false)\b/ } + var QUOTE_STRING = { className: 'string', variants: [ @@ -54,6 +64,7 @@ module.exports = function(hljs) { } ] } + var APOS_STRING = { className: 'string', variants: [ @@ -71,6 +82,7 @@ module.exports = function(hljs) { { begin: /\.(parameter|forwardhelptargetname|forwardhelpcategory|remotehelprunspace|externalhelp)\s+\S+/ } ] } + var PS_COMMENT = hljs.inherit( hljs.COMMENT(null, null), { @@ -91,6 +103,7 @@ module.exports = function(hljs) { { className: 'name', begin: /[\w\d]+(-)[\w\d]+/ } ] } + var PS_CLASS = { className: 'class', beginKeywords: 'class enum', end: /[{]/, excludeEnd: true, @@ -100,11 +113,9 @@ module.exports = function(hljs) { ] } - var IDENT_RE = '[a-zA-Z-_]\\w*'; - var PS_FUNCTION = { className: 'keyword', - begin: /function\s/, end: /(\s|[^A-Z0-9-])/, + begin: /function\s+/, end: /([^A-Z0-9-])/, excludeEnd: true, contains: [ CMDLETS, @@ -124,31 +135,91 @@ module.exports = function(hljs) { } var PS_ARGUMENTS = { - className: 'literal hljs-strong', + className: 'name', variants: [ - { begin: '(-)[\\w\\d]+' }, + { begin: '('.concat( COMPARISON_OPERATORS, ')\\b') }, + { className: 'literal hljs-strong', begin: /(-)[\w\d]+/ }, ] } + var STATIC_DELIMITER = { className: 'section', begin: /::/ } + + var PS_NEW_OBJECT_TYPE = { + className: 'built_in', + begin: /New-Object\s+\w/, end: /$/, + returnBegin: true, + contains: [ + { + className: 'name', begin: /$/, endsParent: true, + }, + { + className: 'meta hljs-strong', + begin: /\s([\w\.])+/, + endsParent: true, + + + } + ], + + + } + + var PS_CLASS_CONSTRUCTOR = { + className: 'name', + begin: /^\s+[A-Z]+\s*?\(.*?\)/, end: /{/, + returnBegin: true, + + contains: [ + { + className: 'name', begin: /[\Z]{0,1}/, endsParent: true, + }, + { + className: 'name', begin: /[\w]+\b/, + endsParent: true, + } + ] + } + + var GENTLEMANS_SET =[ + STATIC_DELIMITER, + PS_CLASS_CONSTRUCTOR, + PS_COMMENT, + BACKTICK_ESCAPE, + hljs.NUMBER_MODE, + QUOTE_STRING, + APOS_STRING, + PS_NEW_OBJECT_TYPE, + CMDLETS, + VAR, + LITERAL + ] + + var PS_TYPE = { + className: 'no-markup', + begin: /\[/, end: /\]/, + excludeBegin: true, + excludeEnd: true, + contains: GENTLEMANS_SET.concat( + 'self', + { className: 'meta hljs-strong', begin: /[\.\w\d]+/ }, + ) + } + + + + return { aliases: ['ps'], lexemes: /-?[A-z\.\-]+/, case_insensitive: true, keywords: KEYWORDS, - contains: [ - CMDLETS, - BACKTICK_ESCAPE, - hljs.NUMBER_MODE, - QUOTE_STRING, - APOS_STRING, - LITERAL, - VAR, - PS_COMMENT, + contains: GENTLEMANS_SET.concat( PS_CLASS, PS_FUNCTION, PS_USING, - PS_ARGUMENTS + PS_ARGUMENTS, + PS_TYPE, - ] + ) } } From 2a8cfa89371bd6f27964c8c975090af4f31193ba Mon Sep 17 00:00:00 2001 From: G8t Guy Date: Tue, 13 Dec 2016 23:40:50 +0500 Subject: [PATCH 4/6] Color scheme tuning. --- src/languages/powershell.js | 46 +++++++++++++++---------------------- 1 file changed, 18 insertions(+), 28 deletions(-) diff --git a/src/languages/powershell.js b/src/languages/powershell.js index 89c38fcde3..b790f8f1d5 100644 --- a/src/languages/powershell.js +++ b/src/languages/powershell.js @@ -100,7 +100,7 @@ module.exports = function(hljs) { className: 'built_in', variants: [ { begin: '('.concat( VALID_VERBS, ')+(-)[\\w\\d]+') }, - { className: 'name', begin: /[\w\d]+(-)[\w\d]+/ } + { className: 'deletion', begin: /[\w\d]+(-)[\w\d]+/ } ] } @@ -119,62 +119,52 @@ module.exports = function(hljs) { excludeEnd: true, contains: [ CMDLETS, - { className: 'name', begin: /[\w\d]+/ } + { className: 'deletion', begin: /[\w\d]+/ } ] } var PS_USING = { - className: 'keyword hljs-strong', + className: 'keyword', begin: /using\s/, end: /$/, contains: [ QUOTE_STRING, APOS_STRING, { className: 'type', begin: /(assembly|command|module|namespace|type)/ }, - { className: 'meta', begin: /\S+/ } + { className: 'symbol', begin: /\S+/ } ] } var PS_ARGUMENTS = { - className: 'name', variants: [ { begin: '('.concat( COMPARISON_OPERATORS, ')\\b') }, - { className: 'literal hljs-strong', begin: /(-)[\w\d]+/ }, + { className: 'literal', begin: /(-)[\w\d]+/ }, ] } - var STATIC_DELIMITER = { className: 'section', begin: /::/ } + var STATIC_DELIMITER = { className: 'deletion', begin: /::/ } var PS_NEW_OBJECT_TYPE = { className: 'built_in', begin: /New-Object\s+\w/, end: /$/, returnBegin: true, contains: [ - { - className: 'name', begin: /$/, endsParent: true, - }, - { - className: 'meta hljs-strong', - begin: /\s([\w\.])+/, - endsParent: true, - - - } - ], - - + { begin: /$/, endsParent: true }, + { className: 'symbol', begin: /\s([\w\.])+/, endsParent: true } + ] } var PS_CLASS_CONSTRUCTOR = { - className: 'name', - begin: /^\s+[A-Z]+\s*?\(.*?\)/, end: /{/, + className: 'keyword', + //begin: /^\s+[A-Z]+\s*?\([\s\S][\s]*?.*?[^]*?\)\s\{/gm, end: /{/, + //begin: /^[ ]+[A-Z]+[ ]+\(.*?\)\s*?\{/, end: /{/, + //begin: /(^[ ]*?|\.)[A-Z]+\s*?\([\s\S]*?\)/, end: /$/, + //begin: /(^[ ]*?)[A-Z]+\s*?\([\s\S]*?\)/, end: /$/, + begin: /[A-Z]+\s*?\([\s\S]*?\)/, end: /$/, returnBegin: true, contains: [ { - className: 'name', begin: /[\Z]{0,1}/, endsParent: true, - }, - { - className: 'name', begin: /[\w]+\b/, + className: 'built_in', begin: /[\w]+\b/, endsParent: true, } ] @@ -182,7 +172,7 @@ module.exports = function(hljs) { var GENTLEMANS_SET =[ STATIC_DELIMITER, - PS_CLASS_CONSTRUCTOR, + // PS_CLASS_CONSTRUCTOR, PS_COMMENT, BACKTICK_ESCAPE, hljs.NUMBER_MODE, @@ -201,7 +191,7 @@ module.exports = function(hljs) { excludeEnd: true, contains: GENTLEMANS_SET.concat( 'self', - { className: 'meta hljs-strong', begin: /[\.\w\d]+/ }, + { className: 'symbol', begin: /[\.\w\d]+/ }, ) } From 7d56cbdca7c1d484f99c27774e27111b04f27f9d Mon Sep 17 00:00:00 2001 From: G8t Guy Date: Wed, 14 Dec 2016 17:18:37 +0500 Subject: [PATCH 5/6] Enhanced Powershell highlighting. --- src/languages/powershell.js | 105 +++++++++++++++++++++--------------- 1 file changed, 63 insertions(+), 42 deletions(-) diff --git a/src/languages/powershell.js b/src/languages/powershell.js index b790f8f1d5..790251ccb1 100644 --- a/src/languages/powershell.js +++ b/src/languages/powershell.js @@ -1,6 +1,10 @@ -module.exports = function(hljs) { +/* + Language: PowerShell + Author: David Mohundro + Contributors: Nicholas Blumhardt , Victor Zhou , Nicolas Le Gall , G8t Guy + */ - // var IDENT_RE = '[a-zA-Z-_]\\w*'; +module.exports = function (hljs) { // https://msdn.microsoft.com/en-us/library/ms714428(v=vs.85).aspx var VALID_VERBS = @@ -26,10 +30,9 @@ module.exports = function(hljs) { '-split|-wildcard|-xor' var KEYWORDS = { - keyword: - 'if else foreach return do while until elseif begin for trap data dynamicparam ' + - 'end break throw param continue finally in switch exit filter try process catch ' + - 'hidden static' + keyword: 'if else foreach return do while until elseif begin for trap data dynamicparam ' + + 'end break throw param continue finally in switch exit filter try process catch ' + + 'hidden static parameter validate[A-Z]+' } var BACKTICK_ESCAPE = { @@ -40,7 +43,9 @@ module.exports = function(hljs) { var VAR = { className: 'variable', variants: [ - {begin: /\$[\w\d][\w\d_:]*/} + { begin: /\$\B/ }, + { className: 'keyword', begin: /\$this/ }, + { begin: /\$[\w\d][\w\d_:]*/ } ] } @@ -99,49 +104,65 @@ module.exports = function(hljs) { var CMDLETS = { className: 'built_in', variants: [ - { begin: '('.concat( VALID_VERBS, ')+(-)[\\w\\d]+') }, - { className: 'deletion', begin: /[\w\d]+(-)[\w\d]+/ } + { begin: '('.concat(VALID_VERBS, ')+(-)[\\w\\d]+') }, + // Invalid cmdlets! + { className: 'subst', begin: /[\w\d]+(-)[\w\d]+/ } ] } var PS_CLASS = { className: 'class', beginKeywords: 'class enum', end: /[{]/, excludeEnd: true, - contains: [ - { beginKeywords: ':' }, - hljs.TITLE_MODE - ] + contains: [hljs.TITLE_MODE] } - var PS_FUNCTION = { + var PS_FUNCTION = { className: 'keyword', begin: /function\s+/, end: /([^A-Z0-9-])/, excludeEnd: true, contains: [ CMDLETS, - { className: 'deletion', begin: /[\w\d]+/ } + // Invalid function names! + { className: 'subst', begin: /[\w\d]+/ } ] } - var PS_USING = { + // Using statment, plus type, plus assembly name. + var PS_USING = { className: 'keyword', begin: /using\s/, end: /$/, contains: [ QUOTE_STRING, APOS_STRING, { className: 'type', begin: /(assembly|command|module|namespace|type)/ }, - { className: 'symbol', begin: /\S+/ } + { className: 'meta', begin: /\S+/ } ] } - var PS_ARGUMENTS = { + // Comperison operators & function named parameters. + var PS_ARGUMENTS = { variants: [ - { begin: '('.concat( COMPARISON_OPERATORS, ')\\b') }, - { className: 'literal', begin: /(-)[\w\d]+/ }, + // PS literals are pretty verbose so it's a good idea to accent them a bit. + { className: 'subst', begin: '('.concat(COMPARISON_OPERATORS, ')\\b') }, + { className: 'literal', begin: /(-)[\w\d]+/ } ] } - var STATIC_DELIMITER = { className: 'deletion', begin: /::/ } + var STATIC_MEMBER = { + className: 'selector-tag', + begin: /::\w+\b/, end: /$/, + returnBegin: true, + contains: [ + { className: 'attribute', begin: /\w+/, endsParent: true } + ] + } + + var HASH_SIGNS = { + className: 'selector-tag', + begin: /\@\B/ + + } + var PS_NEW_OBJECT_TYPE = { className: 'built_in', @@ -149,30 +170,33 @@ module.exports = function(hljs) { returnBegin: true, contains: [ { begin: /$/, endsParent: true }, - { className: 'symbol', begin: /\s([\w\.])+/, endsParent: true } + { className: 'meta', begin: /\s([\w\.])+/, endsParent: true } ] } - var PS_CLASS_CONSTRUCTOR = { - className: 'keyword', - //begin: /^\s+[A-Z]+\s*?\([\s\S][\s]*?.*?[^]*?\)\s\{/gm, end: /{/, - //begin: /^[ ]+[A-Z]+[ ]+\(.*?\)\s*?\{/, end: /{/, - //begin: /(^[ ]*?|\.)[A-Z]+\s*?\([\s\S]*?\)/, end: /$/, - //begin: /(^[ ]*?)[A-Z]+\s*?\([\s\S]*?\)/, end: /$/, - begin: /[A-Z]+\s*?\([\s\S]*?\)/, end: /$/, + // It's a very general rule so I'll narrow it a bit with some strict boundaries + // to avoid any possible false-positive collisions! + var PS_METHODS = { + className: 'name', + begin: /[\w]+[ ]??\(/, end: /$/, returnBegin: true, - contains: [ + { + className: 'keyword', begin: '('.concat( + KEYWORDS.keyword.toString().replace(/\s/g, '|' + ), ')\\b'), + endsParent: true + }, { className: 'built_in', begin: /[\w]+\b/, - endsParent: true, + endsParent: true } ] } - var GENTLEMANS_SET =[ - STATIC_DELIMITER, - // PS_CLASS_CONSTRUCTOR, + var GENTLEMANS_SET = [ + STATIC_MEMBER, + PS_METHODS, PS_COMMENT, BACKTICK_ESCAPE, hljs.NUMBER_MODE, @@ -181,23 +205,21 @@ module.exports = function(hljs) { PS_NEW_OBJECT_TYPE, CMDLETS, VAR, - LITERAL + LITERAL, + HASH_SIGNS ] - var PS_TYPE = { + var PS_TYPE = { className: 'no-markup', begin: /\[/, end: /\]/, excludeBegin: true, excludeEnd: true, contains: GENTLEMANS_SET.concat( 'self', - { className: 'symbol', begin: /[\.\w\d]+/ }, + { className: 'meta', begin: /[\.\w\d]+/ } ) } - - - return { aliases: ['ps'], lexemes: /-?[A-z\.\-]+/, @@ -208,8 +230,7 @@ module.exports = function(hljs) { PS_FUNCTION, PS_USING, PS_ARGUMENTS, - PS_TYPE, - + PS_TYPE ) } } From cafe56129a1401b99ae68959c7a3175ad48e7704 Mon Sep 17 00:00:00 2001 From: G8t Guy Date: Wed, 14 Dec 2016 20:10:13 +0500 Subject: [PATCH 6/6] Sync with master. --- AUTHORS.en.txt | 3 +-- AUTHORS.ru.txt | 2 +- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/AUTHORS.en.txt b/AUTHORS.en.txt index 88db0c2cf4..c8d1c81bdd 100644 --- a/AUTHORS.en.txt +++ b/AUTHORS.en.txt @@ -233,5 +233,4 @@ Contributors: - Kenton Hamaluik - Marvin Saignat - Michael Rodler -- G8t Guy - +- G8t Guy \ No newline at end of file diff --git a/AUTHORS.ru.txt b/AUTHORS.ru.txt index 45fa0c8750..3f3d7617bc 100644 --- a/AUTHORS.ru.txt +++ b/AUTHORS.ru.txt @@ -1,4 +1,4 @@ -Подсветка синтаксиса с автоопределением языка. +Подсветка синтаксиса с автоопределением языка. URL: https://highlightjs.org/