Community

    • Login
    • Search
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search

    Function List with comments after function name

    Help wanted · · · – – – · · ·
    3
    7
    199
    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.
    • Michael Vincent
      Michael Vincent last edited by

      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.

      MAPJe71 1 Reply Last reply Reply Quote 1
      • MAPJe71
        MAPJe71 last edited by

        See FAQ Desk Function List Basics for known issues addition.

        1 Reply Last reply Reply Quote 0
        • MAPJe71
          MAPJe71 @Michael Vincent last edited by

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

          Michael Vincent 1 Reply Last reply Reply Quote 0
          • Michael Vincent
            Michael Vincent @MAPJe71 last edited by

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

            1 Reply Last reply Reply Quote 2
            • MAPJe71
              MAPJe71 last edited by

              See my “Languages” collection.

              1 Reply Last reply Reply Quote 0
              • MAPJe71
                MAPJe71 last edited by

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

                1 Reply Last reply Reply Quote 1
                • Makwana Prahlad
                  Makwana Prahlad Banned last edited by

                  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.

                  1 Reply Last reply Reply Quote 0
                  • First post
                    Last post
                  Copyright © 2014 NodeBB Forums | Contributors