I would like to create a lstlisting language for a syntax that highlights namespaces for readability. Here's what I want to achieve:
\documentclass{standalone}
\usepackage{listings}
\usepackage{xcolor}
\definecolor{gray}{rgb}{0.4,0.4,0.4}
\definecolor{darkblue}{rgb}{0.0,0.0,0.6}
\definecolor{cyan}{rgb}{0.0,0.6,0.6}
\lstset{
basicstyle=\ttfamily,
columns=fullflexible,
showstringspaces=false,
commentstyle=\color{gray}\upshape
}
\lstdefinelanguage{turtle}
{
stringstyle=\color{black},
identifierstyle=\color{darkblue},
keywordstyle=\color{cyan},
moredelim=[is][\color{orange!80!black}]{!}{!},
moredelim=[l][\color{orange!80!black}]{\ }{:} % my best guess: does not work
}
\begin{document}
\lstset{language=turtle}
\begin{lstlisting}
!a!:b !c!:d !e!:f .
\end{lstlisting}
\end{document}
However, I would like to avoid having to put ! explicitly in the input to wrap the namespaces. The command moredelim=[l][\color{orange!80!black}]{\ }{:} has no effect unless I put a space directly before and after each :.

