From c89a00fd51f4c7b228bbfac719263f2f6452892b Mon Sep 17 00:00:00 2001 From: John Kane Date: Fri, 30 Sep 2011 01:00:15 +0100 Subject: [PATCH] Extended the binary operators. --- demo/docs/powershell.ps1 | 2 +- lib/ace/mode/powershell_highlight_rules.js | 18 +++++++++++++++--- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/demo/docs/powershell.ps1 b/demo/docs/powershell.ps1 index d3eb9875..f3a70bc1 100644 --- a/demo/docs/powershell.ps1 +++ b/demo/docs/powershell.ps1 @@ -6,7 +6,7 @@ function Hello($name) { function add($left, $right=4) { if ($right -ne 4) { return $left - } elseif ($left -eq $right) { + } elseif ($left -eq $null -and $right -eq 2) { return 3 } else { return 2 diff --git a/lib/ace/mode/powershell_highlight_rules.js b/lib/ace/mode/powershell_highlight_rules.js index 536b49c4..e1caf7c3 100644 --- a/lib/ace/mode/powershell_highlight_rules.js +++ b/lib/ace/mode/powershell_highlight_rules.js @@ -8,9 +8,19 @@ var TextHighlightRules = require("ace/mode/text_highlight_rules").TextHighlightR var PowershellHighlightRules = function() { var keywords = lang.arrayToMap( - ("function|if|else|elseif|switch|while|default|for|do|until|break|continue|foreach|return|filter|in|trap|throw|param|begin|process|end").split("|") + ("function|if|else|elseif|switch|while|default|for|do|until|break|continue|" + + "foreach|return|filter|in|trap|throw|param|begin|process|end").split("|") ); + var builtinFunctions = lang.arrayToMap( + ("Write-Host").split("|") + ); + + var binaryOperatorsRe = "eq|ne|ge|gt|lt|le|like|notlike|match|notmatch|replace|contains|notcontains|" + + "ieq|ine|ige|igt|ile|ilt|ilike|inotlike|imatch|inotmatch|ireplace|icontains|inotcontains|" + + "is|isnot|as|" + + "and|or|band|bor|not"; + // regexp must not have capturing parentheses. Use (?:) instead. // regexps are ordered -> the first match is used @@ -44,15 +54,17 @@ var PowershellHighlightRules = function() { token : function(value) { if (keywords.hasOwnProperty(value)) return "keyword"; + else if (builtinFunctions.hasOwnProperty(value)) + return "support.function"; else return "identifier"; }, // TODO: Unicode escape sequences // TODO: Unicode identifiers - regex : "[a-zA-Z_$][a-zA-Z0-9_$]*\\b" + regex : "[a-zA-Z_$][a-zA-Z0-9_$\\-]*\\b" }, { token : "keyword.operator", - regex : "\\-(?:" + "eq|ne|ge|gt|lt|le|like|notlike|match|notmatch|replace" + ")" + regex : "\\-(?:" + binaryOperatorsRe + ")" }, { token : "lparen", regex : "[[({]"