3

I have some issues defining a new language for the lstlisting package. The source code shall look like this in the end:

Code

And my latex definition looks like this atm:

\documentclass[]{article}

\usepackage{xcolor}
\usepackage{listings}

\lstdefinelanguage{ST}
{
    % list of keywords
    morekeywords={
        case,of,if,then,end_if,end_case,super,function_block,extends,var,
        constant, byte,,end_var,var_input, real,bool,var_output,
        dint,udint,word,dword,array, of,uint,not,adr
    },
    otherkeywords={
    :, :=, <>,;,\,.,\[,\],\^
    },
    sensitive=false,
    morecomment=[l]{//}, 
    morecomment=[s]{(*}{*)},
    morestring=[b]"
    morestring=[b]' 
}

\lstset{
    language=ST,
    numbers=left,
    numberstyle=\color{purple},
    keywordstyle=\color{blue},
    commentstyle=\color{red!50!brown},
    stringstyle=\color{yellow},
    tabsize=3
}

\begin{document}
    \begin{lstlisting}
     FUNCTION_BLOCK Name EXTENDS Name2
     VAR CONSTANT
     (*
     multi line comment
     *)
     variable   : BYTE := 2#11111110;
     //variable2 : REAL := 16#AF;
     array: ARRAY[0..1] OF Name3;
     END_VAR

    CASE Variable OF
    0:  
        IF SUPER^.init() THEN
            variable := %QX3.1;
        END_IF
    1:  
        variable := FALSE;  
    END_CASE

    \end{lstlisting}
\end{document}

Besides the color which i can adjust later, how can i tell the compiler to color all digits (and even the # sign as well as TRUE and FALSE) also round brackets and dots aren't colored yet.

I guess i don't have to list all the differences. Can someone help me to adjust this?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.