FAQ and help for debugging `parse!` macro
m4rw3r opened this issue · 2 comments
This is an issue collecting problems related to the parse!
macro. Since the error messages are not very helpful from rustc
when dealing with complex macros I will try my best to help here.
-
Q: What does
error: unexpected token:
@__parse_internal ! { @ ACTION_NONTERM ( $ i , $ v : $ v_ty ) ; $ ( $ t ) * } }
mean?A: An error has been encountered in a
let
-statement. Possible causes:- Syntax error on that line
- Last line of a
parse!
macro-invocation.let
-statements are not allowed as the final row of aparse!
invocation since that prevents any return. Use an action withoutlet
(returns the value of the action itself) or useret
orerr
to return a success or error value respectively.
-
Q: What does
error: this function takes 1 parameter but 2 parameters were supplied [E0061] @ CONCAT ( $ f ( $ i , $ ( $ p ) , * ) , $ ( $ v ) * ) ; $ ( $ t ) * } } ; (
mean?A: An invocation of an action has too many or too few parameters listed in its argument list.
parse!
always prepends the input-context of the parser to every function invocation withinparse!
. -
Q: Are type-hints in function calls supported?
A: No, but there is an issue
Declare the type of the resulting variable instead:
let var: MyDataType<Something> = my_action();
Ah! I wish I had found this sooner.
Yes, this is pretty important to have in the docs, since macros lead to such unhelpful compiler diagnostics.
This part has now been moved to the parse!
documentation: http://m4rw3r.github.io/chomp/chomp/macro.parse!.html#debugging