1- const DIGITS = token ( sep1 ( / [ 0 - 9 ] + / , / _ + / ) )
1+ const DIGITS = token ( choice ( '0' , seq ( / [ 1 - 9 ] / , optional ( seq ( optional ( '_' ) , sep1 ( / [ 0 - 9 ] + / , / _ + / ) ) ) ) ) )
2+ const DECIMAL_DIGITS = token ( sep1 ( / [ 0 - 9 ] + / , '_' ) )
23const HEX_DIGITS = token ( sep1 ( / [ A - F a - f 0 - 9 ] + / , '_' ) )
34const PREC = {
45 // https://introcs.cs.princeton.edu/java/11precedence/
@@ -106,7 +107,7 @@ module.exports = grammar({
106107 ) ) ,
107108
108109 octal_integer_literal : $ => token ( seq (
109- choice ( '0o' , '0O' ) ,
110+ choice ( '0o' , '0O' , '0' ) ,
110111 sep1 ( / [ 0 - 7 ] + / , '_' ) ,
111112 optional ( choice ( 'l' , 'L' ) )
112113 ) ) ,
@@ -118,10 +119,10 @@ module.exports = grammar({
118119 ) ) ,
119120
120121 decimal_floating_point_literal : $ => token ( choice (
121- seq ( DIGITS , '.' , optional ( DIGITS ) , optional ( seq ( ( / [ e E ] / ) , optional ( choice ( '-' , '+' ) ) , DIGITS ) ) , optional ( / [ f F d D ] / ) ) ,
122- seq ( '.' , DIGITS , optional ( seq ( ( / [ e E ] / ) , optional ( choice ( '-' , '+' ) ) , DIGITS ) ) , optional ( / [ f F d D ] / ) ) ,
123- seq ( DIGITS , / [ e E p P ] / , optional ( choice ( '-' , '+' ) ) , DIGITS , optional ( / [ f F d D ] / ) ) ,
124- seq ( DIGITS , optional ( seq ( ( / [ e E ] / ) , optional ( choice ( '-' , '+' ) ) , DIGITS ) ) , ( / [ f F d D ] / ) )
122+ seq ( DECIMAL_DIGITS , '.' , optional ( DECIMAL_DIGITS ) , optional ( seq ( ( / [ e E ] / ) , optional ( choice ( '-' , '+' ) ) , DECIMAL_DIGITS ) ) , optional ( / [ f F d D ] / ) ) ,
123+ seq ( '.' , DECIMAL_DIGITS , optional ( seq ( ( / [ e E ] / ) , optional ( choice ( '-' , '+' ) ) , DECIMAL_DIGITS ) ) , optional ( / [ f F d D ] / ) ) ,
124+ seq ( DIGITS , / [ e E p P ] / , optional ( choice ( '-' , '+' ) ) , DECIMAL_DIGITS , optional ( / [ f F d D ] / ) ) ,
125+ seq ( DIGITS , optional ( seq ( ( / [ e E ] / ) , optional ( choice ( '-' , '+' ) ) , DECIMAL_DIGITS ) ) , ( / [ f F d D ] / ) )
125126 ) ) ,
126127
127128 hex_floating_point_literal : $ => token ( seq (
@@ -213,11 +214,19 @@ module.exports = grammar({
213214 $ . switch_expression ,
214215 ) ,
215216
216- cast_expression : $ => prec ( PREC . CAST , seq (
217- '(' ,
218- sep1 ( field ( 'type' , $ . _type ) , '&' ) ,
219- ')' ,
220- field ( 'value' , $ . expression )
217+ cast_expression : $ => prec ( PREC . CAST , choice (
218+ seq (
219+ '(' ,
220+ field ( 'type' , $ . _type ) ,
221+ ')' ,
222+ field ( 'value' , $ . expression ) ,
223+ ) ,
224+ seq (
225+ '(' ,
226+ sep1 ( field ( 'type' , $ . _type ) , '&' ) ,
227+ ')' ,
228+ field ( 'value' , choice ( $ . primary_expression , $ . lambda_expression ) ) ,
229+ ) ,
221230 ) ) ,
222231
223232 assignment_expression : $ => prec . right ( PREC . ASSIGN , seq (
0 commit comments