19 Dec 2007 @ 12:55 AM 
 

Colorizer Part II.V

 

A friend of mine pointed out to me one possible way of finding syntax errors, and resuming parsing after one successfully. The key is to split the input text on some known divider. It’s possible that your grammar won’t have one, but in the case of, say… C#, you can split all the statements on ‘}’ and ‘;’ . Then you can store each as an independently parsed string (even store it’s parse tree in a linked list or array or something) and then flag each with an error or not. This is a great trick, provided that you have some identifiable block/line terminator to split on. For line based grammars this is exceptionally easy.. just split on newlines… for not line based grammars, you might split on block terminators only, like ‘end’ in ‘Simple.’ At least then you have some smaller unit of ‘parse’ to work with and you can track state of parsing across a document with some degree of efficiency. That also means you can trigger the ‘re-parsing’ of small segments when new text is added or pasted. Very interesting. I’m right now trying to think of a case that there wouldn’t be a way to do this… perhaps some functional languages would be eternally nesting… but as far as I’m concerned that’s a corner case ;)

Tags Categories: .NET Coding Posted By: Dave
Last Edit: 19 Dec 2007 @ 12 55 AM

E-mailPermalink
 

Responses to this post » (None)

 


Comments are open. Feel free to leave a comment below.


 Comment Meta:
RSS Feed for comments
TrackBack URI
 

Leave A Comment ...

 

 XHTML:
You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>
\/ More Options ...
Change Theme...
  • Role »
  • Posts »
  • Comments »
Change Theme...
  • VoidVoid (Default)
  • LifeLife
  • EarthEarth
  • WindWind
  • WaterWater
  • FireFire
  • LiteLightweight
  • No Child Pages...