-
Notifications
You must be signed in to change notification settings - Fork 66
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
Update Error handling #116
Changes from all commits
0286dac
ba2d144
41b1102
723a5d2
1290beb
e52dc26
3cca13b
d665366
df77218
4155870
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,14 +11,16 @@ function reportDuplicateRules(ast) { | |
rule(node) { | ||
if (Object.prototype.hasOwnProperty.call(rules, node.name)) { | ||
throw new GrammarError( | ||
"Rule \"" + node.name + "\" is already defined " | ||
+ "at line " + rules[node.name].start.line + ", " | ||
+ "column " + rules[node.name].start.column + ".", | ||
Comment on lines
-14
to
-16
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same as above |
||
node.location | ||
`Rule "${node.name}" is already defined`, | ||
node.nameLocation, | ||
[{ | ||
message: "Original rule location", | ||
location: rules[node.name] | ||
}] | ||
); | ||
} | ||
|
||
rules[node.name] = node.location; | ||
rules[node.name] = node.nameLocation; | ||
} | ||
}); | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,17 +11,19 @@ const visitor = require("../visitor"); | |
function reportIncorrectPlucking(ast) { | ||
const check = visitor.build({ | ||
action(node) { | ||
check(node.expression, true); | ||
check(node.expression, node); | ||
}, | ||
|
||
labeled(node, action) { | ||
if (node.pick) { | ||
if (action) { | ||
throw new GrammarError( | ||
"\"@\" cannot be used with an action block " | ||
+ "at line " + node.location.start.line + ", " | ||
+ "column " + node.location.start.column + ".", | ||
Comment on lines
-21
to
-23
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You should replace self location with action node location, but there is a subtle aspect.
After introducing that property just use There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Also, There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. why doesn't the code block have its own AST node? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Actually, it have -- that is There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm suggesting that the ast should be: {
type: 'semantic_and',
expression: {
type: 'code',
code: ' return true; ',
location: ...
},
location: ...
} instead of: {
type: 'semantic_and',
code: ' return true; ',
location: ...
} There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think, it would be hard to process them if use the visitor pattern as with other kinds of nodes. You always need information from their parent node to process it. So you have to:
I think, that all alternatives not gives us so much and just a new property with an extra location will be enough: {
type: 'semantic_and',
code: ' return true; ',
codeLocation: ..., // for initializer just the same reference, as location
location: ...
} |
||
node.location | ||
"\"@\" cannot be used with an action block", | ||
node.labelLocation, | ||
[{ | ||
message: "Action block location", | ||
location: action.codeLocation | ||
}] | ||
); | ||
} | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is actually a useful information that should be kept. Some other messages just put there their own location, that is useless.
Ideally, this information also should be presented in the error object as a separate field, but right now I can't imagine which format would be better
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree that this should be reintroduced. However, I also prefer the basic sentiment that the underlying message should be short.
I propose:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This would imply that the string being passed to
GrammarError
is actually theshortMessage
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd be happy to do the work if we land this without this piece
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In a later commit, I added a
toString()
, thecodeLocation
bits that @Mingun wanted, and added areferenceLocation
field for the errors that say "you have a problem here that references a thing there", e.g. duplicate labels. I'm open to length, but not sure what value it adds. From pegjs-util, I really likefound
, and wouldn't mind theprolog
,token
, andepilog
fields if they end up being helpful.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
GrammarError
already have alocation
that have more full information.found
is a part ofSyntaxError
already and the mentioned method processes that kind of errors. I don't think thatprolog
,token
, andepilog
fields will be useful, but we can provide method in theSyntaxError
that extracts any token from input stream and error position just by executing specified "errorTokenRule" rule: