I need an idea for practise!
rantingrickjohnson at gmail.com
Thu Jul 17 21:30:26 CEST 2014
On Thursday, July 17, 2014 12:20:13 PM UTC-5, Chris Angelico wrote:
> By the way, one specific point about RR's advice: A
> colorizer should *not* be written using regexps. It'd make
> for an absolute nightmare of impossible-to-debug regexp
Just because *YOU* harbor irrational fears of regexp pattern
syntax, does mean the rest of us should propagate your
religious beliefs and worship your "shrines of
Q: Is using regexps to create a colorizer the *ONLY* method
to create a colorizer?
A: Uh, no!
Q: Is using regexps the *BEST* method to create a
A: Depends on who you ask and what the specific details
Remember, this is "academic exercise", and i believe a damn
*good* exercise because *even* a noob can understand the basic
problems that need to be solved to create a colorizer:
1. I have a finite set of keywords and lexical structures
that need to be located within a text.
2. I need to map colors to patterns so i can paint the
keywords and lexical structures appropriately when i find
3. I need to institute events that will cause the
colorizer to search for the patterns at appropriate times
(for instance: when text is loaded, when text is edited, etc)
3a. Furthermore, i need to refine the breadth of my search
area depending on the current context of the edit --
Should i search *only* the current line being edited, or,
is the editing occurring inside a larger "multi-line
lexical structure" that will need to be considered, OR,
should i search the entire text???
> plus there are fundamental limitations on what you can
> accomplish with them.
Of course, *REMEMBER*, this is an "academic exercise",
intended to familiarize the student with regexps and doing
so in the context of a *real* world problem, who's scope is
within the grasp of a noob, not some rechid flatulence pulled
from the anus of a "so-called" teacher.
But don't tell me for a *SECOND* that a colorizer, and a
damn good one, can not be written utilizing regexps, because
you're either wrong, or you're scared, or you're ignorant,
or you're all of the above!
> You need to use a lexer - a lexical analyzer. Basically,
> to correctly colorize code, you need to have something
> equivalent to the first part of the language interpreter,
> but with a lot more tolerance for errors. That's a pretty
> big thing to write as regexps.
Great Chris, so as a "lesson" for learning *regexps* you
propose that your students write a *lexer* instead. What's
next? Do you propose they drive an auto whilst protruding
their head from the vehicle like a canine, and observing the
plant life on the side of the road to earn a degree in
You know, you would fit in nicely in the American public
school system, since American teachers are not only free of
the requirement of "teaching", they are actually *COMPELLED*
not to do so by the greedy unions.
I SURMISE YOUR DESK WILL BE DEVOID OF ANY "TREE BEARING" FRUITS!
More information about the Python-list