From acb7e767c116599b80db390a09db0941b752fcec Mon Sep 17 00:00:00 2001 From: idleberg <jan@idleberg.com> Date: Thu, 24 Sep 2015 15:22:21 +0200 Subject: [PATCH] [nsis mode] Add --- mode/index.html | 1 + mode/nsis/index.html | 62 +++++++++++++++++++++++++++++++++++++++++++ mode/nsis/nsis.js | 63 ++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 126 insertions(+) create mode 100644 mode/nsis/index.html create mode 100644 mode/nsis/nsis.js diff --git a/mode/index.html b/mode/index.html index 3e1230900..044dee7fd 100644 --- a/mode/index.html +++ b/mode/index.html @@ -88,6 +88,7 @@ option.</p> <li><a href="modelica/index.html">Modelica</a></li> <li><a href="mumps/index.html">MUMPS</a></li> <li><a href="nginx/index.html">Nginx</a></li> + <li><a href="nsis/index.html">NSIS</a></li> <li><a href="ntriples/index.html">NTriples</a></li> <li><a href="clike/index.html">Objective C</a></li> <li><a href="mllike/index.html">OCaml</a></li> diff --git a/mode/nsis/index.html b/mode/nsis/index.html new file mode 100644 index 000000000..a1d7aaa58 --- /dev/null +++ b/mode/nsis/index.html @@ -0,0 +1,62 @@ +<!doctype html> + +<title>CodeMirror: NSIS mode</title> +<meta charset="utf-8"/> +<link rel=stylesheet href="../../doc/docs.css"> + +<link rel=stylesheet href=../../lib/codemirror.css> +<script src=../../lib/codemirror.js></script> +<script src="../../addon/mode/simple.js"></script> +<script src="../../addon/edit/matchbrackets.js"></script> +<script src=nsis.js></script> +<style type=text/css> + .CodeMirror {border-top: 1px solid black; border-bottom: 1px solid black;} +</style> +<div id=nav> + <a href="http://codemirror.net"><h1>CodeMirror</h1><img id=logo src="../../doc/logo.png"></a> + + <ul> + <li><a href="../../index.html">Home</a> + <li><a href="../../doc/manual.html">Manual</a> + <li><a href="https://github.com/codemirror/codemirror">Code</a> + </ul> + <ul> + <li><a href="../index.html">Language modes</a> + <li><a class=active href="#">NSIS</a> + </ul> +</div> + +<article> +<h2>NSIS mode</h2> + + +<textarea id=code> +; This is a comment +!ifdef ERROR + !error "Something went wrong" +!endif + +OutFile "demo.exe" +RequestExecutionLevel user + +!include "LogicLib.nsh" + +Section -mandatory + ${If} 1 > 0 + MessageBox MB_OK "Hello world" + ${EndIf} +SectionEnd +</textarea> + +<script> + var editor = CodeMirror.fromTextArea(document.getElementById('code'), { + mode: 'nsis', + indentWithTabs: true, + smartIndent: true, + lineNumbers: true, + matchBrackets: true + }); +</script> + +<p><strong>MIME types defined:</strong> <code>text/x-nsis</code>.</p> +</article> diff --git a/mode/nsis/nsis.js b/mode/nsis/nsis.js new file mode 100644 index 000000000..3960b2e45 --- /dev/null +++ b/mode/nsis/nsis.js @@ -0,0 +1,63 @@ +// CodeMirror, copyright (c) by Marijn Haverbeke and others +// Distributed under an MIT license: http://codemirror.net/LICENSE + +// Author: Jan T. Sott (http://github.com/idleberg) + +(function(mod) { + if (typeof exports == "object" && typeof module == "object") // CommonJS + mod(require("../../lib/codemirror"), require("../../addon/mode/simple")); + else if (typeof define == "function" && define.amd) // AMD + define(["../../lib/codemirror", "../../addon/mode/simple"], mod); + else // Plain browser env + mod(CodeMirror); +})(function(CodeMirror) { +"use strict"; + +CodeMirror.defineSimpleMode("nsis",{ + start:[ + // Numbers + {regex: /(?:[+-]?)(?:0x[\d,a-f]+)|(?:0o[0-7]+)|(?:0b[0,1]+)|(?:\d+.?\d*)/, token: "number"}, + // Compile Time Commands + {regex: /(?:\!(include|addincludedir|addplugindir|appendfile|cd|delfile|echo|error|execute|packhdr|finalize|getdllversion|system|tempfile|warning|verbose|define|undef|insertmacro|makensis|searchparse|searchreplace))\b/, token: "keyword"}, + // Conditional Compilation + {regex: /(?:\!(if|ifdef|ifmacrodef|ifmacrondef|ifndef|macro))\b/, token: "keyword", indent: true}, + {regex: /(?:\!(else|endif|macroend))\b/, token: "keyword", dedent: true}, + // Runtime Commands + {regex: /(?:Abort|AddBrandingImage|AddSize|AllowRootDirInstall|AllowSkipFiles|AutoCloseWindow|BGFont|BGGradient|BrandingText|BringToFront|Call|CallInstDLL|Caption|ChangeUI|CheckBitmap|ClearErrors|CompletedText|ComponentText|CopyFiles|CRCCheck|CreateDirectory|CreateFont|CreateShortCut|Delete|DeleteINISec|DeleteINIStr|DeleteRegKey|DeleteRegValue|DetailPrint|DetailsButtonText|DirText|DirVar|DirVerify|EnableWindow|EnumRegKey|EnumRegValue|Exch|Exec|ExecShell|ExecWait|ExpandEnvStrings|File|FileBufSize|FileClose|FileErrorText|FileOpen|FileRead|FileReadByte|FileReadUTF16LE|FileReadWord|FileWriteUTF16LE|FileSeek|FileWrite|FileWriteByte|FileWriteWord|FindClose|FindFirst|FindNext|FindWindow|FlushINI|GetCurInstType|GetCurrentAddress|GetDlgItem|GetDLLVersion|GetDLLVersionLocal|GetErrorLevel|GetFileTime|GetFileTimeLocal|GetFullPathName|GetFunctionAddress|GetInstDirError|GetLabelAddress|GetTempFileName|Goto|HideWindow|Icon|IfAbort|IfErrors|IfFileExists|IfRebootFlag|IfSilent|InitPluginsDir|InstallButtonText|InstallColors|InstallDir|InstallDirRegKey|InstProgressFlags|InstType|InstTypeGetText|InstTypeSetText|IntCmp|IntCmpU|IntFmt|IntOp|IsWindow|LangString|LicenseBkColor|LicenseData|LicenseForceSelection|LicenseLangString|LicenseText|LoadLanguageFile|LockWindow|LogSet|LogText|ManifestDPIAware|ManifestSupportedOS|MessageBox|MiscButtonText|Name|Nop|OutFile|Page|PageCallbacks|Pop|Push|Quit|ReadEnvStr|ReadINIStr|ReadRegDWORD|ReadRegStr|Reboot|RegDLL|Rename|RequestExecutionLevel|ReserveFile|Return|RMDir|SearchPath|SectionGetFlags|SectionGetInstTypes|SectionGetSize|SectionGetText|SectionIn|SectionSetFlags|SectionSetInstTypes|SectionSetSize|SectionSetText|SendMessage|SetAutoClose|SetBrandingImage|SetCompress|SetCompressor|SetCompressorDictSize|SetCtlColors|SetCurInstType|SetDatablockOptimize|SetDateSave|SetDetailsPrint|SetDetailsView|SetErrorLevel|SetErrors|SetFileAttributes|SetFont|SetOutPath|SetOverwrite|SetPluginUnload|SetRebootFlag|SetRegView|SetShellVarContext|SetSilent|ShowInstDetails|ShowUninstDetails|ShowWindow|SilentInstall|SilentUnInstall|Sleep|SpaceTexts|StrCmp|StrCmpS|StrCpy|StrLen|SubCaption|Unicode|UninstallButtonText|UninstallCaption|UninstallIcon|UninstallSubCaption|UninstallText|UninstPage|UnRegDLL|Var|VIAddVersionKey|VIFileVersion|VIProductVersion|WindowIcon|WriteINIStr|WriteRegBin|WriteRegDWORD|WriteRegExpandStr|WriteRegStr|WriteUninstaller|XPStyle)\b/, token: "keyword"}, + {regex: /\b(?:Function|PageEx|Section|SectionGroup)\b/, token: "keyword", indent: true}, + {regex: /\b(?:FunctionEnd|PageExEnd|SectionEnd|SectionGroupEnd)\b/, token: "keyword", dedent: true}, + // Options + {regex: /\b(?:ARCHIVE|FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_HIDDEN|FILE_ATTRIBUTE_NORMAL|FILE_ATTRIBUTE_OFFLINE|FILE_ATTRIBUTE_READONLY|FILE_ATTRIBUTE_SYSTEM|FILE_ATTRIBUTE_TEMPORARY|HIDDEN|HKCC|HKCR|HKCU|HKDD|HKEY_CLASSES_ROOT|HKEY_CURRENT_CONFIG|HKEY_CURRENT_USER|HKEY_DYN_DATA|HKEY_LOCAL_MACHINE|HKEY_PERFORMANCE_DATA|HKEY_USERS|HKLM|HKPD|HKU|IDABORT|IDCANCEL|IDD_DIR|IDD_INST|IDD_INSTFILES|IDD_LICENSE|IDD_SELCOM|IDD_UNINST|IDD_VERIFY|IDIGNORE|IDNO|IDOK|IDRETRY|IDYES|MB_ABORTRETRYIGNORE|MB_DEFBUTTON1|MB_DEFBUTTON2|MB_DEFBUTTON3|MB_DEFBUTTON4|MB_ICONEXCLAMATION|MB_ICONINFORMATION|MB_ICONQUESTION|MB_ICONSTOP|MB_OK|MB_OKCANCEL|MB_RETRYCANCEL|MB_RIGHT|MB_RTLREADING|MB_SETFOREGROUND|MB_TOPMOST|MB_USERICON|MB_YESNO|MB_YESNOCANCEL|NORMAL|OFFLINE|READONLY|SHCTX|SHELL_CONTEXT|SW_HIDE|SW_SHOWDEFAULT|SW_SHOWMAXIMIZED|SW_SHOWMINIMIZED|SW_SHOWNORMAL|SYSTEM|TEMPORARY)\b/, token: "atom"}, + {regex: /\b(?:admin|all|auto|both|bottom|bzip2|components|current|custom|directory|force|hide|highest|ifdiff|ifnewer|instfiles|lastused|leave|left|license|listonly|lzma|nevershow|none|normal|notset|right|show|silent|silentlog|textonly|top|try|un\.components|un\.custom|un\.directory|un\.instfiles|un\.license|uninstConfirm|user|Win10|Win7|Win8|WinVista|zlib)\b/, token: "builtin"}, + + // LogicLib + {regex: /\$\{(?:End(If|Unless|While)|Loop(?:Until)|Next)\}/, token: "variable-2", dedent: true}, + {regex: /\$\{(?:Do(Until|While)|Else(?:If(?:Not)?)?|For(?:Each)?|(?:(?:And|Else|Or)?If(?:Cmd|Not|Then)?|Unless)|While)\}/, token: "variable-2", indent: true}, + + // Line Comment + {regex: /(#|;).*/, token: "comment"}, + // Block Comment + {regex: /\/\*/, token: "comment", next: "comment"}, + // Operator + {regex: /[-+\/*=<>!]+/, token: "operator"}, + // Variable + {regex: /\$[\w]+/, token: "variable"}, + // Constant + {regex: /\${[\w]+}/,token: "variable-2"}, + // Language String + {regex: /\$\([\w]+\)/,token: "variable-3"} + ], + comment: [ + {regex: /.*?\*\//, token: "comment", next: "start"}, + {regex: /.*/, token: "comment"} + ], + meta: { + electricInput: /^\s*(FunctionEnd|PageExEnd|SectionEnd|SectionGroupEnd|(\!(endif|macroend))|\$\{(End(If|Unless|While)|Loop(Until)|Next)\})$/, + blockCommentStart: "/*", + blockCommentEnd: "*/", + lineComment: ["#", ";"] + } +}); + +CodeMirror.defineMIME("text/x-nsis", "nsis"); +}); -- GitLab