@@ -359,7 +359,7 @@ function _buffer_lookahead_tokens(lexer, lookahead)
359
359
while true
360
360
raw = Tokenize. next_token (lexer)
361
361
k = kind (raw)
362
- was_whitespace = k in ( K " Whitespace " , K " Comment " , K " NewlineWs " )
362
+ was_whitespace = is_whitespace (k )
363
363
had_whitespace |= was_whitespace
364
364
f = EMPTY_FLAGS
365
365
raw. dotop && (f |= DOTOP_FLAG)
@@ -622,7 +622,7 @@ function _bump_until_n(stream::ParseStream, n::Integer, flags, remap_kind=K"None
622
622
break
623
623
end
624
624
f = flags | (@__MODULE__ ). flags (tok)
625
- is_trivia = k ∈ ( K " Whitespace " , K " Comment " , K " NewlineWs " )
625
+ is_trivia = is_whitespace (k )
626
626
is_trivia && (f |= TRIVIA_FLAG)
627
627
outk = (is_trivia || remap_kind == K " None" ) ? k : remap_kind
628
628
h = SyntaxHead (outk, f)
@@ -686,7 +686,7 @@ function bump_invisible(stream::ParseStream, kind, flags=EMPTY_FLAGS;
686
686
h = SyntaxHead (kind, flags)
687
687
push! (stream. tokens, SyntaxToken (h, (@__MODULE__ ). kind (h), false , b))
688
688
if ! isnothing (error)
689
- emit_diagnostic (stream, b, b- 1 , error= error)
689
+ emit_diagnostic (stream, b: b- 1 , error= error)
690
690
end
691
691
stream. peek_count = 0
692
692
return position (stream)
@@ -797,12 +797,6 @@ function Base.position(stream::ParseStream)
797
797
ParseStreamPosition (lastindex (stream. tokens), lastindex (stream. ranges))
798
798
end
799
799
800
- # Get position of next item to be emitted into the output stream
801
- # TODO : Figure out how to remove this? It's only used with emit_diagnostic
802
- function next_position (stream:: ParseStream )
803
- ParseStreamPosition (lastindex (stream. tokens)+ 1 , lastindex (stream. ranges)+ 1 )
804
- end
805
-
806
800
"""
807
801
emit(stream, mark, kind, flags = EMPTY_FLAGS; error=nothing)
808
802
@@ -819,14 +813,14 @@ function emit(stream::ParseStream, mark::ParseStreamPosition, kind::Kind,
819
813
# nested.
820
814
fbyte = token_first_byte (stream, first_token)
821
815
lbyte = token_last_byte (stream, lastindex (stream. tokens))
822
- emit_diagnostic (stream, fbyte, lbyte, error= error)
816
+ emit_diagnostic (stream, fbyte: lbyte, error= error)
823
817
end
824
818
push! (stream. ranges, range)
825
819
return position (stream)
826
820
end
827
821
828
- function emit_diagnostic (stream:: ParseStream , fbyte :: Integer , lbyte :: Integer ; kws... )
829
- emit_diagnostic (stream. diagnostics, fbyte, lbyte ; kws... )
822
+ function emit_diagnostic (stream:: ParseStream , byterange :: AbstractUnitRange ; kws... )
823
+ emit_diagnostic (stream. diagnostics, byterange ; kws... )
830
824
return nothing
831
825
end
832
826
@@ -849,20 +843,30 @@ function emit_diagnostic(stream::ParseStream; whitespace=false, kws...)
849
843
end
850
844
fbyte = lookahead_token_first_byte (stream, begin_tok_i)
851
845
lbyte = lookahead_token_last_byte (stream, end_tok_i)
852
- emit_diagnostic (stream, fbyte, lbyte; kws... )
846
+ emit_diagnostic (stream, fbyte: lbyte; kws... )
853
847
return nothing
854
848
end
855
849
856
- function emit_diagnostic (stream:: ParseStream , mark:: ParseStreamPosition ; kws... )
857
- emit_diagnostic (stream, token_first_byte (stream, mark. token_index),
858
- _next_byte (stream) - 1 ; kws... )
850
+ function emit_diagnostic (stream:: ParseStream , mark:: ParseStreamPosition ; trim_whitespace= true , kws... )
851
+ i = mark. token_index
852
+ j = lastindex (stream. tokens)
853
+ if trim_whitespace
854
+ while i < j && is_whitespace (stream. tokens[j])
855
+ j -= 1
856
+ end
857
+ while i+ 1 < j && is_whitespace (stream. tokens[i+ 1 ])
858
+ i += 1
859
+ end
860
+ end
861
+ byterange = stream. tokens[i]. next_byte: stream. tokens[j]. next_byte- 1
862
+ emit_diagnostic (stream, byterange; kws... )
859
863
end
860
864
861
865
function emit_diagnostic (stream:: ParseStream , mark:: ParseStreamPosition ,
862
866
end_mark:: ParseStreamPosition ; kws... )
863
- fbyte = token_first_byte ( stream, mark. token_index)
864
- lbyte = token_first_byte ( stream, end_mark. token_index) - 1
865
- emit_diagnostic (stream, fbyte, lbyte; kws... )
867
+ fbyte = stream. tokens[ mark. token_index] . next_byte
868
+ lbyte = stream. tokens[ end_mark. token_index] . next_byte - 1
869
+ emit_diagnostic (stream, fbyte: lbyte; kws... )
866
870
end
867
871
868
872
# -------------------------------------------------------------------------------
@@ -890,19 +894,19 @@ function validate_tokens(stream::ParseStream)
890
894
# jl_strtod_c can return "underflow" even for valid cases such
891
895
# as `5e-324` where the source is an exact representation of
892
896
# `x`. So only warn when underflowing to zero.
893
- underflow0 = code == :underflow && x == 0
897
+ underflow0 = code === :underflow && x == 0
894
898
else
895
899
x, code = parse_float_literal (Float32, text, fbyte, nbyte)
896
- underflow0 = code == :underflow && x == 0
900
+ underflow0 = code === :underflow && x == 0
897
901
end
898
- if code == :ok
902
+ if code === :ok
899
903
# pass
900
- elseif code == :overflow
901
- emit_diagnostic (stream, fbyte, lbyte,
904
+ elseif code === :overflow
905
+ emit_diagnostic (stream, fbyte: lbyte,
902
906
error= " overflow in floating point literal" )
903
907
error_kind = K " ErrorNumericOverflow"
904
908
elseif underflow0
905
- emit_diagnostic (stream, fbyte, lbyte,
909
+ emit_diagnostic (stream, fbyte: lbyte,
906
910
warning= " underflow to zero in floating point literal" )
907
911
end
908
912
elseif k == K " Char"
@@ -917,7 +921,7 @@ function validate_tokens(stream::ParseStream)
917
921
read (charbuf, Char)
918
922
if ! eof (charbuf)
919
923
error_kind = K " ErrorOverLongCharacter"
920
- emit_diagnostic (stream, fbyte, lbyte,
924
+ emit_diagnostic (stream, fbyte: lbyte,
921
925
error= " character literal contains multiple characters" )
922
926
end
923
927
end
@@ -929,7 +933,7 @@ function validate_tokens(stream::ParseStream)
929
933
end
930
934
elseif is_error (k) && k != K " error"
931
935
# Emit messages for non-generic token errors
932
- emit_diagnostic (stream, fbyte, lbyte,
936
+ emit_diagnostic (stream, fbyte: lbyte,
933
937
error= _token_error_descriptions[k])
934
938
end
935
939
if error_kind != K " None"
0 commit comments