I've got a silly situation in my parsec parsers that I would like your help on.
I need to parse a sequence of strongs / chars that are separated by | characters.
So, we could have a|b|'c'|'abcd'
which should be turned into
[a,b,c,abcd]
Space is not allowed, unless inside of a ' ' string. Now, in my na?ve attempt, I got the situation now where I can parse strings like a'a|'bb' to [a'a,bb] but not aa|'b'b' to [aa,b'b].
singleQuotedChar :: Parser Char
singleQuotedChar = noneOf "'" <|> try (string "''" >> return ''')
simpleLabel = do
whiteSpace haskelldef
lab <- many1 (noneOf "|")
return $ lab
quotedLabel = do
whiteSpace haskelldef
char '''
lab <- many singleQuotedChar
char '''
return $ lab
Now, how do I tell the parser to consider ' a stoping ' iff it is followed by a | or white space?
(Or, get some ' char counting into this). The input is user generated, so I cannot rely on them '-ing chars.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…