Adobe Dreamweaver - adding syntax highlighting for SQL

From NoskeWiki
Jump to: navigation, search

About

NOTE: This page is a daughter page of: Adobe Dreamweaver


Dreamweaver comes with a quite a few built-in mappings from file types to code syntax highlighting, but SQL isn't one of these. To add a new extension and syntax highlighting I suggest you first read the explanation here:

For the rest of this document I assume you've read the page above, and just tell you the raw code needed to add syntax highlighting for SQL - or more specifically postgreSQL.



Step 1) Make Sure SQL is in Dreamweaver's Recognized Extensions (Extensions.txt) -> this step not critical

Open: "C:\Program Files\Adobe\Adobe Dreamweaver CS5\configuration\Extensions.txt" (on Windows)
or: "/Users/anoske/Library/Application Support/Adobe/Dreamweaver CS5/en_US/Configuration/Extensions.txt" (on Mac)

and, if not already there (probably it already does), add this line:

SQL:SQL Files

NOTE: If you can't edit this file, try copying the file to your (Windows) desktop, editing there and then dragging back in. This step will only works if you have admin privileges.


Step 2) Mapping a File Extension to (MMDocumentTypes.xml) -> this step not critical

Open: "C:\Program Files\Adobe\Adobe Dreamweaver CS5\configuration\DocumentTypes\MMDocumentTypes.xml" (on Windows)
or: "/Applications/Adobe Dreamweaver CS5/Configuration/MMDocumentTypes.xml" (on Mac)

Add the following line of text after the 2nd last line, just before the "</documenttypes>" tag:

	<documenttype id="SQL" internaltype="Text" winfileextension="sql" macfileextension="sql" file="Default.sql" writebyteordermark="false" mimetype="text/sql">
		<TITLE>
			<MMString:loadString id="mmdocumenttypes_72" />
		</TITLE>
		<description>
			<MMString:loadString id="mmdocumenttypes_73" />
		</description>
	</documenttype>

IMPORTANT: The number in 'mmdocumenttypes_72' and 'mmdocumenttypes_73' should follow on from the numbers above it - so make sure you change them if necessary.



Step 3) Creating a new Syntax Color Scheme (CodeColoring.xml)

Open: "C:\Program Files\Adobe\Adobe Dreamweaver CS5\configuration\CodeColoring\CodeColoring.xml" (on Windows)
or: "/Users/anoske/Library/Application Support/Adobe/Dreamweaver CS5/en_US/Configuration/CodeColoring/CodeColoring.xml" (on Mac)

Then add the following line of text after the first line:

