File tree Expand file tree Collapse file tree 3 files changed +18
-23
lines changed
Expand file tree Collapse file tree 3 files changed +18
-23
lines changed Original file line number Diff line number Diff line change @@ -279,13 +279,11 @@ digImplHoles parseStart filePath implText =
279279parseFragment :: Pos -> Text -> Either ParseError [C. Stmt ]
280280parseFragment fragmentStart fragment = do
281281 let Pos filePath _ _ _ = fragmentStart
282- case Syntax.Parser.Lexer. scan filePath fragment of
283- Left err -> Left (LexicalError err)
284- Right tokens -> do
285- let tokens' = translateTokStream fragmentStart tokens
286- case Parser. parse Parser. statements filePath tokens' of
287- Left (errors, logMsg) -> Left (SyntacticError errors logMsg)
288- Right val -> Right val
282+ let tokens = Syntax.Parser.Lexer. scan filePath fragment
283+ let tokens' = translateTokStream fragmentStart tokens
284+ case Parser. parse Parser. statements filePath tokens' of
285+ Left (errors, logMsg) -> Left (SyntacticError errors logMsg)
286+ Right val -> Right val
289287 where
290288 translateRange :: Pos -> Pos -> Pos
291289 translateRange
Original file line number Diff line number Diff line change @@ -44,11 +44,11 @@ type Parser = ParsecT Void TokStream M
4444--------------------------------------------------------------------------------
4545
4646scanAndParse :: Parser a -> FilePath -> Text -> Either ParseError a
47- scanAndParse parser filepath source = case scan filepath source of
48- Left err -> throwError ( LexicalError err)
49- Right tokens -> case parse parser filepath tokens of
50- Left (errors, logMsg) -> throwError (SyntacticError errors logMsg)
51- Right val -> return val
47+ scanAndParse parser filepath source =
48+ let tokens = scan filepath source
49+ in case parse parser filepath tokens of
50+ Left (errors, logMsg) -> throwError (SyntacticError errors logMsg)
51+ Right val -> return val
5252
5353parse :: Parser a -> FilePath -> TokStream -> Either (NonEmpty (Loc , String ), String ) a
5454parse parser filepath tokenStream =
Original file line number Diff line number Diff line change @@ -483,23 +483,20 @@ lexer =
483483--------------------------------------------------------------------------------
484484type LexicalError = Pos
485485
486- scan :: FilePath -> Text -> Either LexicalError TokStream
486+ scan :: FilePath -> Text -> TokStream
487487scan filepath =
488- translateLoc . Right . runLexer lexer filepath . Text. unpack
488+ translateLoc . runLexer lexer filepath . Text. unpack
489489 where
490490 -- According to the document in Data.Loc.Range, the original meaning of Loc is
491491 -- different from how we use it as Range (to simply put, Range extends 1 in col and charOffset).
492492 -- The lexer records tokens' ranges in Loc, and we use translateLoc to make it Range.
493- translateLoc :: Either LexicalError TokStream -> Either LexicalError TokStream
494- translateLoc (Left x) = Left x
495- translateLoc (Right toks) = Right (f toks)
493+ translateLoc :: TokStream -> TokStream
494+ translateLoc (TsToken (L loc x) rest) = TsToken (L (update loc) x) (translateLoc rest)
496495 where
497- f (TsToken (L loc x) rest) = TsToken (L (update loc) x) (f rest)
498- where
499- update NoLoc = NoLoc
500- update (Loc start (Pos path l c co)) = Loc start (Pos path l (c + 1 ) (co + 1 ))
501- f TsEof = TsEof
502- f (TsError e) = TsError e
496+ update NoLoc = NoLoc
497+ update (Loc start (Pos path l c co)) = Loc start (Pos path l (c + 1 ) (co + 1 ))
498+ translateLoc TsEof = TsEof
499+ translateLoc (TsError e) = TsError e
503500
504501-- | Instances of PrettyToken
505502instance PrettyToken Tok where
You can’t perform that action at this time.
0 commit comments