Skip to content

Instantly share code, notes, and snippets.

@pierre-haessig
Last active December 26, 2015 03:19
Show Gist options
  • Save pierre-haessig/7084872 to your computer and use it in GitHub Desktop.
Save pierre-haessig/7084872 to your computer and use it in GitHub Desktop.
basic Ampl/GNU MathProg language description for gtksourceview (e.g. syntax highlighting in gedit) Pierre Haessig, 2013
<?xml version="1.0" encoding="UTF-8"?>
<!--
basic Ampl/GNU MathProg language description for gtksourceview
(e.g. syntax highlighting in gedit)
to be placed in /usr/share/gtksourceview-3.0/language-specs/ directory
Pierre Haessig, 2013
-->
<language id="ampl" _name="Ampl" version="2.0" _section="Scientific">
<metadata>
<property name="mimetypes">text/plain</property>
<property name="globs">*.ampl</property>
<property name="line-comment-start">#</property>
<property name="block-comment-start">/*</property>
<property name="block-comment-end">*/</property>
</metadata>
<styles>
<style id="comment" _name="Comment" map-to="def:comment"/>
<style id="string" _name="String" map-to="def:string"/>
<style id="escaped-character" _name="Escaped Character" map-to="def:special-char"/>
<style id="printf" _name="printf Conversion" map-to="def:special-char"/>
<style id="keyword" _name="Keyword" map-to="def:keyword"/>
<style id="type" _name="Type" map-to="def:type"/>
<style id="builtin-function" _name="Builtin Function" map-to="def:builtin"/>
</styles>
<definitions>
<context id="ampl">
<include>
<context id="statements" style-ref="keyword">
<keyword>set</keyword>
<keyword>param</keyword>
<keyword>var</keyword>
<keyword>subject to</keyword>
<keyword>subj to</keyword>
<keyword>s.t.</keyword>
<keyword>maximize</keyword>
<keyword>minimize</keyword>
<keyword>solve</keyword>
<keyword>check</keyword>
<keyword>display</keyword>
<keyword>printf</keyword>
<keyword>for</keyword>
<keyword>end</keyword>
<keyword>data</keyword>
</context>
<context id="keywords" style-ref="keyword">
<keyword>and</keyword>
<keyword>by</keyword>
<keyword>cross</keyword>
<keyword>diff</keyword>
<keyword>div</keyword>
<keyword>else</keyword>
<keyword>if</keyword>
<keyword>in</keyword>
<keyword>inter</keyword>
<keyword>less</keyword>
<keyword>mod</keyword>
<keyword>not</keyword>
<keyword>or</keyword>
<keyword>symdiff</keyword>
<keyword>then</keyword>
<keyword>union</keyword>
<keyword>within</keyword>
</context>
<context id="comment-single-line" style-ref="comment">
<start>\#</start>
<end>$</end>
</context>
<context id="comment-multiline" style-ref="comment">
<start>\/\*</start>
<end>\*\/</end>
</context>
<!-- string machinery -->
<define-regex id="escaped-character" extended="true">
\\( # leading backslash
[\\\"\'nrbtfav\?] | # escaped character
[0-7]{1,3} | # one, two, or three octal digits
x[0-9A-Fa-f]+ # 'x' followed by hex digits
)
</define-regex>
<context id="escaped-character" style-ref="escaped-character">
<match>\%{escaped-character}</match>
</context>
<context id="printf" style-ref="printf" extend-parent="false">
<match extended="true">
\%\%|\%
(?:[1-9][0-9]*\$)? # argument
[#0\-\ \+\'I]* # flags
(?:[1-9][0-9]*|\*)? # width
(?:\.\-?(?:[0-9]+|\*))? # precision
(?:hh|ll|[hlLqjzt])? # length modifier
[diouxXeEfFgGaAcsCSpnm] # conversion specifier
</match>
</context>
<context id="single-quoted-string" style-ref="string" end-at-line-end="true" class="string" class-disabled="no-spell-check">
<start>'</start>
<end>'</end>
<include>
<context ref="printf"/>
<context ref="escaped-character"/>
<context ref="def:line-continue"/>
</include>
</context>
<context id="double-quoted-string" style-ref="string" end-at-line-end="true" class="string" class-disabled="no-spell-check">
<start>"</start>
<end>"</end>
<include>
<context ref="printf"/>
<context ref="escaped-character"/>
<context ref="def:line-continue"/>
</include>
</context>
<context ref="def:decimal"/>
<context ref="def:float"/>
<context id="builtin-functions" style-ref="builtin-function">
<!-- <prefix>(?&lt;![\w\.])</prefix> -->
<keyword>abs</keyword>
<keyword>atan</keyword>
<keyword>card</keyword>
<keyword>ceil</keyword>
<keyword>cos</keyword>
<keyword>exp</keyword>
<keyword>floor</keyword>
<keyword>gmtime</keyword>
<keyword>followinglength</keyword>
<keyword>log</keyword>
<keyword>log10</keyword>
<keyword>max1</keyword>
<keyword>min1</keyword>
<keyword>round</keyword>
<keyword>sin</keyword>
<keyword>sqrt</keyword>
<keyword>str2time</keyword>
<keyword>trunc</keyword>
<keyword>Irand224</keyword>
<keyword>Uniform01</keyword>
<keyword>Uniform</keyword>
<keyword>Normal01</keyword>
<keyword>Normal</keyword>
</context>
<context id="iterated-expressions" style-ref="builtin-function">
<!-- <prefix>(?&lt;![\w\.])</prefix> -->
<keyword>sum</keyword>
<keyword>prod</keyword>
<keyword>min</keyword>
<keyword>max</keyword>
</context>
<context id="types" style-ref="type">
<!-- <prefix>(?&lt;![\w\.])</prefix> -->
<keyword>integer</keyword>
<keyword>binary</keyword>
<keyword>symbolic</keyword>
</context>
</include>
</context>
</definitions>
</language>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment