tree-sitter-delphi13-pure 1.4.2 → 1.4.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/grammar.js CHANGED
@@ -123,12 +123,14 @@ function statements(trailing) {
123
123
 
124
124
  [rn('nestedIf'), $ => prec(1,$.if)],
125
125
 
126
- [rn('ifElse'), $ => prec.right(1, seq(
126
+ // Dynamic precedence +1, as exprIf's is -1: where both read the same
127
+ // text, the statement wins (see exprIf).
128
+ [rn('ifElse'), $ => prec.dynamic(1, prec.right(1, seq(
127
129
  $.kIf, field('condition', $._expr), $.kThen,
128
130
  field('then', optional(choice(tr($,'_statement'), $.if))),
129
131
  $.kElse,
130
132
  field('else', lastStatement($))
131
- ))],
133
+ )))],
132
134
 
133
135
  [rn('while'), $ => seq(
134
136
  $.kWhile, field('condition', $._expr), $.kDo,
@@ -442,6 +444,9 @@ module.exports = grammar({
442
444
  [$._declProc ], [ $._declOperator], [$.declConst], [$.declVar],
443
445
  [$.declType], [$.declProp]
444
446
  ),
447
+ // `external L name 'x'` without `;` before `[`: an attribute on the next
448
+ // declaration, or an index on the string. One token too few; GLR decides.
449
+ [$._literal, $.procExternal],
445
450
  // RTTI attributes clash with fpc declaration hints syntax since both
446
451
  // are surrounded by brackets.
447
452
  ...enable_if(rtti,
@@ -665,11 +670,17 @@ module.exports = grammar({
665
670
  // the if-then-else STATEMENT (rn('ifElse')) — this one returns a value.
666
671
  // Right-associative + lower precedence than binary operators so that
667
672
  // `a + if c then x else y` groups as `a + (if c then x else y)`.
668
- exprIf: $ => prec.right(0, seq(
673
+ // Dynamic precedence -1: where an if STATEMENT reads the same text, it
674
+ // wins. Both branches may pass for expressions, as in `if Q then Foo
675
+ // else raise;` (a bare `raise` an identifier) or `if Q then Foo else
676
+ // N := 1;` (the whole if an assignment's target); dcc reads both as
677
+ // statements. Only an expression fits on the right of `:=` or in an
678
+ // argument, so those are unchanged.
679
+ exprIf: $ => prec.dynamic(-1, prec.right(0, seq(
669
680
  $.kIf, field('condition', $._expr),
670
681
  $.kThen, field('then', $._expr),
671
682
  $.kElse, field('else', $._expr),
672
- )),
683
+ ))),
673
684
 
674
685
  _ref: $ => choice(
675
686
  ...enable_if(templates && fpc,
@@ -1867,21 +1878,31 @@ module.exports = grammar({
1867
1878
  '[', optional(seq($.identifier, ':')), delimited($._ref), ']'
1868
1879
  )),
1869
1880
 
1881
+ // The closing `;` may be omitted after `name '<string>'`: dcc accepts it and Borland
1882
+ // shipped it (Delphi 5 shlobj.pas, five `function X; external shell32 name 'X'` lines
1883
+ // before the next routine or `end.`). Deliberately only that form: an optional `;`
1884
+ // after every clause puts ALL declaration starts in the follow set of `_expr` here
1885
+ // and grows the parser by 16% states (measured). A `[` after the string forks (see conflicts).
1870
1886
  procExternal: $ => seq(
1871
1887
  $.kExternal,
1872
1888
  optional($._expr),
1873
- optional(seq(choice($.kName, $.kIndex), $._expr)),
1874
- ...enable_if(delphi, optional($.kDelayed)),
1875
- // Phase 3b iter 17: native library dependency hint
1876
- // function f; cdecl; external LIB name 'foo' dependency 'c++_static','c++abi';
1877
- // (Embarcadero FlatBox2D Android/iOS linker pattern.)
1878
- // Phase 3b iter 35: `dependency` clause may use identifier-name
1879
- // constants too: `dependency LibCPP, LibCPP_ABI` (FireDAC.Phys.IBCli).
1880
- optional(seq(
1881
- $.kDependency,
1882
- delimited1(choice($._literalString, $.identifier)),
1883
- )),
1884
- ';'
1889
+ choice(
1890
+ seq(
1891
+ optional(seq(choice($.kName, $.kIndex), $._expr)),
1892
+ ...enable_if(delphi, optional($.kDelayed)),
1893
+ // Phase 3b iter 17: native library dependency hint
1894
+ // function f; cdecl; external LIB name 'foo' dependency 'c++_static','c++abi';
1895
+ // (Embarcadero FlatBox2D Android/iOS linker pattern.)
1896
+ // Phase 3b iter 35: `dependency` clause may use identifier-name
1897
+ // constants too: `dependency LibCPP, LibCPP_ABI` (FireDAC.Phys.IBCli).
1898
+ optional(seq(
1899
+ $.kDependency,
1900
+ delimited1(choice($._literalString, $.identifier)),
1901
+ )),
1902
+ ';'
1903
+ ),
1904
+ seq($.kName, $.literalString)
1905
+ )
1885
1906
  ),
1886
1907
 
1887
1908
  // INITIALIZERS --------------------------------------------------------
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "tree-sitter-delphi13-pure",
3
- "version": "1.4.2",
3
+ "version": "1.4.4",
4
4
  "description": "Pure Delphi 13 tree-sitter sub-grammar — drops {$IFDEF}/pp_* tokens entirely and expects preprocessor-resolved source as input. Pairs with delphi13-preprocessor to reach 99%+ pass on real Delphi 13 corpora.",
5
5
  "main": "bindings/node",
6
6
  "types": "bindings/node",