diff --git a/hledger-lib/Hledger/Read/CsvReader.hs b/hledger-lib/Hledger/Read/CsvReader.hs index ab56feb8d..e221be515 100644 --- a/hledger-lib/Hledger/Read/CsvReader.hs +++ b/hledger-lib/Hledger/Read/CsvReader.hs @@ -222,11 +222,11 @@ validateCsv rules numhdrlines (Right rs) = validate $ applyConditionalSkips $ dr where filternulls = filter (/=[""]) skipCount r = - case getEffectiveAssignment rules r "skip" of - Nothing -> Nothing - Just "" -> Just 1 - Just "end" -> Just maxBound - Just x -> Just (read x) + case (getEffectiveAssignment rules r "end", getEffectiveAssignment rules r "skip") of + (Nothing, Nothing) -> Nothing + (Just _, _) -> Just maxBound + (Nothing, Just "") -> Just 1 + (Nothing, Just x) -> Just (read x) applyConditionalSkips [] = [] applyConditionalSkips (r:rest) = case skipCount r of @@ -601,7 +601,8 @@ journalfieldnames = ,"date" ,"description" ,"status" - ,"skip" -- skip is not really a field, but we list it here to allow conditional rules that skip records + ,"skip" -- skip and end are not really fields, but we list it here to allow conditional rules that skip records + ,"end" ] assignmentseparatorp :: CsvRulesParser () diff --git a/hledger-lib/hledger_csv.m4.md b/hledger-lib/hledger_csv.m4.md index 18b5d6ca1..1659ded16 100644 --- a/hledger-lib/hledger_csv.m4.md +++ b/hledger-lib/hledger_csv.m4.md @@ -194,7 +194,7 @@ Note, interpolation strips any outer whitespace, so a CSV value like `if` *`PATTERN`*\ *`PATTERN`*...\ -    *`skip end`*... +    *`end`*... This applies one or more field assignments, only to those CSV records matched by one of the PATTERNs. The patterns are case-insensitive regular expressions which match anywhere @@ -203,7 +203,7 @@ specific field). When there are multiple patterns they can be written on separate lines, unindented. The field assignments are on separate lines indented by at least one space. -Instead of field assignments you can specify `skip N` to skip the next N records (including the one that matchied) or `skip end` to skip the rest of the file. +Instead of field assignments you can specify `skip` or `skip 1` to skip this record, `skip N` to skip the next N records (including the one that matchied) or `end` to skip the rest of the file. Examples: ```rules diff --git a/tests/csv.test b/tests/csv.test index f9c2c2bb5..831e48d79 100644 --- a/tests/csv.test +++ b/tests/csv.test @@ -372,7 +372,7 @@ if HEADER if END OF FILE - skip end + end if MIDDLE skip 3