on master help sign in
PParser.hs: Add |filename| parser

As it stands, it reads in either a (possibly namespaced) identifier, which was the old behavior, or a double-quoted string, which is the new behavior. This could be improved by actually testing that it's returning a filename, but I'm clumsy with the parser abstraction, and it wasn't clear to me from the Trifecta docs I looked through how to pass it through System.FilePath.takeFileName and then enforce that it was a non-empty string.

commitc772bf53c4c8ed512676d32b10393c6d497d46ad authorJeremy W. Sherman <jeremyw.sherman@gmail.com> dateSun 11 Oct 2015, 23:51 (11 years ago) parent2cda43e
1 file changed+8
src/Pkg/PParser.hs+8
src/Pkg/PParser.hs+8
@@ -62,6 +62,14 @@ pPkg = do
6262 eof
6363 return st
6464
65+
66+-- | Parses a filename.
67+-- |
68+-- | Treated for now as an identifier or a double-quoted string.
69+filename :: (MonadicParsing m, HasLastTokenSpan m) => m String
70+filename = try $ (token $ stringLiteral <|> (fst <$> identifier)) <?> "filename"
71+
72+
6573pClause :: PParser ()
6674pClause = do reserved "executable"; lchar '=';
6775 exec <- fst <$> iName []