on master help sign in
Slightly simplify Code.whatIsNext logic
commit2a1ace1e1e1d6229e90967e6e8e3034f00952263 authorEvan Czaplicki <evancz@users.noreply.github.com> dateMon 20 May 2019, 15:47 (7 years ago) parent20f9106
1 file changed+9−18
compiler/src/Reporting/Render/Code.hs+9−18
compiler/src/Reporting/Render/Code.hs+9−18
@@ -218,15 +218,16 @@ whatIsNext (Source sourceLines) row col =
218218 Keyword keyword
219219
220220 Nothing ->
221− case takeWhile isSymbol chars of
222− op@(_:_) ->
223− Operator op
221+ case chars of
222+ [] ->
223+ Other
224224
225− []
226− | isNext ')' chars -> Close "parenthesis" ')'
227− | isNext ']' chars -> Close "square bracket" ']'
228− | isNext '}' chars -> Close "curly brace" '}'
229− | otherwise -> Other
225+ c:cs
226+ | isSymbol c -> Operator (c : takeWhile isSymbol cs)
227+ | c == ')' -> Close "parenthesis" ')'
228+ | c == ']' -> Close "square bracket" ']'
229+ | c == '}' -> Close "curly brace" '}'
230+ | otherwise -> Other
230231
231232
232233isSymbol :: Char -> Bool
@@ -234,16 +235,6 @@ isSymbol char =
234235 IntSet.member (Char.ord char) binopCharSet
235236
236237
237−isNext :: Char -> [Char] -> Bool
238−isNext expected chars =
239− case chars of
240− [] ->
241− False
242−
243− actual:_ ->
244− actual == expected
245−
246−
247238startsWithKeyword :: [Char] -> [Char] -> Bool
248239startsWithKeyword restOfLine keyword =
249240 List.isPrefixOf keyword restOfLine