peggy icon indicating copy to clipboard operation
peggy copied to clipboard

Grammar action errors need to be more informative (inherited from PEGjs)

Open stoneRdev opened this issue 3 years ago • 2 comments

Issue type

  • Bug Report: no
  • Feature Request: yes
  • Question: no
  • Not an issue: no

Prerequisites

  • Can you reproduce the issue?: yes
  • Did you search the repository issues?: yes (kind of)
  • Did you check the forums?: no (what forums?)
  • Did you perform a web search (google, yahoo, etc)?: yes

Description

So, as it stands, grammar action errors are about as vague than C++ segfaults. For example, take this small grammar:

{
	const def1 = 1
        const def2 = 2
	const a = [def1 def2]
}

line = i / l

i = [ \t\n\r+]
l = [a-z]i

The error output is: missing ] after element list Now, while this is fine in such a small example (its easy to spot), errors like this in a large grammar file is a headache.

I'd like to request the action errors to be reported the same as grammar errors, for example:

line = i / l

i = [ \t\n\r+
l = [a-z]i

outputs Line 3, column 5: Expected "!", "$", "&", "(", ".", character class, comment, end of line, identifier, literal, or whitespace but "[" found., which is magnitudes more helpful.

I think a good solution to this would be to at least include the line number for the action errors

Steps to Reproduce

  1. Make a grammar file
  2. Make a small typo (or other mistake) in javascript action
  3. Observe cryptographically secure error message

Example code: Oops, provided above in description

Expected behavior:

I'd expect errors in action contexts to at least be descriptive enough to find the error Actual behavior:

Errors in action context are vague and not helpful

Software

  • PEG.js: ^0.10.0
  • Node.js: v14.16.0
  • NPM or Yarn: yarn (primary) 1.22.10, npm 6.14.11
  • Browser: N/A
  • OS: Windows 8.1 32 bit os, 64 bit processor
  • Editor: Sublime 3.2.2 all day

stoneRdev avatar Apr 23 '21 00:04 stoneRdev

inherited from https://github.com/pegjs/pegjs/issues/668

stoneRdev avatar Apr 23 '21 00:04 stoneRdev

Plan of attack: add optional sourceMap support. Make sure that the debugging experience isn't too weird.

hildjj avatar Apr 27 '21 16:04 hildjj

Closing this now that sourceMap support has landed.

hildjj avatar Mar 01 '23 16:03 hildjj