I've been using the Listings package to develop a new language definition to display some source code for an academic project I'm working on. The language I want to display has various assignment operators akin to <=, <-, :=: etc. and I've declared them in the otherkeywords section. The problem I'm having is that when styling my comments to appear green the operators declared as otherkeywords don't get styled by the comment style and remain their original keyword style. The confusing thing is that the otherkeywords style is set using the keywordstyle command and the keywords themselves behave normally within a commented section.
Code: Select all
% My language definition
\lst@definelanguage[]{OPL}%
{
keywords={maximize, minimize, subject, to, forall, sum, solve, int, int+, float, float+, enum,
ftoi, mod, abs, maxint, sqrt, ceil, floor, distToInt, frac, trunc, infinity, first, last, card, ord, next,
prev, range, in, struct, prod, min, max, union, inter, not, initialize, var, dmin, dmax, dsize,
bound, dnexthigher, alldifferent, circuit, distribute, try, endtry, tryall, if, endif, then, else, while, select,
once, search, when, onValue, generate, generationMin, generationMax, generateSeq},
otherkeywords={..,=,<,>,<=,=>,==},
comment=[l][\color{eclipse-comments}]{//},%
morecomment=[s][\color{eclipse-comments}]{/*}{*/},%
string=[b][\color{eclipse-strings}]\``,%
morestring=[b][\color{eclipse-strings}]',%
basicstyle=\sffamily,
keywordstyle=\color{eclipse-keywords},
tabsize=4,
showstringspaces=false,
numbers=left, %% number lines
numberstyle=\tiny, %% the style of the numbers in the side
numberblanklines=true,
showspaces=false,
showtabs=false,
}[keywords,comments,strings]%
\definecolor{eclipse-keywords}{rgb}{0.55,0,0.337}
\definecolor{eclipse-strings}{rgb}{0.165,0,1}
\definecolor{eclipse-comments}{rgb}{0.247,0.498,0.373}
% This is the test code I'm trying to format, the = within the /* */ comment style show up as the eclipse-keywords colour rather than
% the correct eclipse-comments colour.
\begin{lstlisting}[language=OPL]
// A nice comment
maximize
sum(i in 1..n) c[i]*x[i]
subject to
forall (i in 1..n) sum(j in 1..n) d[i,j] <= s;
/*
*int i = 3;
*float pi = 3.14;
*enum Days {Monday,Tuesday,Wednesday,Thursday,Friday,Saturday,Sunday};
*/
\end{lstlisting}