Kaydet (Commit) 4c3730ca authored tarafından Igor Shaula's avatar Igor Shaula Kaydeden (comit) Matthew Brush

LexPowerShell fixes and improvements

* fix here-string highlighting
* add doccomment keyword highlighting
* add #region folding

Closes #132
üst df589a9d
......@@ -4,7 +4,10 @@
default=default
comment=comment
commentstream=comment_doc
commentdockeyword=comment_doc_keyword
string=string
here_string=string
here_character=character
character=character
number=number
variable=type
......@@ -22,6 +25,7 @@ keywords=begin break catch continue default do else elseif end filter finally fo
cmdlets=add-computer add-content add-history add-member add-pssnapin add-type checkpoint-computer clear-content clear-eventlog clear-history 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-psbreakpoint disable-psremoting disable-pssessionconfiguration disable-wsmancredssp disconnect-pssession disconnect-wsman enable-computerrestore enable-psbreakpoint enable-psremoting enable-pssessionconfiguration enable-wsmancredssp enter-pssession exit-pssession export-alias export-cimcommand 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-help get-history get-host get-hotfix get-item get-itemproperty get-job 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-service get-tracesource get-transaction get-typedata get-uiculture get-unique get-variable get-winevent get-wmiobject get-wsmancredssp get-wsmaninstance group-object import-alias import-clixml import-counter import-csv import-localizeddata import-module import-pssession 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-item new-itemproperty new-module new-modulemanifest new-object new-psdrive new-pssession new-pssessionconfigurationfile new-pssessionoption new-pstransportoption 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 receive-pssession register-engineevent register-jobevent register-objectevent register-pssessionconfiguration register-wmievent remove-computer remove-event remove-eventlog remove-item remove-itemproperty remove-job 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-location set-psbreakpoint set-psdebug set-pssessionconfiguration 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 test-wsman trace-command unblock-file undo-transaction unregister-event unregister-pssessionconfiguration 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
aliases=ac asnp cat cd chdir clc clear clhy cli clp cls clv cnsn compare copy cp cpi cpp cvpa dbp del diff dir dnsn ebp echo epal epcsv epsn erase etsn exsn fc fl ft fw gal gbp gc gci gcm gcs gdr ghy gi gjb gl gm gmo gp gps 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 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 si sl sleep sls sort sp spjb spps spsv start sujb sv swmi tee type wjb write
functions=clear-host get-verb help importsystemmodules mkdir more oss param parameter prompt psedit tabexpansion2
docComment=component description example externalhelp forwardhelpcategory forwardhelptargetname functionality inputs link notes outputs parameter remotehelprunspace role synopsis
user1=
[settings]
......
......@@ -40,6 +40,7 @@ static void ColourisePowerShellDoc(unsigned int startPos, int length, int initSt
WordList &keywords3 = *keywordlists[2];
WordList &keywords4 = *keywordlists[3];
WordList &keywords5 = *keywordlists[4];
WordList &keywords6 = *keywordlists[5];
styler.StartAt(startPos);
......@@ -52,9 +53,26 @@ static void ColourisePowerShellDoc(unsigned int startPos, int length, int initSt
sc.SetState(SCE_POWERSHELL_DEFAULT);
}
} else if (sc.state == SCE_POWERSHELL_COMMENTSTREAM) {
if(sc.atLineStart) {
while(IsASpaceOrTab(sc.ch)) {
sc.Forward();
}
if (sc.ch == '.' && IsAWordChar(sc.chNext)) {
sc.SetState(SCE_POWERSHELL_COMMENTDOCKEYWORD);
}
}
if (sc.ch == '>' && sc.chPrev == '#') {
sc.ForwardSetState(SCE_POWERSHELL_DEFAULT);
}
} else if (sc.state == SCE_POWERSHELL_COMMENTDOCKEYWORD) {
if(!IsAWordChar(sc.ch)) {
char s[100];
sc.GetCurrentLowered(s, sizeof(s));
if (!keywords6.InList(s + 1)) {
sc.ChangeState(SCE_POWERSHELL_COMMENTSTREAM);
}
sc.SetState(SCE_POWERSHELL_COMMENTSTREAM);
}
} else if (sc.state == SCE_POWERSHELL_STRING) {
// This is a doubles quotes string
if (sc.ch == '\"') {
......@@ -65,6 +83,18 @@ static void ColourisePowerShellDoc(unsigned int startPos, int length, int initSt
if (sc.ch == '\'') {
sc.ForwardSetState(SCE_POWERSHELL_DEFAULT);
}
} else if (sc.state == SCE_POWERSHELL_HERE_STRING) {
// This is a doubles quotes here-string
if (sc.atLineStart && sc.ch == '\"' && sc.chNext == '@') {
sc.Forward(2);
sc.SetState(SCE_POWERSHELL_DEFAULT);
}
} else if (sc.state == SCE_POWERSHELL_HERE_CHARACTER) {
// This is a single quote here-string
if (sc.atLineStart && sc.ch == '\'' && sc.chNext == '@') {
sc.Forward(2);
sc.SetState(SCE_POWERSHELL_DEFAULT);
}
} else if (sc.state == SCE_POWERSHELL_NUMBER) {
if (!IsADigit(sc.ch)) {
sc.SetState(SCE_POWERSHELL_DEFAULT);
......@@ -107,6 +137,10 @@ static void ColourisePowerShellDoc(unsigned int startPos, int length, int initSt
sc.SetState(SCE_POWERSHELL_STRING);
} else if (sc.ch == '\'') {
sc.SetState(SCE_POWERSHELL_CHARACTER);
} else if (sc.ch == '@' && sc.chNext == '\"') {
sc.SetState(SCE_POWERSHELL_HERE_STRING);
} else if (sc.ch == '@' && sc.chNext == '\'') {
sc.SetState(SCE_POWERSHELL_HERE_CHARACTER);
} else if (sc.ch == '$') {
sc.SetState(SCE_POWERSHELL_VARIABLE);
} else if (IsADigit(sc.ch) || (sc.ch == '.' && IsADigit(sc.chNext))) {
......@@ -159,11 +193,23 @@ static void FoldPowerShellDoc(unsigned int startPos, int length, int initStyle,
levelNext--;
}
} else if (foldComment && style == SCE_POWERSHELL_COMMENTSTREAM) {
if (stylePrev != SCE_POWERSHELL_COMMENTSTREAM) {
if (stylePrev != SCE_POWERSHELL_COMMENTSTREAM && stylePrev != SCE_POWERSHELL_COMMENTDOCKEYWORD) {
levelNext++;
} else if (styleNext != SCE_POWERSHELL_COMMENTSTREAM) {
} else if (styleNext != SCE_POWERSHELL_COMMENTSTREAM && styleNext != SCE_POWERSHELL_COMMENTDOCKEYWORD) {
levelNext--;
}
} else if (foldComment && style == SCE_POWERSHELL_COMMENT) {
if (ch == '#') {
unsigned int j = i + 1;
while ((j < endPos) && IsASpaceOrTab(styler.SafeGetCharAt(j))) {
j++;
}
if (styler.Match(j, "region")) {
levelNext++;
} else if (styler.Match(j, "endregion")) {
levelNext--;
}
}
}
if (!IsASpace(ch))
visibleChars++;
......@@ -194,6 +240,7 @@ static const char * const powershellWordLists[] = {
"Aliases",
"Functions",
"User1",
"DocComment",
0
};
......
......@@ -1160,20 +1160,23 @@ static const HLStyle highlighting_styles_PO[] =
#define highlighting_lexer_POWERSHELL SCLEX_POWERSHELL
static const HLStyle highlighting_styles_POWERSHELL[] =
{
{ SCE_POWERSHELL_DEFAULT, "default", FALSE },
{ SCE_POWERSHELL_COMMENT, "comment", FALSE },
{ SCE_POWERSHELL_STRING, "string", FALSE },
{ SCE_POWERSHELL_CHARACTER, "character", FALSE },
{ SCE_POWERSHELL_NUMBER, "number", FALSE },
{ SCE_POWERSHELL_VARIABLE, "variable", FALSE },
{ SCE_POWERSHELL_OPERATOR, "operator", FALSE },
{ SCE_POWERSHELL_IDENTIFIER, "identifier", FALSE },
{ SCE_POWERSHELL_KEYWORD, "keyword", FALSE },
{ SCE_POWERSHELL_CMDLET, "cmdlet", FALSE },
{ SCE_POWERSHELL_ALIAS, "alias", FALSE },
{ SCE_POWERSHELL_FUNCTION, "function", FALSE },
{ SCE_POWERSHELL_USER1, "user1", FALSE },
{ SCE_POWERSHELL_COMMENTSTREAM, "commentstream", FALSE },
{ SCE_POWERSHELL_DEFAULT, "default", FALSE },
{ SCE_POWERSHELL_COMMENT, "comment", FALSE },
{ SCE_POWERSHELL_STRING, "string", FALSE },
{ SCE_POWERSHELL_CHARACTER, "character", FALSE },
{ SCE_POWERSHELL_NUMBER, "number", FALSE },
{ SCE_POWERSHELL_VARIABLE, "variable", FALSE },
{ SCE_POWERSHELL_OPERATOR, "operator", FALSE },
{ SCE_POWERSHELL_IDENTIFIER, "identifier", FALSE },
{ SCE_POWERSHELL_KEYWORD, "keyword", FALSE },
{ SCE_POWERSHELL_CMDLET, "cmdlet", FALSE },
{ SCE_POWERSHELL_ALIAS, "alias", FALSE },
{ SCE_POWERSHELL_FUNCTION, "function", FALSE },
{ SCE_POWERSHELL_USER1, "user1", FALSE },
{ SCE_POWERSHELL_COMMENTSTREAM, "commentstream", FALSE },
{ SCE_POWERSHELL_HERE_STRING, "here_string", FALSE },
{ SCE_POWERSHELL_HERE_CHARACTER, "here_character", FALSE },
{ SCE_POWERSHELL_COMMENTDOCKEYWORD, "commentdockeyword", FALSE },
};
static const HLKeyword highlighting_keywords_POWERSHELL[] =
{
......@@ -1182,6 +1185,7 @@ static const HLKeyword highlighting_keywords_POWERSHELL[] =
{ 2, "aliases", FALSE },
{ 3, "functions", FALSE },
{ 4, "user1", FALSE },
{ 5, "docComment", FALSE },
};
#define highlighting_properties_POWERSHELL EMPTY_PROPERTIES
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment