@@ -18,7 +18,6 @@ const PREC = Object.assign({}, Python.PREC, {
1818 gil_spec_exception_value : 1 ,
1919 new : 23 ,
2020 cast : 24 ,
21- lambda_parameters : 25 ,
2221} ) ;
2322
2423module . exports = grammar ( Python , {
@@ -310,8 +309,7 @@ module.exports = grammar(Python, {
310309 optional ( seq ( "=" , $ . expression ) ) ,
311310 repeat ( seq (
312311 "," ,
313- $ . identifier ,
314- optional ( field ( "alias" , $ . string ) ) ,
312+ $ . c_identifier ,
315313 optional ( seq ( "=" , $ . expression ) ) ,
316314 ) ) ,
317315 $ . _newline ,
@@ -455,10 +453,18 @@ module.exports = grammar(Python, {
455453 ) ,
456454 ) ,
457455
456+ c_function_pointer_type : $ =>
457+ seq (
458+ $ . c_type ,
459+ "(" , "*" , ")" ,
460+ $ . c_parameters ,
461+ ) ,
462+
463+
458464 c_function_pointer_name : $ =>
459- seq ( "(" , "*" , field ( "name" , $ . identifier ) , ")" ) ,
465+ seq ( "(" , "*" , $ . c_identifier , ")" ) ,
460466
461- c_function_pointer_type : $ =>
467+ c_function_pointer : $ =>
462468 seq (
463469 $ . c_type ,
464470 $ . c_function_pointer_name ,
@@ -507,7 +513,7 @@ module.exports = grammar(Python, {
507513 seq (
508514 repeat ( $ . storageclass ) ,
509515 "ctypedef" ,
510- choice ( $ . cvar_decl , $ . c_function_pointer_type , $ . struct , $ . enum , $ . fused , $ . class_definition , $ . extern_block ) ,
516+ choice ( $ . cvar_decl , $ . c_function_pointer , $ . struct , $ . enum , $ . fused , $ . class_definition , $ . extern_block ) ,
511517 optional ( ";" ) ,
512518 ) ,
513519
@@ -527,6 +533,7 @@ module.exports = grammar(Python, {
527533 optional ( $ . gil_spec ) ,
528534 optional ( $ . exception_value ) ,
529535 optional ( $ . gil_spec ) ,
536+ optional ( "const" ) ,
530537 choice (
531538 seq ( ":" , $ . _suite ) ,
532539 $ . _newline ,
@@ -546,27 +553,6 @@ module.exports = grammar(Python, {
546553 "]" ,
547554 ) ,
548555
549- lambda_parameters : $ =>
550- prec . right (
551- PREC . lambda_parameters ,
552- choice (
553- $ . identifier ,
554- $ . tuple_pattern ,
555- $ . _parameters ,
556- ) ,
557- ) ,
558-
559- lambda : $ =>
560- prec (
561- PREC . lambda ,
562- seq (
563- "lambda" ,
564- field ( "parameters" , optional ( $ . lambda_parameters ) ) ,
565- ":" ,
566- field ( "body" , $ . expression ) ,
567- ) ,
568- ) ,
569-
570556 c_parameters : $ => seq ( "(" , optional ( $ . _typedargslist ) , ")" ) ,
571557
572558 // e.g.
@@ -632,7 +618,7 @@ module.exports = grammar(Python, {
632618 $ . dictionary_splat_pattern ,
633619 ) ,
634620 ":" ,
635- field ( "type" , choice ( $ . c_type , $ . string ) ) ,
621+ field ( "type" , $ . type ) ,
636622 ) ,
637623 ) ,
638624 ) ,
@@ -653,8 +639,7 @@ module.exports = grammar(Python, {
653639 seq (
654640 repeat ( $ . storageclass ) ,
655641 choice ( "struct" , "union" ) ,
656- $ . identifier ,
657- optional ( field ( "alias" , $ . string ) ) ,
642+ $ . c_identifier ,
658643 choice ( $ . _newline , seq ( ":" , $ . struct_suite ) ) ,
659644 ) ,
660645 struct_suite : $ =>
@@ -663,7 +648,7 @@ module.exports = grammar(Python, {
663648 seq (
664649 $ . _indent ,
665650 choice (
666- repeat ( $ . cvar_decl ) ,
651+ repeat ( choice ( $ . cvar_decl , $ . c_function_pointer ) ) ,
667652 $ . pass_statement ,
668653 ) ,
669654 $ . _dedent ,
@@ -680,16 +665,35 @@ module.exports = grammar(Python, {
680665 seq (
681666 $ . identifier ,
682667 optional ( seq ( "(" , $ . c_type , ")" ) ) ,
683- optional ( seq ( ":" , $ . c_type ) ) ,
684668 ) ,
685669 ) ,
686- choice ( $ . _newline , seq ( ":" , $ . _suite ) ) ,
687- ) ,
670+ ":" ,
671+ choice ( $ . _enum_suite , $ . _enum_statements ) ,
672+ $ . _newline ) ,
673+
674+ _enum_suite : $ => seq (
675+ $ . _indent ,
676+ $ . enum_block ,
677+ $ . _dedent ) ,
678+
679+ enum_block : $ => seq (
680+ repeat1 ( $ . _enum_statements ) ,
681+ ) ,
682+
683+ _enum_statements : $ => commaSep1 ( $ . _enum_statement ) ,
684+
685+ _enum_statement : $ => seq (
686+ $ . c_identifier , optional ( seq ( "=" , $ . expression ) ) ,
687+ ) ,
688+
689+ // Optional alias used in underlying C library
690+ c_identifier : $ =>
691+ seq ( field ( "name" , $ . identifier ) , optional ( field ( "alias" , $ . string ) ) ) ,
688692
689693 cppclass : $ =>
690694 seq (
691695 "cppclass" ,
692- $ . identifier ,
696+ $ . c_identifier ,
693697 optional ( $ . template_params ) ,
694698 optional ( "nogil" ) ,
695699 choice ( $ . _newline , seq ( ":" , $ . _cppclass_suite ) ) ,
@@ -763,7 +767,7 @@ module.exports = grammar(Python, {
763767 PREC . cast ,
764768 seq (
765769 "<" ,
766- $ . c_type ,
770+ choice ( $ . c_type , $ . c_function_pointer_type ) ,
767771 optional ( "?" ) ,
768772 ">" ,
769773 $ . expression ,
0 commit comments