;csv: cleanups, drop match operator for now
This commit is contained in:
parent
3aebf03864
commit
fb788a64e8
@ -420,7 +420,7 @@ type RegexpPattern = String
|
|||||||
|
|
||||||
-- | A single test for matching a CSV record, in one way or another.
|
-- | A single test for matching a CSV record, in one way or another.
|
||||||
data Matcher =
|
data Matcher =
|
||||||
RecordMatcher RegexpPattern -- ^ match if this regexp matches the overall CSV record
|
RecordMatcher RegexpPattern -- ^ match if this regexp matches the overall CSV record
|
||||||
| FieldMatcher CsvFieldReference RegexpPattern -- ^ match if this regexp matches the referenced CSV field's value
|
| FieldMatcher CsvFieldReference RegexpPattern -- ^ match if this regexp matches the referenced CSV field's value
|
||||||
deriving (Show, Eq)
|
deriving (Show, Eq)
|
||||||
|
|
||||||
@ -675,22 +675,22 @@ matcherp :: CsvRulesParser Matcher
|
|||||||
matcherp = try fieldmatcherp <|> recordmatcherp
|
matcherp = try fieldmatcherp <|> recordmatcherp
|
||||||
|
|
||||||
-- A single whole-record matcher.
|
-- A single whole-record matcher.
|
||||||
-- A pattern on the whole line, not containing any of the match operators (~).
|
-- A pattern on the whole line, not beginning with a csv field reference.
|
||||||
recordmatcherp :: CsvRulesParser Matcher
|
recordmatcherp :: CsvRulesParser Matcher
|
||||||
recordmatcherp = do
|
recordmatcherp = do
|
||||||
lift $ dbgparse 2 "trying matcherp"
|
lift $ dbgparse 2 "trying matcherp"
|
||||||
-- pos <- currentPos
|
-- pos <- currentPos
|
||||||
_ <- optional (matchoperatorp >> lift (skipMany spacenonewline) >> optional newline)
|
-- _ <- optional (matchoperatorp >> lift (skipMany spacenonewline) >> optional newline)
|
||||||
r <- regexp
|
r <- regexp
|
||||||
-- when (null ps) $
|
-- when (null ps) $
|
||||||
-- Fail.fail "start of record matcher found, but no patterns afterward\n(patterns should not be indented)\n"
|
-- Fail.fail "start of record matcher found, but no patterns afterward\n(patterns should not be indented)\n"
|
||||||
return $ RecordMatcher r
|
return $ RecordMatcher r
|
||||||
<?> "record matcher"
|
<?> "record matcher"
|
||||||
|
|
||||||
-- | A single matcher for a specific field. A csv field reference (like %date or %1),
|
-- | A single matcher for a specific field. A csv field reference
|
||||||
-- a match operator (~), and a pattern on the rest of the line, optionally
|
-- (like %date or %1), and a pattern on the rest of the line,
|
||||||
-- space-separated. Eg:
|
-- optionally space-separated. Eg:
|
||||||
-- %description ~ chez jacques
|
-- %description chez jacques
|
||||||
fieldmatcherp :: CsvRulesParser Matcher
|
fieldmatcherp :: CsvRulesParser Matcher
|
||||||
fieldmatcherp = do
|
fieldmatcherp = do
|
||||||
lift $ dbgparse 2 "trying fieldmatcher"
|
lift $ dbgparse 2 "trying fieldmatcher"
|
||||||
@ -701,7 +701,7 @@ fieldmatcherp = do
|
|||||||
-- return f')
|
-- return f')
|
||||||
f <- csvfieldreferencep <* lift (skipMany spacenonewline)
|
f <- csvfieldreferencep <* lift (skipMany spacenonewline)
|
||||||
-- optional operator.. just ~ (case insensitive infix regex) for now
|
-- optional operator.. just ~ (case insensitive infix regex) for now
|
||||||
_op <- fromMaybe "~" <$> optional matchoperatorp
|
-- _op <- fromMaybe "~" <$> optional matchoperatorp
|
||||||
lift (skipMany spacenonewline)
|
lift (skipMany spacenonewline)
|
||||||
r <- regexp
|
r <- regexp
|
||||||
return $ FieldMatcher f r
|
return $ FieldMatcher f r
|
||||||
@ -714,25 +714,25 @@ csvfieldreferencep = do
|
|||||||
f <- fieldnamep
|
f <- fieldnamep
|
||||||
return $ '%' : quoteIfNeeded f
|
return $ '%' : quoteIfNeeded f
|
||||||
|
|
||||||
-- A match operator, indicating the type of match to perform.
|
|
||||||
-- Currently just ~ meaning case insensitive infix regex match.
|
|
||||||
matchoperatorp :: CsvRulesParser String
|
|
||||||
matchoperatorp = fmap T.unpack $ choiceInState $ map string
|
|
||||||
["~"
|
|
||||||
-- ,"!~"
|
|
||||||
-- ,"="
|
|
||||||
-- ,"!="
|
|
||||||
]
|
|
||||||
|
|
||||||
-- A single regular expression
|
-- A single regular expression
|
||||||
regexp :: CsvRulesParser RegexpPattern
|
regexp :: CsvRulesParser RegexpPattern
|
||||||
regexp = do
|
regexp = do
|
||||||
lift $ dbgparse 3 "trying regexp"
|
lift $ dbgparse 3 "trying regexp"
|
||||||
notFollowedBy matchoperatorp
|
-- notFollowedBy matchoperatorp
|
||||||
c <- lift nonspace
|
c <- lift nonspace
|
||||||
cs <- anySingle `manyTill` lift eolof
|
cs <- anySingle `manyTill` lift eolof
|
||||||
return $ strip $ c:cs
|
return $ strip $ c:cs
|
||||||
|
|
||||||
|
-- -- A match operator, indicating the type of match to perform.
|
||||||
|
-- -- Currently just ~ meaning case insensitive infix regex match.
|
||||||
|
-- matchoperatorp :: CsvRulesParser String
|
||||||
|
-- matchoperatorp = fmap T.unpack $ choiceInState $ map string
|
||||||
|
-- ["~"
|
||||||
|
-- -- ,"!~"
|
||||||
|
-- -- ,"="
|
||||||
|
-- -- ,"!="
|
||||||
|
-- ]
|
||||||
|
|
||||||
--------------------------------------------------------------------------------
|
--------------------------------------------------------------------------------
|
||||||
-- Converting CSV records to journal transactions
|
-- Converting CSV records to journal transactions
|
||||||
|
|
||||||
@ -1131,8 +1131,8 @@ tests_CsvReader = tests "CsvReader" [
|
|||||||
,test "fieldmatcherp" $
|
,test "fieldmatcherp" $
|
||||||
parseWithState' defrules matcherp "%description A A\n" @?= (Right $ FieldMatcher "%description" "A A")
|
parseWithState' defrules matcherp "%description A A\n" @?= (Right $ FieldMatcher "%description" "A A")
|
||||||
|
|
||||||
,test "fieldmatcherp with operator" $
|
-- ,test "fieldmatcherp with operator" $
|
||||||
parseWithState' defrules matcherp "%description ~ A A\n" @?= (Right $ FieldMatcher "%description" "A A")
|
-- parseWithState' defrules matcherp "%description ~ A A\n" @?= (Right $ FieldMatcher "%description" "A A")
|
||||||
|
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|||||||
@ -239,13 +239,11 @@ description %description_ %itemtitle
|
|||||||
comment itemid:%itemid, fromemail:%fromemail, toemail:%toemail, time:%time, type:%type, status:%status_
|
comment itemid:%itemid, fromemail:%fromemail, toemail:%toemail, time:%time, type:%type, status:%status_
|
||||||
|
|
||||||
# convert to short currency symbols
|
# convert to short currency symbols
|
||||||
# Note: in conditional block regexps, the line of csv being matched is
|
if %currency USD
|
||||||
# a synthetic one: the unquoted field values, with commas between them.
|
|
||||||
if ,USD,
|
|
||||||
currency $
|
currency $
|
||||||
if ,EUR,
|
if %currency EUR
|
||||||
currency E
|
currency E
|
||||||
if ,GBP,
|
if %currency GBP
|
||||||
currency P
|
currency P
|
||||||
|
|
||||||
# generate postings
|
# generate postings
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user