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

Interpolate values on Grammar creation #88

Open
ReubenJ opened this issue Sep 13, 2024 · 1 comment
Open

Interpolate values on Grammar creation #88

ReubenJ opened this issue Sep 13, 2024 · 1 comment
Labels
enhancement New feature or request

Comments

@ReubenJ
Copy link
Member

ReubenJ commented Sep 13, 2024

Related to #69, it would be ideal to support something like the following use case when programmatically creating grammars.

n = 10
@cfgrammar begin
    A = |(1:$n)
end

or even something as simple as

n = 10
@cfgrammar begin
    A = $n
end

Currently, you have to make use of add_rule! to achieve something like this:

n = 10
[add_rule!(g, :(A = $i)) for i in 1:n]

or

n = 10
add_rule!(g, :(A = $n))
@ReubenJ ReubenJ added the enhancement New feature or request label Sep 13, 2024
@janvandermeulen
Copy link
Member

Design Issue

To solve this some variables will have to be substituted to get the desired behavior. But some languages naturally have variables. Take for example the following grammar

g = HerbGrammar.@csgrammar begin
    Real = |(0:9)
    Real = x
    Real = Real + Real
    Real = Real - Real
    Real = Real * Real
end

If x is defined in the context, should it automatically substitute it? In this case likely not, but how do you define the difference?

@janvandermeulen janvandermeulen removed their assignment Nov 14, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

When branches are created from issues, their pull requests are automatically linked.

2 participants