Skip to content

Commit

Permalink
Better parser for :load (#430)
Browse files Browse the repository at this point in the history
Parses file names like the shell does (i.e. it can deal with escaped spaces etc.).  Can also even accept bare, unescaped spaces in the file name since `:load` doesn't need to split the input into multiple parts.

Closes #322.
  • Loading branch information
byorgey authored Jan 2, 2025
1 parent eabf3d1 commit c93df52
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/Disco/Interactive/Commands.hs
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ import Polysemy.Reader
import System.FilePath (splitFileName)
import Text.Megaparsec hiding (State, runParser)
import Text.Megaparsec.Char qualified as C
import Text.Megaparsec.Char.Lexer qualified as L
import Text.PrettyPrint.Boxes qualified as B
import Unbound.Generics.LocallyNameless (
Name,
Expand Down Expand Up @@ -269,7 +270,9 @@ parseCommandArgs allCommands cmd = maybe badCmd snd $ find ((cmd `isPrefixOf`) .

-- | Parse a file name.
fileParser :: Parser FilePath
fileParser = many C.spaceChar *> many (satisfy (not . isSpace))
fileParser = many C.spaceChar *> some (escapedSpace <|> L.charLiteral <|> anySingle)
where
escapedSpace = try (C.char '\\' *> C.char ' ')

-- | A parser for something entered at the REPL prompt.
lineParser :: REPLCommands -> Parser SomeREPLExpr
Expand Down
2 changes: 2 additions & 0 deletions test\file.disco
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
x : N
x = 3

0 comments on commit c93df52

Please sign in to comment.