-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
16g OOP: Error reporting #41
Conversation
Let's start simple: associate each Expr with a token that best represents its position in the code, only for error reporting purposes: Since each Expr is going to need this, we put the code in the Expr parent class. |
Let's start simple: associate each Expr with a token that best represents its position in the code, only for error reporting purposes: Since each Expr is going to need this, we put the code in the Expr parent class. We add a ... except for Literals, which are a little special: their init comes directly from TypedValue. I want to preserve this equivalence between Literals and TypedValues, so I don't just want Literals to start implementing their own init. Instead, let's make TypedValue multiple-inheritance-friendly by enabling Time to start adding tokens to Exprs. |
In the parser, we use a helper function to make Exprs. Let's upgrade it to pass tokens: [8cec6ef] |
And then we add tokens wherever we can: [7f5d41c] |
RefactoringLet's take the chance to do some refactoring where it will make token association easier. Assign expressionsAssign expressions (
The difference between them is that the Assign statement expects a line break after the Assign expression, while the FOR statement expects the keyword TO after the Assign expression. Let's refactor them with an We'll use this in an ExprStmt in place of an Assign Stmt. One less Stmt, one more use of ExprStmt! In the meantime, the Assign Expr clashes with the Assign Stmt, so let's disable the latter by commenting it out: [9b0a410] Upgrade the Add an And also in |
BugfixUsing the chance to fix some bugs in our Binary Exprs: [de7f460] Our |
Resolving Assign ExprsNow we add a resolver for the new Assign Expr: And use it in the And update our Assign ExprStmt verifier: Then we can remove our old |
Interpreting Assign ExprsAll the code is there already. We convert our old Net change: We remove Assign Stmt, and add Assign Expr. Did we really gain anything? Yes, primarily in the simplification of the FOR Stmt. It is now easier to assign tokens to its various Exprs. |
BugfixesFirst we resolve the attribute collision between the Next, we have to wrap our And then a little refactoring, as a treat, to group our ExprStmts together in the resolver, since they use the same entry point: [15ce968] |
Result:
Our line and column info is back! This is going to need extensive testing and review of each possible kind of error, to ensure that the error messages are helpful. That is an eternal work in progress, and too long for the rest of this chapter. We'll deal with other suboptimal error messages as and when they crop up. |
Earlier, we broke error reporting when I decided to avoid the use of tokens in the resolver and interpreter. Error messages still appear, but we have no idea where in the code they are coming from.
Now that the code is better organized and more clearly structured, let's restore it.
How are we going to report errors from the resolver and interpreter without tokens? We will probably still need them, but they can't be a part of the resolution/execution path.