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

Failed to compile grammar containing imports #517

Open
damienflament opened this issue May 26, 2024 · 3 comments
Open

Failed to compile grammar containing imports #517

damienflament opened this issue May 26, 2024 · 3 comments
Assignees

Comments

@damienflament
Copy link

damienflament commented May 26, 2024

Hi,

My grammar is now too big to be kept in a single file. I gave a try to the import mechanism but the grammar failed to compile.

So I tested with two simple files and got the same error:

main.pegjs:

import { Digit } from 'lib.js'

Number = Digit+

lib.js:

Digit = [0-9]
$ yarn peggy lib.pegjs
$ yarn peggy main.pegjs
Error parsing grammar
error: Possible infinite loop when parsing (repetition used with an expression that may not consume any input)
 --> main.pegjs:3:10
  |
3 | Number = Digit+
  |          ^^^^^^
$ yarn peggy --version
4.0.2

What am I doing wrong ?

@hildjj
Copy link
Contributor

hildjj commented May 26, 2024

This is a real problem with how we're currently doing imports. I think I might have marked all imported rules as "might consume nothing", rather than marking each one with the correct information.

I think I know how to fix this, so assigning it to myself.

@hildjj hildjj self-assigned this May 26, 2024
@hildjj
Copy link
Contributor

hildjj commented May 26, 2024

In the meantime, you should be able to achieve your goals by removing the import statement and compiling with peggy main.pegjs lib.pegjs.

@hildjj
Copy link
Contributor

hildjj commented May 29, 2024

In order to solve this, I think we're going to need to either import or otherwise read in the library grammar when generating the main grammar. That likely means that we're going to need a new async top-level entrypoint.

This is something that has been contemplated in the past, but is going to require some discussion. Join us on the Peggy Discord if you want to follow along.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants