ILOG OPL syntax highlighting for gEdit

This article offers the syntax highlighting definition file for gEdit 2.16.

Place the following content into the file ~/.gnome2/gtksourceview-1.0/language-specs/opl.lang. The definitions are not yet complete, I will update them eventually.

Due to gEdit limitations, the definitions allow highlighting according to lexical analysis, but they do not understand grammar. That means that the syntax will be highlighted according to the token used, but not according to their meaning within the model.

Probably, gEdit will incorrectly recognize your OPL file as C++ source code. Therefore, change the syntax highlighting: View->Highligh Mode->Sources->OPL.

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE language SYSTEM "language.dtd">
<!--Created using the CPP.lang file as a template-->
<language _name="OPL" version="1.0" _section="Sources" mimetypes="text/opl">

	<line-comment _name = "Line Comment" style= "Comment">
		<start-regex>//</start-regex>
	</line-comment>

	<block-comment _name = "Block Comment" style = "Comment">
		<start-regex>/\*</start-regex>
        	<end-regex>\*/</end-regex>
	</block-comment>

	<string _name = "String" style = "String" end-at-line-end = "TRUE">
		<start-regex>&quot;</start-regex>
		<end-regex>&quot;</end-regex>
	</string>

	<string _name = "Symbol" style = "String" end-at-line-end = "TRUE">
		<start-regex>&apos;</start-regex>
		<end-regex>&apos;</end-regex>
	</string>

	<keyword-list _name = "Keywords" style = "Keyword" case-sensitive="TRUE">
		<keyword>all</keyword>
		<keyword>and</keyword>
		<keyword>assert</keyword>
		<keyword>boolean</keyword>
		<keyword>constraint</keyword>
		<keyword>constraints</keyword>
		<keyword>CP</keyword>
		<keyword>CPLEX</keyword>
		<keyword>cumulFunction</keyword>
		<keyword>DBConnection</keyword>
		<keyword>DBconnection</keyword>
		<keyword>DBExecute</keyword>
		<keyword>DBexecute</keyword>
		<keyword>DBRead</keyword>
		<keyword>DBread</keyword>
		<keyword>DBUpdate</keyword>
		<keyword>DBupdate</keyword>
		<keyword>dexpr</keyword>
		<keyword>diff</keyword>
		<keyword>div</keyword>
		<keyword>dvar</keyword>
		<keyword>else</keyword>
		<keyword>execute</keyword>
		<keyword>false</keyword>
<!--		<keyword>float</keyword>
		<keyword>float+</keyword>-->
		<keyword>forall</keyword>
		<keyword>from</keyword>
		<keyword>if</keyword>
		<keyword>in</keyword>
		<keyword>include</keyword>
		<keyword>infinity</keyword>
