From b50a2719137973f2b8611132a79699e439f19000 Mon Sep 17 00:00:00 2001 From: Jan Mas Rovira Date: Fri, 27 Dec 2024 18:57:07 +0100 Subject: [PATCH] update loc --- .../Translation/ImportScanner/FlatParse.hs | 16 ++++++---------- .../Translation/ImportScanner/Megaparsec.hs | 2 +- src/Juvix/Data/ImportScan.hs | 2 ++ 3 files changed, 9 insertions(+), 11 deletions(-) diff --git a/src/Juvix/Compiler/Concrete/Translation/ImportScanner/FlatParse.hs b/src/Juvix/Compiler/Concrete/Translation/ImportScanner/FlatParse.hs index 8105558ac5..2f68aff86b 100644 --- a/src/Juvix/Compiler/Concrete/Translation/ImportScanner/FlatParse.hs +++ b/src/Juvix/Compiler/Concrete/Translation/ImportScanner/FlatParse.hs @@ -79,26 +79,22 @@ bareIdentifier = do t <- many (satisfy L.validTailChar) return (pack (h : t)) -dottedIdentifier :: Parser e (NonEmpty Text) -dottedIdentifier = lexeme (nonEmpty' <$> sepBy1 bareIdentifier dot) +bareDottedIdentifier :: Parser e (NonEmpty Text) +bareDottedIdentifier = nonEmpty' <$> sepBy1 bareIdentifier dot where dot :: Parser e () dot = $(char '.') pImport :: Parser e ImportScanParsed -pImport = do - withSpan helper $ \names _importScanLoc -> +pImport = lexeme $ do + iden <- lexeme bareIdentifier + guard (iden == Str.import_) + withSpan bareDottedIdentifier $ \names _importScanLoc -> return ImportScan { _importScanLoc, _importScanKey = nonEmptyToTopModulePathKey names } - where - helper :: Parser e (NonEmpty Text) - helper = do - iden <- lexeme bareIdentifier - guard (iden == Str.import_) - dottedIdentifier pToken :: Parser e Token pToken = diff --git a/src/Juvix/Compiler/Concrete/Translation/ImportScanner/Megaparsec.hs b/src/Juvix/Compiler/Concrete/Translation/ImportScanner/Megaparsec.hs index fdf4e9adaf..3418b37e67 100644 --- a/src/Juvix/Compiler/Concrete/Translation/ImportScanner/Megaparsec.hs +++ b/src/Juvix/Compiler/Concrete/Translation/ImportScanner/Megaparsec.hs @@ -35,6 +35,6 @@ parserStateToScanResult st = fromImport :: Import 'Parsed -> ImportScan fromImport i = ImportScan - { _importScanLoc = getLoc i, + { _importScanLoc = getLoc (i ^. importModulePath), _importScanKey = topModulePathKey (i ^. importModulePath) } diff --git a/src/Juvix/Data/ImportScan.hs b/src/Juvix/Data/ImportScan.hs index 79672c3fc9..7b223d94b7 100644 --- a/src/Juvix/Data/ImportScan.hs +++ b/src/Juvix/Data/ImportScan.hs @@ -10,6 +10,8 @@ import Juvix.Prelude.Base data ImportScan' a = ImportScan { _importScanKey :: TopModulePathKey, + -- The loc corresponds only to the module name. So it does not include the + -- import keyword _importScanLoc :: a } deriving stock (Show, Eq, Generic)