For your limited use case, you don't need anything as formal as a parser. Regular expressions are sufficient.
It's not hard to write a regular expression that matches conventional quoted strings: '['\r\n]*'
. Likewise, it's not complicated to write an expression to match a character code, as long as you're not concerned about limiting the range of numbers matched*: #(\d+|\$[0-9A-Fa-f]+)
. Once you have those building blocks, you only need to put them together:
('[^\n\r']*'|#(\d+|\$[0-9A-Fa-f]+))+
That will work for most code, but it's not enough for arbitrary Delphi files. That regular expression can match inside comments. Even worse is that it may match text that appears to straddle a comment. For example:
{ 'foo{}'
That's a comment followed by a single quote, not the string literal foo{}
. You can work around this by augmenting your regular expression to match comments, too. Then, as you work through your results, skip the comments.
* You shouldn't need to worry about the number range because you can expect to run your program against valid Delphi code.