Fix keyword typos, support bare raise and property re-publication#20
Fix keyword typos, support bare raise and property re-publication#20wpostma wants to merge 6 commits into
Conversation
kSafecall was /safecal/i (missing trailing 'l'), so safecall was never recognized as a keyword. This caused thousands of parse errors in COM type library imports (MSHTML, Word_TLB, mscorlib_TLB, etc.). kSealed was /seled/i (missing 'a'), so sealed classes were never recognized. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
In Delphi, `raise;` without an expression re-raises the current exception inside an except block. The grammar required an expression after raise, causing parse errors on this common pattern. Tested: edblocal.pas errors dropped from 474 to 14. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
In Delphi, descendant classes can re-publish inherited properties without repeating the type: `property Align;`, `property Font;`, optionally with specifiers like `property Visible stored False;` or `property BookmarkSize write SetBookmarkSize;`. The grammar required `: type` after every property name. Made it optional so both full declarations and re-publications parse. Tested against 15 synthetic cases and real-world files: - FMX.StdCtrls.pas: 1,598 -> 0 errors - FireDAC.Comp.DataSet.pas: 2,118 -> 0 errors - AdvToolBar.pas: 612 -> 312 errors (remaining are other gaps) Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
|
Fixes top three issues in PR'ing them because they're the lowest risk changes, and I have validated against 400 of my largest pas files in my local working folders. |
Delphi's JNI/Android binding generator produces identifiers containing $ signs (e.g. val$transformer, Address$CacheKey$1). These are valid Delphi identifiers but the grammar rejected them. Added $ to the continuation character class of the identifier rule. No conflict with hex literals ($FF) since those start with $ while identifiers start with [a-zA-Z_]. Scanned 400 real-world .pas files: $ is the only non-standard character that appears in actual identifiers (all others like backtick, accented chars were inside comments/strings). Tested: Clover.JNI.AllClasses.pas errors dropped from 1,924 to 0. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
|
Note on the |
|
I've run into the bare raise issue in a current use of this, I would be happy to see this merged :) |
Can you pull this branch in from my fork and try it with your cases? Testing effort would probably get it merged. |
|
I can whip something together, I was using the crate as-is but I can use a local repo instead. |
|
@Isopod any interest in this pr ? |
- Fix safecall/sealed keyword regex typos (Issues Isopod#19/Isopod#20) - Support bare raise; without exception expression - Support property re-publication without type (property Name;) - Allow $ in identifiers for JNI binding names - Support for-var-in loops (for var Item in List do) (Issue Isopod#15) - Add inline const declarations in statement blocks (Issue Isopod#17)
Switches to AntoineGS/tree-sitter-pascal which includes Isopod/tree-sitter-pascal#20, fixing parsing of bare `raise;` (reraise) statements that were previously dropped.
|
I can confirm it resolves my issue with the bare |
Summary
Three grammar fixes for Delphi/Object Pascal constructs that produce parse errors on valid code:
kSafecallregex typo:/safecal/i→/safecall/i— the missing trailinglmeantsafecallwas never recognized as a keyword, causing thousands of errors in COM type library imports (MSHTML, Word_TLB, mscorlib_TLB, etc.)kSealedregex typo:/seled/i→/sealed/i—sealedclasses were never recognizedraise;: Delphi allowsraise;without an expression to re-raise the current exception inside anexceptblock. Made the expression field optional.property Align;,property Font;, optionally with specifiers likeproperty Visible stored False;orproperty BookmarkSize write SetBookmarkSize;. Made the: typeportion ofdeclPropoptional.Testing
Validated against 400 unique
.pasfiles (182.6 MB, 5.1M lines) from real-world Delphi codebases including Embarcadero RTL/FMX/VCL sources, TMS components, ElevateDB, JCL/JEDI, mORMot, DevExpress, and business applications.Results from specific files:
readonly/dispinterface gapsGrammar changes