Community
    • Login

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

    Scheduled Pinned Locked Moved Help wanted · · · – – – · · ·
    4 Posts 3 Posters 2.1k Views 1 Watching
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • Martin1975M Offline
      Martin1975
      last edited by

      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
      
      Alan KilbornA 1 Reply Last reply Reply Quote 0
      • Alan KilbornA Offline
        Alan Kilborn @Martin1975
        last edited by

        @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.

        1 Reply Last reply Reply Quote 3
        • MAPJe71M Offline
          MAPJe71
          last edited by

          @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>
          
          Martin1975M 1 Reply Last reply Reply Quote 3
          • Martin1975M Offline
            Martin1975 @MAPJe71
            last edited by

            @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

            1 Reply Last reply Reply Quote 4

            Hello! It looks like you're interested in this conversation, but you don't have an account yet.

            Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.

            With your input, this post could be even better 💗

            Register Login
            • First post
              Last post
            The Community of users of the Notepad++ text editor.
            Powered by NodeBB | Contributors