purpleidea / mgmt

Next generation distributed, event-driven, parallel config management!
https://purpleidea.com/tags/mgmtconfig/
GNU General Public License v3.0
3.67k stars 315 forks source link

Dig into line/row numbers in the parser #732

Open purpleidea opened 10 months ago

purpleidea commented 10 months ago

Description:

We currently don't have good position (line/row) information about errors from the parser. We'd like to have that information both from parser errors (an error that occurs during the parsing stage) but we'd also like to have that positional information when it occurs in a later stage, such as type unification, and so on.

To get that information, we need to embed it in each AST node. Figure out how this works in goyacc, and propose an early proof-of-concept. We'll help you morph that from rough code to production polish if needed.

Some information is here: https://github.com/purpleidea/mgmt/blob/7777107d83ff21094392a637bb426e2a1bad5cf1/lang/parser/parser.y#L1509

More here: https://github.com/purpleidea/mgmt/blob/7777107d83ff21094392a637bb426e2a1bad5cf1/lang/parser/parser.y#L1483

Design:

You probably want to eventually add a new interface that sets the position of row/col for each AST node, either that, or am embedded struct with the data, or both. Don't worry about how this works right away, but I expect that's where we'll end up.

Minimally-viable:

At a bare minimum, try and get mgmt running with a simple mcl file that shows an obvious type unification error (4 == "foo") type of thing. Then we'll see if we can print the line numbers of those expressions and statements.

Longer term:

We should want to pass the line information into the type unification, so that we can include that information when we error.

Questions?

Ask early and often. Post an early version of the code, even if it doesn't compile or work perfectly. Don't spend tool long without checking-in if you feel lost.

Cheers!

ffrank commented 8 months ago

@Juneezee have you been working on this? I would be up for cooperating.

Juneezee commented 8 months ago

@Juneezee have you been working on this? I would be up for cooperating.

Hi @ffrank, thanks for offering to help! I have been occupied with work lately I haven't had a chance to dive into this yet.

ffrank commented 8 months ago

So far I have come up with #750 but it's fraught.