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