imp:journal: include directive now allows a same-line comment
This commit is contained in:
parent
dbf54facc2
commit
2371f677e5
@ -1340,8 +1340,7 @@ isSameLineCommentStart _ = False
|
|||||||
-- Right "\n\n"
|
-- Right "\n\n"
|
||||||
--
|
--
|
||||||
followingcommentp :: TextParser m Text
|
followingcommentp :: TextParser m Text
|
||||||
followingcommentp =
|
followingcommentp = fst <$> followingcommentpWith (void $ takeWhileP Nothing (/= '\n'))
|
||||||
fst <$> followingcommentpWith (void $ takeWhileP Nothing (/= '\n')) -- XXX support \r\n ?
|
|
||||||
|
|
||||||
{-# INLINABLE followingcommentp #-}
|
{-# INLINABLE followingcommentp #-}
|
||||||
|
|
||||||
|
|||||||
@ -289,18 +289,22 @@ directivep = (do
|
|||||||
-- Examples: foo.j, ../foo/bar.j, timedot:/foo/2020*, *.journal
|
-- Examples: foo.j, ../foo/bar.j, timedot:/foo/2020*, *.journal
|
||||||
includedirectivep :: MonadIO m => ErroringJournalParser m ()
|
includedirectivep :: MonadIO m => ErroringJournalParser m ()
|
||||||
includedirectivep = do
|
includedirectivep = do
|
||||||
|
-- parse
|
||||||
string "include"
|
string "include"
|
||||||
lift skipNonNewlineSpaces1
|
lift skipNonNewlineSpaces1
|
||||||
prefixedglob <- rstrip . T.unpack <$> takeWhileP Nothing (/= '\n') -- don't consume newline yet
|
prefixedglob <- rstrip . T.unpack <$> takeWhileP Nothing (`notElem` [';','\n'])
|
||||||
|
lift followingcommentp
|
||||||
|
-- save the position (does sequencing wrt newline matter ? seems not)
|
||||||
parentoff <- getOffset
|
parentoff <- getOffset
|
||||||
parentpos <- getSourcePos
|
parentpos <- getSourcePos
|
||||||
|
-- find file(s)
|
||||||
let (mprefix,glb) = splitReaderPrefix prefixedglob
|
let (mprefix,glb) = splitReaderPrefix prefixedglob
|
||||||
paths <- getFilePaths parentoff parentpos glb
|
paths <- getFilePaths parentoff parentpos glb
|
||||||
let prefixedpaths = case mprefix of
|
let prefixedpaths = case mprefix of
|
||||||
Nothing -> paths
|
Nothing -> paths
|
||||||
Just fmt -> map ((show fmt++":")++) paths
|
Just fmt -> map ((show fmt++":")++) paths
|
||||||
|
-- parse them inline
|
||||||
forM_ prefixedpaths $ parseChild parentpos
|
forM_ prefixedpaths $ parseChild parentpos
|
||||||
void newline
|
|
||||||
|
|
||||||
where
|
where
|
||||||
getFilePaths
|
getFilePaths
|
||||||
|
|||||||
@ -61,12 +61,19 @@ $ hledger -f - print
|
|||||||
>2 //
|
>2 //
|
||||||
>= 1
|
>= 1
|
||||||
|
|
||||||
# ** 6. trailing whitespace after the filename does not make a file nonexistent
|
# ** 6. trailing whitespace after the filename is ignored
|
||||||
<
|
<
|
||||||
include a.timeclock
|
include a.timeclock
|
||||||
$ hledger -f - check
|
$ hledger -f - check
|
||||||
|
|
||||||
# ** 7. include relative to home
|
# ** 7. a same-line or multi-line following comment is ignored
|
||||||
|
<
|
||||||
|
include a.timeclock ; comment
|
||||||
|
; comment
|
||||||
|
; comment
|
||||||
|
$ hledger -f - check
|
||||||
|
|
||||||
|
# ** 8. include relative to home
|
||||||
<
|
<
|
||||||
include ~/included.journal
|
include ~/included.journal
|
||||||
$ printf '2018/01/01\n (A) 1\n' >included.journal; HOME="$PWD" hledger -f - print; rm -rf included.journal
|
$ printf '2018/01/01\n (A) 1\n' >included.journal; HOME="$PWD" hledger -f - print; rm -rf included.journal
|
||||||
@ -78,17 +85,17 @@ $ printf '2018/01/01\n (A) 1\n' >included.journal; HOME="$PWD" hledger -f - pr
|
|||||||
# The next tests require hard coded file names, so are not concurrent-safe.
|
# The next tests require hard coded file names, so are not concurrent-safe.
|
||||||
# They use different file names so a single concurrent shelltest invocation will be fine.
|
# They use different file names so a single concurrent shelltest invocation will be fine.
|
||||||
|
|
||||||
# ** 8. test that order of include files is maintained
|
# ** 9. test that order of include files is maintained
|
||||||
$ printf 'include _b\n' >_a; touch _b; hledger -f _a stats -v | grep _ | sed -e 's%.*/%%'; rm -rf _a _b
|
$ printf 'include _b\n' >_a; touch _b; hledger -f _a stats -v | grep _ | sed -e 's%.*/%%'; rm -rf _a _b
|
||||||
_a
|
_a
|
||||||
_b
|
_b
|
||||||
|
|
||||||
# ** 9. and with --auto code path
|
# ** 10. and with --auto code path
|
||||||
$ printf 'include _d\n=\n' >_c; touch _d; hledger -f _c stats -v --auto | grep _ | sed -e 's%.*/%%'; rm -rf _c _d
|
$ printf 'include _d\n=\n' >_c; touch _d; hledger -f _c stats -v --auto | grep _ | sed -e 's%.*/%%'; rm -rf _c _d
|
||||||
_c
|
_c
|
||||||
_d
|
_d
|
||||||
|
|
||||||
# ** 10. include using old !include directive
|
# ** 11. include using old !include directive
|
||||||
<
|
<
|
||||||
!include f.journal
|
!include f.journal
|
||||||
$ printf '2018/01/01\n (A) 1\n' >f.journal; hledger -f - print; rm -f f.journal
|
$ printf '2018/01/01\n (A) 1\n' >f.journal; hledger -f - print; rm -f f.journal
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user