Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error using online Peggy - Can't find variable: util #371

Closed
dselman opened this issue Mar 6, 2023 · 6 comments · Fixed by #385
Closed

Error using online Peggy - Can't find variable: util #371

dselman opened this issue Mar 6, 2023 · 6 comments · Fixed by #385

Comments

@dselman
Copy link
Contributor

dselman commented Mar 6, 2023

When I use a parser within the Peggy online editor the parser displays an error:

Can't find variable: util

The same parser works when used from the command line or in a Node.js application.

The web-browser (latest Safari) displays the following two error messages in the console:

SyntaxError: Invalid regular expression: invalid group specifier name
TypeError: undefined is not an object (evaluating 'ann.from.line')

image

To reproduce

  1. Copy the peg grammar: https://github.com/accordproject/concerto/blob/main/packages/concerto-cto/lib/parser.pegjs
  2. Paste the grammar into the editor and then type the following input text (which is valid and should create an AST):
namespace test
  1. The error Can't find variable: util appears below the parser input window.
@Mingun
Copy link
Member

Mingun commented Mar 6, 2023

Doesn't reproduced for me. What exactly online editor did you mean? https://peggyjs.org/online? I tried to paste https://raw.githubusercontent.com/accordproject/concerto/cd9edf745a85f6b7fec818b700810a3a9f5bee0a/packages/concerto-cto/lib/parser.pegjs an the parser was generated without errors. Input namespace test parsed as:

{
  '$class': 'concerto.metamodel@1.0.0.Model',
  decorators: [],
  namespace: 'test',
  imports: [],
  declarations: []
}

@dselman
Copy link
Contributor Author

dselman commented Mar 6, 2023

Doesn't reproduced for me.

Interesting! I just tried it in Chrome and it works, so it appears to be an issue specific to Safari. I am using Safari Version 16.2 (18614.3.7.1.5).

@hildjj
Copy link
Contributor

hildjj commented Mar 6, 2023

I can reproduce this in Safari. This looks to be an error in node-inspect-extracted. I'm going to try updating to the latest version of that package first, then see if there is still a problem.

@hildjj
Copy link
Contributor

hildjj commented Mar 6, 2023

This should be fixed in Safari 16.4 according to this. I think maybe we should just test for util being available, and fall back on console.log("%O", result) for those that have broken browsers.

@hildjj
Copy link
Contributor

hildjj commented Mar 6, 2023

OK, take a look at the pretty awful hack that is #372. I'd rather not change the offending line in node-inspect-extracted for two reasons: capturing the intent of the negative lookbehind adequately will be a little tough, and b) I'm trying to keep that code as close to nodejs source as possible.

@Mingun
Copy link
Member

Mingun commented Mar 9, 2023

I forgot to mention, that I've checked on Firefox 110.0.1, but I also use the old Firefox ESR 52.9.0 because of its plugins, and this error affects it also (of course)

hildjj added a commit to hildjj/peggy that referenced this issue Mar 16, 2023
hildjj added a commit to hildjj/peggy that referenced this issue Mar 21, 2023
* main:
  Update deps, CHANGELOG, version.  Rebuild.
  Fix typos.  Move parens to correct place.
  Rebuilt patch from scratch, incorporating comments
  Update dependencies
  Remove --optimize.  Fixes peggyjs#392.
  --allowed-start-rule=\* documented for CLI.  Fixes peggyjs#386.
  Put parens around integer conversions in repetition.  Fixes peggyjs#381.
  Tweaking the error format() documentation
  Authors and small grammar fix
  Change silver to hex
  Update to node-inspect-extracted@2.0.2
  Update CHANGELOG
  Make online version work in old browsers.  Fixes peggyjs#371.
  Updating grammarSource documentation
  Add Marcel Bolten to authors
  Remove redundant options variants in behavior test
  Handle null and undefined explicitly
  Fixes peggyjs#374.  CLI was throwing exception on grammar errors without a CLI test also being specified.
  Stub out new CHANGELOG.md section
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
3 participants