Make `normand.ParseError` contain a list of messages v0.15.0
authorPhilippe Proulx <eeppeliteloop@gmail.com>
Fri, 6 Oct 2023 15:24:53 +0000 (11:24 -0400)
committerPhilippe Proulx <eeppeliteloop@gmail.com>
Fri, 6 Oct 2023 18:01:52 +0000 (14:01 -0400)
commitf5dcb24cf44ba80ff91c48bb607f6761a37838c3
treee3f11064a637345ac21311b480edf909ace0fdcf
parent12b5dbc00bcadb1feb11cf7f0583de646a61aacf
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>
README.adoc
normand/normand.py
pyproject.toml
tests/conftest.py
tests/fail-macro-exp-nested-1.nt [new file with mode: 0644]
tests/fail-macro-exp-nested-2.nt [new file with mode: 0644]
This page took 0.024201 seconds and 4 git commands to generate.