Open ZedThree opened 1 week ago
A couple more details:
type_qualifier
kind
and len
slightly differently, but this means it only fixes it for the case where variables are called either kind
or len
. Luckily, with tree-sitter
, we can use a query to find out how many projects actually use one of these attributes as an identifier!((variable_declaration
(identifier) @name
(#any-of? @name
"abstract"
...
)))
Searching everything:
tree-sitter query keyword_identifiers.query \
$(fd -e f90 .) \
| grep "pattern:" -A1 \
| grep -oE "text:.*" \
| sort | uniq -c | sort -h
And from our corpus of 60 projects, 2.5M lines, these are total number of matches:
1 text: `external`
1 text: `sequence`
1 text: `static`
3 text: `parameter`
3 text: `shared`
4 text: `constant`
5 text: `public`
8 text: `save`
10 text: `pointer`
11 text: `texture`
12 text: `contiguous`
25 text: `allocatable`
30 text: `optional`
35 text: `kind`
42 text: `target`
69 text: `device`
218 text: `len`
1066 text: `value`
(some of these are false positives from files with preprocessor macros confusing tree-sitter)
So looks like it really needs fixing for value
in particular. I think if you name your variable optional
or allocatable
, you should not be surprised at weirdness!
Example snippet:
gets parsed as:
Rename
len
tofoo
as we get the correct:Two potential fixes:
kind
andlen
fromtype_qualifier
, and only allowing them on derived type componentsvariable_modification
andassignment_statement