Partial Parsing for colour coding
2 posts in topic
Flat View  Flat View

Posted By:   sonali_chitnis
Posted On:   Tuesday, April 24, 2001 12:26 AM

Is it possible to parse a file on block by block basis.Rather than writing the compelete file and then parsing it I want to check validity of the file while it is being written.I want this to support color coding of the syntactically correct blocks in the file.
For example while writing a java file If I write a syntactically correct "For loop" it should get parsed so that i can colour code it.Here please note that i have not written the complete java file.

Re: Re: Partial Parsing for colour coding

Posted By:   Sandip_Chitale  
Posted On:   Wednesday, April 25, 2001 11:55 PM

Atleast for color-coding purposes one does not need to parse a file. This is especially true for comments as
comments are normally ignored by the

One can simply tokenize the file using what are called "lexers". Then you could catagorize the
tokens into say-





Each catagory could have an associated a javax.swing.text.Style. Then you could
apply that style to that run of the
text. You could use javax.swing.JTextPane for it.

There is a sample implementation here -


Re: Partial Parsing for colour coding

Posted By:   Terence_Parr  
Posted On:   Wednesday, April 25, 2001 05:56 PM

You are essentially asking about incremental parsing, which is not a easy thing to do. You have to break up the input into multiple chunks of what is valid and what is not yet valid. Not an easy thing to do as it has to be properly integrated into an editor etc...

On the other hand, if your computer is fast, you could reparse most of the input upon keypress ;)
About | Sitemap | Contact