Skip to content

Commit fd9075d

Browse files
committed
Cleanup: rename textbuf -> unsafe_textbuf
1 parent ec51994 commit fd9075d

File tree

4 files changed

+24
-21
lines changed

4 files changed

+24
-21
lines changed

src/diagnostics.jl

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -91,11 +91,6 @@ function show_diagnostics(io::IO, diagnostics::AbstractVector{Diagnostic}, text:
9191
show_diagnostics(io, diagnostics, SourceFile(text))
9292
end
9393

94-
function emit_diagnostic(diagnostics::AbstractVector{Diagnostic},
95-
byterange::AbstractUnitRange; kws...)
96-
push!(diagnostics, Diagnostic(first(byterange), last(byterange); kws...))
97-
end
98-
9994
function any_error(diagnostics::AbstractVector{Diagnostic})
10095
any(is_error(d) for d in diagnostics)
10196
end

src/expr.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -459,7 +459,7 @@ function build_tree(::Type{Expr}, stream::ParseStream;
459459
filename=nothing, first_line=1, kws...)
460460
source = SourceFile(sourcetext(stream), first_index=first_byte(stream),
461461
filename=filename, first_line=first_line)
462-
txtbuf = textbuf(stream)
462+
txtbuf = unsafe_textbuf(stream)
463463
args = Any[]
464464
childranges = UnitRange{Int}[]
465465
childheads = SyntaxHead[]

src/parse_stream.jl

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -901,11 +901,16 @@ function emit_diagnostic(stream::ParseStream, mark::ParseStreamPosition,
901901
emit_diagnostic(stream, fbyte:lbyte; kws...)
902902
end
903903

904+
function emit_diagnostic(diagnostics::AbstractVector{Diagnostic},
905+
byterange::AbstractUnitRange; kws...)
906+
push!(diagnostics, Diagnostic(first(byterange), last(byterange); kws...))
907+
end
908+
904909
#-------------------------------------------------------------------------------
905910
# ParseStream Post-processing
906911

907912
function validate_tokens(stream::ParseStream)
908-
txtbuf = textbuf(stream)
913+
txtbuf = unsafe_textbuf(stream)
909914
toks = stream.tokens
910915
charbuf = IOBuffer()
911916
for i = 2:length(toks)
@@ -1104,11 +1109,14 @@ function sourcetext(stream::ParseStream; steal_textbuf=false)
11041109
end
11051110

11061111
"""
1107-
textbuf(stream)
1112+
unsafe_textbuf(stream)
11081113
11091114
Return the `Vector{UInt8}` text buffer being parsed by this `ParseStream`.
1115+
1116+
!!! warning
1117+
The caller must hold a reference to `stream` while using textbuf
11101118
"""
1111-
textbuf(stream) = stream.textbuf
1119+
unsafe_textbuf(stream) = stream.textbuf
11121120

11131121
first_byte(stream::ParseStream) = first(stream.tokens).next_byte # Use sentinel token
11141122
last_byte(stream::ParseStream) = _next_byte(stream)-1

src/parser.jl

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -125,8 +125,8 @@ function emit_diagnostic(ps::ParseState, args...; kws...)
125125
emit_diagnostic(ps.stream, args...; kws...)
126126
end
127127

128-
function textbuf(ps::ParseState)
129-
textbuf(ps.stream)
128+
function unsafe_textbuf(ps::ParseState)
129+
unsafe_textbuf(ps.stream)
130130
end
131131

132132
function first_child_position(ps::ParseState, pos::ParseStreamPosition)
@@ -3143,7 +3143,7 @@ function parse_brackets(after_parse::Function,
31433143
return opts
31443144
end
31453145

3146-
is_indentation(b::UInt8) = (b == UInt8(' ') || b == UInt8('\t'))
3146+
_is_indentation(b::UInt8) = (b == u8" " || b == u8"\t")
31473147

31483148
# Parse a string, embedded interpolations and deindent triple quoted strings
31493149
# by marking indentation characters as whitespace trivia.
@@ -3157,7 +3157,7 @@ function parse_string(ps::ParseState, raw::Bool)
31573157
indent_ref_i = 0
31583158
indent_ref_len = typemax(Int)
31593159
indent_chunks = acquire_positions(ps.stream)
3160-
buf = textbuf(ps)
3160+
txtbuf = unsafe_textbuf(ps)
31613161
chunk_flags = raw ? RAW_STRING_FLAG : EMPTY_FLAGS
31623162
bump(ps, TRIVIA_FLAG)
31633163
first_chunk = true
@@ -3212,10 +3212,10 @@ function parse_string(ps::ParseState, raw::Bool)
32123212
if triplestr && first_chunk && span(t) <= 2 &&
32133213
begin
32143214
s = span(t)
3215-
b = buf[last_byte(t)]
3215+
b = txtbuf[last_byte(t)]
32163216
# Test whether the string is a single logical newline
3217-
(s == 1 && (b == UInt8('\n') || b == UInt8('\r'))) ||
3218-
(s == 2 && (buf[first_byte(t)] == UInt8('\r') && b == UInt8('\n')))
3217+
(s == 1 && (b == u8"\n" || b == u8"\r")) ||
3218+
(s == 2 && (txtbuf[first_byte(t)] == u8"\r" && b == u8"\n"))
32193219
end
32203220
# First line of triple string is a newline only: mark as trivia.
32213221
# """\nx""" ==> (string-s "x")
@@ -3253,8 +3253,8 @@ function parse_string(ps::ParseState, raw::Bool)
32533253
# """\n $a \n $b""" ==> (string-s a " \n" b)
32543254
# """\n $a\n $b\n""" ==> (string-s " " a "\n" " " b "\n")
32553255
#
3256-
if prev_chunk_newline && (b = buf[first_byte(t)];
3257-
b != UInt8('\n') && b != UInt8('\r'))
3256+
if prev_chunk_newline && (b = txtbuf[first_byte(t)];
3257+
b != u8"\n" && b != u8"\r")
32583258
# Compute length of longest common prefix of mixed
32593259
# spaces and tabs, in bytes
32603260
#
@@ -3267,7 +3267,7 @@ function parse_string(ps::ParseState, raw::Bool)
32673267
# No indentation found yet. Find indentation we'll
32683268
# use as a reference
32693269
i = first_byte(t) - 1
3270-
while i < last_byte(t) && is_indentation(buf[i+1])
3270+
while i < last_byte(t) && _is_indentation(txtbuf[i+1])
32713271
i += 1
32723272
end
32733273
indent_ref_i = first_byte(t)
@@ -3277,7 +3277,7 @@ function parse_string(ps::ParseState, raw::Bool)
32773277
# shortening length if necessary.
32783278
j = 0
32793279
while j < span(t) && j < indent_ref_len
3280-
if buf[j + first_byte(t)] != buf[j + indent_ref_i]
3280+
if txtbuf[j + first_byte(t)] != txtbuf[j + indent_ref_i]
32813281
break
32823282
end
32833283
j += 1
@@ -3287,7 +3287,7 @@ function parse_string(ps::ParseState, raw::Bool)
32873287
# Prepare a place for indentiation trivia, if necessary
32883288
push!(indent_chunks, bump_invisible(ps, K"TOMBSTONE"))
32893289
end
3290-
b = buf[last_byte(t)]
3290+
b = txtbuf[last_byte(t)]
32913291
prev_chunk_newline = b == UInt8('\n') || b == UInt8('\r')
32923292
end
32933293
bump(ps, chunk_flags)

0 commit comments

Comments
 (0)