I am currently writing a PEG.js grammar and I want it to output custom errors. For instance I currently have this structure for creating a function.
//Function Declaration
FUNCTION_DECLARATION =
FUNCTION __ t:(TYPE/VOID) __ n:KEY a:ARGUMENT_DECLARATION
_ b:FUNCTION_BLOCK
(END)
{return {context : "FUNCTION_DECLARATION",location:location(), type:t,name:n,
args:a, block:b};
}
I want to be able to detect specific errors, like a missing END tag at the end of the function declaration. To do this, I need to be able to run a {action] when the expression DOES NOT MATCH.
Does anyone know how to do this? I only know how to run {action] when the expression actually matches as you can see with my return statement.
Additionally, it would be great if it was possible for the error location to point to the part of the expression that was already parsed before the missing END.
Best regards, Ricardo