Skip to content

Feature Request: *Optionally* add some more information while reporting errors #1083

@oxcrow

Description

@oxcrow

Hi,

I absolutely love how pest can report errors in a simple manner.

I have fixed many bugs within my grammar because of pest's error reports.

However sometimes some extra information is needed, and simple error reports are not enough.

Such as this error report.

Error:   --> 22:5
   |
22 |     // Error: We used a comment // not a /// documentation
   |     ^---
   |
   = expected value

This is generated because I used // instead of /// within this code I'm trying to parse.

/// Documentation of this struct
struct MyStruct {
    /// Documentation of these values
    x,y,z* float
    // Error: We used a comment // not a /// documentation
    a,b,c* usize
}

As shown in this pest grammar a value was expected thus the error was thrown.

value = { doc* ~ ids  ~ scope? ~ ":"? ~ type ~ ","? }

However the issue is, the error happened because we used a // comment instead of a /// documentation comment.

The error was thrown because pest could not find the doc* node within the code.

Thus although the error reported by pest is correct, it can also unintentionally mislead anyone who uses the compiler., because the user most likely does not know that pest expected a doc* node but the code contains something else.

Thus to me at least it would be better if pest also printed out on which node of the grammar pest failed to parse.

Maybe the error could be reported as this:

Error:   --> 22:5
   |
22 |     // Error: We used a comment // not a /// documentation
   |     ^---
   |
   = expected value
      expected doc* but received comment
      where,  value = { doc* ~ ids  ~ scope? ~ ":"? ~ type ~ ","? }
      failed to parse at doc* node of value = { doc* ~ ids  ~ scope? ~ ":"? ~ type ~ ","? }
                                                  ^--- Error 

I do not know if this will be difficult to implement. However if it is implemented it will allow us to debug pest grammar in an easier way.

Thank you.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions