'*******************************************************************************
' EverEdit Syntax File
' Language:  	NSIS
' Maintainer:	gfm688  
' History:
' 	2012/10/28 First Version
'   2013/02/26 Modify: FoldText/IndentText add IfNot
'*******************************************************************************
Include(".\const.mac")

Set nsi=CreateParser()
nsi.AddSnippet "nsis.snippet"

'Comment
nsi.AddRegion(nsi.CreateRegion(COLOR_COMMENT1, "+#+", "$", false))
nsi.AddRegion((nsi.CreateRegion(COLOR_COMMENT1, "+;+", "$", false)))
nsi.AddRegion(nsi.CreateRegion(COLOR_COMMENT2, "+/*+", "+*/+", false))

'String
Set rString1=nsi.CreateRegion(COLOR_STRING1, "(?<!\$\\)'", "(?<!\$\\)'|(?<!\\\s*)$", false)
Set rString2=nsi.CreateRegion(COLOR_STRING2, "(?<!\$\\)""", "(?<!\$\\)""|(?<!\\\s*)$", false)
Set rString3=nsi.CreateRegion(COLOR_STRING1, "(?<!\$\\)`", "(?<!\$\\)`|(?<!\\\s*)$", false)
nsi.AddRegion(rString1)
nsi.AddRegion(rString2)
nsi.AddRegion(rString3)

'Number
nsi.AddItem(nsi.CreateItem(COLOR_NUMBER, "\b(\d+|0x([:xdigit:]+))\b", false))

'Reserved word
Set wWord=nsi.CreateWord(COLOR_WORD1, "Abort AddBrandingImage AddSize AutoCloseWindow BGFont BGGradient BrandingText BringToFront Call CallInstDLL Caption ChangeUI ClearErrors ComponentText GetDLLVersion GetDLLVersionLocal GetFileTime GetFileTimeLocal GetFontVersion GetFontVersionLocal GetFontName GetFontNameLocal CopyFiles CRCCheck CreateDirectory CreateFont CreateShortCut SetDatablockOptimize DeleteINISec DeleteINIStr DeleteRegKey DeleteRegValue Delete DetailPrint DirText DirShow DirVar DirVerify GetInstDirError AllowRootDirInstall CheckBitmap EnableWindow EnumRegKey EnumRegValue Exch Exec ExecWait ExecShell ExpandEnvStrings FindWindow FindClose FindFirst FindNext File FileBufSize FlushINI ReserveFile FileClose FileErrorText FileOpen FileRead FileWrite FileReadByte FileWriteByte FileReadUTF16LE FileWriteUTF16LE FileReadWord FileWriteWord FileSeek Function FunctionEnd GetDlgItem GetFullPathName GetTempFileName HideWindow Icon IfAbort IfErrors IfFileExists IfRebootFlag IfSilent InstallDirRegKey InstallColors InstallDir InstProgressFlags InstType IntOp IntCmp IntCmpU IntFmt IsWindow Goto LangString LangStringUP LicenseData LicenseForceSelection LicenseLangString LicenseText LicenseBkColor LoadLanguageFile LogSet LogText MessageBox Nop Name OutFile Page PageCallbacks PageEx PageExEnd Pop Push Quit ReadINIStr ReadRegDWORD ReadRegStr ReadEnvStr Reboot RegDLL Rename Return RMDir Section SectionEnd SectionIn SubSection SectionGroup SubSectionEnd SectionGroupEnd SearchPath SectionSetFlags SectionGetFlags SectionSetInstTypes SectionGetInstTypes SectionGetText SectionSetText SectionGetSize SectionSetSize GetCurInstType SetCurInstType InstTypeSetText InstTypeGetText SendMessage SetAutoClose SetCtlColors SetBrandingImage SetCompress SetCompressor SetCompressorDictSize SetCompressionLevel SetDateSave SetDetailsView SetDetailsPrint SetErrors SetErrorLevel GetErrorLevel SetFileAttributes SetFont SetOutPath SetOverwrite SetPluginUnload SetRebootFlag SetRegView SetShellVarContext SetSilent ShowInstDetails ShowUninstDetails ShowWindow SilentInstall SilentUnInstall Sleep StrCmp StrCmpS StrCpy StrLen SubCaption UninstallExeName UninstallCaption UninstallIcon UninstPage UninstallText UninstallSubCaption UnRegDLL WindowIcon WriteINIStr WriteRegBin WriteRegDWORD WriteRegStr WriteRegExpandStr WriteUninstaller XPStyle RequestExecutionLevel MiscButtonText DetailsButtonText UninstallButtonText InstallButtonText SpaceTexts CompletedText GetFunctionAddress GetLabelAddress GetCurrentAddress InitPluginsDir AllowSkipFiles Var VIAddVersionKey VIProductVersion LockWindow FindProc", false)
AddAutoCaseWord

