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

peggy使用import引入编译后的peggy文件时的报错 (Error when peggy uses import to introduce compiled peggy files) #548

Open
cy-biggray opened this issue Sep 11, 2024 · 6 comments

Comments

@cy-biggray
Copy link

import { select,ident_part,from,__,_ } from '../../common/common.js';

// select.peggy:
selectStatement
= select _ colunm_clause:colunm_clause _ from _ table_name:table_name __ ';'{ return column_name=${colunm_clause}, table_name=${table_name}}

colunm_clause
= column_name
/ '*'

column_name
= name:ident_part* {return name.join("")}

这段代码,当引入的ident_part后有其他属性时就会报错。如果 name:ident_part {return name.join("")}就不会报错。
错误内容: Possible infinite loop when parsing (repetition used with an expression that may not consume any input);

// common.peggy

ident_part
= [A-Za-z0-9]

select
= 'select'i

from
= 'from'i

__ = whitespace*
_ = whitespace+

whitespace
= [ \t\r\n];

@cy-biggray
Copy link
Author

但是如果使用括号并添加任意内容后就不会报错了 name:(__ ident_part)* {return name.join("")}

@hildjj
Copy link
Contributor

hildjj commented Sep 11, 2024

We'll need someone's help translating to English if we're going to be able to help you for real. In the meantime, you might try reading this:

https://en.wikipedia.org/wiki/Left_recursion#Removing_direct_left_recursion

@hildjj
Copy link
Contributor

hildjj commented Sep 11, 2024

这段代码,当引入的ident_part后有其他属性时就会报错。如果 name:ident_part {return name.join("")}就不会报错。 错误内容

Google Translate says:

This code will report an error if there are other attributes after the imported ident_part. If name:ident_part {return name.join("")}, no error will be reported. Error content:

@hildjj
Copy link
Contributor

hildjj commented Sep 11, 2024

import statements in your peggy file aren't working very well yet, they still need a lot of work. I would recommend doing this instead at the moment:

peggy select.peggy ../../common/common.js

which will combine the grammars together at generation time.

@hildjj hildjj changed the title peggy使用import引入编译后的peggy文件时的报错 peggy使用import引入编译后的peggy文件时的报错 (Error when peggy uses import to introduce compiled peggy files) Sep 11, 2024
@cy-biggray
Copy link
Author

peggy select.peggy .. /.. /common/common.js If there are repeated rule definitions, the tree shake operation is not performed. This makes the packaged file larger.

@cy-biggray
Copy link
Author

I self-test, even if the import does not report errors, he generated content is about only a large peggy file size.
And it uses require to associate other peggy files, and there is auxiliary code.

Can you use parse.parse to generate grammer first? Then create a rollup-like configuration file. Generate CPU based on file import
The dependency tree. Then merge the final peggy files from the bottom up

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