NOTE: You can add it further down, but it's a long document, so I suggest the start.

	<scheme MMString:name="SQL/scheme/name" id="SQL" doctypes="SQL" priority="50">
		<ignoreCase>Yes</ignoreCase>
		<ignoreTags>Yes</ignoreTags>
		<defaultText MMString:name="CodeColor_SQLDefaultText/defaultText/name" id="CodeColor_SQLDefaultText" />
		<commentStart MMString:name="CodeColor_SQLComment/commentStart/name" id="CodeColor_SQLComment"><![CDATA[/*]]></commentStart>
		<commentEnd><![CDATA[*/]]></commentEnd>
		<endOfLineComment>--</endOfLineComment>
		<stringStart MMString:name="CodeColor_SQLString/stringStart/name" id="CodeColor_SQLString"><![CDATA["]]></stringStart>
		<stringEnd><![CDATA["]]></stringEnd>
		<stringStart><![CDATA[']]></stringStart>
		<stringEnd><![CDATA[']]></stringEnd>
		<stringEsc><![CDATA[\]]></stringEsc>
		<brackets MMString:name="CodeColor_SQLBracket/brackets/name" id="CodeColor_SQLBracket"><![CDATA[{[()]}]]></brackets>
		<operators MMString:name="CodeColor_SQLOperator/operators/name" id="CodeColor_SQLOperator"><![CDATA[+-*/%<>!=]]></operators>
		<numbers MMString:name="CodeColor_SQLNumber/numbers/name" id="CodeColor_SQLNumber" />
		<idChar1>_$abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ</idChar1>
		<keywords MMString:name="CodeColoring/CodeColoring/CodeColor_SQLReservedWords/keywords/name" id="CodeColor_SQLReservedWords">
                        <!-- some of the most common: -->
			<keyword>ABORT</keyword>
			<keyword>ACTION</keyword>
			<keyword>AFTER</keyword>
			<keyword>ALTER</keyword>
			<keyword>BEFORE</keyword>
			<keyword>CONNECT</keyword>
			<keyword>COUNT</keyword>
			<keyword>CREATE</keyword>
			<keyword>DATABASE</keyword>
			<keyword>DEFAULT</keyword>
			<keyword>DELETE</keyword>
			<keyword>DROP</keyword>
			<keyword>EXISTS</keyword>
			<keyword>FOREIGN</keyword>
			<keyword>FROM</keyword>
			<keyword>GLOBAL</keyword>
			<keyword>GROUP</keyword>
			<keyword>IN</keyword>
			<keyword>INCREMENT</keyword>
			<keyword>INSERT</keyword>
			<keyword>INTO</keyword>
			<keyword>IS</keyword>
			<keyword>JOIN</keyword>
			<keyword>KEY</keyword>
			<keyword>PRIMARY</keyword>
			<keyword>SELECT</keyword>
			<keyword>TABLE</keyword>
			<keyword>UNION</keyword>
			<keyword>UNIQUE</keyword>
			<keyword>WHERE</keyword>
 
                        <!-- quite commonly used: -->
			<keyword>ACCESS</keyword>
			<keyword>ADMIN</keyword>
			<keyword>AGGREGATE</keyword>
			<keyword>ALIAS</keyword>
			<keyword>ALL</keyword>
			<keyword>ALWAYS</keyword>
			<keyword>ASSERTION</keyword>
			<keyword>ATOMIC</keyword>
			<keyword>ATTRIBUTE</keyword>
			<keyword>ATTRIBUTES</keyword>
			<keyword>BACKWARD</keyword>
			<keyword>BEGIN</keyword>
			<keyword>BOTH</keyword>
			<keyword>CARDINALITY</keyword>
			<keyword>CASCADE</keyword>
			<keyword>CASCADED</keyword>
			<keyword>CHECK</keyword>
			<keyword>CHECKED</keyword>
			<keyword>CLOSE</keyword>
			<keyword>CLUSTER</keyword>
			<keyword>COALESCE</keyword>
			<keyword>COBOL</keyword>
			<keyword>COLLATE</keyword>
			<keyword>COLLECT</keyword>
			<keyword>COLUMN</keyword>
			<keyword>COLUMN_NAME</keyword>
			<keyword>COMMENT</keyword>
			<keyword>COMMIT</keyword>
			<keyword>COMMITTED</keyword>
			<keyword>CONDITION</keyword>
			<keyword>CONSTRAINT</keyword>
			<keyword>CONTAINS</keyword>
			<keyword>COPY</keyword>
			<keyword>CREATEROLE</keyword>
			<keyword>CREATEUSER</keyword>
			<keyword>CROSS</keyword>
			<keyword>DEALLOCATE</keyword>
			<keyword>DECLARE</keyword>
			<keyword>DESC</keyword>
			<keyword>DESCRIBE</keyword>
			<keyword>DESTROY</keyword>
			<keyword>DESTRUCTOR</keyword>
			<keyword>DISCONNECT</keyword>
			<keyword>DISTINCT</keyword>
			<keyword>ENABLE</keyword>
			<keyword>FOR</keyword>
			<keyword>GET</keyword>
			<keyword>GROUPING</keyword>
			<keyword>IGNORE</keyword>
			<keyword>INDEX</keyword>
			<keyword>INNER</keyword>
			<keyword>INTERSECTION</keyword>
			<keyword>LEFT</keyword>
			<keyword>ON</keyword>
			<keyword>ROW</keyword>
			<keyword>SET</keyword>
			<keyword>WHEN</keyword>
			<keyword>VALUE</keyword>
			<keyword>VALUES</keyword>
 
                       <!-- less common: -->
			<keyword>ALLOCATE</keyword>
			<keyword>ASENSITIVE</keyword>
			<keyword>ASSIGNMENT</keyword>
			<keyword>ASYMMETRIC</keyword>
			<keyword>AUTHORIZATION</keyword>
			<keyword>CASE</keyword>
			<keyword>CAST</keyword>
			<keyword>CATALOG</keyword>
			<keyword>CHECKPOINT</keyword>
			<keyword>CLASS</keyword>
			<keyword>COMPLETION</keyword>
			<keyword>CONDITION_NUMBER</keyword>
			<keyword>CONNECTION</keyword>
			<keyword>CONNECTION_NAME</keyword>
			<keyword>CONTINUE</keyword>
			<keyword>CONVERSION</keyword>
			<keyword>CONVERT</keyword>
			<keyword>CORRESPONDING</keyword>
			<keyword>CURRENT</keyword>
			<keyword>CURRENT_DATE</keyword>
			<keyword>CURRENT_TIME</keyword>
			<keyword>CURRENT_TIMESTAMP</keyword>
			<keyword>CYCLE</keyword>
			<keyword>DESCRIPTOR</keyword>
			<keyword>DISPATCH</keyword>
			<keyword>DOMAIN</keyword>
			<keyword>EXISTING</keyword>
			<keyword>FILTER</keyword>
			<keyword>FORCE</keyword>
			<keyword>FREE</keyword>
			<keyword>FULL</keyword>
			<keyword>FUNCTION</keyword>
			<keyword>IMMEDIATE</keyword>
			<keyword>IMMUTABLE</keyword>
			<keyword>IMPLICIT</keyword>
			<keyword>INHERIT</keyword>
			<keyword>INHERITS</keyword>
			<keyword>INSTANCE</keyword>
			<keyword>INSTANTIABLE</keyword>
			<keyword>LOCK</keyword>
			<keyword>MATCH</keyword>
			<keyword>MODIFY</keyword>
			<keyword>NAME</keyword>
			<keyword>NAMES</keyword>
			<keyword>NESTING</keyword>
			<keyword>NULLABLE</keyword>
			<keyword>OBJECT</keyword>
			<keyword>OF</keyword>
			<keyword>OFFSET</keyword>
			<keyword>OPEN</keyword>
			<keyword>OUTER</keyword>
			<keyword>PASSWORD</keyword>
			<keyword>PRIVILEGES</keyword>
			<keyword>RECURSIVE</keyword>
			<keyword>REF</keyword>
			<keyword>REFERENCES</keyword>
			<keyword>REFERENCING</keyword>
			<keyword>RELEASE</keyword>
			<keyword>RENAME</keyword>
			<keyword>RESET</keyword>
			<keyword>RESULT</keyword>
			<keyword>RETURN</keyword>
			<keyword>ROLLBACK</keyword>
			<keyword>ROLLUP</keyword>
			<keyword>ROW_COUNT</keyword>
			<keyword>ROW_NUMBER</keyword>
			<keyword>ROWS</keyword>
			<keyword>SCHEMA</keyword>
			<keyword>SEARCH</keyword>
			<keyword>SQL</keyword>
			<keyword>TO</keyword>
			<keyword>TRANSACTION</keyword>
			<keyword>TRIGGER</keyword>
			<keyword>USING</keyword>
			<keyword>VALID</keyword>
			<keyword>VIEW</keyword>
			<keyword>WITH</keyword>
			<keyword>WITHIN</keyword>
			<keyword>WITHOUT</keyword>
			<keyword>ZONE</keyword>
 
                       <!-- operators: -->
			<keyword>ABS</keyword>
			<keyword>ABSOLUTE</keyword>
			<keyword>ADD</keyword>
			<keyword>ALSO</keyword>
			<keyword>AND</keyword>
			<keyword>ANY</keyword>
			<keyword>ARE</keyword>
			<keyword>ARRAY</keyword>
			<keyword>AS</keyword>
			<keyword>ASC</keyword>
			<keyword>AVG</keyword>
			<keyword>BETWEEN</keyword>
			<keyword>CEIL</keyword>
			<keyword>CEILING</keyword>
			<keyword>CHAR_LENGTH</keyword>
			<keyword>ELSE</keyword>
			<keyword>EQUALS</keyword>
			<keyword>EXCLUDE</keyword>
			<keyword>FLOOR</keyword>
			<keyword>INTERSECT</keyword>
			<keyword>LENGTH</keyword>
			<keyword>MAX</keyword>
			<keyword>MIN</keyword>
			<keyword>NO</keyword>
			<keyword>NOT</keyword>
			<keyword>OR</keyword>
			<keyword>SQRT</keyword>
			<keyword>SUBSTRING</keyword>
			<keyword>SUM</keyword>
			<keyword>THAN</keyword>
			<keyword>THEN</keyword>
			<keyword>TRIM</keyword>
 
                       <!-- some data types + constants: -->
			<keyword>BIGINT</keyword>
			<keyword>BINARY</keyword>
			<keyword>BIT</keyword>
			<keyword>BIT_LENGTH</keyword>
			<keyword>BITVAR</keyword>
			<keyword>BLOB</keyword>
			<keyword>BOOLEAN</keyword>
			<keyword>CHAR</keyword>
			<keyword>CHAR_LENGTH</keyword>
			<keyword>CHARACTER</keyword>
			<keyword>DATA</keyword>
			<keyword>DATE</keyword>
			<keyword>DOUBLE</keyword>
			<keyword>FLOAT</keyword>
			<keyword>INT</keyword>
			<keyword>INTEGER</keyword>
			<keyword>NUMBER</keyword>
			<keyword>REAL</keyword>
			<keyword>SMALLINT</keyword>
			<keyword>TIME</keyword>
			<keyword>TIMESTAMP</keyword>
			<keyword>VARCHAR</keyword>
 
			<keyword>ISNULL</keyword>
			<keyword>NULL</keyword>
			<keyword>FALSE</keyword>
			<keyword>TRUE</keyword>
		</keywords>
		<sampleText doctypes="SQL"><![CDATA[/* SQL */
SELECT Title, Year
FROM Books
WHERE Author="Noske"
]]></sampleText>
	</scheme>


NOTE: Believe it or not this is just a subset of posetgreSQL/SQL reserved words. Here I've only included ~200 of the more common keywords, but there are well over 600 in total! If interested in adding more you can see a more exhaustive list here or click "View Source" and there's a hidden HTML comment below this text.




Step 4) Creating a new Syntax Color Scheme (Colors.xml)

Open: "C:\Program Files\Adobe\Adobe Dreamweaver CS5\configuration\CodeColoring\Colors.xml" (on Windows)
or: "/Users/anoske/Library/Application Support/Adobe/Dreamweaver CS5/en_US/Configuration/CodeColoring/Colors.xml" (on Mac)

And add the following line of text to the 3rd last line, just before the </colorGroup> tag:

        <syntaxColor id="CodeColor_SQLReservedWords" text="#0000FF" />
	<syntaxColor id="CodeColor_SQLNumber" text="#FF0000" />
        <syntaxColor id="CodeColor_SQLOperator" text="#773300" />
	<syntaxColor id="CodeColor_SQLBracket" text="#009988" />
	<syntaxColor id="CodeColor_SQLString" text="#990099" />
        <syntaxColor id="CodeColor_SQLComment" text="#009900" />

These colors are blue, red, brown, aqua, purple and dark green (respectively) but it's fairly easy to change them if you prefer other colors.


Step 5) Reload Dreamweaver and Check it Works!

Having edited four different files, make sure you've saved them all and now quit and restart Dreamweaver. If you've made all these changes correctly you should now be able to open a .py file and see your new Python color scheme / syntax highlighting appear! Finally!

Don't hesitate to e-mail me if you have further comments. As mentioned, different operating systems and/or versions of Dreamweaver may have these files located in slightly different locations.


See Also

Links