Skip to content

Commit bf50578

Browse files
Issue#1420: Delimited comment tokens were not classified correctly. (#1422)
1 parent 3d58538 commit bf50578

File tree

4 files changed

+79
-2
lines changed

4 files changed

+79
-2
lines changed
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
--------------------------------------------------------------------------------
2+
0 |
3+
--------------------------------------------------------------------------------
4+
1 | /**
5+
<class 'vsg.token.delimited_comment.beginning'>
6+
<class 'vsg.token.delimited_comment.text'>
7+
--------------------------------------------------------------------------------
8+
2 |
9+
<class 'vsg.token.delimited_comment.text'>
10+
--------------------------------------------------------------------------------
11+
3 | This should pass
12+
<class 'vsg.token.delimited_comment.text'>
13+
--------------------------------------------------------------------------------
14+
4 |
15+
<class 'vsg.token.delimited_comment.text'>
16+
--------------------------------------------------------------------------------
17+
5 | */
18+
<class 'vsg.token.delimited_comment.ending'>
19+
--------------------------------------------------------------------------------
20+
6 |
21+
<class 'vsg.parser.blank_line'>
22+
--------------------------------------------------------------------------------
23+
7 | /**
24+
<class 'vsg.token.delimited_comment.beginning'>
25+
<class 'vsg.token.delimited_comment.text'>
26+
--------------------------------------------------------------------------------
27+
8 |
28+
<class 'vsg.token.delimited_comment.text'>
29+
--------------------------------------------------------------------------------
30+
9 | This should also pass
31+
<class 'vsg.token.delimited_comment.text'>
32+
--------------------------------------------------------------------------------
33+
10 |
34+
<class 'vsg.token.delimited_comment.text'>
35+
--------------------------------------------------------------------------------
36+
11 | **/
37+
<class 'vsg.token.delimited_comment.text'>
38+
<class 'vsg.token.delimited_comment.ending'>
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
/**
2+
3+
This should pass
4+
5+
*/
6+
7+
/**
8+
9+
This should also pass
10+
11+
**/

vsg/vhdlFile/classify/comment.py

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,34 @@ def classify(lTokens, lObjects, oOptions):
1919

2020

2121
def classify_closing_comment_delimiters(iToken, lObjects, oOptions):
22+
if ending_token_exists(iToken, lObjects, oOptions):
23+
replace_token_with_ending_token(iToken, lObjects, oOptions)
24+
oOptions.clear_inside_delimited_comment()
25+
elif ending_token_should_exist(iToken, lObjects, oOptions):
26+
replace_token_with_ending_token(iToken, lObjects, oOptions)
27+
remove_last_star_from_previous_token(iToken, lObjects, oOptions)
28+
oOptions.clear_inside_delimited_comment()
29+
30+
31+
def ending_token_exists(iToken, lObjects, oOptions):
32+
return oOptions.inside_delimited_comment() and lObjects[iToken].get_value() == "*/"
33+
34+
35+
def ending_token_should_exist(iToken, lObjects, oOptions):
36+
return oOptions.inside_delimited_comment() and lObjects[iToken].get_value() == "/" and lObjects[iToken - 1].get_value().endswith("*")
37+
38+
39+
def replace_token_with_ending_token(iToken, lObjects, oOptions):
2240
sToken = lObjects[iToken].get_value()
23-
if oOptions.inside_delimited_comment() and sToken == "*/":
41+
if sToken == "*/":
2442
lObjects[iToken] = token.ending(sToken)
25-
oOptions.clear_inside_delimited_comment()
43+
else:
44+
lObjects[iToken] = token.ending("*" + sToken)
45+
46+
47+
def remove_last_star_from_previous_token(iToken, lObjects, oOptions):
48+
sToken = lObjects[iToken - 1].get_value()[:-1]
49+
lObjects[iToken - 1] = token.text(sToken)
2650

2751

2852
def classify_opening_comment_delimiters(iToken, lObjects, oOptions):

vsg/vhdlFile/vhdlFile.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
aggregate,
77
attribute_name,
88
choices,
9+
delimited_comment,
910
direction,
1011
exponent,
1112
logical_operator,
@@ -523,6 +524,9 @@ def post_token_assignments(lTokens):
523524
lParenId = []
524525
for iToken, oToken in enumerate(lTokens):
525526
sValue = oToken.get_value()
527+
if isinstance(oToken, delimited_comment.text):
528+
continue
529+
526530
if isinstance(oToken, (resolution_indication.resolution_function_name, type_mark.name, attribute_name.name, todo.name)):
527531
sLowerValue = oToken.get_lower_value()
528532

0 commit comments

Comments
 (0)