Skip to content

Commit

Permalink
Improve syntax highlighting of grammar listings
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
henrikt-ma committed Mar 28, 2021
1 parent 4a84072 commit 7ecf658
Showing 1 changed file with 15 additions and 7 deletions.
22 changes: 15 additions & 7 deletions mlsshared.sty
Expand Up @@ -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
Expand Down

0 comments on commit 7ecf658

Please sign in to comment.