% Copyright 2012-2022, Alexander Shibakov
% This file is part of SPLinT
%
% SPLinT is free software: you can redistribute it and/or modify
% it under the terms of the GNU General Public License as published by
% the Free Software Foundation, either version 3 of the License, or
% (at your option) any later version.
%
% SPLinT is distributed in the hope that it will be useful,
% but WITHOUT ANY WARRANTY; without even the implied warranty of
% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
% GNU General Public License for more details.
%
% You should have received a copy of the GNU General Public License
% along with SPLinT.  If not, see <http://www.gnu.org/licenses/>.

\let\currentparsernamespace\parsernamespace
\let\parsernamespace\indexpseudonamespace % use the correct namespace
\input yypretty.sty % input standard prettified tokens first 
                    % so that we can change their appearance below
\let\parsernamespace\cwebclinknamespace
\prettywordpair{.origin&}{{$\cdot\cdot$}}% special . name in \ld\ scripts
\let\parsernamespace\currentparsernamespace

\prettywordpairwvis{comma}{{\tt,}}{,}
\prettywordpairwvis{semicolon}{{\tt;}}{;}
\prettywordpair@@{file\_NAME\_list}{{\ifinheader\itbold\else\it\fi file\_{\rm name}\_list}}
\prettywordpair@@{high\_level\_library\_NAME\_list}{{\ifinheader\itbold\else\it\fi high\_level\_library\_{\rm name}\_list}}
\prettywordpair@@{low\_level\_library\_NAME\_list}{{\ifinheader\itbold\else\it\fi low\_level\_library\_{\rm name}\_list}}
\prettywordpair@@{NAME}{{\rm name}}
\prettywordpair@@wvis{LNAME}{{\rm name$_{\rm L}$}}{name_L}
\prettywordpair@@{END}{{\rm end}}
\prettywordpair@@{UNARY}{{\rm unary}}
\prettywordpair@@{VERSIONK}{{\tt VERSION}$_{\rm K}$}
\prettytoken{ALIGN}
\prettytoken{MIN}
\prettytoken{MAX}
\prettytoken{TARGET}
\prettytoken{ASSERT}
\prettytoken{INSERT}
\prettywordpair@@wvis{PLUSEQ}{{}$\MRL{+{\K}}${}}{=+}
\prettywordpair@@wvis{MINUSEQ}{{}$\MRL{-{\K}}${}}{=-}
\prettywordpair@@wvis{MULTEQ}{{}$\MRL{\times{\K}}${}}{=*}
\prettywordpair@@wvis{DIVEQ}{{}$\MRL{{\div}{\K}}${}}{=/}
\prettywordpair@@wvis{ANDEQ}{{}$\Xandxeq${}}{=W}
\prettywordpair@@wvis{OREQ}{{}$\Xorxeq${}}{=V}
\prettywordpair@@wvis{LSHIFTEQ}{{}$\MRL{\ll{\K}}${}}{=<<}
\prettywordpair@@wvis{RSHIFTEQ}{{}$\MRL{\gg{\K}}${}}{=>>}
\prettywordpair@@wvis{NE}{{}$\not=${}}{= }
\prettywordpair@@wvis{LE}{{}$\leq${}}{<=}
\prettywordpair@@wvis{GE}{{}$\geq${}}{>=}
\prettywordpair@@wvis{EQ}{{}$=${}}{=}
\prettywordpair@@wvis{OROR}{{}$\V${}}{||}
\prettywordpair@@wvis{ANDAND}{{}$\W${}}{&&}
\prettywordpair@@wvis{LSHIFT}{{}$\ll${}}{<<}
\prettywordpair@@wvis{RSHIFT}{{}$\gg${}}{>>}
\prettywordpair@@wvis{=}{{}$\K${}}{=:}
\prettywordpair@@{+}{{}$+${}}
\prettywordpair@@{-}{{}$-${}}
\prettywordpair@@{!}{{}$\CM${}}
\prettywordpair@@{~}{{}$\R${}}
\prettywordpair@@{^}{{}$\XOR${}}
\prettywordpair@@{|}{{}$\OR${}}
\prettywordpair@@{&}{{}$\AND${}}
\prettywordpair@@{\{}{{\ntt@\{}}% the purpose is to adjust the indexing
\prettywordpair@@{\}}{{\ntt@\}}}% the purpose is to adjust the indexing

% the switches below are sloppy, since the macros in the index
% read a-z as letters (category 11) whereas the parser records them as 
% non-letters, it would be beter to use category 12 throughout (by,
% for example passing the context as a stream of character codes

\def\gtsymswitch{%
    exp \raw exp *left *right\raw {%
        {}$>${}% 
    }
}

\def\gtsymswitchdefault{{\tt >}}

\def\ltsymswitch{%
    exp \raw exp *left *right\raw {%
        {}$<${}% 
    }
}

\def\ltsymswitchdefault{{\tt <}}

\setspecialcharsfrom\gtsymswitch
\setspecialcharsfrom\ltsymswitch

% the visual key switches below slightly abuse the properties of
% \yyifsamestring, namely that it ignores the category code of the characters

\prettywordpair@@wvis{>}{{%
    \let\default\gtsymswitchdefault
    \switchon{#1}\in\gtsymswitch
}}{%
    \yyifsamestring{exp}{#1}{> exp}{%
        \yyifsamestring{*left}{#1}{> exp}{%
            \yyifsamestring{*right}{#1}{> exp}{>}%
        }%
    }%
}

\prettywordpair@@wvis{<}{{%
    \let\default\ltsymswitchdefault
    \switchon{#1}\in\ltsymswitch
}}{%
    \yyifsamestring{exp}{#1}{< exp}{%
        \yyifsamestring{*left}{#1}{< exp}{%
            \yyifsamestring{*right}{#1}{< exp}{<}%
        }%
    }%
}

\def\astsymswitch{%
    exp \raw exp *left *right\raw {%
        {}$\times${}% 
    }
}

\def\astsymswitchdefault{{\tt *}}

\setspecialcharsfrom\astsymswitch

\prettywordpair@@wvis{*}{%
    {%
        \let\default\astsymswitchdefault
        \switchon{#1}\in\astsymswitch
    }%
}{%
    \yyifsamestring{exp}{#1}{* exp}{%
        \yyifsamestring{*left}{#1}{* exp}{%
            \yyifsamestring{*right}{#1}{* exp}{*}%
        }%
    }%
}

\prettywordpair@@{/}{{}$/${}}

\expandafter\prettywordpair@@\expandafter{\harmlesscomment}{{}$\div${}}
