How can I define multiple identifier classes and styles in listings?
You're halfway there. The listings
manual (p.31 in v1.5b) tells you that multiple classes of identifiers and associated styles can be defined by using
\emph=[<number>]{<identifier list>}
\emphstyle=[<number>]{<identifier style>}
where <number>
is some integer of your choice that gets associated with the class of identifiers in question.
\documentclass{article}
\usepackage{xcolor}
\usepackage{listings}
\lstset%
{%
emph=[1]%
{%
DELETE,
GET,
POST,
PUT,
},
emphstyle=[1]{\color{green}},
%
emph=[2]% Variable Types
{%
blob,
datetime,
integer,
string,
},
emphstyle=[2]{\color{blue}},
}
\begin{document}
...
\begin{lstlisting}
{
"id": {integer},
"login": {string},
"password": {string},
"name": {string},
"picture": {
File Resource
}
}
...
PUT /files/{file_id}
\end{lstlisting}
\end{document}
A supplement to @Jubobs's answer as a reminder for users of listings v1.6
(maybe also for versions later on, I haven't checked yet).
In listings v1.6
, the valid syntax for specifying group in emph
and keywords
has been changed into
emph={[2]...}, emphstyle={[2]...}
keywords={[1]...}, keywordstyle={[1]...}
These can be found in the listings
manual (v1.6, p22).