I've been reading through the sexp.h file reference in an attempt to generate helpful errors when parsing a lisp-like sequence fails because an operator or operand was not formatted as expected.
I am currently using the cparse_sexp
function to parse a lisp-style expression into a series of s-expressions elt
objects:
pc = cparse_sexp(
(char*)expression.c_str(),
expression.length,
pc);
where pc
is a pointer of type pcont_t*
and expression
is an std::string
. I then use this pc
pointer to look at the elt
objects using pc->last_sexp
.
However, if I run into a value that I don't know how to deal with, I'd like to be able to write something like this:
Error was encountered at byte `123` in the vicinity of: (Operator Operand1 Operand2) ^
Where the (Operator Operand1 Operand2)
line is taken from the original expression
string.
To achieve this I need to know the location from which the respective token was taken. I know I can see the sbuffer
value within the pcont_t
type, but that just gives me a pointer to the original string. lastPos
is supposed to give me the current position, but it just returns the end of the string. How can I parse the string as I use it so that I can see where I'm at?