Skip to content

Commit ee6aefe

Browse files
daniel-oterod-alonso
authored andcommitted
Allow call expressions in derived type definitions
To support macro calls that declare type members
1 parent 381f1b4 commit ee6aefe

6 files changed

Lines changed: 716038 additions & 708387 deletions

File tree

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
2+
From: Daniel Otero <daniel.otero@appentra.com>
3+
Date: Thu, 16 Apr 2026 16:12:01 +0200
4+
Subject: Allow call expressions in derived type definitions
5+
6+
To support macro calls that declare type members
7+
---
8+
grammar.js | 4 +++
9+
test/corpus/constructs.txt | 53 ++++++++++++++++++++++++++++++++++++++
10+
2 files changed, 57 insertions(+)
11+
12+
diff --git a/grammar.js b/grammar.js
13+
index 57d9d08..c93b475 100644
14+
--- a/grammar.js
15+
+++ b/grammar.js
16+
@@ -811,6 +811,10 @@ module.exports = grammar({
17+
$.preproc_call,
18+
alias($.preproc_if_in_derived_type, $.preproc_if),
19+
alias($.preproc_ifdef_in_derived_type, $.preproc_ifdef),
20+
+ // This is required so that macro function calls are allowed to declare
21+
+ // derived type field. The precedence is required for resolving
22+
+ // ambiguity with
23+
+ prec(-1, $.call_expression),
24+
)),
25+
optional($.derived_type_procedures),
26+
$.end_type_statement,
27+
diff --git a/test/corpus/constructs.txt b/test/corpus/constructs.txt
28+
index 719824a..34d5316 100644
29+
--- a/test/corpus/constructs.txt
30+
+++ b/test/corpus/constructs.txt
31+
@@ -2837,3 +2837,56 @@ Block Data (Obsolescent)
32+
(name
33+
(identifier)))
34+
(end_of_statement)))
35+
+
36+
+================================================================================
37+
+Derived Type Macro Call Member
38+
+================================================================================
39+
+
40+
+#define BAR(x) integer :: x
41+
+program test
42+
+ type foo
43+
+ BAR(member)
44+
+ end type foo
45+
+end program test
46+
+
47+
+--------------------------------------------------------------------------------
48+
+
49+
+(translation_unit
50+
+ (preproc_function_def
51+
+ (whitespace)
52+
+ (identifier)
53+
+ (preproc_params
54+
+ (identifier))
55+
+ (whitespace)
56+
+ (preproc_arg))
57+
+ (program
58+
+ (program_statement
59+
+ (whitespace)
60+
+ (name
61+
+ (identifier))
62+
+ (end_of_statement))
63+
+ (whitespace)
64+
+ (derived_type_definition
65+
+ (derived_type_statement
66+
+ (whitespace)
67+
+ (type_name
68+
+ (identifier))
69+
+ (end_of_statement))
70+
+ (whitespace)
71+
+ (call_expression
72+
+ (identifier)
73+
+ (argument_list
74+
+ (identifier)))
75+
+ (whitespace)
76+
+ (end_type_statement
77+
+ (whitespace)
78+
+ (whitespace)
79+
+ (name
80+
+ (identifier)))
81+
+ (end_of_statement))
82+
+ (end_program_statement
83+
+ (whitespace)
84+
+ (whitespace)
85+
+ (name
86+
+ (identifier)))
87+
+ (end_of_statement)))

grammar.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -811,6 +811,10 @@ module.exports = grammar({
811811
$.preproc_call,
812812
alias($.preproc_if_in_derived_type, $.preproc_if),
813813
alias($.preproc_ifdef_in_derived_type, $.preproc_ifdef),
814+
// This is required so that macro function calls are allowed to declare
815+
// derived type field. The precedence is required for resolving
816+
// ambiguity with
817+
prec(-1, $.call_expression),
814818
)),
815819
optional($.derived_type_procedures),
816820
$.end_type_statement,

0 commit comments

Comments
 (0)