Results 1 to 3 of 3

Thread: QTextEdit parenthesis matcher works - but only partially

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    May 2010
    Posts
    3
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default QTextEdit parenthesis matcher works - but only partially

    Hello dear llist,

    writing an interactive Lisp-editor I added a parenthesis matcher. I found a nice solution in Qt Quarterly issue 31/2009 at

    http://doc.trolltech.com/qq/

    Works well basically, but has a minor bug somewhere. Marking a left parenthesis always marks the corresponding right parenthesis correctly.

    But vice versa - so marking a right parenthesis - won't work in some cases. Examples how marking the last right parenthesis will behave:

    ;; fails
    (defun primep
    ((= 0 (mod x 2)) nil)
    )

    ;; works
    (defun primep
    ((= 0 (mod x 2)) nil))

    ;; works
    (defun nextprime (x)
    (loop for i from x
    when (primep i) return i))

    ;; fails
    (defun primep (x)
    (cond
    ((not (integerp x)) nil)
    ((< x 2) nil)
    ((= x 2) 2)
    ((= 0 (mod x 2)) nil)
    (t (loop for i from 3 to (isqrt x) by 2
    never (= 0 (mod x i))))))

    ;; fails
    (defun infix2prefix (infix-expression)
    (list (second infix-expression)
    (first infix-expression)
    (third infix-expression)))

    To try it out, paste it in the example code, which could be found at the link mentioned above or as attachment.

    To give you a more detailed pointer and to spare your time: The hot spot is near the end of "textedit.cpp", where you find the three functions:

    matchParentheses()
    matchLeftParenthesis(...
    matchRightParenthesis(...

    matchLeftParenthesis always works regardless how the code is formatted or how parenthesis are nested. matchRightParenthesis will work mostly, but not in every case. Interestingly matchRightParenthesis is only a mirror image from the left-function. So one would expect, that it will work as well as the left counterpart.

    Tried out a lot, but I am running out of ideas. Hope that some more clever people than I could give me a pointer.


    Kind regards, Heinz
    Attached Files Attached Files

Similar Threads

  1. Replies: 3
    Last Post: 26th April 2010, 03:15
  2. Replies: 5
    Last Post: 31st January 2009, 07:36
  3. Replies: 2
    Last Post: 19th December 2008, 15:57
  4. Replies: 1
    Last Post: 16th February 2007, 07:22

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.