Set wWord=nsi.CreateWord(COLOR_MACRO, "!AddPluginDir !AddIncludeDir !packhdr !system !execute !include !cd !if !ifdef !ifndef !endif !define !undef !else !echo !warning !error !verbose !macro !macroend !insertmacro !ifmacrodef !ifmacrondef !tempfile !delfile !appendfile !searchparse !searchreplace", false, "!")
AddAutoCaseWord

'Parameter
Set wWord=nsi.CreateWord(COLOR_WORD4, "custom license components directory instfiles uninstConfirm true false on off force show hide nevershow normal silent silentlog auto zlib bzip2 lzma try ifnewer manual alwaysoff RO SW_SHOWNORMAL SW_SHOWMAXIMIZED SW_SHOWMINIMIZED HKCR HKEY_CLASSES_ROOT HKLM HKEY_LOCAL_MACHINE HKCU HKEY_CURRENT_USER HKU HKEY_USERS HKCC HKEY_CURRENT_CONFIG HKDD HKEY_DYN_DATA HKPD HKEY_PERFORMANCE_DATA SHCTX FILE_ATTRIBUTE_NORMAL ARCHIVE FILE_ATTRIBUTE_ARCHIVE HIDDEN FILE_ATTRIBUTE_HIDDEN OFFLINE FILE_ATTRIBUTE_OFFLINE READONLY FILE_ATTRIBUTE_READONLY SYSTEM FILE_ATTRIBUTE_SYSTEM TEMPORARY FILE_ATTRIBUTE_TEMPORARY MB_OK MB_OKCANCEL MB_ABORTRETRYIGNORE MB_RETRYCANCEL MB_YESNO MB_YESNOCANCEL MB_ICONEXCLAMATION MB_ICONINFORMATION MB_ICONQUESTION MB_ICONSTOP MB_TOPMOST MB_SETFOREGROUND MB_RIGHT MB_DEFBUTTON1 MB_DEFBUTTON2 MB_DEFBUTTON3 MB_DEFBUTTON4 MB_RTLREADING IDABORT IDCANCEL IDIGNORE IDNO IDOK IDRETRY IDYES SW_HIDE current all none listonly textonly both lastused checkbox radiobuttons ifdiff leave transparent SET CUR END ALT CONTROL EXT SHIFT ProductName Comments CompanyName LegalCopyright FileDescription FileVersion ProductVersion InternalName LegalTrademarks OriginalFilename PrivateBuild SpecialBuild un.custom un.license un.components un.directory un.instfiles un.uninstConfirm Uninstall left right top bottom notext IDD_LICENSE IDD_DIR IDD_SELCOM IDD_INST IDD_INSTFILES IDD_UNINST IDD_VERIFY user highest admin", false, ".:")
AddAutoCaseWord

Set wWord=nsi.CreateWord(COLOR_WORD4, "/lang /TRIMLEFT /TRIMRIGHT /TRIMCENTER /windows /NOCUSTOM /CUSTOMSTRING /COMPONENTSONLYONCUSTOM /e /REBOOTOK /nonfatal /a /r /oname /ifempty /NOUNLOAD /FILESONLY /SHORT /ITALIC /UNDERLINE /STRIKE /TIMEOUT /IMGID /RESIZETOFIT /components /silent /SD /x /date /BRANDING /gray /SOLID /FINAL /math /file /utcdate /ignorecase /noerrors", false, "/")
AddAutoCaseWord

'Plugin call
nsi.AddItem(nsi.CreateItem(COLOR_WORD3, "\b\w+\:\:\w+\b", false))

