- Notifications
You must be signed in to change notification settings - Fork 10.5k
/
Copy pathkinds.py
40 lines (36 loc) · 1.13 KB
/
kinds.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
"""
All the known base syntax kinds. These will all be considered non-final classes
and other types will be allowed to inherit from them.
"""
SYNTAX_BASE_KINDS= ['Decl', 'Expr', 'Pattern', 'Stmt',
'Syntax', 'SyntaxCollection', 'Type']
defkind_to_type(kind):
"""
Converts a SyntaxKind to a type name, checking to see if the kind is
Syntax or SyntaxCollection first.
A type name is the same as the SyntaxKind name with the suffix "Syntax"
added.
"""
ifkindin ["Syntax", "SyntaxCollection"]:
returnkind
ifkind.endswith("Token"):
return"TokenSyntax"
returnkind+"Syntax"
deflowercase_first_word(name):
"""
Lowercases the first word in the provided camelCase or PascalCase string.
EOF -> eof
IfKeyword -> ifKeyword
EOFToken -> eofToken
"""
word_index=0
threshold_index=1
forcinname:
ifc.islower():
ifword_index>threshold_index:
word_index-=1
break
word_index+=1
ifword_index==0:
returnname
returnname[:word_index].lower() +name[word_index:]