I need an idea for practise!

Rick Johnson rantingrickjohnson at gmail.com
Fri Jul 18 05:07:27 CEST 2014


On Thursday, July 17, 2014 9:03:40 PM UTC-5, Chris Angelico wrote:
> [colorizers] might well be able to *utilize* regexps [...]
> but very few modern programming languages can be fully and
> correctly defined within the limits of regexp syntax.

We're not talking about "defining" or "interpreting"
languages Chris, we're simply talking about "colorizers" --
which simply search for lexical patterns and apply *COLOR*
to the resulting matches!
    
    PAY ATTENTION!
 
> For instance, how can you recognize and thus colorize
> assignments differently from name references, to
> distinguish between "foo = 1" and "foo == 1"?

First of all, why the heck would want to colorize something
like that? And if your intention is "highlight" cases where a
programmer uses "==" in a condition, then you need to use a
"source code analyzer", like Pylint!

Secondly, as the number of colorizer targets increases, the
effectiveness of colored text decreases -- from a "human
comprehension" perspective that is. For me, only the
following targets need colorizing:

      Keywords
      Built-ins
      Terminated Strings
      Un-terminated Strings
      Comments
      Annotations
      
That's it! Anymore color and your code starts to resemble a
Pollock drip painting.

Now, finally, if you cannot write a regexp that matches:

  1. One or more alphanumeric chars(or the US) followed by
  zero or more spaces followed by two equals chars followed
  by zero or more spaces followed by one or more alphanumeric
  chars(or the US)
      
or
    
  2. One or more alphanumeric_chars(or the US) followed by
  zero or more spaces followed by one equals char followed
  by zero or more spaces, followed by one or more
  alphanumeric chars(or the US)
  
    
Then you are either joking or trolling or you need to read
the Python re docs.

    https://docs.python.org/2/library/re.html#module-re




More information about the Python-list mailing list