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”:
    1)
    Each function/macro starts at the beginning of a line with “#macro”.
    2)
    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.
    3)
    Single-line comments are indicated by a double hashtag “##”.
    4)
    Multi-line comments are started by “#" and ended by "#”.
    5)
    Each function/macro end with “#end”, which again is placed at the beginning of a line.
    6)
    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:

    #if($dummy)
     #set($dummy = false)
    #end
    

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

    #macro(Macro_ShowNotes)
    ##single-line comment
    #set($dummy = true)
    #if($dummy)
     #set($dummy = false)
    #end
    #*
     multi-line comment
     multi-line comment
    *#
    #if(!$dummy)
     #set($dummy = true)
    #end
    #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>
    #end
    


  • @Martin1975

    There is info about the “appdata” part of your question here: https://community.notepad-plus-plus.org/topic/15740/faq-desk-what-is-appdata

    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:

    <NotepadPlus>
    	<functionList>
    		<associationMap>
    			<association id=         "vtl_syntax"        userDefinedLangName="VTL"                />
    			<association id=         "vtl_syntax"        userDefinedLangName="Velocity"           />
    			<association id=         "vtl_syntax"        ext=".vm"                                />
    		</associationMap>
    		<parsers>
    			<!-- ============================================== [ VTL / Velocity ] -->
    
    			<!--
    			|   Based on:
    			|       https://community.notepad-plus-plus.org/topic/19098/function-list-parser-for-user-defined-language-velocity
    			\-->
    			<parser
    				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
    					"
    			>
    				<function
    					mainExpr="(?x)                                              # free-spacing (see `RegEx - Pattern Modifiers`)
    							^\h*                                                # optional leading white-space at start-of-line
    							(?:\x23macro)
    							\K                                                  # discard text matched so far
    							\(
    							(?'VALID_ID'
    								[A-Za-z][\w-]*
    							)
    							(?:
    								\h+
    								\$(?&amp;VALID_ID)
    							)*
    							\)
    						"
    				/>
    			</parser>
    
    			<!-- ================================================================= -->
    		</parsers>
    	</functionList>
    </NotepadPlus>
    


  • @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
    Martin


Log in to reply