Community
    • Login

    FunctionList with UDL

    Scheduled Pinned Locked Moved Help wanted · · · – – – · · ·
    3 Posts 2 Posters 535 Views
    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.
    • Akil Turner-RichardsA
      Akil Turner-Richards
      last edited by

      Good Day,
      I have defined a custom language using the UDL and I’ve already edited the overrideMap file to include this language. I’m having problems with writing the Regex in order to parse the functions. The syntax for defining a function is very simple:

      Lbl Foo
         Code
      Return
      

      There’s no defining parameters or any bracketing or parentheses. However, in the case that I may want to conditionally exit, I can also include conditional Return statements:

      Lbl Foo
         Code
         ReturnIf Something
         Code
         Return!If Someotherthing
      Return
      

      Additionally, I would like to ensure that commented out functions aren’t parsed. They look like this:

      ./single line comment
      .../
         multi
         line
         comment
      ...
      

      How do I accomplish this in my FunctionList file? What I have so far is this:

      <?xml version="1.0" encoding="UTF-8" ?>
       <NotepadPlus>
      	<functionList>
      		<!-- ====================================================== [ Axe ] -->
      			<parser 
      				displayName="Axe"
      				id="axe_function"
      			>
      				<function mainExpr="(?x)Lbl">
      					<functionName>
      						<nameExpr expr="(?x)Lbl"/>
      					</functionName>
      				</function>
      			</parser>
      	</functionList>
      </NotepadPlus>
      

      I’m hoping someone far more knowledgeable than me can help. Thanks.

      PeterJonesP 1 Reply Last reply Reply Quote 0
      • PeterJonesP
        PeterJones @Akil Turner-Richards
        last edited by

        @Akil-Turner-Richards

        However, in the case that I may want to conditionally exit, I can also include conditional Return statements

        That will affect the UDL, but not the FunctionList, because FunctionList is only looking for the beginning of the function name.

        If you want the function name, not just Lbl to show up in the function list, use something like

        				<function mainExpr="(?x-s) Lbl \h+ .*">
        					<functionName>
        						<nameExpr expr="(?x-s) Lbl \h+ .*"/>
        					</functionName>
        				</function>
        

        If you want to strip Lbl out of the FunctionList panel, then change <nameExpr expr="(?x-s) Lbl \h+ \K .*"/>

        For the UDL, how to handle the Return vs ReturnIf or Return!If can vary. I defined mine as Folding In Code 2, which then means that the Return will not match ReturnIf or Return!If.

        (Sorry, I was going to include an image, but image paste-embedding isn’t working this instant… hopefully, that will start working again soon)

        Additionally, I would like to ensure that commented out functions aren’t parsed.

        Then you need the commentExpr attribute in the <parser open-tag. I developed the following based on my understanding and guesses.

        <?xml version="1.0" encoding="UTF-8" ?>
         <NotepadPlus>
            <functionList>
                <!-- ====================================================== [ Axe ] -->
                    <parser 
                        displayName="Axe"
                        id="axe_function"
                        commentExpr="(?x)                                               # Utilize inline comments (see `RegEx - Pattern Modifiers`)
                            # single line comment defined here: ./ followed by anything
                            (?xm-s)                                                     # ^$ matches inside multiline match; . doesn't match newline
                            \s+                                                         # must be a space or newline before the ./
                            \.                                                          # literal .
                            /                                                           # literal /
                            .*                                                          # 0 or more after ./
                            $                                                           # until EOL
                        |                   # OR
                            # multi line comment defined here: .../ followed by anything, ending with ...
                            (?xms)                                                      # inline comments, ^$ matches any line, . matches newline
                            \s+
                            \.{3}
                            /
                            .*?
                            ^
                            \s*
                            \.{3}
                        "
                    >
                        <function mainExpr="(?x-s) Lbl \h+ .*">
                            <functionName>
                                <nameExpr expr="(?x-s) Lbl \h+ .*"/>
                            </functionName>
                        </function>
                    </parser>
            </functionList>
        </NotepadPlus>
        

        So if I have the blah.axe file:

        ./single line comment
        Lbl foo
            Code
            ReturnIf Something
            Code
            Return!If Someotherthing
        Return
        
        ./Lbl dotslash
        
        code
        
        .../
            multi
            line
            comment
        ...
        
        code
        
        .../
        Lbl commented
            Code
        Return
        ...
        
        code
        
        Lbl final
            Code
        Return
        

        It will show a function list of

        • Lbl foo
        • Lbl final

        (Again, I was going to embed an image, but it’s not letting me.)

        With your original code, it showed

        • Lbl foo
        • Lbl dotslash
        • Lbl commented
        • Lbl final

        So I think that confirms it does what you want.

        Akil Turner-RichardsA 1 Reply Last reply Reply Quote 4
        • Akil Turner-RichardsA
          Akil Turner-Richards @PeterJones
          last edited by

          @PeterJones Thanks so much! This is exactly what I wanted. Appreciate the swift response.

          1 Reply Last reply Reply Quote 0
          • PeterJonesP PeterJones referenced this topic on
          • First post
            Last post
          The Community of users of the Notepad++ text editor.
          Powered by NodeBB | Contributors