Make `normand.ParseError` contain a list of messages
A `normand.ParseError` instance now contains a list of
`normand.ParseErrorMessage`.
A `normand.ParseErrorMessage` instance contains a message text and a
source text location.
This adds precious context to a parsing error.
For example, with
!macro meow(yeah)
{yeah:8}
!end
!macro mix(yeah)
aa bb m:meow({yeah * 2})
!end
m:mix(12)
"hello" m:mix(899)
m:mix(16)
m:mix(19)
we now get
10:9 - While expanding the macro `mix`:
6:9 - While expanding the macro `meow`:
2:4 - Value 1,798 is outside the 8-bit range when evaluating
expression `yeah`
Without this patch, the only available message would be the last one,
and you wouldn't know which macro expansion(s) triggered the parsing
error.
The CLI and `tests/conftest.py` are modified to take multiple parsing
error messages into account.
There was a little challenge with fixed-length number item instances
handled after the rest (in _Gen._gen_fl_num_item_insts()): at this
point, there's no current try/except context for macro expansions
because they're already handled. My current strategy is to keep a
current stack of parsing error messages (`self._parse_error_msgs`)
during the generation: when the generator initially fails to evaluate
the expression of a fixed-length number item, it copies a snapshot of
those messages to the `_FlNumItemInst` object so that we can restore
them if there's a parsing error later during
_Gen._gen_fl_num_item_insts().
Adding two nested macro expansion test to make sure we get all the
expected parsing error messages. Other tests are unchanged (single
parsing error message).
Change-Id: Iba8499608f86165e02d6d040795222cafcbca4a9
Signed-off-by: Philippe Proulx <eeppeliteloop@gmail.com>
This page took 0.025402 seconds and 4 git commands to generate.