<!--		<keyword>int</keyword>
		<keyword>int+</keyword>-->
		<keyword>intensity</keyword>
		<keyword>inter</keyword>
		<keyword>interval</keyword>
		<keyword>invoke</keyword>
		<keyword>key</keyword>
		<keyword>main</keyword>
		<keyword>max</keyword>
		<keyword>maximize</keyword>
		<keyword>maxint</keyword>
		<keyword>min</keyword>
		<keyword>minimize</keyword>
		<keyword>mod</keyword>
		<keyword>not in</keyword>
		<keyword>optional</keyword>
		<keyword>or</keyword>
		<keyword>ordered</keyword>
		<keyword>piecewise</keyword>
		<keyword>prepare</keyword>
		<keyword>prod</keyword>
		<keyword>pwlFunction</keyword>
		<keyword>range</keyword>
		<keyword>reversed</keyword>
		<keyword>sequence</keyword>
		<keyword>setof</keyword>
		<keyword>SheetConnection</keyword>
		<keyword>SheetRead</keyword>
		<keyword>SheetWrite</keyword>
		<keyword>size</keyword>
		<keyword>sorted</keyword>
		<keyword>stateFunction</keyword>
		<keyword>stepFunction</keyword>
		<keyword>stepwise</keyword>
		<keyword>string</keyword>
		<keyword>subject to</keyword>
		<keyword>sum</keyword>
		<keyword>symdiff</keyword>
		<keyword>to</keyword>
		<keyword>true</keyword>
		<keyword>tuple</keyword>
		<keyword>types</keyword>
		<keyword>union</keyword>
		<keyword>using</keyword>
		<keyword>with</keyword>
	</keyword-list>

	<keyword-list _name = "Types" style = "Data Type" case-sensitive="TRUE">
		<keyword>float</keyword>
		<keyword>int</keyword>
		<keyword>float+</keyword>
		<keyword>int+</keyword>
		<keyword>string</keyword>
		<keyword>boolean</keyword>
	</keyword-list>

	<pattern-item _name = "Tuple" style = "Data Type">
		<regex>\{\w*\}</regex>
	</pattern-item>

	<keyword-list _name="Functions" style="Function">
		<keyword>abs</keyword>
		<keyword>allDifferent</keyword>
		<keyword>allMinDistance</keyword>
		<keyword>allowedAssignments</keyword>
		<keyword>alternative</keyword>
		<keyword>alwaysConstant</keyword>
		<keyword>alwaysEqual</keyword>
		<keyword>alwaysIn</keyword>
		<keyword>alwaysNoState</keyword>
		<keyword>append</keyword>
		<keyword>asSet</keyword>
		<keyword>before</keyword>
		<keyword>card</keyword>
		<keyword>ceil</keyword>
		<keyword>count</keyword>
		<keyword>cumulFunctionValue</keyword>
		<keyword>distToInt</keyword>
		<keyword>dual</keyword>
		<keyword>element</keyword>
		<keyword>endAtEnd</keyword>
		<keyword>endAtStart</keyword>
		<keyword>endBeforeEnd</keyword>
		<keyword>endBeforeStart</keyword>
		<keyword>endEval</keyword>
		<keyword>endOf</keyword>
		<keyword>exp</keyword>
		<keyword>first</keyword>
		<keyword>first</keyword>
		<keyword>floatValue</keyword>
		<keyword>floor</keyword>
		<keyword>forbiddenAssignments</keyword>
		<keyword>forbidEnd</keyword>
		<keyword>forbidExtent</keyword>
		<keyword>forbidStart</keyword>
		<keyword>frac</keyword>
		<keyword>ftoi</keyword>
		<keyword>heightAtEnd</keyword>
		<keyword>heightAtStart</keyword>
		<keyword>intValue</keyword>
		<keyword>inverse</keyword>
		<keyword>item</keyword>
		<keyword>last</keyword>
		<keyword>last</keyword>
		<keyword>length</keyword>
		<keyword>lengthEval</keyword>
		<keyword>lengthOf</keyword>
		<keyword>lex</keyword>
		<keyword>lg</keyword>
		<keyword>ln</keyword>
		<keyword>log</keyword>
		<keyword>matchAt</keyword>
		<keyword>maxl</keyword>
		<keyword>minl</keyword>
		<keyword>next</keyword>
		<keyword>nextc</keyword>
		<keyword>noOverlap</keyword>
		<keyword>numberOfSegments</keyword>
		<keyword>ord</keyword>
		<keyword>pack</keyword>
		<keyword>pow</keyword>
		<keyword>presenceOf</keyword>
		<keyword>prev</keyword>
		<keyword>prev</keyword>
		<keyword>prevc</keyword>
		<keyword>pulse</keyword>
		<keyword>rand</keyword>
		<keyword>reducedCost</keyword>
		<keyword>round</keyword>
		<keyword>segmentEnd</keyword>
		<keyword>segmentStart</keyword>
		<keyword>segmentValue</keyword>
		<keyword>sgn</keyword>
		<keyword>sizeEval</keyword>
		<keyword>sizeOf</keyword>
		<keyword>slack</keyword>
		<keyword>span</keyword>
		<keyword>sqrt</keyword>
		<keyword>srand</keyword>
		<keyword>standardDeviation</keyword>
		<keyword>startAtEnd</keyword>
		<keyword>startAtStart</keyword>
		<keyword>startBeforeEnd</keyword>
		<keyword>startBeforeStart</keyword>
		<keyword>startEval</keyword>
		<keyword>startOf</keyword>
		<keyword>stateFunctionValue</keyword>
		<keyword>step</keyword>
		<keyword>stepAtEnd</keyword>
		<keyword>stepAtStart</keyword>
		<keyword>synchronize</keyword>
		<keyword>trunc</keyword>
	</keyword-list>

	<pattern-item _name = "Decimal" style = "Decimal">
		<regex>\b([1-9][0-9]*|0)([Uu]([Ll]|LL|ll)?|([Ll]|LL|ll)[Uu]?)?\b</regex>
	</pattern-item>

	<pattern-item _name = "Floating Point Number" style = "Floating Point">
		<regex>\b([0-9]+[Ee][-]?[0-9]+|([0-9]*\.[0-9]+|[0-9]+\.)([Ee][-]?[0-9]+)?)[fFlL]?</regex>
	</pattern-item>

	<pattern-item _name = "Octal Number" style = "Base-N Integer">
		<regex>\b0[0-7]+([Uu]([Ll]|LL|ll)?|([Ll]|LL|ll)[Uu]?)?\b</regex>
	</pattern-item>

	<pattern-item _name = "Hex Number" style = "Base-N Integer">
		<regex>\b0[xX][0-9a-fA-F]+([Uu]([Ll]|LL|ll)?|([Ll]|LL|ll)[Uu]?)?\b</regex>
	</pattern-item>


</language>

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: