Function List with comments after function name



  • I’m using a Cisco User Defined Language where I have exclamation points defined as comments:

                <Keywords name="Comments">00! 01 02((EOL)) 03 04</Keywords>
    

    This works fine in the Notepad++ edit view from a lexer point of view. I’ve also created a function list parser for this language that “partially” works. It follows:

    			<!-- ==================================================== [ CiscoIOS ] -->
    
    			<parser
    				displayName="Cisco IOS"
    				id         ="ciscoios"
    				commentExpr="(?x)
    								(?m-s:\!.*$)                                    # Single Line Comment
    							"
    			>
    				<function
    					mainExpr="(?:(?:^interface\s+\w+(?:/\d+)*)|(?:^router\s+\w+(?:\s+\d+)*))">
    					<functionName>
    						<nameExpr expr="(?:(?:^interface\s+)|(?:^router\s+))\K((\w)|(\.))+"/>
    						<nameExpr expr="((\w)|(\.))+"/>
    					</functionName>
    				</function>
    			</parser>
    
    

    The issue is when I have a config file that looks like this:

    interface Ethernet1
       switchport access vlan 280
       switchport trunk allowed vlan 280-281
       switchport mode trunk
    !
    interface Ethernet2
       switchport access vlan 281
       switchport trunk allowed vlan 280-281
       switchport mode trunk
    !
    interface Ethernet3
    !
    interface Ethernet4
    !
    

    The function list shows:

    Ethernet1
    Ethernet2
    

    It does not show Ethernet3 and 4. However, if I put a space before the exclamation point on the line after Ethernet3, Ethernet3 will show in the function list (after saving). Same for Ethernet4.

    It seems the comment character (exclamation point) on the first position of the line following the regex function name match renders the match invalid and it doesn’t show up in the function list.

    I’m sure it’s a combination of my regex-fu, sub-par understanding of UDLs and probably something stupid I’m missing. Hoping someone has a fix for this?

    Somewhat related: https://community.notepad-plus-plus.org/topic/19140/function-list-with-bash-scripts-not-fully-populating My answer for Bash illustrates the same behavior so maybe a fix here I can apply with that Bash parser too?

    Cheers.



  • See FAQ Desk Function List Basics for known issues addition.



  • @Michael-Vincent I guess “known issues” #4 and #5 apply.



  • @MAPJe71 said in Function List with comments after function name:

    I guess “known issues” #4 and #5 apply.

    Actually no, I have that covered. It was Issue #1:

    "Known Issues:

    Comment has to be preceded by at least two white-space characters e.g. carriage-return + line-feed, line-feed + one space or tab, or 2 spaces (for inline comment)."

    I converted my config from Unix line endings to Windows line endings and magically all the “Ethernet#” appeared in the function list. So that’s why adding a space before the comment worked, I needed 2 characters ( LF + space, or CR+LF ).

    Thanks for your comprehensive tutorial, you seem to be the master of the Function List parsers! I’ve added quite a few to my functionList.xml including some for UDL’s (protobuf, Cisco IOS).

    Cheers.





  • @Michael-Vincent Strange, I copied your parser and example config file “as is”, imported an UDL (CiscoIOS_1), added the applicable extension and UDL association, started Notepad++ and Function List displayed all four Ethernet interfaces.



  • Hello,@Michael-Vincent

    Regex Explanation :

    (?i) - modifier to make the search case-insensitive
    (?<=^function) - positive lookbehind to find the position immediately preceded by the sub-string function at the start of the line
    \s+ - matches 1+ occurrences of a white-space character
    \K - forget everything matched so far
    \w+ - matches 1+ occurrences of all the characters which fall within the character class [a-zA-Z0-9_]
    Add the following parser tag to the file functionList.xml

    <parser id="mylang" displayName="mylang_syntax">
        <function mainExpr="(?i)(?<=^function)\s+\K\w+" />
    </parser>
    

    I hope this information will be useful.
    Thank you.


Log in to reply