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

Missing table capture "{| p |}" in the "re" grammar #1

Open
mingodad opened this issue Apr 16, 2022 · 4 comments
Open

Missing table capture "{| p |}" in the "re" grammar #1

mingodad opened this issue Apr 16, 2022 · 4 comments

Comments

@mingodad
Copy link

Trying to use the re grammar shown at http://www.inf.puc-rio.br/~roberto/lpeg/re.html I found that it's missing the table capture {| p |} pattern.

For my usage example see here edubart/nelua-lang#190 (comment)

@edubart
Copy link

edubart commented Apr 18, 2022

Hey @mingodad from what I've seen and used, table captures in re is there documented and working as expected, so I don't see any issues here. Also this repository is a mirror, and I don't think Roberto answers here, if you want an answer back you should ask questions or report issues in Lua mailing list, there more people will also be able to test and help.

Also make sure to be test this in pure LPeg library before reporting as LPeg issue (no LPegLabel or LPegRex forks).

@mingodad
Copy link
Author

I'm not saying that it's not implemented, I'm saying that it's not in the documentation grammar of re, see it ammended reproduced here :

p = [=[

pattern         <- exp !.
exp             <- S (grammar / alternative)

alternative     <- seq ('/' S seq)*
seq             <- prefix*
prefix          <- '&' S prefix / '!' S prefix / suffix
suffix          <- primary S (([+*?]
                            / '^' [+-]? num
                            / '->' S (string / '{}' / name)
                            / '=>' S name) S)*

primary         <- '(' exp ')' / string / class / defined
                 / '{:' (name ':')? exp ':}'
                 / '=' name
                 / '{}'
                 / '{~' exp '~}'
                 / '{|' exp '|}'   --!!! <<< missing table capture
                 / '{' exp '}'
                 / '.'
                 / name S !arrow
                 / '<' name '>'          -- old-style non terminals

grammar         <- definition+
definition      <- name S arrow exp

class           <- '[' '^'? item (!']' item)* ']'
item            <- defined / range / .
range           <- . '-' [^]]

S               <- (%s / '--' [^%nl]*)*   -- spaces and comments
name            <- [A-Za-z][A-Za-z0-9_]*
arrow           <- '<-'
num             <- [0-9]+
string          <- '"' [^"]* '"' / "'" [^']* "'"
defined         <- '%' name

]=]

print(re.match(p, p))   -- a self description must match itself

@edubart
Copy link

edubart commented Apr 18, 2022

Oh now I understand, indeed it is missing there. It an issue only in an example of the re documentation page then.

Still chances are higher of that being fixed if this gets reported in the Lua mailing list.

@mingodad
Copy link
Author

The mentioned grammar also is missing an underscore for the first character of a name that is in code and is accepted:
In the documentation:

name            <- [A-Za-z][A-Za-z0-9_]*

In the code:

name            <- [A-Za-z_][A-Za-z0-9_]*

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