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

POP not follow the Atomic rule #721

Open
huacnlee opened this issue Oct 11, 2022 · 4 comments
Open

POP not follow the Atomic rule #721

huacnlee opened this issue Oct 11, 2022 · 4 comments

Comments

@huacnlee
Copy link
Member

huacnlee commented Oct 11, 2022

mark = ${ PUSH(mark_wrap) ~ mark_string ~ POP }
mark_wrap = { "***" | "**" | "*" | "~~" | "__" | "`" }
mark_string = {(!(PEEK) ~ ANY)* }

With text:

**H.263**

Output

- mark
  - mark_wrap: "**"
  - mark_string: "H.263"

image

Expected

- mark
  - mark_wrap: "**"
  - mark_string: "H.263"
  - mark_wrap: "**"

image

@tomtau
Copy link
Contributor

tomtau commented Oct 25, 2022

@huacnlee not sure if this is a bug or if this is fixable without breaking changes. POP is a builtin rule which behaves in that way (similarly to PEEK or if one e.g. had ANY* inside an atomic rule).
One potential workaround is to introduce another rule, e.g.:

mark = ${ PUSH(mark_wrap) ~ mark_string ~ mark_wrap_pop }
mark_wrap_pop = { POP }
...

@huacnlee
Copy link
Member Author

Ok, I got it.

@huacnlee
Copy link
Member Author

huacnlee commented Jun 5, 2023

I have met this problem again.

attr_quoted =  { PUSH(quote) ~ attr_value ~ POP }
attr_value  =  { (!PEEK ~ ANY)* }
quote       =  { "\"" | "'" }

Get

- attr_quoted
  - quote: "\""
  - attr_value: "https://google.com"

Why the PUSH can return value, but POP not?

PUSH and POP is a pair, why not them do the same behavior?

And if we write this with:

attr_quoted =  { PUSH(quote) ~ attr_value ~ end_quote }
end_quote = { POP }
attr_value  =  { (!PEEK ~ ANY)* }
quote       =  { "\"" | "'" }

The pest syntax is looks like not too good.

@tomtau

@huacnlee huacnlee reopened this Jun 5, 2023
@tomtau
Copy link
Contributor

tomtau commented Jun 5, 2023

Why the PUSH can return value, but POP not?

PUSH and POP is a pair, why not them do the same behavior?

These decisions were a long time ago; not sure if @dragostis, @CAD97 or anyone from @pest-parser/triage can recall it?

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

No branches or pull requests

2 participants