I'm sorry for posting a non-working code. It's fixed now.
NOTE: Why Overleaf was having issues, was that the length unit "zw" was not useable on non-pLaTeX environments(default English environment for Overleaf). I failed to notice this issue since my local environment is in pLaTeX(commonly used for Japanese files), and in there it worked just fine. It takes quite a hassle to use pLaTeX on Overleaf so I just fixed the units. Also, Overleaf seems to not color things as defined, so probably better to copy the code on to your local TeX editor for testing.
Also I integrated the solution Stefan has proposed. This gave a peculiar result, with both "boolean" and "boolean(1)" having the "boolean" part in orange rather than the "boolean(1)" having the "boolean(" part in blue.
I tried around checking if this was due to order of definition, or numbering, but no. Changing the order of definition, or the keyword numbers did not change the result. It seems the shorter keyword gets noticed first, and then once that is done it doesn't recognize any other keyword definition.
I don't know how I could get around this...
Code: Select all
\documentclass{article}
\usepackage{listings}
\usepackage[dvipdfmx]{color}
%Define Colors
\definecolor{gray}{RGB}{102,102,102} %#666666
\definecolor{lightblue}{RGB}{0,102,153} %#006699
\definecolor{lightgreen}{RGB}{102,153,0} %#669900
\definecolor{bluegreen}{RGB}{51,153,126} %#33997e
\definecolor{magenta}{RGB}{217,74,122} %#d94a7a
\definecolor{orange}{RGB}{226,102,26} %#e2661a
\definecolor{purple}{RGB}{125,71,147} %#7d4793
\definecolor{green}{RGB}{113,138,98} %#718a62
\lstdefinelanguage{Processing}{
%keyword1&2&6
morekeywords = [1]{abstract, class, continue, default, enum, extends, false, final, finally, implements, import, instanceof, interface, native, new, null, package, private, protected, public, static, strictfp, throws, transient, true, void, volatile, length, assert, case, return, super, this, throw},
%keyword3
morekeywords = [2]{catch, do, for, if, else, switch, synchronized, while, try},
%keyword4
morekeywords = [3]{width, height, pixelHight, displayHeight, displayWidth, focused, frameCount, frameRate, key, keyCode, keyPressed, mouseButton, mousePressed, mouseX, mouseY, pixels, pixelWidth, pmouseX, pmouseY},
%keyword5
morekeywords = [4]{Array, ArrayList, Boolean, Byte, BufferedReader, Character, Class, Double, Float, Integer, HashMap, PrintWriter, String, StringBuffer, StringBuilder, Thread, boolean, byte, char, color, double, float, int, long, short, FloatDict, FloatList, IntDict, IntList, JSONArray, JSONObject, PFont, PGraphics, PImage, PShader, PShape, PVector, StringDict, StringList, Table, TableRow, XML},
%function1
morekeywords = [5]{boolean(},
keywordstyle = [1]\color{bluegreen},
keywordstyle = [2]\color{lightgreen},
keywordstyle = [3]\color{magenta},
keywordstyle = [4]\color{orange},
keywordstyle = [5]\color{lightblue},
sensitive = true,
morecomment = [l]{//},
morecomment = [s]{/*}{*/},
morecomment = [s]{/**}{*/},
commentstyle = \color{gray},
morestring = [b]",
morestring = [b]',
stringstyle = \color{purple}
}
\lstset{
language={Processing},
basicstyle={\small},
identifierstyle={\small},
commentstyle={\small\itshape},
keywordstyle={\small\bfseries},
ndkeywordstyle={\small},
stringstyle={\small\ttfamily},
frame={tb},
breaklines=true,
columns=[l]{fullflexible},
numbers=left,
xrightmargin=0em,
xleftmargin=3em,
numberstyle={\scriptsize},
stepnumber=1,
numbersep=1em,
lineskip=-0.5ex,
}
\begin{document}
\begin{lstlisting}
boolean;
boolean(1);
\end{lstlisting}
\end{document}