RomanYankovsky / DelphiAST

Abstract syntax tree builder for Delphi
Mozilla Public License 2.0
271 stars 116 forks source link

Fix for comment capture with ANSI and Borland comment types #267

Closed kjpowerworld closed 6 years ago

kjpowerworld commented 6 years ago

Most of the time comments aren't captured properly and thus the OnComment event isn't being called. This fixes the issue.

RomanYankovsky commented 6 years ago

Can you please give more information about the issue you've fixed? I'm a bit confused with these +1, -2 etc

kjpowerworld commented 6 years ago

The problem is that the original lexer code never actually captured Borland or ANSI comment types. For Borland comments, BraceOpenProc is always called before BorProc is ever called, meaning that the BorProc procedure never actually captures comments and calls the OnComment handler. Furthermore, RoundOpenProc is always called before AnsiProc is ever called, meaning that AnsiProc likewise never captures comments. After fixing that (by adding the appropriate capture code into the BraceOpenProc and RoundOpenProc procedures), I found off by one errors with the capturing code, which explains the excess of +1 and -1 adjustments that you see.

Where I noticed this with the DelphiAST was that TPasSyntaxTreeBuilder.Comments was never populated with Borland comments (denoted using '{' and '}') or ANSI comments (denoted using '(*' and '*)'). For most scenarios this isn't an issue, but when processing a DPR file that references units with forms, the form names are included in comments, requiring processing of comment strings.

RomanYankovsky commented 6 years ago

Nice catch! Thank you, @kjpowerworld