ganezdragon / tree-sitter-perl

a perl parser for javascript
MIT License
33 stars 9 forks source link

Optional semicolons #37

Closed mbudde closed 6 months ago

mbudde commented 1 year ago

In a block with a single statement leaving out the optional semicolon results in a parse error:

{ 1 }
(standalone_block) ; [1:1 - 5]
 (ERROR) ; [1:3 - 3]
  (integer) ; [1:3 - 3]

When there's more than one statement the parse error goes away but the parse tree seems to contain a semicolon that doesn't exist (not sure if that is intentioal):

{ 1; 2 }
(standalone_block) ; [1:1 - 8]
 (integer) ; [1:3 - 3]
 (semi_colon) ; [1:4 - 4]
 (integer) ; [1:6 - 6]
 (semi_colon) ; [1:7 - 6]
ganezdragon commented 6 months ago

@mbudde . I took my time. But this is done :) I'm also planning make semicolons inline, so they only appear during error and does not end up clouding the tree.

ganezdragon commented 6 months ago

{ 1 }

should produce

  (standalone_block [59, 0] - [59, 5]
    (integer [59, 2] - [59, 3])))

map { $_*2 } (1,2), should produce,

(array_function [59, 0] - [59, 18]
    (function_name [59, 0] - [59, 3])
    (block [59, 4] - [59, 12]
      (binary_expression [59, 6] - [59, 10]
        variable: (special_scalar_variable [59, 6] - [59, 8])
        variable: (integer [59, 9] - [59, 10])))
    (array [59, 13] - [59, 18]
      (integer [59, 14] - [59, 15])
      (integer [59, 16] - [59, 17]))))

Basically, the last statement in block/file can end without a semicolon