From 7ecf6580bd31af41ceceb2e9c89020eeb26f2552 Mon Sep 17 00:00:00 2001 From: Henrik Tidefelt Date: Sun, 28 Mar 2021 23:22:14 +0200 Subject: [PATCH] Improve syntax highlighting of grammar listings Changes include: - Make sure only actual Modelica keywords are highlighted as such. - Highlight fixed strings in same way as Modelica keywords. - Make BNF syntactical constructs stand out by having upright shape (using italics for production rule names). That production rule names are set in italics will also make it easier to tell the difference between a grammar listing and a Modelica listing when reading the document. --- mlsshared.sty | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/mlsshared.sty b/mlsshared.sty index e8a541c00..0e05da4f3 100644 --- a/mlsshared.sty +++ b/mlsshared.sty @@ -86,19 +86,27 @@ % Note: within only a keyword in grammar \lstdefinelanguage{grammar}{% basicstyle=\upshape\ttfamily\smallifpdf, % size of fonts used for the code - alsoletter={}, + identifierstyle=\itshape, alsodigit={-}, breaklines=true, breakatwhitespace=true, - morekeywords=[2]{% - letters,annotation,assert,block,break,class,connect,connector,constant,constrainedby,discrete,% + morekeywords=[1]{% + annotation,assert,block,break,class,connect,connector,constant,constrainedby,discrete,% each,encapsulated,else,elseif,elsewhen,end,expandable,extends,external,final,flow,for,% function,if,in,inner,initial,input,import,loop,model,operator,outer,% output,package,parameter,partial,record,redeclare,replaceable,return,% - size,stream,terminate,then,type,when,while,algorithm,equation,% - protected,public,and,false,not,or,true,pure,impure,stream,transition,initialState,% - within}, - morekeywords=[1]{|} + stream,terminate,then,type,when,while,algorithm,equation,% + protected,public,and,false,not,or,true,pure,impure,within,% + }, + % Instead of using color to highlight BNF syntactical constructs as below, the production rule names + % are set in italics, so that the syntactical constructs stand out by having upright shape. +% alsoletter={|,\{,\},[,],(,)}, +% morekeywords=[2]{|,\{,\},[,],(,)}, + morekeywords=[3]{% + letters,% + }, + morestring=[b]{"}, + stringstyle=\color{keywordcolor1}, % For the grammar, fixed strings and keywords are the same kind of token. }[keywords,comments,strings] % Duplicate this definition here to avoid issue