Hacker News new | ask | show | jobs
by ansible 678 days ago
> If I start parsing from an arbitrary offset in the code, ...

Why would you ever do that? What's the point?

There are many other examples, but in C and C++, if you don't start parsing at the beginning, you're definitely going to get many things wrong. What if you start parsing in the middle of an identifier? How can you possibly expect to get something useful from that?

2 comments

> Why would you ever do that? What's the point?

Syntax highlighting code visible on the screen

> Syntax highlighting code visible on the screen

That... does not work in most programming languages. Especially so for showing indent levels correctly. Generally speaking, the language server (or whatever) is parsing the entire file.

> Why would you ever do that? What's the point?

Performance, mostly. If you have to re-parse part of the code many times a second, in a text editor. For [pseudo]structural editing or syntax highlighting, for example.

Cache the position of quotes/apostrophes, etc.

Optimizing for your edge case would require everyone writing and reading code to conform to this extra thing, which seems completely unnecessary. Machines are pretty fast.

https://www.youtube.com/watch?app=desktop&v=ZI198eFghJk Modernizing Compiler Design for Carbon Toolchain - Chandler Carruth - CppNow 2023