@@ -614,6 +614,8 @@ function lex_less(l::Lexer)
614
614
else
615
615
if accept (l, ' >' )
616
616
return emit (l, K " <-->" )
617
+ elseif accept (l, ' -' )
618
+ return emit_error (l, K " ErrorInvalidOperator" )
617
619
else
618
620
return emit (l, K " <--" )
619
621
end
@@ -772,33 +774,13 @@ function lex_digit(l::Lexer, kind)
772
774
return emit_error (l, K " ErrorInvalidNumericConstant" )
773
775
elseif is_operator_start_char (ppc) && ppc != = ' :'
774
776
readchar (l)
775
- return emit_error (l, K " ErrorAmbiguousNumericConstant" )
776
- elseif (! (isdigit (ppc) ||
777
- iswhitespace (ppc) ||
778
- is_identifier_start_char (ppc)
779
- || ppc == ' ('
780
- || ppc == ' )'
781
- || ppc == ' ['
782
- || ppc == ' ]'
783
- || ppc == ' {'
784
- || ppc == ' }'
785
- || ppc == ' ,'
786
- || ppc == ' ;'
787
- || ppc == ' @'
788
- || ppc == ' `'
789
- || ppc == ' "'
790
- || ppc == ' :'
791
- || ppc == ' ?'
792
- || ppc == ' #'
793
- || ppc == EOF_CHAR))
794
- kind = K " Integer"
795
-
796
- return emit (l, kind)
777
+ return emit_error (l, K " ErrorAmbiguousNumericConstant" ) # `1.+`
797
778
end
798
779
readchar (l)
799
780
800
781
kind = K " Float"
801
- accept_number (l, isdigit)
782
+ accept (l, ' _' ) && return emit_error (l, K " ErrorInvalidNumericConstant" ) # `1._`
783
+ had_fraction_digs = accept_number (l, isdigit)
802
784
pc, ppc = dpeekchar (l)
803
785
if (pc == ' e' || pc == ' E' || pc == ' f' ) && (isdigit (ppc) || ppc == ' +' || ppc == ' -' || ppc == ' −' )
804
786
kind = pc == ' f' ? K " Float32" : K " Float"
@@ -807,17 +789,20 @@ function lex_digit(l::Lexer, kind)
807
789
if accept_batch (l, isdigit)
808
790
pc,ppc = dpeekchar (l)
809
791
if pc === ' .' && ! dotop2 (ppc)
810
- accept (l, ' . ' )
811
- return emit_error (l, K " ErrorInvalidNumericConstant" )
792
+ readchar (l )
793
+ return emit_error (l, K " ErrorInvalidNumericConstant" ) # `1.e1.`
812
794
end
813
795
else
814
- return emit_error (l, K " ErrorInvalidNumericConstant" )
796
+ return emit_error (l, K " ErrorInvalidNumericConstant" ) # `1.e`
815
797
end
816
- elseif pc == ' .' && ( is_identifier_start_char ( ppc) || ppc == EOF_CHAR )
798
+ elseif pc == ' .' && ppc != ' . ' && ! is_operator_start_char (ppc )
817
799
readchar (l)
818
- return emit_error (l, K " ErrorInvalidNumericConstant" )
800
+ return emit_error (l, K " ErrorInvalidNumericConstant" ) # `1.1.`
801
+ elseif ! had_fraction_digs && (is_identifier_start_char (pc) ||
802
+ pc == ' (' || pc == ' [' || pc == ' {' ||
803
+ pc == ' @' || pc == ' `' || pc == ' "' )
804
+ return emit_error (l, K " ErrorAmbiguousNumericDotMultiply" ) # `1.(` `1.x`
819
805
end
820
-
821
806
elseif (pc == ' e' || pc == ' E' || pc == ' f' ) && (isdigit (ppc) || ppc == ' +' || ppc == ' -' || ppc == ' −' )
822
807
kind = pc == ' f' ? K " Float32" : K " Float"
823
808
readchar (l)
@@ -826,44 +811,54 @@ function lex_digit(l::Lexer, kind)
826
811
pc,ppc = dpeekchar (l)
827
812
if pc === ' .' && ! dotop2 (ppc)
828
813
accept (l, ' .' )
829
- return emit_error (l, K " ErrorInvalidNumericConstant" )
814
+ return emit_error (l, K " ErrorInvalidNumericConstant" ) # `1e1.`
830
815
end
831
816
else
832
- return emit_error (l, K " ErrorInvalidNumericConstant" )
817
+ return emit_error (l, K " ErrorInvalidNumericConstant" ) # `1e+`
833
818
end
834
819
elseif position (l) - startpos (l) == 1 && l. chars[1 ] == ' 0'
835
820
kind == K " Integer"
821
+ is_bin_oct_hex_int = false
836
822
if pc == ' x'
837
823
kind = K " HexInt"
838
824
isfloat = false
839
825
readchar (l)
840
- ! (ishex (ppc) || ppc == ' .' ) && return emit_error (l, K " ErrorInvalidNumericConstant" )
841
- accept_number (l, ishex)
826
+ had_digits = accept_number (l, ishex)
842
827
pc,ppc = dpeekchar (l)
843
828
if pc == ' .' && ppc != ' .'
844
829
readchar (l)
845
- accept_number (l, ishex)
830
+ had_digits |= accept_number (l, ishex)
846
831
isfloat = true
847
832
end
848
833
if accept (l, " pP" )
849
834
kind = K " Float"
850
835
accept (l, " +-−" )
851
- if ! accept_number (l, isdigit)
852
- return emit_error (l, K " ErrorInvalidNumericConstant" )
836
+ if ! accept_number (l, isdigit) || ! had_digits
837
+ return emit_error (l, K " ErrorInvalidNumericConstant" ) # `0x1p` `0x.p0`
853
838
end
854
839
elseif isfloat
855
- return emit_error (l, K "ErrorInvalidNumericConstant " )
840
+ return emit_error (l, K "ErrorHexFloatMustContainP " ) # `0x.` `0x1.0`
856
841
end
842
+ is_bin_oct_hex_int = ! isfloat
857
843
elseif pc == ' b'
858
- ! isbinary (ppc) && return emit_error (l, K " ErrorInvalidNumericConstant" )
859
844
readchar (l)
860
- accept_number (l, isbinary)
845
+ had_digits = accept_number (l, isbinary)
861
846
kind = K " BinInt"
847
+ is_bin_oct_hex_int = true
862
848
elseif pc == ' o'
863
- ! isoctal (ppc) && return emit_error (l, K " ErrorInvalidNumericConstant" )
864
849
readchar (l)
865
- accept_number (l, isoctal)
850
+ had_digits = accept_number (l, isoctal)
866
851
kind = K " OctInt"
852
+ is_bin_oct_hex_int = true
853
+ end
854
+ if is_bin_oct_hex_int
855
+ pc = peekchar (l)
856
+ if ! had_digits || isdigit (pc) || is_identifier_start_char (pc)
857
+ accept_batch (l, c-> isdigit (c) || is_identifier_start_char (c))
858
+ # `0x` `0xg` `0x_` `0x-`
859
+ # `0b123` `0o78p` `0xenomorph` `0xaα`
860
+ return emit_error (l, K " ErrorInvalidNumericConstant" )
861
+ end
867
862
end
868
863
end
869
864
return emit (l, kind)
0 commit comments