title: Regular expression incremental parsing
body: <p>Are there languages or tools that support the parsing of regexes on a character-by-character basis? </p>
  
  <p>I think this may be equivalent to "regexes on streams" which is something that seems to be one of the features of the upcoming Perl version 6. </p>
  
  <p>Basically I want to do this because I'm building a tool that does translation of a terminal stream over a pseudo-terminal, and it occurred to me that the ultimate sort of flexibility that should be attainable is by allowing the specification of regex-replace expressions. </p>
  
  <p>The use case is that I want to allow my mouse scroll events to be passed to a naive program such as the <code>less</code> pager, which means my tool (which spawns <code>less</code> over a PTY) will be doing something like issuing the code <code>\x1b[?1000h</code> which switches on mouse reporting, and then subsequently translating every mouse wheel escape code received thereafter such as <code>\x1b[M!!</code> (the last several chars encode the mouse position within the terminal and should be ignored but also stripped) into the <code>\x1b[A</code> Up-arrow code. </p>
  
  <p>As you can see being able to specify a regex that works on the stdin terminal-reading stream to generate the translated stream to send to the slave pty would be ideal. </p>
  
  <p>Do I need to wait for Perl 6 to be able to achieve this? There must be particular reasons for why regex engines generally require having the whole string available? </p>
  
  <p>It's pretty obvious I don't need the full blown power of regex here. I can speculate for instance that it might be the case that supporting backtracking makes stream-parsing regex impossible. </p>
  
  <p>So since I don't need backtracking maybe there is some sort of light-weight regex engine out there that provides a stream API. It just seems like taking advantage of some form of parsing system (if one exists that is suitable) would be smarter than building something arbitrary. </p>