lib, doc, test: csv parser gains "end" command for "if" block

This commit is contained in:
Dmitry Astapov 2019-10-15 23:47:19 +01:00
parent 3e5f0e8dd5
commit 3c7d5d466d
3 changed files with 10 additions and 9 deletions

View File

@ -222,11 +222,11 @@ validateCsv rules numhdrlines (Right rs) = validate $ applyConditionalSkips $ dr
where where
filternulls = filter (/=[""]) filternulls = filter (/=[""])
skipCount r = skipCount r =
case getEffectiveAssignment rules r "skip" of case (getEffectiveAssignment rules r "end", getEffectiveAssignment rules r "skip") of
Nothing -> Nothing (Nothing, Nothing) -> Nothing
Just "" -> Just 1 (Just _, _) -> Just maxBound
Just "end" -> Just maxBound (Nothing, Just "") -> Just 1
Just x -> Just (read x) (Nothing, Just x) -> Just (read x)
applyConditionalSkips [] = [] applyConditionalSkips [] = []
applyConditionalSkips (r:rest) = applyConditionalSkips (r:rest) =
case skipCount r of case skipCount r of
@ -601,7 +601,8 @@ journalfieldnames =
,"date" ,"date"
,"description" ,"description"
,"status" ,"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 () assignmentseparatorp :: CsvRulesParser ()

View File

@ -194,7 +194,7 @@ Note, interpolation strips any outer whitespace, so a CSV value like
`if` *`PATTERN`*\ `if` *`PATTERN`*\
*`PATTERN`*...\ *`PATTERN`*...\
    *`skip end`*...     *`end`*...
This applies one or more field assignments, only to those CSV records matched by one of the PATTERNs. 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 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. on separate lines, unindented.
The field assignments are on separate lines indented by at least one space. 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: Examples:
```rules ```rules

View File

@ -372,7 +372,7 @@ if HEADER
if if
END OF FILE END OF FILE
skip end end
if MIDDLE if MIDDLE
skip 3 skip 3