Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

That's not a particularly hard problem, all tools which try to solve it (for example, IntelliJ), solve it easily. For example, here's the syntax tree that rust-analyzer builds for this example:

    fn foo() { }

    fn

    fn bar() { }
Syntax tree (whitespace nodes elided for clarity):

    SOURCE_FILE@[0; 31)
      FN_DEF@[0; 12)
        FN_KW@[0; 2)
        NAME@[3; 6)
          IDENT@[3; 6) "foo"
        ...
      FN_DEF@[14; 16)
        FN_KW@[14; 16)
        err: `expected a name`
      FN_DEF@[18; 30)
        FN_KW@[18; 20)
        NAME@[21; 24)
          IDENT@[21; 24) "bar"
        ...
The problem is, a lot of tools are build with the assumption that the code is correct&complete, and don't try to tackle this problem at all.


When llvm was young, one of its design goals was to be useful for live code analysis, to prevent that problem of having two parsers that might not agree.

Sounds like we lost some of that along the way.




Consider applying for YC's Winter 2026 batch! Applications are open till Nov 10

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: