code: def parse(s, state):
      while state.position < len(s):
          length = looking_at_escape(s[state.position :], state)
          if length:
              state.parsed_token(length, TOK_ESCAPE)
              continue
          if state.in_brackets:
              if s[state.position] != "]":
                  state.parsed_token(1, TOK_BRACKET_EXP)
              else:
                  state.close_brackets()
          else:
              length = looking_at_repeat(s[state.position :], state)
              if length:
                  state.parsed_repeat(length)
                  continue
              if s[state.position] == "[":
                  state.open_brackets()
                  continue
              if s[state.position] == "^":
                  if state.position:
                      raise ValueError(
                          "^ can only appear at the start of a regular expression"
                      )
                  else:
                      state.parsed_special()
                  continue
              if s[state.position] == "$":
                  if state.position < len(s) - 1:
                      raise ValueError(
                          "$ can only appear at the end of a regular expression"
                      )
                  else:
                      state.parsed_special()
                      continue
              if s[state.position] == "|":
                  state.parsed_special()
                  continue
              if s[state.position] == ".":
                  state.parsed_token(1, TOK_SPECIAL)
                  continue
              if s[state.position] == ")":
                  state.close_group()
                  continue
              if handle_open_group(s[state.position :], state):
                  continue
              # Otherwise, assume normal character
              state.parsed_token()
      if state.open_expression_start is not None:
          state.token_labels[state.open_expression_start] = STYLE_ERROR
          raise ValueError("Incomplete expression")
      return state
  
imports: import re
  import wx
  import wx.stc
label_desc: Use image node_id 5 for calling a global function with example usage: parse(s, state) and returns: state