• Login
Community
  • Login

Does the UDL miss the ablity to recognize methods and classes?

Scheduled Pinned Locked Moved Help wanted · · · – – – · · ·
classmethodsyntaxudlhighlighting
19 Posts 5 Posters 5.4k 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.
  • C
    Claudia Frank @Andreas Wiese
    last edited by Claudia Frank Aug 9, 2018, 8:19 PM Aug 9, 2018, 8:17 PM

    @Andreas-Wiese

    if you are asking whether udl supports regex then the answer is no, not currently
    but if the question is if the python script could be used with regex then yes, it can and
    it is used in this example

    As you see, only the keywords true and null have been defined, as well as
    two delimiters, one using ( and ) and the other for strings using ’ and ’

    A script to accomplish this could look like this

    from Npp import editor, notepad, NOTIFICATION, SCINTILLANOTIFICATION, INDICATORSTYLE
    
    # to use this for a different language, three steps need to be done
    
    # 1. replace the EnhancedUDLLexer string with a different but unique name,
    # Note, checkout the string_needs_to_be_replace_here marks
    try:
        # string_needs_to_be_replace_here
        EnhancedUDLLexer().main()
    except NameError:
    
        # string_needs_to_be_replace_here
        class SingletonEnhancedUDLLexer(type):
            _instances = {}
            def __call__(cls, *args, **kwargs):
                if cls not in cls._instances:
                    # string_needs_to_be_replace_here
                    cls._instances[cls] = super(SingletonEnhancedUDLLexer, cls).__call__(*args, **kwargs)
                return cls._instances[cls]
    
        # string_needs_to_be_replace_here
        class EnhancedUDLLexer(object):
    
            # string_needs_to_be_replace_here
            __metaclass__ = SingletonEnhancedUDLLexer
    
            @staticmethod
            def set_indicator_attributes(indicator_number, fore=(0,0,0)):
                editor.indicSetFore(indicator_number, fore)
                editor.indicSetStyle(indicator_number, INDICATORSTYLE.TEXTFORE)
                return indicator_number
    
    
            @staticmethod
            def paint_it(indicator, pos, length):
                editor.setIndicatorCurrent(indicator)
                editor.indicatorFillRange(pos,length)
    
    
            def do_regex(self, regex, indicator, start_position, end_position):
                editor.setIndicatorCurrent(indicator)
                editor.indicatorClearRange(start_position, end_position-start_position)
                editor.research(regex,
                                lambda m: self.paint_it(indicator, m.span(0)[0], m.span(0)[1] - m.span(0)[0]),
                                0,
                                start_position,
                                end_position)
    
    
            def style(self):
                line_number = editor.getFirstVisibleLine()
                start_position = editor.positionFromLine(line_number)
                end_position = editor.getLineEndPosition(line_number + editor.linesOnScreen())
                for indicator, regex in self.regex_dict.items():
                    self.do_regex(regex, indicator, start_position, end_position)
    
    
            def __init__(self):
                editor.callbackSync(self.on_updateui, [SCINTILLANOTIFICATION.UPDATEUI])
                notepad.callback(self.on_langchanged, [NOTIFICATION.LANGCHANGED])
                notepad.callback(self.on_bufferactivated, [NOTIFICATION.BUFFERACTIVATED])
    
                self.__is_lexer_doc = False
                self.get_lexer_name = lambda: notepad.getLanguageName(notepad.getLangType())
    
    
            def set_lexer_doc(self,bool_value):
                editor.setProperty(self.__class__.__name__, 1 if bool_value is True else -1)
                self.__is_lexer_doc = bool_value
    
    
            def on_bufferactivated(self,args):
                if self.get_lexer_name() == self.lexer_name and editor.getPropertyInt(self.__class__.__name__) != -1:
                    self.__is_lexer_doc = True
                else:
                    self.__is_lexer_doc = False
    
    
            def on_updateui(self,args):
                if self.__is_lexer_doc:
                    self.style()
    
    
            def on_langchanged(self,args):
                self.set_lexer_doc(True if self.get_lexer_name() == self.lexer_name else False)
    
    
            def main(self):
                # 2. define the lexer language, normally like what is returned by notepad.getLanguageName
                self.lexer_name = 'udf - test'
    
                # 3. define needed indicator_ids, indicator_fore_colors and regexes
                self.regex_dict = {
                                    self.set_indicator_attributes(18, fore=(131,255,245)) : u'([A-Za-z][\w+]*)(?=\()',
                                    self.set_indicator_attributes(19, fore=(255,137,115)) : u'([A-Za-z][\w+]*)(?=\.)',
                                  }
    
                self.set_lexer_doc(True)
                self.style()
    
        # string_needs_to_be_replace_here
        EnhancedUDLLexer().main()
    

    Note, focus was on portability not on performance and
    you need to call it for each of the two views npp supports if you want
    to have it automatically coloring udl docs in both views.

    Cheers
    Claudia

    S 1 Reply Last reply Aug 10, 2018, 11:53 AM Reply Quote 1
    • S
      Scott Sumner @Claudia Frank
      last edited by Aug 10, 2018, 11:53 AM

      @Claudia-Frank

      I’m looking forward to seeing steps 2 and 3! :-D

      C 1 Reply Last reply Aug 10, 2018, 11:55 AM Reply Quote 0
      • C
        Claudia Frank @Scott Sumner
        last edited by Aug 10, 2018, 11:55 AM

        @Scott-Sumner

        well, might happen when you start scrolling :-D

        Cheers
        Claudia

        S 1 Reply Last reply Aug 10, 2018, 11:57 AM Reply Quote 2
        • S
          Scott Sumner @Claudia Frank
          last edited by Scott Sumner Aug 10, 2018, 11:58 AM Aug 10, 2018, 11:57 AM

          @Claudia-Frank

          Got it! (I guess I expected them to be closer together, like is shown here )

          :-D

          C 1 Reply Last reply Aug 10, 2018, 12:02 PM Reply Quote 0
          • C
            Claudia Frank @Scott Sumner
            last edited by Aug 10, 2018, 12:02 PM

            @Scott-Sumner

            well sometimes you have to have changes in your life to keep it exciting :-)
            Seems we are back to future again - I answered your question 1 minute before you
            were asking it and you did it even 3 minutes before I was answering it :-D

            Cheers
            Claudia

            S 1 Reply Last reply Aug 10, 2018, 12:12 PM Reply Quote 3
            • S
              Scott Sumner @Claudia Frank
              last edited by Aug 10, 2018, 12:12 PM

              @Claudia-Frank

              back to the future again

              Yea, I’d much rather see 10-Aug-2018 7:47a than 2 minutes ago or six months ago anyway, but geez, if they’re going to do it that way (relatively), can’t they at least get it right? This will be confusing to any future readers, so here is the progression of the last several posting timestamps, as of RIGHT NOW:

              Imgur

              It would be really cool to go to an absolute timestamp here, how can that be made to happen?

              C 1 Reply Last reply Aug 10, 2018, 12:17 PM Reply Quote 2
              • C
                Claudia Frank @Scott Sumner
                last edited by Aug 10, 2018, 12:17 PM

                @Scott-Sumner

                Now it is back on track - thx for your image otherwise future readers must think we are insane :-)

                Cheers
                Claudia

                1 Reply Last reply Reply Quote 2
                • P
                  PeterJones
                  last edited by PeterJones Aug 10, 2018, 1:10 PM Aug 10, 2018, 1:09 PM

                  There have been times that immediately after hitting SUBMIT, I see “PeterJones posted 7 minutes ago”…

                  I almost wonder if the timestamp issue here is similar to the one I described in the browser refresh thread : if there’s more than one server here, with different times – so that some people get one timestamp and some get the other.

                  The other possibility I can think of: NodeBB might assign the timestamp when you hit REPLY and get the compose window, rather than when you hit SUBMIT. So if you take longer to author and post your node, your post goes farther into the past. (Though if you’re replying to an existing node, I don’t see how that would explain your post showing with an earlier timestamp than the one you’re replying to. That goes back to my multiple-server-times hypothesis.)

                  update: appropriately, this one showed up as exactly “7 minutes ago” like I said above. :-)

                  C 1 Reply Last reply Aug 10, 2018, 1:29 PM Reply Quote 2
                  • C
                    Claudia Frank @PeterJones
                    last edited by Claudia Frank Aug 10, 2018, 1:31 PM Aug 10, 2018, 1:29 PM

                    @PeterJones

                    what is strange is that if you hover over the timestamp then it does show the correct time.
                    Although I don’t know the server setup I would say that nowadays no server-ops should
                    have troubles to install “clustered” servers with time sync - most OSes which
                    support clustering do have it anyway and rely on it to work correctly.
                    It’s really strange …

                    Cheers
                    Claudia

                    Update: just said and proven to be incorrect. Just hovered, immediately after submitting the post,
                    over the timestamp and … it is wrong.

                    1 Reply Last reply Reply Quote 2
                    • C
                      Claudia Frank
                      last edited by Aug 10, 2018, 1:36 PM

                      I see - once the post passes the “lead time” it is correct again.

                      Cheers
                      Claudia

                      Χ 1 Reply Last reply Aug 14, 2018, 6:20 AM Reply Quote 2
                      • Χ
                        Χρήστος Κοτζιάς @Claudia Frank
                        last edited by Χρήστος Κοτζιάς Aug 14, 2018, 6:22 AM Aug 14, 2018, 6:20 AM

                        @Claudia-Frank

                        *AUTO
                        DEMODISK = 0
                        ORG = $5400
                        TR ON
                        LST OFF

                        ***PRINCE OF PERSIA
                        ***COPYRIGHT 1989 JORDAN MECHNER

                        ORG ORG

                        JMP AUTOCTRL
                        JMP CHECKSTRIKE
                        JMP CHECKSTAB
                        JMP AUTOPLAYBACK
                        JMP CUTCHECK

                        JMP CUTGUARD
                        JMP ADDGUARD
                        JMP CUT

                        ADDAMOB LDX $0500 ;THIS IS A COMMENT, THE ABOVE LINE ISN’T ACTUALCODE

                        (LABEL MNEMONIC(LDX) OPERAND($0500) ;COMMENT)

                        CPX #MAXMOB
                        BEQ :RTS

                        INX
                        STX NUMMOB

                        JMP SAVEMOB

                        .
                        .
                        .
                        .

                        This is a 6502 assembly source code made with the Merlin assembler for the Prince of Persia game (copyright to Jordan Mechner)

                        Somewhere in the middle of that code you will see the typical syntax of the assembler. It goes like --> a) LABEL b) MENMONIC c) OPERAND and d) COMMENTS

                        4 columns all the time, some of them are optional (LABELS and COMMENTS and rarely OPERANDS)

                        1. Mnemonics are fixed keywords. I can highlight them. :)
                        2. Operands are sometimes fixed and sometimes not, but I don’t want to highlight the non-fixed since I can highlight the fixed ones.
                        3. Comments start with “;” or “*” and I can highlight them.
                        4. Labels are not fixed keywords and I want to use a different color for them.
                          LABELS -always- start in the beginning of a new line. NO space precedes them.
                          Is it possible to color every word and ONLY THAT WORD who is the first ONE of each line of code???

                        Thanks in advance :)

                        C 1 Reply Last reply Aug 14, 2018, 1:01 PM Reply Quote 1
                        • C
                          Claudia Frank @Χρήστος Κοτζιάς
                          last edited by Aug 14, 2018, 1:01 PM

                          @Χρήστος-Κοτζιάς

                          Yes, can be done when you are willing to install python script plugin.

                          From my understanding of 6502 assembler and your description the label needs to be
                          followed by known mnemonic fields. Keeping this in mind and using a slightly
                          modified version of the script I posted above you would get something like

                          The part of the script which needs to be modified is within the main function

                              def main(self):
                                  # 2. define the lexer language, normally like what is returned by notepad.getLanguageName
                                  self.lexer_name = 'Assembly'
                          
                                  # 3. define needed indicator_ids, indicator_fore_colors and regexes
                                  self.regex_dict = {
                                                      self.set_indicator_attributes(18, fore=(131,255,245)) : u'^\w+?(?= LDA| LDX| LDY)',
                                                    }
                          
                                  self.set_lexer_doc(True)
                                  self.style()
                          

                          First you need to change the self.lexer_name with your udl name.
                          Run notepad.getLanguageName(notepad.getLangType()) in the python script console
                          after assigning your udl language to a document. I chose the assembly lexer for
                          demonstration purpose.

                          Second you need to extend the list of know mnemonic words in the regex

                          u'^\w+?(?= LDA| LDX| LDY)',
                          

                          Cheers
                          Claudia

                          Χ 1 Reply Last reply Aug 15, 2018, 8:55 AM Reply Quote 2
                          • Χ
                            Χρήστος Κοτζιάς
                            last edited by Χρήστος Κοτζιάς Aug 15, 2018, 8:24 AM Aug 15, 2018, 8:22 AM

                            This post is deleted!
                            1 Reply Last reply Reply Quote 0
                            • Χ
                              Χρήστος Κοτζιάς @Claudia Frank
                              last edited by Aug 15, 2018, 8:55 AM

                              @Claudia-Frank

                              http://tinypic.com/r/4r4904/9

                              I have uploaded a screenshot from the built-in editor of the Merlin Pro assembler (Applewin emulator, Enhanced Apple IIe system)

                              Can you see it?

                              C 1 Reply Last reply Aug 15, 2018, 11:57 AM Reply Quote 0
                              • C
                                Claudia Frank @Χρήστος Κοτζιάς
                                last edited by Aug 15, 2018, 11:57 AM

                                @Χρήστος-Κοτζιάς

                                Yes, I’m able to see your uploaded image.
                                What is your question or what did I miss?

                                Cheers
                                Claudia

                                1 Reply Last reply Reply Quote 0
                                14 out of 19
                                • First post
                                  14/19
                                  Last post
                                The Community of users of the Notepad++ text editor.
                                Powered by NodeBB | Contributors