@@ -42,6 +42,7 @@ using Base.Meta, Sockets, StyledStrings
42
42
using JuliaSyntaxHighlighting
43
43
import InteractiveUtils
44
44
import FileWatching
45
+ import Base. JuliaSyntax: kind, @K_str , @KSet_str , Tokenize. tokenize
45
46
46
47
export
47
48
AbstractREPL,
@@ -1700,49 +1701,16 @@ answer_color(r::StreamREPL) = r.answer_color
1700
1701
input_color (r:: LineEditREPL ) = r. envcolors ? Base. input_color () : r. input_color
1701
1702
input_color (r:: StreamREPL ) = r. input_color
1702
1703
1703
- let matchend = Dict (" \" " => r" \" " , " \"\"\" " => r" \"\"\" " , " '" => r" '" ,
1704
- " `" => r" `" , " ```" => r" ```" , " #" => r" $" m , " #=" => r" =#|#=" )
1705
- global _rm_strings_and_comments
1706
- function _rm_strings_and_comments (code:: Union{String,SubString{String}} )
1707
- buf = IOBuffer (sizehint = sizeof (code))
1708
- pos = 1
1709
- while true
1710
- i = findnext (r" \" (?!\"\" )|\"\"\" |'|`(?!``)|```|#(?!=)|#=" , code, pos)
1711
- isnothing (i) && break
1712
- match = SubString (code, i)
1713
- j = findnext (matchend[match]:: Regex , code, nextind (code, last (i)))
1714
- if match == " #=" # possibly nested
1715
- nested = 1
1716
- while j != = nothing
1717
- nested += SubString (code, j) == " #=" ? + 1 : - 1
1718
- iszero (nested) && break
1719
- j = findnext (r" =#|#=" , code, nextind (code, last (j)))
1720
- end
1721
- elseif match[1 ] != ' #' # quote match: check non-escaped
1722
- while j != = nothing
1723
- notbackslash = findprev (!= (' \\ ' ), code, prevind (code, first (j))):: Int
1724
- isodd (first (j) - notbackslash) && break # not escaped
1725
- j = findnext (matchend[match]:: Regex , code, nextind (code, first (j)))
1726
- end
1727
- end
1728
- isnothing (j) && break
1729
- if match[1 ] == ' #'
1730
- print (buf, SubString (code, pos, prevind (code, first (i))))
1731
- else
1732
- print (buf, SubString (code, pos, last (i)), ' ' , SubString (code, j))
1733
- end
1734
- pos = nextind (code, last (j))
1735
- end
1736
- print (buf, SubString (code, pos, lastindex (code)))
1737
- return String (take! (buf))
1738
- end
1739
- end
1740
-
1741
1704
# heuristic function to decide if the presence of a semicolon
1742
1705
# at the end of the expression was intended for suppressing output
1743
- ends_with_semicolon (code:: AbstractString ) = ends_with_semicolon (String (code))
1744
- ends_with_semicolon (code:: Union{String,SubString{String}} ) =
1745
- contains (_rm_strings_and_comments (code), r" ;\s *$" )
1706
+ function ends_with_semicolon (code)
1707
+ semi = false
1708
+ for tok in tokenize (code)
1709
+ kind (tok) in KSet " Whitespace NewlineWs Comment EndMarker" && continue
1710
+ semi = kind (tok) == K " ;"
1711
+ end
1712
+ return semi
1713
+ end
1746
1714
1747
1715
function banner (io:: IO = stdout ; short = false )
1748
1716
if Base. GIT_VERSION_INFO. tagged_commit
0 commit comments