title: How do you implement syntax highlighting?
body: <p>I am embarking on some learning and I want to write my own syntax highlighting for files in C++. </p>
  
  <p>Can anyone give me ideas on how to go about doing this?</p>
  
  <p>To me it seems that when a file is opened: </p>
  
  <ol>
  <li><p>It would need to be parsed and decided what type of source file it is. Trusting the extension might not be fool-proof</p></li>
  <li><p>A way to know what keywords/commands apply to what language</p></li>
  <li><p>A way to decide what color each keyword/command gets</p></li>
  </ol>
  
  <p>I want to do this on OS X, using C++ or Objective-C.</p>
  
  <p>Can anyone provide pointers on how I might get started with this?</p>