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

Naming regex patterns? #41

Open
osa1 opened this issue Mar 4, 2020 · 1 comment
Open

Naming regex patterns? #41

osa1 opened this issue Mar 4, 2020 · 1 comment

Comments

@osa1
Copy link
Contributor

osa1 commented Mar 4, 2020

Suppose I have this lexical syntax for a token:

Identifier ::= <Initial> <Subsequent>*
Initial ::= a..z
Subsequent ::= Initial | ...

Here the Initial part is used in both Identifier and Subsequent. As far as I understand, currently the only way to do this in plex's lexer! is by duplicating Initial part, something like:

lexer! {
    ...
    r"[a-z]([a-z]|[<subsequent>])*" => ...
}

In the simplified example above the repetition of [a-z] is not too bad, but in the actual use case the syntax is much more complex and the repetition is a real problem.

Ideally I should be able to give this regex [a-z] a name and use it in other regex patterns. Maybe something like:

lexer! {
    ...
    let initial = "[a-z]"
    let subsequent = "..."
    r"$initial($initial|[$subsequent])*" => ...
}

Is this currently possible with plex? If not I think this would be a useful addition to it.

@goffrie
Copy link
Owner

goffrie commented Mar 9, 2020

This isn't possible today. It's a good idea though! Unfortunately I don't have much time these days to work on plex :(

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