Results 1 to 3 of 3

Thread: Qtextedit parsing multiple lines as in an IDE

  1. #1
    Join Date
    Mar 2013
    Posts
    12
    Qt products
    Platforms
    Windows

    Default Qtextedit parsing multiple lines as in an IDE

    I'm trying to write my own code-editor, I figure its a good way to learn pyQt. I am using a qtextedit, in which i can write code(it's not real code, more pseudo code). Each line represents ending in a semi-colon represents some command e.g.

    Qt Code:
    1. PSEUDO->FWD->90;
    2. PSEUDO->STOP;
    3. PSEUDO->RIGHT 90;
    4. PSEUDO->FWD 10;
    To copy to clipboard, switch view to plain text mode 

    These are relatively easy to read, as the user presses the [ENTER] the current line is read, parsed and checked for errors so the following

    Qt Code:
    1. PSEUDO->RIGHT -pi/2
    To copy to clipboard, switch view to plain text mode 

    would generate an error because the line doesn't end in a semi-colon and the value following RIGHT needs to be a number.(my editor, my rules).All this I have more or less got working.

    I would like to know how to do multiple lines though. I am familiar with editors such as Eclipse,sublime or visual studio which handle muliple lines very well, in my case

    Qt Code:
    1. PSEUDO->DO:
    2. FWD->90
    3. RIGHT->45
    4. FWD->10
    5. LEFT->55
    6. FWD->50
    7. STOP;
    To copy to clipboard, switch view to plain text mode 

    Should all be read in and treated as one statement, starting at the keyword PSEUDO and ending at the semi-colon. However the following should be read as 3 separate statements.
    Qt Code:
    1. PSEUDO->DO:
    2. FWD->90
    3. RIGHT->45
    4. FWD->10
    5. LEFT->55
    6. FWD->50
    7. STOP;
    8.  
    9. PSEUDO->DO:
    10. FWD->90
    11. RIGHT->45
    12. STOP;
    13.  
    14. PSEUDO->BACK 10;
    To copy to clipboard, switch view to plain text mode 

    My question how can I go about reading multiple lines as described above from QTextEditor as discreet statements. Should I do the parse/check whenever I press the [ENTER] key for a new line?

    I'm using python2.7,pyQT, and QTextEdit. But if there are any Qt samples I'll do my best to follow.

    My first idea is using an anchor, i.e whenever the word PSEUDO-> is written I drop an anchor just before the word, and then when a semi-colon( is typed. I read backwards from the semi-colon to the last anchor.
    • Is this a good suggestion?
    • Can anchors be used in this way?
    • What do editors like QtCreator,Eclipse,Sublime or even Visual Studio do to solve this kind of problem

  2. #2
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,734
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: Qtextedit parsing multiple lines as in an IDE

    Your syntax makes the semicolon the end-of-statement mark.
    Naive approach assuming the statements are processed as entered:
    • Keep a statement buffer.
    • When the user presses Enter copy the line onto the end of the buffer.
    • Look at the last non-space in the buffer, if it is ';' then process the buffer and empty it.

    If terminating semicolons can appear mid-line then you have to process only the whole statements in the buffer and keep whatever remains afterwards.

  3. #3
    Join Date
    Mar 2013
    Posts
    12
    Qt products
    Platforms
    Windows

    Default Re: Qtextedit parsing multiple lines as in an IDE

    Just curious, but could I use a regular expression, I am not fully familiar to QRegEx or QRegularExpression, but could I use them in some way to determine when its sensible to parse a statement? If so any suggestions on how I could go about doing so?

Similar Threads

  1. Struct Parsing, multiple name typedef failing
    By Syndacate in forum Qt Tools
    Replies: 1
    Last Post: 12th July 2011, 07:47
  2. QTextEdit html parsing trouble
    By DpoHro in forum Qt Programming
    Replies: 1
    Last Post: 20th January 2008, 11:40
  3. QTextEdit: how to get lines?
    By claudio in forum Qt Programming
    Replies: 2
    Last Post: 15th July 2007, 21:08
  4. Spaces between lines in QTextEdit
    By troorl_ua in forum Qt Programming
    Replies: 1
    Last Post: 3rd July 2007, 00:06
  5. space between lines in QTextEdit
    By Lele in forum Qt Programming
    Replies: 2
    Last Post: 19th September 2006, 13:05

Tags for this Thread

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.