I defined my own programming language using listings and, to do so, I had to use the literate option a lot in my definition. For example, to make parentheses bold and green, I did this:
\definecolor{darkgreen}{rgb}{0, 0.65, 0.2}
\lstdefinelanguage{lang}{
comment=[l]{\#},
literate=
{(}{{{\textbf{\color{darkgreen}(}}}}1
{)}{{{\textbf{\color{darkgreen})}}}}1
}
It works fine. However, I want the replacements defined in the literate option not to be applied inside comments. For example:
(a b c) # These parentheses should be green
# (a b c) # These shouldn't
Is this possible at all?