Skip to content

Commit 39d346d

Browse files
committed
Add basic support for directives between if/else and inside case
1 parent e73b2c8 commit 39d346d

File tree

8 files changed

+192
-25
lines changed

8 files changed

+192
-25
lines changed

grammar.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2829,8 +2829,8 @@ const rules = {
28292829
// ** A.6.6 Conditional statements
28302830
conditional_statement: $ => prec.right(seq(
28312831
optional($.unique_priority),
2832-
'if', '(', $.cond_predicate, ')', $.statement_or_null,
2833-
repseq('else', 'if', '(', $.cond_predicate, ')', $.statement_or_null),
2832+
'if', '(', $.cond_predicate, ')', $.statement_or_null, optional($.conditional_compilation_directive), // $.conditional_compilation_directive out of LRM
2833+
repseq('else', 'if', '(', $.cond_predicate, ')', $.statement_or_null, optional($.conditional_compilation_directive)), // $.conditional_compilation_directive out of LRM
28342834
optseq('else', $.statement_or_null)
28352835
)),
28362836

@@ -2874,7 +2874,8 @@ const rules = {
28742874

28752875
case_item: $ => choice(
28762876
seq(commaSep1($.case_item_expression), ':', $.statement_or_null),
2877-
seq('default', optional(':'), $.statement_or_null)
2877+
seq('default', optional(':'), $.statement_or_null),
2878+
$.conditional_compilation_directive, // Out of LRM
28782879
),
28792880

28802881
case_pattern_item: $ => choice(

test/corpus/cva6/cf_math_pkg.txt

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -237,12 +237,8 @@ endpackage
237237
(primary_literal
238238
(string_literal
239239
(quoted_string
240-
(quoted_string_item)))))))))))))))))))))
241-
(function_statement_or_null
242-
(function_statement
243-
(statement
244-
(statement_item
245-
(conditional_compilation_directive)))))
240+
(quoted_string_item))))))))))))))))
241+
(conditional_compilation_directive))))))
246242
(comment)
247243
(function_statement_or_null
248244
(function_statement

test/corpus/github/issue_37.txt

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
============================================
2+
github/issue_37
3+
============================================
4+
5+
module foo;
6+
initial begin
7+
if (1'b1) begin
8+
// ...
9+
end
10+
`ifdef FOO
11+
else begin
12+
// ...
13+
end
14+
`endif
15+
end
16+
endmodule
17+
18+
----
19+
20+
(source_file
21+
(module_declaration
22+
(module_ansi_header
23+
(module_keyword)
24+
name: (simple_identifier))
25+
(initial_construct
26+
(statement_or_null
27+
(statement
28+
(statement_item
29+
(seq_block
30+
(statement_or_null
31+
(statement
32+
(statement_item
33+
(conditional_statement
34+
(cond_predicate
35+
(expression
36+
(primary
37+
(primary_literal
38+
(integral_number
39+
(binary_number
40+
size: (unsigned_number)
41+
base: (binary_base)
42+
value: (binary_value)))))))
43+
(statement_or_null
44+
(statement
45+
(statement_item
46+
(seq_block
47+
(comment)))))
48+
(conditional_compilation_directive
49+
(ifdef_condition
50+
(simple_identifier)))
51+
(statement_or_null
52+
(statement
53+
(statement_item
54+
(seq_block
55+
(comment)))))))))
56+
(statement_or_null
57+
(statement
58+
(statement_item
59+
(conditional_compilation_directive)))))))))))

test/corpus/github/issue_39.txt

Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
============================================
2+
github/issue_39
3+
============================================
4+
5+
module foo;
6+
initial begin
7+
case (a)
8+
2'b00: bar();
9+
2'b01: baz();
10+
`ifdef FOO
11+
2'b10: quz();
12+
`endif
13+
endcase
14+
end
15+
endmodule
16+
17+
----
18+
19+
(source_file
20+
(module_declaration
21+
(module_ansi_header
22+
(module_keyword)
23+
name: (simple_identifier))
24+
(initial_construct
25+
(statement_or_null
26+
(statement
27+
(statement_item
28+
(seq_block
29+
(statement_or_null
30+
(statement
31+
(statement_item
32+
(case_statement
33+
(case_keyword)
34+
(case_expression
35+
(expression
36+
(primary
37+
(hierarchical_identifier
38+
(simple_identifier)))))
39+
(case_item
40+
(case_item_expression
41+
(expression
42+
(primary
43+
(primary_literal
44+
(integral_number
45+
(binary_number
46+
size: (unsigned_number)
47+
base: (binary_base)
48+
value: (binary_value)))))))
49+
(statement_or_null
50+
(statement
51+
(statement_item
52+
(subroutine_call_statement
53+
(subroutine_call
54+
(tf_call
55+
(hierarchical_identifier
56+
(simple_identifier)))))))))
57+
(case_item
58+
(case_item_expression
59+
(expression
60+
(primary
61+
(primary_literal
62+
(integral_number
63+
(binary_number
64+
size: (unsigned_number)
65+
base: (binary_base)
66+
value: (binary_value)))))))
67+
(statement_or_null
68+
(statement
69+
(statement_item
70+
(subroutine_call_statement
71+
(subroutine_call
72+
(tf_call
73+
(hierarchical_identifier
74+
(simple_identifier)))))))))
75+
(case_item
76+
(conditional_compilation_directive
77+
(ifdef_condition
78+
(simple_identifier))))
79+
(case_item
80+
(case_item_expression
81+
(expression
82+
(primary
83+
(primary_literal
84+
(integral_number
85+
(binary_number
86+
size: (unsigned_number)
87+
base: (binary_base)
88+
value: (binary_value)))))))
89+
(statement_or_null
90+
(statement
91+
(statement_item
92+
(subroutine_call_statement
93+
(subroutine_call
94+
(tf_call
95+
(hierarchical_identifier
96+
(simple_identifier)))))))))
97+
(case_item
98+
(conditional_compilation_directive)))))))))))))

test/corpus/uvm/1800.2-2020-2.0/src/base/uvm_cmdline_report.txt

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -844,12 +844,8 @@ endclass : uvm_cmdline_set_severity
844844
(expression
845845
(primary
846846
(hierarchical_identifier
847-
(simple_identifier))))))))))))))))))
848-
(function_statement_or_null
849-
(function_statement
850-
(statement
851-
(statement_item
852-
(conditional_compilation_directive)))))
847+
(simple_identifier)))))))))))))
848+
(conditional_compilation_directive))))))
853849
(function_statement_or_null
854850
(function_statement
855851
(statement

test/corpus/uvm/1800.2-2020-2.0/src/base/uvm_root.txt

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3679,11 +3679,8 @@ endfunction
36793679
(expression
36803680
(primary
36813681
(hierarchical_identifier
3682-
(simple_identifier)))))))))))))))))))
3683-
(statement_or_null
3684-
(statement
3685-
(statement_item
3686-
(conditional_compilation_directive))))
3682+
(simple_identifier)))))))))))))))
3683+
(conditional_compilation_directive)))))
36873684
(statement_or_null
36883685
(statement
36893686
(statement_item
@@ -3780,11 +3777,8 @@ endfunction
37803777
(primary_literal
37813778
(integral_number
37823779
(decimal_number
3783-
(unsigned_number)))))))))))))))))))
3784-
(statement_or_null
3785-
(statement
3786-
(statement_item
3787-
(conditional_compilation_directive))))
3780+
(unsigned_number)))))))))))))))
3781+
(conditional_compilation_directive)))))
37883782
(comment)
37893783
(statement_or_null
37903784
(statement

test/files/github/issue_37.sv

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
module foo;
2+
initial begin
3+
if (1'b1) begin
4+
// ...
5+
end
6+
`ifdef FOO
7+
else begin
8+
// ...
9+
end
10+
`endif
11+
end
12+
endmodule

test/files/github/issue_39.sv

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
module foo;
2+
initial begin
3+
case (a)
4+
2'b00: bar();
5+
2'b01: baz();
6+
`ifdef FOO
7+
2'b10: quz();
8+
`endif
9+
endcase
10+
end
11+
endmodule

0 commit comments

Comments
 (0)