diff options
| author | adelon <22380201+adelon@users.noreply.github.com> | 2026-07-27 03:19:11 +0200 |
|---|---|---|
| committer | adelon <22380201+adelon@users.noreply.github.com> | 2026-07-27 15:03:30 +0200 |
| commit | d4c07b17ce39649e070948821bd24220cda8881c (patch) | |
| tree | f32f85ad609d2c29005e74acebced8f0b057b413 /source/Syntax | |
| parent | cf6b9e77360fc9735e5f2bb09223efaf291d71f5 (diff) | |
Load selected sources as strict UTF-8
Diffstat (limited to 'source/Syntax')
| -rw-r--r-- | source/Syntax/Token.hs | 23 |
1 files changed, 13 insertions, 10 deletions
diff --git a/source/Syntax/Token.hs b/source/Syntax/Token.hs index 9ce7fb9..8fa2a1f 100644 --- a/source/Syntax/Token.hs +++ b/source/Syntax/Token.hs @@ -34,7 +34,6 @@ import Report.Location import Control.Monad.Combinators import Control.Monad.State.Strict -import Data.Char (isAlphaNum) import Data.List.NonEmpty qualified as NonEmpty import Data.Text qualified as Text import Prettyprinter (Pretty(..)) @@ -307,33 +306,37 @@ document = do is <- importBlock es <- many environment eof - return (is, es) + return (unLocated <$> is, es) -importBlock :: Lexer [FilePath] +importBlock :: Lexer [Located FilePath] importBlock = do void (skipManyTill skipChar importLineOrBeginEnv) - many (importLine <* whitespace) + many importLine where -- When skipping to the import block, we first need to try parsing whitespace to properly handle comments and avoid picking up a commented import line at the start of the import block. skipChar, importLineOrBeginEnv :: Lexer () skipChar = comment <|> void anySingle importLineOrBeginEnv = lookAhead (void (Char.string "\\import{") <|> void beginToplevelEnvironment) - importLine :: Lexer FilePath = do + importLine :: Lexer (Located FilePath) = lexeme do Char.string "\\import{" path <- some (satisfy isTheoryNameChar) Char.char '}' pure path isTheoryNameChar :: Char -> Bool - isTheoryNameChar c = isAlphaNum c || c `elem` (".-_/" :: [Char]) + isTheoryNameChar c = + c /= '}' && c /= '\n' && c /= '\r' && c /= '\0' -- TODO remove once we have a proper build system and incremental compilation -gatherImports :: Text -> [FilePath] -gatherImports raw = case runParser (evalStateT importBlock (initLexerState (FileId maxBound))) "TODO filename" raw of - Left err -> error (errorBundlePretty err) - Right paths -> paths +gatherImports + :: FileId + -> String + -> Text + -> Either (ParseErrorBundle Text Void) [Located FilePath] +gatherImports fileId file = + runParser (evalStateT importBlock (initLexerState fileId)) file beginToplevelEnvironment :: Lexer (Located Text) |
