From f399d380e7ea75e5e4b3e18e851e97c4902a7d1e Mon Sep 17 00:00:00 2001 From: Olle Fredriksson Date: Wed, 24 Jan 2024 00:37:55 +0100 Subject: [PATCH] wip --- src/LanguageServer/LineColumns.hs | 2 +- src/Lexer.hs | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/LanguageServer/LineColumns.hs b/src/LanguageServer/LineColumns.hs index 52ef8c4..b21bc71 100644 --- a/src/LanguageServer/LineColumns.hs +++ b/src/LanguageServer/LineColumns.hs @@ -28,7 +28,7 @@ fromAbsolute moduleName = do Just filePath -> do rope <- fetch $ Query.FileRope filePath let toLineColumn (Position.Absolute i) = - case Rope.splitAt (fromIntegral i) rope of + case Rope.utf8SplitAt (fromIntegral i) rope of Nothing -> UTF16.LineColumn 0 0 Just (rope', _) -> let Rope.Position row column = Rope.lengthAsPosition rope' diff --git a/src/Lexer.hs b/src/Lexer.hs index d4718ba..9f205db 100644 --- a/src/Lexer.hs +++ b/src/Lexer.hs @@ -111,7 +111,7 @@ data State = State satisfy :: Word8 -> (Word8 -> Bool) -> (Char -> Bool) -> State -> Maybe Int satisfy c satisfyASCII satisfyNonASCII State {..} | c < 128 = if satisfyASCII c then Just 1 else Nothing - | otherwise = do + | otherwise = case Utf8.utf8LengthByLeader c of 2 | position + 1 < end, satisfyNonASCII (Utf8.chr2 c (index input $ position + 1)) -> Just 2 3 | position + 2 < end, satisfyNonASCII (Utf8.chr3 c (index input $ position + 1) (index input $ position + 2)) -> Just 3 @@ -180,7 +180,7 @@ lex state@State {..} | Just n <- satisfy c isASCIIIdentifierStart Char.isAlpha state -> identifier position lineColumn $ incColumn n state c - | Just n <- satisfy c isASCIIOperator (\c -> Char.isSymbol c || Char.isPunctuation c) state -> + | Just n <- satisfy c isASCIIOperator (\c' -> Char.isSymbol c' || Char.isPunctuation c') state -> operator position lineColumn $ incColumn n state ------------------------------------------------------------------------- -- Error @@ -275,7 +275,7 @@ dotIdentifier !startPosition !startLineColumn !dotPosition !dotLineColumn state@ | otherwise = case index input position of c | Just n <- satisfy c isASCIIIdentifierCont Char.isAlpha state -> identifier startPosition startLineColumn $ incColumn n state - | Just n <- satisfy c isASCIIOperator (\c -> Char.isSymbol c || Char.isPunctuation c) state -> + | Just n <- satisfy c isASCIIOperator (\c' -> Char.isSymbol c' || Char.isPunctuation c') state -> identifierToken input startPosition startLineColumn dotPosition $ operator dotPosition dotLineColumn $ incColumn n state | otherwise -> identifierToken input startPosition startLineColumn dotPosition $ @@ -322,7 +322,7 @@ operator !startPosition !startLineColumn state@State {..} | position >= end = operatorToken input startPosition startLineColumn position Empty | otherwise = case index input position of c - | Just n <- satisfy c isASCIIOperator (\c -> Char.isSymbol c || Char.isPunctuation c) state -> + | Just n <- satisfy c isASCIIOperator (\c' -> Char.isSymbol c' || Char.isPunctuation c') state -> operator startPosition startLineColumn $ incColumn n state | otherwise -> operatorToken input startPosition startLineColumn position $