@@ -626,76 +626,44 @@ Integer_Literal
626
626
;
627
627
628
628
fragment Decimal_Integer_Literal
629
- : Decimal_Digits Integer_Type_Suffix?
629
+ : Decimal_Digit Decorated_Decimal_Digit* Integer_Type_Suffix?
630
630
;
631
631
632
- fragment Decimal_Digits
633
- : Decimal_Digit
634
- | Decimal_Digit Decimal_Digits_And_Underscores? Decimal_Digit
632
+ fragment Decorated_Decimal_Digit
633
+ : '_'* Decimal_Digit
635
634
;
636
-
635
+
637
636
fragment Decimal_Digit
638
637
: '0'..'9'
639
638
;
640
639
641
- fragment Decimal_Digits_And_Underscores
642
- : Decimal_Digits_And_Underscore+
643
- ;
644
-
645
- fragment Decimal_Digits_And_Underscore
646
- : Decimal_Digit
647
- | '_'
648
- ;
649
-
650
640
fragment Integer_Type_Suffix
651
641
: 'U' | 'u' | 'L' | 'l' |
652
642
'UL' | 'Ul' | 'uL' | 'ul' | 'LU' | 'Lu' | 'lU' | 'lu'
653
643
;
654
644
655
645
fragment Hexadecimal_Integer_Literal
656
- : ('0x' | '0X') Hex_Digits Integer_Type_Suffix?
646
+ : ('0x' | '0X') Decorated_Hex_Digit+ Integer_Type_Suffix?
657
647
;
658
648
659
- fragment Hex_Digits
649
+ fragment Decorated_Hex_Digit
660
650
: '_'* Hex_Digit
661
- | '_'* Hex_Digit Hex_Digits_And_Underscores? Hex_Digit
662
651
;
663
-
652
+
664
653
fragment Hex_Digit
665
654
: '0'..'9' | 'A'..'F' | 'a'..'f'
666
655
;
667
-
668
- fragment Hex_Digits_And_Underscores
669
- : Hex_Digits_And_Underscore+
670
- ;
671
-
672
- fragment Hex_Digits_And_Underscore
673
- : Hex_Digit
674
- | '_'
675
- ;
676
-
656
+
677
657
fragment Binary_Integer_Literal
678
- : '0b' Binary_Digits Integer_Type_Suffix?
679
- | '0B' Binary_Digits Integer_Type_Suffix?
658
+ : ('0b' | '0B') Decorated_Binary_Digit+ Integer_Type_Suffix?
680
659
;
681
660
682
- fragment Binary_Digits
661
+ fragment Decorated_Binary_Digit
683
662
: '_'* Binary_Digit
684
- | '_'* Binary_Digit Binary_Digits_And_Underscores? Binary_Digit
685
663
;
686
-
664
+
687
665
fragment Binary_Digit
688
- : '0'
689
- | '1'
690
- ;
691
-
692
- fragment Binary_Digits_And_Underscores
693
- : Binary_Digits_And_Underscore+
694
- ;
695
-
696
- fragment Binary_Digits_And_Underscore
697
- : Binary_Digit
698
- | '_'
666
+ : '0' | '1'
699
667
;
700
668
```
701
669
@@ -721,17 +689,22 @@ To permit the smallest possible `int` and `long` values to be written as integer
721
689
> 123 // decimal, int
722
690
> 10_ 543_ 765 Lu // decimal, ulong
723
691
> 1_2__3___4____5 // decimal, int
692
+ > _123 // invalid; no leading _ allowed
693
+ > 123_ // invalid; no trailing _allowed
724
694
>
725
695
> 0x Ff // hex, int
726
696
> 0X 1b_ a0_ 44_ fE L // hex, long
727
697
> 0x 1ade_ 3FE1_ 29Aa UL // hex, ulong
728
698
> 0x_abc // hex, int
699
+ > _0x123 // invalid; no leading _ allowed
729
700
> 0xabc_ // invalid; no trailing _ allowed
730
701
>
731
702
> 0b 101 // binary, int
732
703
> 0B 1001_ 1010 u // binary, uint
733
704
> 0b 1111_ 1111_ 0000 UL // binary, ulong
734
705
> 0B __111 // binary, int
706
+ > __0B111 // invalid; no leading _ allowed
707
+ > 0B 111__ // invalid; no trailing _ allowed
735
708
> ```
736
709
>
737
710
> * end example *
@@ -742,14 +715,15 @@ Real literals are used to write values of types `float`, `double`, and `decimal`
742
715
743
716
```ANTLR
744
717
Real_Literal
745
- : Decimal_Digits '.' Decimal_Digits Exponent_Part ? Real_Type_Suffix ?
746
- | '.' Decimal_Digits Exponent_Part ? Real_Type_Suffix ?
747
- | Decimal_Digits Exponent_Part Real_Type_Suffix ?
748
- | Decimal_Digits Real_Type_Suffix
718
+ : Decimal_Digit Decorated_Decimal_Digit * '.'
719
+ Decimal_Digit Decorated_Decimal_Digit * Exponent_Part ? Real_Type_Suffix ?
720
+ | '.' Decimal_Digit Decorated_Decimal_Digit * Exponent_Part ? Real_Type_Suffix ?
721
+ | Decimal_Digit Decorated_Decimal_Digit * Exponent_Part Real_Type_Suffix ?
722
+ | Decimal_Digit Decorated_Decimal_Digit * Real_Type_Suffix
749
723
;
750
724
751
725
fragment Exponent_Part
752
- : ('e' | 'E' ) Sign ? Decimal_Digits
726
+ : ('e' | 'E' ) Sign ? Decimal_Digit Decorated_Decimal_Digit *
753
727
;
754
728
755
729
fragment Sign
@@ -789,7 +763,11 @@ The value of a real literal of type `float` or `double` is determined by using t
789
763
> 15 D // double
790
764
> 19 . 73 M // decimal
791
765
> 1 .F // invalid; ill-formed (parsed as "1." and "F")
766
+ > _1 .2 F // invalid; no leading _ allowed
767
+ > 1_.2F // invalid; no trailing _ allowed in integer part
768
+ > 1 ._234 // invalid; no leading _ allowed in fraction
792
769
> 1.234_ // invalid; no trailing _ allowed in fraction
770
+ > .3e_5F // invalid; no leading _ allowed in exponent
793
771
> . 3 e 5_ F // invalid; no trailing _ allowed in exponent
794
772
> ```
795
773
>
0 commit comments