Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Use _external_end_of_statement
  • Loading branch information
inaki-amatria committed Oct 27, 2025
commit 6a17eb8da2174a2d30c3caef718337377046d615
48 changes: 48 additions & 0 deletions codee/patches/0023-Use-_external_end_of_statement.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?I=C3=B1aki=20Amatria=20Barral?= <inaki.amatria@appentra.com>
Date: Mon, 27 Oct 2025 15:27:51 +0100
Subject: Use `_external_end_of_statement`

---
grammar.js | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/grammar.js b/grammar.js
index f1c074f..a19a824 100644
--- a/grammar.js
+++ b/grammar.js
@@ -153,14 +153,14 @@ module.exports = grammar({
$.system_lib_string,
alias($.preproc_call_expression, $.call_expression),
)),
- /\r?\n/,
+ $._external_end_of_statement,
),

preproc_def: $ => seq(
preprocessor('define'),
field('name', $.identifier),
field('value', optional($.preproc_arg)),
- token(prec(1, /\r?\n/)), // force newline to win over preproc_arg
+ $._external_end_of_statement,
),

preproc_function_def: $ => seq(
@@ -168,7 +168,7 @@ module.exports = grammar({
field('name', $.identifier),
field('parameters', $.preproc_params),
field('value', optional($.preproc_arg)),
- token.immediate(/\r?\n/),
+ $._external_end_of_statement,
),

preproc_params: $ => seq(
@@ -178,7 +178,7 @@ module.exports = grammar({
preproc_call: $ => seq(
field('directive', $.preproc_directive),
field('argument', optional($.preproc_arg)),
- token.immediate(/\r?\n/),
+ $._external_end_of_statement,
),

...preprocIf('', $ => repeat($._top_level_item)),
8 changes: 4 additions & 4 deletions grammar.js
Original file line number Diff line number Diff line change
Expand Up @@ -153,22 +153,22 @@ module.exports = grammar({
$.system_lib_string,
alias($.preproc_call_expression, $.call_expression),
)),
/\r?\n/,
$._external_end_of_statement,
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

With the addition of $.whitespace as an external rule, this change becomes necessary. Otherwise, tree-sitter-fortran fails to recognize newline characters, since they may be consumed silently by the external scanner. The issue is that the external scanner reads tokens directly from the input buffer without checking valid_symbols, which is a bug that should be reported upstream. This behavior has made proper whitespace parsing extremely difficult.

),

preproc_def: $ => seq(
preprocessor('define'),
field('name', $.identifier),
field('value', optional($.preproc_arg)),
token(prec(1, /\r?\n/)), // force newline to win over preproc_arg
$._external_end_of_statement,
),

preproc_function_def: $ => seq(
preprocessor('define'),
field('name', $.identifier),
field('parameters', $.preproc_params),
field('value', optional($.preproc_arg)),
token.immediate(/\r?\n/),
$._external_end_of_statement,
),

preproc_params: $ => seq(
Expand All @@ -178,7 +178,7 @@ module.exports = grammar({
preproc_call: $ => seq(
field('directive', $.preproc_directive),
field('argument', optional($.preproc_arg)),
token.immediate(/\r?\n/),
$._external_end_of_statement,
),

...preprocIf('', $ => repeat($._top_level_item)),
Expand Down
Loading