Improved ASP syntax for Sublime Text

Remark: I know, ASP is not a real programming language, but it is commonly used in this way, as it is synonym with "VBScript for dynamic web pages". So, in this context, when I refer to "ASP language" actually I'm referring to its synonym.

Description

 
I had the opportunity to use Sublime Text for editing some ASP/HTML code. I think it's an excellent editor for code developers. The syntax of each language is totally configurable, through related files in YAML format containing Ruby's Regular Expression. This allows to identify parts of code as logical concepts (Variables, Strings, etc.), thus you may assign different behaviours to these parts - for example, a different color.
Unfortunately, the default ASP syntax included in Sublime Text is very poor. Therefore, I decided to improve it and share for those who need it.

How to "install"

 
1. The first step is to add a packages manager to the editor. This addon is called Package Control and allows to manage Sublime Text's packages more friendly. I referred to https://packagecontrol.io/ for installing it.
2. Through Package Control, we need to add another package to the editor: PackageResourceViewer. Thus, use the command Package Control: Install Package that you can find in the command list (Tools > Command Palette) if step 1. was successfully done. Scroll down the list until you find PackageResourceViewer and click on it. Automatic installation will do the rest.
3. Command list (Tools > Command Palette) now should show a new command, PackageResourceViewer: Open Resource. Through this new command, select ASP and then ASP.sublime-syntax. The file with syntax rules will be opened. Press ESC to exit the command.
4. The opened file, ASP.sublime-syntax, contains syntax rules for ASP language. Now, you only need to substitute original text in the file with the following:
%YAML 1.2 --- # http://www.sublimetext.com/docs/3/syntax.html name: ASP comment: "ASP SCRIPTING SYNTAX - By Massimiliano Ginocchio: Version 1.1 (based on Version 1.0 by Rich Barton) Note: .asp is handled by asp/html" file_extensions: - asa scope: source.asp contexts: main: - include: core core: - include: other - include: braces-round - include: user-function-definition - include: comments - include: keywords - include: strings - include: supports - include: numerics - include: user-function-call - include: variables braces-round: - match: '\(|\)' scope: meta.brace.round.asp comments: - match: (').*$? scope: comment.line.apostrophe.asp captures: 1: punctuation.definition.comment.asp - match: (REM ).*$\n? scope: comment.line.rem.asp captures: 1: punctuation.definition.comment.asp keywords: - match: (?i:\b(If|Then|Else|ElseIf|End If|While|Wend|For|To|Each|In|Step|Case|Select|End Select|End with|Return|Continue|Do|Until|Loop|Next|With|Exit Do|Exit For|Exit Function|Exit Property|Exit Sub)\b) scope: keyword.control.asp - match: '=|>=|<|>|<|<>|\+|-|\*|\^|&|\b(?i:(Mod|And|Not|Or|Xor|Is))\b' scope: keyword.operator.asp - match: (?i:\b(Call|Class|Const|Dim|Redim|Function|Sub|Property|End Property|End sub|End Function|Set|Let|Get|New|Randomize|Option Explicit|On Error Resume Next|On Error GoTo)\b) scope: storage.type.asp - match: (?i:\b(Private|Public|Default)\b) scope: storage.modifier.asp - match: (?i:\b(Empty|False|Nothing|Null|True)\b) scope: constant.language.asp numerics: - match: '\b((0(x|X)[0-9a-fA-F]*)|(([0-9]+\.?[0-9]*)|(\.[0-9]+))((e|E)(\+|-)?[0-9]+)?)(L|l|UL|ul|u|U|F|f)?\b' scope: constant.numeric.asp other: - match: "," scope: meta.delimiter.comma.asp - match: (\(\s*\)) scope: meta.function-call.without-arguments.asp strings: - match: '"' captures: 0: punctuation.definition.string.begin.asp push: - meta_scope: string.quoted.double.asp - match: '"(?!")' captures: 0: punctuation.definition.string.end.asp pop: true - match: '""' scope: constant.character.escape.apostrophe.asp supports: - match: (?i:\b(Application|ObjectContext|Request|Response|Server|Session)\b) scope: support.class.asp - match: (?i:\b(Contents|StaticObjects|ClientCertificate|Cookies|Form|QueryString|ServerVariables)\b) scope: support.class.collection.asp - match: (?i:\b(TotalBytes|Buffer|CacheControl|Charset|ContentType|Expires|ExpiresAbsolute|IsClientConnected|PICS|Status|ScriptTimeout|CodePage|LCID|SessionID|Timeout)\b) scope: support.constant.asp - match: (?i:\b(BeginTrans|CommitTrans|RollbackTrans|Execute|Open|Close|EOF|BOF|MoveNext|MoveFirst|State|CommandTimeout|Fields|ActiveConnection|ConnectionTimeout|Update|RecordCount|CommandType|CursorType|LockType|Name|tables|type|Columns|DefinedSize)\b) scope: support.function.db.asp - match: (?i:\b(CreateFolder|FolderExists|DeleteFile|FileExists|GetFolder|SubFolders|Files|BinaryRead|Err|Number|Clear|Description|Lock|Unlock|SetAbort|SetComplete|BianryRead|AddHeader|AppendToLog|BinaryWrite|Clear|End|Flush|Redirect|Write|CreateObject|HTMLEncode|MapPath|URLEncode|Abandon|GetFile|OpenAsTextStream|AtEndOfStream|SkipLine|ReadLine)\b) scope: support.function.asp - match: (?i:\b(Application_OnEnd|Application_OnStart|OnTransactionAbort|OnTransactionCommit|Session_OnEnd|Session_OnStart|Class_Initialize|Class_Terminate)\b) scope: support.function.event.asp - match: (?i:\b(Array|Add|Asc|Atn|CBool|CByte|CCur|CDate|CDbl|Chr|CInt|CLng|Conversions|Cos|CreateObject|CSng|CStr|Date|DateAdd|DateDiff|DatePart|DateSerial|DateValue|Day|Derived|Math|Escape|Eval|Exists|Exp|Filter|FormatCurrency|FormatDateTime|FormatNumber|FormatPercent|GetLocale|GetObject|GetRef|Hex|Hour|InputBox|InStr|InStrRev|Int|Fix|IsArray|IsDate|IsEmpty|IsNull|IsNumeric|IsObject|Item|Items|Join|Keys|Count|LBound|LCase|Left|Len|LoadPicture|Log|LTrim|RTrim|Trim|Maths|Mid|Minute|Month|MonthName|MsgBox|Now|Oct|Remove|RemoveAll|Replace|RGB|Right|Rnd|Round|ScriptEngine|ScriptEngineBuildVersion|ScriptEngineMajorVersion|ScriptEngineMinorVersion|Second|SetLocale|Sgn|Sin|Space|Split|Sqr|StrComp|String|StrReverse|Tan|Time|Timer|TimeSerial|TimeValue|TypeName|UBound|UCase|Unescape|VarType|Weekday|WeekdayName|Year)\b) scope: support.function.vb.asp - match: (?i:\b(vbtrue|fvbalse|vbcr|vbcrlf|vbformfeed|vblf|vbnewline|vbnullchar|vbnullstring|vbtab|vbverticaltab|vbbinarycompare|vbtextcomparevbsunday|vbmonday|vbtuesday|vbwednesday|vbthursday|vbfriday|vbsaturday|vbusesystemdayofweek|vbfirstjan1|vbfirstfourdays|vbfirstfullweek|vbgeneraldate|vblongdate|vbshortdate|vblongtime|vbshorttime|vbobjecterror|vbEmpty|vbNull|vbInteger|vbLong|vbSingle|vbDouble|vbCurrency|vbDate|vbString|vbObject|vbError|vbBoolean|vbVariant|vbDataObject|vbDecimal|vbByte|vbArray)\b) scope: support.type.vb.asp user-function-call: - match: '(?i)([a-z_0-9]*[a-z_][a-z0-9_]*\s*)(\()' captures: 1: meta.function-call.asp 2: punctuation.definition.parameters.begin.asp user-function-definition: - match: '\s*((?i:function|sub))\s*([a-zA-Z_]\w*)\s*(\()([^)]*)(\)).*\n?' scope: meta.function.asp captures: 1: storage.type.function.asp 2: entity.name.function.asp 3: punctuation.definition.parameters.begin.asp 4: variable.parameter.function.asp 5: punctuation.definition.parameters.end.asp variables: - match: '[a-zA-Z_x7f-xff][a-zA-Z0-9_x7f-xff]*?\b' scope: variable.other.asp

Disclaimer

 
All software on this website is provided "AS IS" without any warranty, either expressed or implied, including, but not limited to, the implied warranties of merchantability and fitness for a particular purpose. The author will not be liable for any special, incidental, consequential or indirect damages due to loss of data or any other reason.
Propositive suggestions are welcome. You may contact me at: info@gmas.it
Torna su
Testi, immagini, filmati, software sono opera mia, salvo dove diversamente specificato.