Community
    • Login

    FunctionList not working for UDL

    Scheduled Pinned Locked Moved Help wanted · · · – – – · · ·
    5 Posts 3 Posters 289 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.
    • G
      Grether2000
      last edited by

      I have a custom UDL syntax highlighting for CNC g-code and am trying to get the function list to populate for this. I am not even sure if it is trying to create the FunctionList for it though. It isn’t showing the filename or anything in the FunctionList window. I did check and at least a python file sample did work. So at least the built in ones are working.

      Debug info:

      Notepad++ v8.6.5   (64-bit)
      Build time : Mar 29 2024 - 17:04:43
      Path : C:\Program Files\Notepad++\notepad++.exe
      Command Line : 
      Admin mode : OFF
      Local Conf mode : OFF
      Cloud Config : OFF
      Periodic Backup : ON
      OS Name : Windows 10 Pro (64-bit
      OS Version : 22H2
      OS Build : 19045.4170
      Current ANSI codepage : 1252
      Plugins : 
          ComparePlugin (2.0.2)
          HexEditor (0.9.12)
          mimeTools (3.1)
          NCneticNpp (1)
          NppConverter (4.6)
          NppExec (0.8.2)
          NppExport (0.4)
          NppToolBucket (1.10.6622.41516)
          SQLinFormNpp64 (5.3.35)
          XMLTools (3.1.1.13)
      

      In %appdata%\notepad++\functionList
      overrideMap.xml I added after the other UDL samples

      <association id= "G-Code_PMC.xml"   userDefinedLangName= "GCode PMC" />
      

      In %appdata%\notepad++\functionList\ I created G-Code_PMC.xml
      I want to match the entire lines for the two regex.

      <?xml version="1.0" encoding="UTF-8" ?>
      <NotepadPlus>
      	<functionList>
      		<!-- GCode_PMC - Computer Numeric Control Syntax for use at PMC                              -->
      
      		<parser displayName="GCode PMC"  
      						id="gcodepmc_function"
      						<!-- commentExpr="(?s:/\*.*?\*/)|(?m-s://.*?$)" -->
      		>
      			<function
      				mainExpr="(?x)                                     # Utilize inline comments (see `RegEx - Pattern Modifiers`)
      					  ^(?im-s:[O:]\d+.*$)	             # Program number and comment
      					| ^(?im-s:\s*\(\s*INDEX.*\s*\)	     # Tool change Comment line
      					"
      			/>
      		</parser>
      	</functionList>
      </NotepadPlus>
      

      A trimmed down sample file of the CNC g-code
      This is recognized and working with my style UDL “GCode PMC”
      I’m only looking to match the O#### line and ( INDEX TO… ) lines But ANY matching would be a start.

      %
      O9332 (TESTCODE.M08)
      
      N0010
      #619=0010
      ( INDEX TO B0. -- T11 40-0652 FACEMILL 2.000 X 90 ALUM - CAT 40, ENDMILL  EXT LENGTH 1.500   )
      T11
      M6
      ...
      
      N0020
      #619=0020
      ( INDEX TO B0. -- T12 40-0733 TD 0.2500  :S - "CAT 40, ER-20 X2.5"  EXT LENGTH 1.880   )
      T12
      M6
      ...
      
      N0030
      #619=0030
      ( INDEX TO B0. -- T13 41-3812 EM 0500 :1FL - CAT 40 SHORT ER-20 HOLDER  EXT LENGTH 1.750   )
      T13
      M6
      ...
      
      G90 G0 Z14.0 M09
      ( TOTAL TIME =29:22.7   MIN. )
      M30
      %
      
      PeterJonesP 1 Reply Last reply Reply Quote 1
      • PeterJonesP
        PeterJones @Grether2000
        last edited by PeterJones

        @Grether2000,

        I pared it back to bare-bones, then slowly built it up close to yours

        775437c7-8f0f-4360-8a16-2e80aac26054-image.png

        <?xml version="1.0" encoding="UTF-8" ?>
        <NotepadPlus>
            <functionList>
        		<!-- GCode_PMC - Computer Numeric Control Syntax for use at PMC                              -->
                <parser
                    displayName="GCode PMC"
                    id         ="gcodepmc_function"
                >
                    <function
                        mainExpr="(?x)								# Utilize inline comments (see `RegEx - Pattern Modifiers`)
        					^(?im-s:[O:]\d+.*$)						# Program number and comment
        					|
        					^(?im-s:\s*.*INDEX.*$)						# Tool change Comment line
        				"
                    >
                        <functionName>
                            <nameExpr expr="(?x)					# Utilize inline comments (see `RegEx - Pattern Modifiers`)
        						^(?im-s:[O:]\d+.*$)					# Program number and comment
        						|
        						^(?im-s:\s*\(\s*.*INDEX.*\))		# Tool change Comment line
        				"/>
                        </functionName>
                    </function>
                </parser>
            </functionList>
        </NotepadPlus>
        

        One problem was your comment inside the <parser ...<!-- ... --> ... > – XML does not allow a comment nested inside the brackets of a tag like that…

        There was something subtle in the regex that didn’t let it work as-is (at least for me), so I got it to a functioning point starting from scratch and slowly adding similar features.

        And I’ve never tried a function without a functionName, so I put that in without ever trying without it.

        G 1 Reply Last reply Reply Quote 4
        • guy038G
          guy038
          last edited by guy038

          Hello, @grether2000, @peterjones and All,

          @grether2000, I suppose that you can simplify the G-Code_PMC.xml file as below :

          <?xml version="1.0" encoding="UTF-8" ?>
          <NotepadPlus>
              <functionList>
                  <!-- GCode_PMC - Computer Numeric Control Syntax for use at PMC -->
                  <parser
                      displayName="GCode PMC"
                      id         ="gcodepmc_function"
                  >
                      <function
                          mainExpr=
                          "(?x)                                     # See 'RegEx - Pattern Modifiers'
                              (?-s)^[O:]\d+.*                       # Program number and comment
                              |                                     # OR
                              (?-is)^[\t\x20]*\([\t\x20]*INDEX.*\)  # Tool change Comment line
                          "
                      >
                      </function>
                  </parser>
              </functionList>
          </NotepadPlus>
          

          Now :

          • If all your lines, which contain the INDEX string, are of the form ( INDEX ......)

          AND

          • IF all your lines, beginning with an O uppercase letter, are followed with a number

          you may even use these less restrictive regexes :

          <?xml version="1.0" encoding="UTF-8" ?>
          <NotepadPlus>
              <functionList>
                  <!-- GCode_PMC - Computer Numeric Control Syntax for use at PMC -->
                  <parser
                      displayName="GCode PMC"
                      id         ="gcodepmc_function"
                  >
                      <function
                          mainExpr=
                          "(?x)                 # See 'RegEx - Pattern Modifiers'
                              (?-s)^[O:].*      # Program number and comment
                              |                 # OR
                              (?-is)^.*INDEX.*  # Tool change Comment line
                          "
                      >
                      </function>
                  </parser>
              </functionList>
          </NotepadPlus>
          

          I’m also wondering about the colon character within the regex for the Program number and comment rule :

          Do you mean that the line :9332 (TESTCODE.M08) can be a legal line ?

          Best Regards,

          guy038

          PS :

          • For my tests, I simply linked the G-Code_PMC.xml file to the None (Normal Text) language, by default, with the following line in the overrideMap.xml file
                      <association id="G-Code_PMC.xml" langID="0" />
          
          • I tried to get information about G-Code from this site :

          https://linuxcnc.org/docs/html/gcode/overview.html

          1 Reply Last reply Reply Quote 1
          • G
            Grether2000 @PeterJones
            last edited by Grether2000

            @PeterJones THANK YOU!
            This solved the problem.
            I wasn’t sure it was even working for a while, that was causing me to pull my hair out looking for the cause. After all it was just a stupid mistake with not removing parts I didn’t need.
            Now that I have it working I can make any adjustments to the regex. I’ll need to add some other matches for other machines and their comment formats.

            @guy038 Thank you as well.
            Yes the O or : are valid.
            Your examples give me a few suggestions on ways to improve this for how the code can get created, or saved after use. These are actually comments, and not functions. But it is how we document and organize the code by the tooling used.

            PeterJonesP 1 Reply Last reply Reply Quote 3
            • PeterJonesP
              PeterJones @Grether2000
              last edited by PeterJones

              @Grether2000 said in FunctionList not working for UDL:

              I’ll need to add some other matches for other machines and their comment formats.

              When you’ve got it working, feel free to submit your UDL and its FunctionList to the UDL Collection – right now, it doesn’t have a section for FunctionList, but since FunctionLists can be associated with UDLs, I think it makes sense to add a folder to house them.

              —

              Update: The UDL Collection repo now has the functionList folder, and has the attributes and validators necessary to handle Function List definitions for the UDLs as well.

              1 Reply Last reply Reply Quote 2
              • First post
                Last post
              The Community of users of the Notepad++ text editor.
              Powered by NodeBB | Contributors