| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 428f064 commit dde0028
9 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -107,7 +107,7 @@ power: atom trailer* ['**' factor] | |||
| 107 | 107 | atom: ('(' [yield_expr|testlist_gexp] ')' | | |
| 108 | 108 | '[' [listmaker] ']' | | |
| 109 | 109 | '{' [dictsetmaker] '}' | | |
| 110 | - NAME | NUMBER | STRING+ | '.' '.' '.') | ||
| 110 | + NAME | NUMBER | STRING+ | '...') | ||
| 111 | 111 | listmaker: test ( list_for | (',' test)* [','] ) | |
| 112 | 112 | testlist_gexp: test ( gen_for | (',' test)* [','] ) | |
| 113 | 113 | lambdef: 'lambda' [varargslist] ':' test | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -59,10 +59,11 @@ extern "C" { | |||
| 59 | 59 | #define DOUBLESLASHEQUAL 49 | |
| 60 | 60 | #define AT 50 | |
| 61 | 61 | #define RARROW 51 | |
| 62 | + #define ELLIPSIS 52 | ||
| 62 | 63 | /* Don't forget to update the table _PyParser_TokenNames in tokenizer.c! */ | |
| 63 | - #define OP 52 | ||
| 64 | - #define ERRORTOKEN 53 | ||
| 65 | - #define N_TOKENS 54 | ||
| 64 | + #define OP 53 | ||
| 65 | + #define ERRORTOKEN 54 | ||
| 66 | + #define N_TOKENS 55 | ||
| 66 | 67 | ||
| 67 | 68 | /* Special definitions for cooperation with parser */ | |
| 68 | 69 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -113,7 +113,7 @@ def __init__(self): | |||
| 113 | 113 | token.LBRACE: self.atom_lbrace, | |
| 114 | 114 | token.NUMBER: self.atom_number, | |
| 115 | 115 | token.STRING: self.atom_string, | |
| 116 | - token.DOT: self.atom_ellipsis, | ||
| 116 | + token.ELLIPSIS: self.atom_ellipsis, | ||
| 117 | 117 | token.NAME: self.atom_name, | |
| 118 | 118 | } | |
| 119 | 119 | self.encoding = None | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -121,6 +121,7 @@ def testStringLiterals(self): | |||
| 121 | 121 | def testEllipsis(self): | |
| 122 | 122 | x = ... | |
| 123 | 123 | self.assert_(x is Ellipsis) | |
| 124 | + self.assertRaises(SyntaxError, eval, ".. .") | ||
| 124 | 125 | ||
| 125 | 126 | class GrammarTests(unittest.TestCase): | |
| 126 | 127 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -61,9 +61,10 @@ | |||
| 61 | 61 | DOUBLESLASHEQUAL = 49 | |
| 62 | 62 | AT = 50 | |
| 63 | 63 | RARROW = 51 | |
| 64 | - OP = 52 | ||
| 65 | - ERRORTOKEN = 53 | ||
| 66 | - N_TOKENS = 54 | ||
| 64 | + ELLIPSIS = 52 | ||
| 65 | + OP = 53 | ||
| 66 | + ERRORTOKEN = 54 | ||
| 67 | + N_TOKENS = 55 | ||
| 67 | 68 | NT_OFFSET = 256 | |
| 68 | 69 | #--end constants-- | |
| 69 | 70 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -83,7 +83,7 @@ def maybe(*choices): return group(*choices) + '?' | |||
| 83 | 83 | r"~") | |
| 84 | 84 | ||
| 85 | 85 | Bracket = '[][(){}]' | |
| 86 | - Special = group(r'\r?\n', r'[:;.,@]') | ||
| 86 | + Special = group(r'\r?\n', r'\.\.\.', r'[:;.,@]') | ||
| 87 | 87 | Funny = group(Operator, Bracket, Special) | |
| 88 | 88 | ||
| 89 | 89 | PlainToken = group(Number, Funny, String, Name) | |
@@ -334,8 +334,8 @@ def generate_tokens(readline): | |||
| 334 | 334 | spos, epos, pos = (lnum, start), (lnum, end), end | |
| 335 | 335 | token, initial = line[start:end], line[start] | |
| 336 | 336 | ||
| 337 | - if initial in numchars or \ | ||
| 338 | - (initial == '.' and token != '.'): # ordinary number | ||
| 337 | + if (initial in numchars or # ordinary number | ||
| 338 | + (initial == '.' and token != '.' and token != '...')): | ||
| 339 | 339 | yield (NUMBER, token, spos, epos, line) | |
| 340 | 340 | elif initial in '\r\n': | |
| 341 | 341 | yield (NL if parenlev > 0 else NEWLINE, | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -93,6 +93,7 @@ char *_PyParser_TokenNames[] = { | |||
| 93 | 93 | "DOUBLESLASHEQUAL", | |
| 94 | 94 | "AT", | |
| 95 | 95 | "RARROW", | |
| 96 | + "ELLIPSIS", | ||
| 96 | 97 | /* This table must match the #defines in token.h! */ | |
| 97 | 98 | "OP", | |
| 98 | 99 | "<ERRORTOKEN>", | |
@@ -1082,6 +1083,16 @@ PyToken_ThreeChars(int c1, int c2, int c3) | |||
| 1082 | 1083 | break; | |
| 1083 | 1084 | } | |
| 1084 | 1085 | break; | |
| 1086 | + case '.': | ||
| 1087 | + switch (c2) { | ||
| 1088 | + case '.': | ||
| 1089 | + switch (c3) { | ||
| 1090 | + case '.': | ||
| 1091 | + return ELLIPSIS; | ||
| 1092 | + } | ||
| 1093 | + break; | ||
| 1094 | + } | ||
| 1095 | + break; | ||
| 1085 | 1096 | } | |
| 1086 | 1097 | return OP; | |
| 1087 | 1098 | } | |
@@ -1278,13 +1289,22 @@ tok_get(register struct tok_state *tok, char **p_start, char **p_end) | |||
| 1278 | 1289 | c = tok_nextc(tok); | |
| 1279 | 1290 | if (isdigit(c)) { | |
| 1280 | 1291 | goto fraction; | |
| 1281 | - } | ||
| 1282 | - else { | ||
| 1292 | + } else if (c == '.') { | ||
| 1293 | + c = tok_nextc(tok); | ||
| 1294 | + if (c == '.') { | ||
| 1295 | + *p_start = tok->start; | ||
| 1296 | + *p_end = tok->cur; | ||
| 1297 | + return ELLIPSIS; | ||
| 1298 | + } else { | ||
| 1299 | + tok_backup(tok, c); | ||
| 1300 | + } | ||
| 1301 | + tok_backup(tok, '.'); | ||
| 1302 | + } else { | ||
| 1283 | 1303 | tok_backup(tok, c); | |
| 1284 | - *p_start = tok->start; | ||
| 1285 | - *p_end = tok->cur; | ||
| 1286 | - return DOT; | ||
| 1287 | 1304 | } | |
| 1305 | + *p_start = tok->start; | ||
| 1306 | + *p_end = tok->cur; | ||
| 1307 | + return DOT; | ||
| 1288 | 1308 | } | |
| 1289 | 1309 | ||
| 1290 | 1310 | /* Number */ | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1410,7 +1410,7 @@ ast_for_atom(struct compiling *c, const node *n) | |||
| 1410 | 1410 | PyArena_AddPyObject(c->c_arena, pynum); | |
| 1411 | 1411 | return Num(pynum, LINENO(n), n->n_col_offset, c->c_arena); | |
| 1412 | 1412 | } | |
| 1413 | - case DOT: /* Ellipsis */ | ||
| 1413 | + case ELLIPSIS: /* Ellipsis */ | ||
| 1414 | 1414 | return Ellipsis(LINENO(n), n->n_col_offset, c->c_arena); | |
| 1415 | 1415 | case LPAR: /* some parenthesized expressions */ | |
| 1416 | 1416 | ch = CHILD(n, 1); | |
| Back | FazBrowse Home | New Git URL |
0 commit comments