Sublime Forum

Classic ASP syntax highlighting

#1

I have this legacy project that I have to support. It is written in classic ASP, using JavaScript as the language (instead of VBScript).

I see that the default Sublime Text 3 install makes some assumptions about how to highlight the syntax, but it’s kind of broken.

I am looking for a solution how I can configure the syntax highlighting for *.asp files that
a) recognizes where the code is (content between <% %> tags)
b) treats the code as JavaScript
c) uses the html highlighting for the code parts outside the code tags

If all those points can not be met, maybe at least the points a and b can?

0 Likes

#2

ah I guess you have a directive like <%@ language="Javascript" %> at the top of the page? you’re right that it currently has no effect on syntax highlighting in ST atm.
I suggest installing https://packagecontrol.io/packages/PackageResourceViewer, and then you should be able to, from the command palette, open the ASP package, HTML ASP sublime-syntax file and find the regular expressions for <% which will set a VBScript context. Change those to JavaScript, save, and you should be good to go.
Sorry for the vaguearities, I’m on mobile atm.

0 Likes

#3

Thanks, I got as far as opening the HTML-ASP.sublime-syntax file, but there are no any references to VBScript what I could then change to JScript or JavaScript.

0 Likes

#4

ah yeah, for some reason, whomever first wrote this syntax definition decided that VBScript == ASP, so they named and scoped it wrongly. The change you need to make is:

--- Shipped Packages/ASP/HTML-ASP.sublime-syntax    2017-12-02 10:49:22
+++ Packages/ASP/HTML-ASP.sublime-syntax    2018-08-22 10:26:13
@@ -44,17 +44,17 @@
 
   begin_embedded_asp:
     - meta_content_scope: source.asp.embedded.html
     - match: '(?=%>)'
       pop: true
-    - include: scope:source.asp
+    - include: scope:source.js
 
   begin_embedded_asp_expression:
     - meta_content_scope: source.asp.embedded.html
     - match: '(?=%>)'
       pop: true
-    - include: scope:source.asp#expression
+    - include: scope:source.js#expression-statement
 
   close_embedded_asp:
     - match: '%>'
       scope: punctuation.section.embedded.end.asp
       pop: true
0 Likes

#5

Great! This fixed that. ASP classic, of course, is the platform of yesterday, but if one has to write code for it, if you ask me, JScript (Microsoft’s version of JavaScript) is so much better choice than VBScript.

0 Likes