How do I modify the key-value option
\lstdefinelanguage{mybnf}{
morestring = [b]''
}
To obtain the following result:
that is, to be able to have the delimiters defined in a different style (in this case different color) from the content?
Following is my MWE:
\documentclass{article}
\usepackage{fontspec}
\usepackage{longtable, booktabs}
\usepackage{listings, listings-ext, listingsutf8}
\usepackage{xcolor}
\setmainfont{Tisa OT}
\setsansfont{TeX Gyre Heros Cn}
\setmonofont{Fira Code}
%
% general listing colors
%
\definecolor{listing-background}{HTML}{F7F7F7}
\definecolor{listing-rule}{HTML}{B3B2B3}
\definecolor{listing-numbers}{HTML}{B3B2B3}
\definecolor{listing-text-color}{HTML}{000000}
\definecolor{listing-keyword}{HTML}{435489}
\definecolor{listing-keyword-2}{HTML}{1284CA} % additional keywords
\definecolor{listing-keyword-3}{HTML}{9137CB} % additional keywords
\definecolor{listing-identifier}{HTML}{435489}
\definecolor{listing-string}{HTML}{00999A}
\definecolor{listing-comment}{HTML}{8E8E8E}
\lstdefinestyle{etturaz_listings_style}{
language = java,
alsolanguage = scala,
numbers = left,
xleftmargin = 2.7em,
framexleftmargin = 2.5em,
backgroundcolor = \color{white},
basicstyle = \color{listing-text-color}\linespread{1.0}\small\ttfamily,
breaklines = true,
frame = single,
framesep = 0.19em,
rulecolor = \color{listing-rule},
frameround = ffff,
tabsize = 3,
numberstyle = \color{listing-numbers},
aboveskip = 1.0em,
belowskip = 0.1em,
abovecaptionskip = 0em,
belowcaptionskip = 1.0em,
keywordstyle = {\color{listing-keyword}\bfseries},
keywordstyle = {[2]\color{listing-keyword-2}\bfseries},
keywordstyle = {[3]\color{listing-keyword-3}\bfseries\itshape},
sensitive = true,
identifierstyle = \color{listing-identifier},
commentstyle = \color{listing-comment},
stringstyle = \color{listing-string},
showstringspaces = false,
escapeinside = {/*@}{@*/}, % Allow LaTeX inside these special comments
literate = {«}{{\guillemotleft}}1 {»}{{\guillemotright}}1
{…}{{\ldots}}1 {≥}{{>=}}1 {≤}{{<=}}1 {„}{{\glqq}}1 {“}{{\grqq}}1
{”}{{''}}1 {<\%}{{{\color{listing-keyword}<\%}}}2
}
\lstset{style=etturaz_listings_style}
\lstdefinelanguage{Scala}{
morekeywords={
% normal keywords (without data types)
abstract, case, catch, class, def, do, else, extends, false, final,
finally, for, forSome, if, implicit, import, lazy, macro, match, new,
null, object, override, package, private, protected, return, sealed,
super, this, throw, trait, try, true, type, val, var, while, with, yield,
_, :, ;, =, =>, <-, <:
},
morekeywords={[2] % data types
String, Boolean,Byte,Character,Double,Float,Integer,Long,Short, Number,BigDecimal,BigInteger
},
morekeywords={[2] % data types
Seq, List, Map
},
sensitive,
morecomment = [l]//,
morecomment = [s]{/*}{*/},
morecomment = [s]{/**}{*/},
%
morestring = [b]',
morestring = [s][\color{black}]{"}{"}
}
\lstdefinelanguage{xbnf}{
morekeywords={
% normal keywords (without data types)
::=
}
sensitive,
morecomment = [l]//,
morecomment = [s]{(*}{*)},
morestring = [b]',
morestring = [s][\color{black}]{"}{"}
}
\begin{document}
% \lstset{language=Scala}
\begin{lstlisting}[language=Scala]
def stringDivideBy(aStr: String, bStr: String): Option[Int] =
parseInt(aStr).flatMap { aNum =>
parseInt(bStr).flatMap { bNum =>
divide(aNum, bNum)
}
}
\end{lstlisting}
\begin{lstlisting}[language=xbnf]
json ::= element
value ::= object | array | string | number | "true" | "false" | "null"
(* So here the two apostrophes in '{' should be green and the bracket black *)
object ::= '{' ws '}' | '{' member {',' member} '}'
member ::= ws string ws ':' element
array ::= '[' ws ']' | '[' element {',' element} ']'
element ::= ws value ws
(* Here, again, two green black and the double quote black*)
string ::= '"' '"' | character {character} '"'
character ::= 'A' | ... | 'Z' | 'a' | ... | 'z' | escape
\end{lstlisting}
\end{document}
Thanks



literal. – Skillmon Apr 04 '20 at 15:52"""which isn't quite the same as'"'or"'"... You could achieve that by setting a switch for single and double quotes. – Skillmon Apr 04 '20 at 17:31\newif\ifGuidoneInSingleQuotesand\newif\ifGuidoneInDoubleQuotesthen you use\GuidoneInSingleQuotestruein the literal of'and\GuidoneInDoubleQuotestruein the literal of". You can then check whether you're currently in quotes using\ifGuidoneInSingleQuotes <true>\else <false>\fi. – Skillmon Apr 04 '20 at 18:35\newifcontrol structure; that is, do I writeliterate = {"}{_what do I put here?_}. Thanks for your support, really appreciated. – Guidone Apr 04 '20 at 20:34Pygmentsandminted. – projetmbc May 01 '21 at 12:16