class VowelLexer(BaseLexer): """Simple lexer to highlight vowels""" # Define some style IDs STC_STYLE_VOWEL_DEFAULT, \ STC_STYLE_VOWEL_KW = range(2) def __init__(self): super(VowelLexer, self).__init__() # Attributes mylist = ["good", "bad"] # self.vowels = [ord(char) for word in "BEGIN_FORTRAN END_FORTRAN BEGIN_C END_C BEGIN_PYTHON END_PYTHON"] # self.vowels = [ord(char) for word in "good", "bad" for char in word] self.vowels = [ord(char) for char in "good" + "bad"] # m = re.search("good",) def StyleText(self, event): """Handle the EVT_STC_STYLENEEDED event""" stc = event.GetEventObject() # Last correctly styled character last_styled_pos = stc.GetEndStyled() # Get styling range for this call line = stc.LineFromPosition(last_styled_pos) start_pos = stc.PositionFromLine(line) end_pos = event.GetPosition() # Walk the line and find all the vowels to style # Note: little inefficient doing one char at a time # but just to illustrate the process. while start_pos < end_pos: stc.StartStyling(start_pos, 0x1f) char = stc.GetCharAt(start_pos) if char in self.vowels: # Set Vowel Keyword style style = VowelLexer.STC_STYLE_VOWEL_KW else: # Set Default style style = VowelLexer.STC_STYLE_VOWEL_DEFAULT # Set the styling byte information for 1 char from # current styling position (start_pos) with the # given style. stc.SetStyling(1, style) start_pos += 1