Skip to content
This repository was archived by the owner on Dec 20, 2024. It is now read-only.

Commit c380b61

Browse files
committedNov 9, 2021
New scanner.c to better handle newlines
This imitates the Automatic Semicolon Insertions (ASI) done in Javascript for Kotlin, to better deal with newlines that can cut certain definitions and expressions in two. This closes fwcd#32 test plan: see new newlines.txt corpus test
1 parent c1d330d commit c380b61

File tree

9 files changed

+236862
-199600
lines changed

9 files changed

+236862
-199600
lines changed
 

‎binding.gyp

+1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
],
99
"sources": [
1010
"src/parser.c",
11+
"src/scanner.c",
1112
"bindings/node/binding.cc"
1213
],
1314
"cflags_c": [

‎grammar.js

+8-3
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,10 @@ module.exports = grammar({
103103
[$.user_type, $.function_type],
104104
],
105105

106+
externals: $ => [
107+
$._automatic_semicolon,
108+
],
109+
106110
extras: $ => [
107111
$.comment,
108112
/\s+/ // Whitespace
@@ -135,7 +139,8 @@ module.exports = grammar({
135139
choice(
136140
seq("[", repeat1($._unescaped_annotation), "]"),
137141
$._unescaped_annotation
138-
)
142+
),
143+
$._semi
139144
),
140145

141146
package_header: $ => seq("package", $.identifier, $._semi),
@@ -542,9 +547,9 @@ module.exports = grammar({
542547

543548
// See also https://github.com/tree-sitter/tree-sitter/issues/160
544549
// generic EOF/newline token
545-
_semi: $ => /[\r\n]+/,
550+
_semi: $ => choice($._automatic_semicolon, ';'),
546551

547-
_semis: $ => /[\r\n]+/,
552+
_semis: $ => choice($._automatic_semicolon, ';'),
548553

549554
assignment: $ => choice(
550555
prec.left(PREC.ASSIGNMENT, seq($.directly_assignable_expression, $._assignment_and_operator, $._expression)),

0 commit comments

Comments
 (0)