spacepaste

  1.  
  2. class VowelLexer(BaseLexer):
  3. """Simple lexer to highlight vowels"""
  4. # Define some style IDs
  5. STC_STYLE_VOWEL_DEFAULT, \
  6. STC_STYLE_VOWEL_KW = range(2)
  7. def __init__(self):
  8. super(VowelLexer, self).__init__()
  9. # Attributes
  10. mylist = ["good", "bad"]
  11. # self.vowels = [ord(char) for word in "BEGIN_FORTRAN END_FORTRAN BEGIN_C END_C BEGIN_PYTHON END_PYTHON"]
  12. # self.vowels = [ord(char) for word in "good", "bad" for char in word]
  13. self.vowels = [ord(char) for char in "good" + "bad"]
  14. # m = re.search("good",)
  15. def StyleText(self, event):
  16. """Handle the EVT_STC_STYLENEEDED event"""
  17. stc = event.GetEventObject()
  18. # Last correctly styled character
  19. last_styled_pos = stc.GetEndStyled()
  20. # Get styling range for this call
  21. line = stc.LineFromPosition(last_styled_pos)
  22. start_pos = stc.PositionFromLine(line)
  23. end_pos = event.GetPosition()
  24. # Walk the line and find all the vowels to style
  25. # Note: little inefficient doing one char at a time
  26. # but just to illustrate the process.
  27. while start_pos < end_pos:
  28. stc.StartStyling(start_pos, 0x1f)
  29. char = stc.GetCharAt(start_pos)
  30. if char in self.vowels:
  31. # Set Vowel Keyword style
  32. style = VowelLexer.STC_STYLE_VOWEL_KW
  33. else:
  34. # Set Default style
  35. style = VowelLexer.STC_STYLE_VOWEL_DEFAULT
  36. # Set the styling byte information for 1 char from
  37. # current styling position (start_pos) with the
  38. # given style.
  39. stc.SetStyling(1, style)
  40. start_pos += 1
  41.