Question on the line fold example
Closed this issue · 2 comments
https://stackoverflow.com/questions/37256316/parsing-many-blocks-with-foldline
I just red this post and got helped for the same sort of problem in my code.
Finally I solved the problem, but I didn't follow the exact instruction the first answerer gave.
I changed lexers to remove leading whitespaces than trailing whitespaces.
for example, original lexeme
is
lexeme p = p <* spc
But my version used in the line folding parser is
lexeme' p = spc >> p
And I didn't need to putting extra space consumers between parsers.
The solution is so simple, now I wonder if there is some reason not doing in this way.
(even if not in a line folding parser, what is the reason to prefer removing trailing whitespaces to removing leading ones?)
No, I never tried to go the other way around and remove leading whitespace. I think that somehow the approaches should be more-or-less equivalent, that is, in some cases picking up leading whitespace as part of lexeme may have some benefits and in the other cases picking up trailing whitespace may be a good idea.
Closing for lack of activity, feel free to re-open if necessary.