Skip to content

Commit 8a78fa5

Browse files
committed
Python: add more weak keywords
The parser extacted keywords like "else" and "try" as tags. Signed-off-by: Masatake YAMATO <[email protected]>
1 parent 08fd0c4 commit 8a78fa5

File tree

5 files changed

+35
-0
lines changed

5 files changed

+35
-0
lines changed
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
--sort=no
2+
--kinds-Python=*
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
x input.py /^ x = 1$/;" v
2+
x input.py /^ x = 2$/;" v
3+
f input.py /^def f(text, pat):$/;" f
4+
text input.py /^def f(text, pat):$/;" z function:f file:
5+
pat input.py /^def f(text, pat):$/;" z function:f file:
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
if True:
2+
x = 1
3+
else:
4+
x = 2
5+
6+
def f(text, pat):
7+
if "." in text:
8+
return []
9+
try: regexp = pat

Units/parser-python.r/variable-annotations.d/expected.tags

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
primes input.py /^primes: List[int] = []$/;" v typeref:typename:List[int]
22
some_list input.py /^some_list: List[int] = [] # variable with initial value$/;" v typeref:typename:List[int]
33
sane_world input.py /^ sane_world = True$/;" v
4+
sane_world input.py /^ sane_world = False$/;" v
45
t input.py /^t: Tuple[int, ...] = (1, 2, 3)$/;" v typeref:typename:Tuple[int, ...]
56
header input.py /^header, kind, body = message$/;" v
67
kind input.py /^header, kind, body = message$/;" v

parsers/python.c

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ enum {
4444
KEYWORD_lambda,
4545
KEYWORD_pass,
4646
KEYWORD_return,
47+
KEYWORD_REST
4748
};
4849
typedef int keywordId; /* to allow KEYWORD_NONE */
4950

@@ -164,6 +165,22 @@ static const keywordTable PythonKeywordTable[] = {
164165
{ "return", KEYWORD_return },
165166
};
166167

168+
/* Taken from https://docs.python.org/3/reference/lexical_analysis.html#keywords */
169+
const static struct keywordGroup PythonRestKeywords = {
170+
.value = KEYWORD_REST,
171+
.addingUnlessExisting = true,
172+
.keywords = {
173+
"False", "await", "else", "import", "pass",
174+
"None", "break", "except", "in", "raise",
175+
"True", "class", "finally", "is", "return",
176+
"and", "continue", "for", "lambda", "try",
177+
"as", "def", "from", "nonlocal", "while",
178+
"assert", "del", "global", "not", "with",
179+
"async", "elif", "if", "or", "yield",
180+
NULL
181+
},
182+
};
183+
167184
typedef enum eTokenType {
168185
/* 0..255 are the byte's value */
169186
TOKEN_EOF = 256,
@@ -1718,6 +1735,7 @@ static void initialize (const langType language)
17181735
Lang_python = language;
17191736

17201737
TokenPool = objPoolNew (16, newPoolToken, deletePoolToken, clearPoolToken, NULL);
1738+
addKeywordGroup (&PythonRestKeywords, Lang_python);
17211739
}
17221740

17231741
static void finalize (langType language CTAGS_ATTR_UNUSED, bool initialized)

0 commit comments

Comments
 (0)