lib: implement skip end in csv reader
This commit is contained in:
parent
b2ba1086b6
commit
38db7eb24d
@ -225,6 +225,7 @@ validateCsv rules numhdrlines (Right rs) = validate $ applyConditionalSkips $ dr
|
|||||||
case getEffectiveAssignment rules r "skip" of
|
case getEffectiveAssignment rules r "skip" of
|
||||||
Nothing -> Nothing
|
Nothing -> Nothing
|
||||||
Just "" -> Just 1
|
Just "" -> Just 1
|
||||||
|
Just "end" -> Just maxBound
|
||||||
Just x -> Just (read x)
|
Just x -> Just (read x)
|
||||||
applyConditionalSkips [] = []
|
applyConditionalSkips [] = []
|
||||||
applyConditionalSkips (r:rest) =
|
applyConditionalSkips (r:rest) =
|
||||||
|
|||||||
@ -178,12 +178,12 @@ Note, interpolation strips any outer whitespace, so a CSV value like
|
|||||||
## conditional block
|
## conditional block
|
||||||
|
|
||||||
`if` *`PATTERN`*\
|
`if` *`PATTERN`*\
|
||||||
*`FIELDASSIGNMENTS or skip N`*...
|
*`FIELDASSIGNMENTS` or `skip N` or `skip end`*...
|
||||||
|
|
||||||
`if`\
|
`if`\
|
||||||
*`PATTERN`*\
|
*`PATTERN`*\
|
||||||
*`PATTERN`*...\
|
*`PATTERN`*...\
|
||||||
*`FIELDASSIGNMENTS or skip N`*...
|
*`FIELDASSIGNMENTS` or `skip N` or `skip 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
|
||||||
@ -192,7 +192,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).
|
Instead of field assignments you can specify `skip N` to skip the next N records (including the one that matchied). Special form `skip end` will cause the rest of the file to be skipped.
|
||||||
|
|
||||||
Examples:
|
Examples:
|
||||||
```rules
|
```rules
|
||||||
|
|||||||
@ -359,6 +359,8 @@ AND THIS
|
|||||||
AND THIS ONE
|
AND THIS ONE
|
||||||
10/2009/09,Flubber Co,50
|
10/2009/09,Flubber Co,50
|
||||||
*** END OF FILE ***
|
*** END OF FILE ***
|
||||||
|
More lines of the trailer here
|
||||||
|
They all should be ignored
|
||||||
RULES
|
RULES
|
||||||
fields date, description, amount
|
fields date, description, amount
|
||||||
date-format %d/%Y/%m
|
date-format %d/%Y/%m
|
||||||
@ -366,9 +368,12 @@ currency $
|
|||||||
account1 assets:myacct
|
account1 assets:myacct
|
||||||
|
|
||||||
if HEADER
|
if HEADER
|
||||||
END OF FILE
|
|
||||||
skip
|
skip
|
||||||
|
|
||||||
|
if
|
||||||
|
END OF FILE
|
||||||
|
skip end
|
||||||
|
|
||||||
if MIDDLE
|
if MIDDLE
|
||||||
skip 3
|
skip 3
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user