'Variable
Set itemVar=nsi.CreateItem(COLOR_VAR, "(?<!\$(?=\$[^\\{]))\$(?!\\[^rnt""'`]|\$\\[rnt""'`])(\{\S+?(?<!\$\{[^}]*\$\{[^}]*)\}|\(\S+?(?<!\$\([^)]*\$\([^)]*)\)|R?\d|INSTDIR|OUTDIR|CMDLINE|LANGUAGE|PROGRAMFILES32|PROGRAMFILES64|PROGRAMFILES|COMMONFILES32|COMMONFILES64|COMMONFILES|DESKTOP|EXEDIR|EXEFILE|EXEPATH|WINDIR|SYSDIR|TEMP|STARTMENU|SMPROGRAMS|SMSTARTUP|QUICKLAUNCH|HWNDPARENT|PLUGINSDIR|DOCUMENTS|SENDTO|RECENT|FAVORITES|MUSIC|PICTURES|VIDEOS|NETHOOD|FONTS|TEMPLATES|APPDATA|LOCALAPPDATA|PRINTHOOD|INTERNET_CACHE|COOKIES|HISTORY|PROFILE|ADMINTOOLS|RESOURCES_LOCALIZED|CDBURN_AREA|[\w\.]*)", false)
nsi.AddItem(itemVar)
rString1.AddItem(itemVar)
rString2.AddItem(itemVar)
rString3.AddItem(itemVar)

Set wWord=nsi.CreateWord(COLOR_VAR, "$INSTDIR $OUTDIR $CMDLINE $LANGUAGE $PROGRAMFILES $PROGRAMFILES32 $PROGRAMFILES64 $COMMONFILES $COMMONFILES32 $COMMONFILES64 $DESKTOP $EXEDIR $EXEFILE $EXEPATH $WINDIR $SYSDIR $TEMP $STARTMENU $SMPROGRAMS $SMSTARTUP $QUICKLAUNCH $HWNDPARENT $PLUGINSDIR $DOCUMENTS $SENDTO $RECENT $FAVORITES $MUSIC $PICTURES $VIDEOS $NETHOOD $FONTS $TEMPLATES $APPDATA $LOCALAPPDATA $PRINTHOOD $INTERNET_CACHE $COOKIES $HISTORY $PROFILE $ADMINTOOLS $RESOURCES_LOCALIZED $CDBURN_AREA", false, "$")
AddAutoCaseWord

'Callback function
Set wWord=nsi.CreateWord(COLOR_DEFAULT, ".onGUIInit .onInit .onGUIEnd .onInstFailed .onInstSuccess .onMouseOverSection .onSelChange .onUserAbort .onVerifyInstDir .onRebootFailed un.onGUIInit un.onGUIEnd un.onInit un.onUninstFailed un.onUninstSuccess un.onUserAbort un.onRebootFailed", false, ".")
AddAutoCaseWord

Call nsi.FoldText("^\s*((Function|Section(Group)?|!(macro|if((macro)?n?(def)?)))\b|\$\{(If(Not)?|Unless|Do(While|Until)?|While|For(Each)?|Select|Switch)\}(\s|$))", false)
Call nsi.UnfoldText("^\s*(((Function|Section(Group)?|!macro)End|!endif)\b|\$\{(End(If|Unless|While|Select|Switch)|Loop(While|Until)?|Next)\}(\s|$))", false)

Call nsi.IndentText("^\s*((Function|Section(Group)?|!(macro|else|if((macro)?n?(def)?)))\b|\$\{((Or|And|Else)?(If(Not)?|Unless)|Do(While|Until)?|While|For(Each)?|Select|Switch|Case(\d|Else)?|Else)\})(\s|$)", false)
Call nsi.UnIndentText("^\s*(((Function|Section(Group)?|!macro)End|!endif)\b|(!else|\$\{((Or|And|Else)(If|Unless)|Case\d?)\})(?![\t ])|\$\{(End(If|Unless|While|Select|Switch)|Loop(While|Until)?|Next|(Case)?Else)\})", false)

Call nsi.SetPairs("{}()""""``''")

Call nsi.CommentLine(";")
Call nsi.CommentBlock("/*", "*/")

Sub AddAutoCaseWord()
	wWord.AutoCase=true
	nsi.AddWord(wWord)
End Sub
