RFC: How to handle line-endings in parsers

Andreas Pakulat apaku at gmx.de
Thu Jan 25 22:44:58 UTC 2007


Hi,

after getting the latest bugreport against the QM in 3.4 I thought a bit
about line-endings in files that kdevelop parses. The QM in 3.4 just
can't handle windows or macos lineendings (\r\n or \r) and it always
writes back \n for newly inserted lines.

For KDevelop3 this issue isn't that big as KDevelop is only used on
*nix, however the issue is much worse for KDevelop4. And there it
not only affects the QM, AM or CM, I think it also affects the
language parsers, as we do change the text contents.

My idea is to handle this is to read the first line of a file and
determine its line-ending. Then storing this information in the AST for
that file so it can be re-used. This would mean we read the file twice
(or at least parts of it), unless somebody can come up with a solution
that does this while parsing the file.

The kdev-pg based parsers currently ignore the \r or change it into a \n
before lexing the content. I don't know the kate interface, but unless
Kate does the change of line-endings on saving the file they might be
affected too.

So any ideas how to not screw up the users line-endings are appreciated.

Andreas

-- 
Your depth of comprehension may tend to make you lax in worldly ways.




More information about the KDevelop-devel mailing list