diff --git a/hledger-lib/Hledger/Read/JournalReader.hs b/hledger-lib/Hledger/Read/JournalReader.hs index ad0290226..a5cd09e4e 100644 --- a/hledger-lib/Hledger/Read/JournalReader.hs +++ b/hledger-lib/Hledger/Read/JournalReader.hs @@ -549,10 +549,14 @@ definedirectivep = do string "define" >> lift restofline >> return () exprdirectivep = do string "expr" >> lift restofline >> return () valuedirectivep = do string "value" >> lift restofline >> return () evaldirectivep = do string "eval" >> lift restofline >> return () -pythondirectivep = do string "python" >> lift restofline >> many (indented $ lift restofline) >> return () - where - indented = (lift skipNonNewlineSpaces1 >>) commandlineflagdirectivep = do string "--" >> lift restofline >> return () +pythondirectivep = do + string "python" >> lift restofline + many $ indentedline <|> blankline + return () + where + indentedline = lift skipNonNewlineSpaces1 >> lift restofline + blankline = lift skipNonNewlineSpaces >> newline >> return "" "blank line" keywordp :: String -> JournalParser m () keywordp = void . string . fromString diff --git a/hledger/test/ledger-compat/syntax/hledger-other.test b/hledger/test/ledger-compat/syntax/hledger-other.test index e77af5403..0ae6d4c80 100644 --- a/hledger/test/ledger-compat/syntax/hledger-other.test +++ b/hledger/test/ledger-compat/syntax/hledger-other.test @@ -69,7 +69,11 @@ tag Receipt assert value != "foobar" value some_func python - import os + def option_pyfirst(context): + print("In --pyfirst (from %s)" % context) + + def option_pysecond(context, val): + print("In --pysecond=%s (from %s)" % (val, context)) eval foo --command-line-flag