Commit c99e907d authored by Robert Bradshaw's avatar Robert Bradshaw

Allow Cython keywords to be used as names.

Only cdef, cpdef, and ctypedef are dissallowed.
parent 97dd8ad0
...@@ -22,10 +22,10 @@ eval_input: testlist NEWLINE* ENDMARKER ...@@ -22,10 +22,10 @@ eval_input: testlist NEWLINE* ENDMARKER
decorator: '@' dotted_name [ '(' [arglist] ')' ] NEWLINE decorator: '@' dotted_name [ '(' [arglist] ')' ] NEWLINE
decorators: decorator+ decorators: decorator+
decorated: decorators (classdef | funcdef) decorated: decorators (classdef | funcdef)
funcdef: 'def' NAME parameters ':' suite funcdef: 'def' PY_NAME parameters ':' suite
parameters: '(' [varargslist] ')' parameters: '(' [varargslist] ')'
varargslist: ((fpdef ['=' test] ',')* varargslist: ((fpdef ['=' test] ',')*
('*' NAME [',' '**' NAME] | '**' NAME) | ('*' PY_NAME [',' '**' PY_NAME] | '**' PY_NAME) |
fpdef ['=' (test | '*')] (',' fpdef ['=' (test | '*')])* [','] fpdef ['=' (test | '*')] (',' fpdef ['=' (test | '*')])* [',']
['.' '.' '.']) ['.' '.' '.'])
fpdef: maybe_typed_name | '(' fplist ')' fpdef: maybe_typed_name | '(' fplist ')'
...@@ -54,19 +54,19 @@ import_stmt: import_name | import_from ...@@ -54,19 +54,19 @@ import_stmt: import_name | import_from
import_name: ('import' | 'cimport') dotted_as_names import_name: ('import' | 'cimport') dotted_as_names
import_from: ('from' ('.'* dotted_name | '.'+) import_from: ('from' ('.'* dotted_name | '.'+)
('import' | 'cimport') ('*' | '(' import_as_names ')' | import_as_names)) ('import' | 'cimport') ('*' | '(' import_as_names ')' | import_as_names))
import_as_name: NAME ['as' NAME] import_as_name: PY_NAME ['as' PY_NAME]
dotted_as_name: dotted_name ['as' NAME] dotted_as_name: dotted_name ['as' PY_NAME]
import_as_names: import_as_name (',' import_as_name)* [','] import_as_names: import_as_name (',' import_as_name)* [',']
dotted_as_names: dotted_as_name (',' dotted_as_name)* dotted_as_names: dotted_as_name (',' dotted_as_name)*
dotted_name: NAME ('.' NAME)* dotted_name: PY_NAME ('.' PY_NAME)*
global_stmt: 'global' NAME (',' NAME)* global_stmt: 'global' PY_NAME (',' PY_NAME)*
exec_stmt: 'exec' expr ['in' test [',' test]] exec_stmt: 'exec' expr ['in' test [',' test]]
assert_stmt: 'assert' test [',' test] assert_stmt: 'assert' test [',' test]
compound_stmt: if_stmt | while_stmt | for_stmt | try_stmt | with_stmt | funcdef | classdef | decorated compound_stmt: if_stmt | while_stmt | for_stmt | try_stmt | with_stmt | funcdef | classdef | decorated
if_stmt: 'if' test ':' suite ('elif' test ':' suite)* ['else' ':' suite] if_stmt: 'if' test ':' suite ('elif' test ':' suite)* ['else' ':' suite]
while_stmt: 'while' test ':' suite ['else' ':' suite] while_stmt: 'while' test ':' suite ['else' ':' suite]
for_stmt: 'for' exprlist ('in' testlist | 'from' expr comp_op NAME comp_op expr ['by' expr])':' suite ['else' ':' suite] for_stmt: 'for' exprlist ('in' testlist | 'from' expr comp_op PY_NAME comp_op expr ['by' expr])':' suite ['else' ':' suite]
try_stmt: ('try' ':' suite try_stmt: ('try' ':' suite
((except_clause ':' suite)+ ((except_clause ':' suite)+
['else' ':' suite] ['else' ':' suite]
...@@ -106,11 +106,11 @@ atom: ('(' [yield_expr|testlist_comp] ')' | ...@@ -106,11 +106,11 @@ atom: ('(' [yield_expr|testlist_comp] ')' |
'{' [dictorsetmaker] '}' | '{' [dictorsetmaker] '}' |
'`' testlist1 '`' | '`' testlist1 '`' |
new_expr | new_expr |
NAME | NUMBER | STRING+) PY_NAME | NUMBER | STRING+)
listmaker: test ( list_for | (',' test)* [','] ) listmaker: test ( list_for | (',' test)* [','] )
testlist_comp: test ( comp_for | (',' test)* [','] ) testlist_comp: test ( comp_for | (',' test)* [','] )
lambdef: 'lambda' [varargslist] ':' test lambdef: 'lambda' [varargslist] ':' test
trailer: '(' [arglist] ')' | '[' subscriptlist ']' | '.' NAME trailer: '(' [arglist] ')' | '[' subscriptlist ']' | '.' PY_NAME
subscriptlist: subscript (',' subscript)* [','] subscriptlist: subscript (',' subscript)* [',']
subscript: '.' '.' '.' | test | [test] ':' [test] [sliceop] subscript: '.' '.' '.' | test | [test] ':' [test] [sliceop]
sliceop: ':' [test] sliceop: ':' [test]
...@@ -119,7 +119,7 @@ testlist: test (',' test)* [','] ...@@ -119,7 +119,7 @@ testlist: test (',' test)* [',']
dictorsetmaker: ( (test ':' test (comp_for | (',' test ':' test)* [','])) | dictorsetmaker: ( (test ':' test (comp_for | (',' test ':' test)* [','])) |
(test (comp_for | (',' test)* [','])) ) (test (comp_for | (',' test)* [','])) )
classdef: 'class' NAME ['(' [testlist] ')'] ':' suite classdef: 'class' PY_NAME ['(' [testlist] ')'] ':' suite
arglist: (argument ',')* (argument [','] arglist: (argument ',')* (argument [',']
|'*' test (',' argument)* [',' '**' test] |'*' test (',' argument)* [',' '**' test]
...@@ -150,8 +150,8 @@ signedness: 'unsigned' | 'signed' ...@@ -150,8 +150,8 @@ signedness: 'unsigned' | 'signed'
longness: 'char' | 'short' | 'long' | 'long' 'long' longness: 'char' | 'short' | 'long' | 'long' 'long'
int_type: signedness [longness] | longness | [signedness] [longness] ('int' | 'double') | 'complex' # TODO: [unsigned] double doesn't make sens, but we need long double int_type: signedness [longness] | longness | [signedness] [longness] ('int' | 'double') | 'complex' # TODO: [unsigned] double doesn't make sens, but we need long double
type: ['const'] (NAME ('.' NAME)* | int_type) ['complex'] [type_qualifiers] type: ['const'] (NAME ('.' PY_NAME)* | int_type) ['complex'] [type_qualifiers]
maybe_typed_name: ['const'] (NAME [('.' NAME)* ['complex'] [type_qualifiers] NAME] | int_type ['complex'] [type_qualifiers] NAME) maybe_typed_name: ['const'] (NAME [('.' PY_NAME)* ['complex'] [type_qualifiers] NAME] | int_type ['complex'] [type_qualifiers] NAME)
teplate_params: '[' NAME (',' NAME)* ']' teplate_params: '[' NAME (',' NAME)* ']'
type_qualifiers: type_qualifier+ type_qualifiers: type_qualifier+
type_qualifier: '*' | '**' | '&' | type_index type_qualifier: '*' | '**' | '&' | type_index
...@@ -174,15 +174,16 @@ ctypedef_stmt: 'ctypedef' (cvar_decl | struct | enum) ...@@ -174,15 +174,16 @@ ctypedef_stmt: 'ctypedef' (cvar_decl | struct | enum)
# Requires a type # Requires a type
cvar_decl: [visibility] type cname (NEWLINE | cfunc) cvar_decl: [visibility] type cname (NEWLINE | cfunc)
# Allows an assignment # Allows an assignment
cvar_def: maybe_typed_name (['=' test] (',' NAME ['=' test])* NEWLINE | cfunc) cvar_def: maybe_typed_name (['=' test] (',' PY_NAME ['=' test])* NEWLINE | cfunc)
visibility: 'public' | 'api' | 'readonly' | 'extern' visibility: 'public' | 'api' | 'readonly' | 'extern'
cfunc: [teplate_params] parameters [gil_spec] [exception_value] (':' suite | NEWLINE) cfunc: [teplate_params] parameters [gil_spec] [exception_value] (':' suite | NEWLINE)
exception_value: 'except' (['?'] expr | '*' | '+' [NAME]) exception_value: 'except' (['?'] expr | '*' | '+' [PY_NAME])
gil_spec: 'with' ('gil' | 'nogil') | 'nogil' gil_spec: 'with' ('gil' | 'nogil') | 'nogil'
cname: NAME [STRING]
cclass: classdef cclass: classdef
fused: 'fused' NAME ':' NEWLINE INDENT ( type NEWLINE)+ DEDENT fused: 'fused' PY_NAME ':' NEWLINE INDENT ( type NEWLINE)+ DEDENT
enum: 'enum' [cname] (NEWLINE | ':' enum_suite) enum: 'enum' [cname] (NEWLINE | ':' enum_suite)
enum_suite: NEWLINE INDENT (cname ['=' NUMBER] NEWLINE | pass_stmt NEWLINE)+ DEDENT enum_suite: NEWLINE INDENT (cname ['=' NUMBER] NEWLINE | pass_stmt NEWLINE)+ DEDENT
struct: ('struct' | 'union') cname (NEWLINE | (':' struct_suite)) struct: ('struct' | 'union') cname (NEWLINE | (':' struct_suite))
...@@ -194,4 +195,7 @@ cppclass_suite: NEWLINE INDENT (cvar_decl | ctype_decl | pass_stmt NEWLINE)+ DED ...@@ -194,4 +195,7 @@ cppclass_suite: NEWLINE INDENT (cvar_decl | ctype_decl | pass_stmt NEWLINE)+ DED
extern_block: 'extern' 'from' ('*' | STRING) ['namespace' STRING] [gil_spec] ':' (pass_stmt | extern_suite) extern_block: 'extern' 'from' ('*' | STRING) ['namespace' STRING] [gil_spec] ':' (pass_stmt | extern_suite)
extern_suite: NEWLINE INDENT (['cdef' | 'cpdef'] (cvar_decl | cdef_type_decl) | ctypedef_stmt)+ DEDENT extern_suite: NEWLINE INDENT (['cdef' | 'cpdef'] (cvar_decl | cdef_type_decl) | ctypedef_stmt)+ DEDENT
cname: NAME [STRING] cy_type_kwd: 'struct' | 'union' | 'fused' | 'cppclass' | 'int' | 'double' | 'complex'
cy_kwd: cy_type_kwd | signedness | longness | visibility | 'gil' | 'nogil' | 'namespace' | 'const' | 'by'
PY_NAME: NAME | cy_kwd
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment