On Sun, Jun 02, 2002 at 04:23:11PM -0500, David Beers wrote:
> > ?
> > AFAIK editors supporting syntax highlighting perform a 
> > textual analysis on
> > the text (usually source code, but not necessarily), 
> > following a set of rules
> > that permit to augment the internal representation of the text with
> > attributes (syntactic class and consequently color, font, 
> > ...). But these
> > attributes are usually kept internally and never saved along with the
> > original text or source code, so the hypothetical compiler translating
> > the same source file will never see anything but the original 
> > source code,
> > without any attributes or tags.
> 
> I considered this, but it sounds like an awfully expensive operation for a
> Palm application. Consider how often this textual analysis would need to
> take place. Every time the screen is redrawn (like if you scroll or insert
> some text) you would need to check each word on the screen against a huge
> list of API keywords.  It seems like the key to this working on a Palm is to
> break the analysis into small chunks (one word or line at a time) and to
> make the result of the analysis persistent in the text.  Or am I missing
> something?

No, you don't need to repeat the textual analysis at each screen redraw
operation. In the worst case you'll have to re-analyze the text only
when it does change. But there are a lot of possible optimizations: you
can (pre)identify syntactical boundaries and perform the analysis only
within boundaries of the modified portion for example, restricting it
to the visible area, ...
And the naive approach of searching each word in a list of keywords is
a very ingenuous one: an O(n * m) complexity! You can use a smarter
algorithm using hash tables or suffix trees (digital searching), ...

> 
> > Perhaps the easiest way to specify syntax rules suitable for 
> > syntax highlight
> > is through the use of regular expressions or similar pattern 
> > language, but
> > there are issues to keep into consideration like literal text 
> > contained
> > in strings or comments and so on. 
> 
> I've heard of regular expressions but am not familiar with them. I'll
> investigate this. If anyone  can point me in a specific direction with some
> links, I'd appreciate it.  

Google can find a good deal of links for you:

   http://etext.lib.virginia.edu/helpsheets/regex.html
   http://sitescooper.org/tao_regexps.html
   http://www.javaworld.com/javaworld/jw-07-2001/jw-0713-regex.html
   ...

If you have handy a unix workstation you can also use the `man' and/or `info'
commands:

   man 7 regex

   info rx

(POSIX standard 1003.2 defines a minimal regular expression language for
unix-like (well, POSIX-compliant actually) operating systems).

> > 
> > You can look at the source code of freely available editors 
> > implementing
> > syntax highlighting (like jed, vim, emacs, ...)
> 
> Any examples of something similar to these written for the Palm? In addition
> to my concerns about processor-intensive operations on the Palm, I've only
> been programming C for a few months and mostly just know the Palm API. Aside
> from that my programming knowledge mostly consists of scripting languages
> like Javascript and VBScript. 

Perhaps you could start with a less ambitious project then. Writing a
text editor is a difficult task per se, and adding syntax highlighting
only increases the complexity.
Note that the Palm CPU is faster than the ones you could find in many
workstations of some years ago. Writing good code is also a matter
of using the proper algorithms and making good use of available
resources.

Cheers,
Marco

-- 
========================================================================
Marco Pantaleoni                                  [EMAIL PROTECTED]
Padova, Italy                                              [EMAIL PROTECTED]
elastiC language developer                   http://www.elasticworld.org

-- 
For information on using the Palm Developer Forums, or to unsubscribe, please see 
http://www.palmos.com/dev/support/forums/

Reply via email to