Function-List-Parser for User-Defined-Language "Velocity"

  • Hello all,

    I have Notepad++ v7.3.3 installed, on Windows 10, 64 Bit.
    I am trying to develop a function list parser for a used-defined language called “Velocity Template Language” (in short “Velocity”).
    In the context in which I use “Velocity”, it is used to write customized reports for the ALM-tool “Polarion”.

    I have looked around the forum and the web for similiar topics and I found quite some things,
    but I can’t get it transferred to fit on my task and I am not sure, where the problems really occur.
    Below is a description of what I am trying to achieve.
    Thanks in advance for any solution proposals or hints.

    First question that I am not sure about:
    The file “functionList.xml” in which the parsers are defined, is present twice.
    Once in: <user>\AppData\Roaming\Notepad++
    Once in: C:\Program Files (x86)\Notepad++ (can only be edited with Admin-rights)
    Which file needs to be modified? Only one of them or both?
    Why are two files present at all?

    Main question is about the parser:
    I think to have understood the general setup of how to define a parser (association id, <function> and <functionName>).
    However, I probaly don’t get the regular expressions right.
    The “Velocity”-language in terms of “functions” is build up like this, in “Velocity” a function is called a “macro”:
    Each function/macro starts at the beginning of a line with “#macro”.
    Then, in brackets, first the name of the function/macro follows.
    After that, one or more parameters passed to the function/macro may follow.
    Each parameter starts with a “$”.
    Parameters are separated by spaces.
    Single-line comments are indicated by a double hashtag “##”.
    Multi-line comments are started by “#" and ended by "#”.
    Each function/macro end with “#end”, which again is placed at the beginning of a line.
    Within the body of the function/macro different commands may appear.
    For example, there may commands like “if” or “foreach” which all have the same structure like:

     #set($dummy = false)

    Here is an example of a macro with no parameters passed, so the function name “Macro_ShowNotes” should be extracted in this case:

    ##single-line comment
    #set($dummy = true)
     #set($dummy = false)
     multi-line comment
     multi-line comment
     #set($dummy = true)
    #end ##end of macro

    Here is an example of a macro with two parameters passed. Now, the function name “Macro_ShowTable” should be extracted:

    #macro(Macro_ShowTable $RowItems $ColItems)
    <body of macro>

  • @Martin1975

    There is info about the “appdata” part of your question here:

    But basically, or rather typically, if you run an installed version of Notepad++, your configuration settings (including the function list) are stored in the “appdata” location.

    If you create a zero-length file called doLocalConf.xml in the same folder where notepad++.exe is, after a restart you will be running with the configuration files from that same folder, and the “appdata” info will not be used.

  • @Martin1975

    Try this parser:

    			<association id=         "vtl_syntax"        userDefinedLangName="VTL"                />
    			<association id=         "vtl_syntax"        userDefinedLangName="Velocity"           />
    			<association id=         "vtl_syntax"        ext=".vm"                                />
    			<!-- ============================================== [ VTL / Velocity ] -->
    			|   Based on:
    				displayName="VTL - Velocity Template Language"
    				id         ="vtl_syntax"
    				commentExpr="(?x)                                               # free-spacing (see `RegEx - Pattern Modifiers`)
    							(?s:\x23\x2A(?!\x2A).*?\x2A\x23)                    # Multi Line Comment
    						|	(?m-s:\x23{2}.*$)                                   # Single Line Comment
    						|	(?s:\x23\x2A{2}.*?\x2A\x23)                         # Java Doc Comment
    					mainExpr="(?x)                                              # free-spacing (see `RegEx - Pattern Modifiers`)
    							^\h*                                                # optional leading white-space at start-of-line
    							\K                                                  # discard text matched so far
    			<!-- ================================================================= -->

  • @MAPJe71

    Dear MAPJe71,

    thank you for the excellent solution.
    It worked perfectly right out-of-the-box and does exactly what I was looking for.

    Thanks again and best regards

Log in to reply