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

Support parameterized rules as arguments #64

Closed
pdubroy opened this issue Feb 20, 2016 · 3 comments
Closed

Support parameterized rules as arguments #64

pdubroy opened this issue Feb 20, 2016 · 3 comments

Comments

@pdubroy
Copy link
Contributor

pdubroy commented Feb 20, 2016

From @mroeder:

G {
  Start = call<double, "x">
  call<rule, param> = rule<param>
  double<x> = x x
}

throws a Error: FIXME: should catch this earlier at Apply.pexprs.Apply.introduceParams (./src/pexprs-introduceParams.js:63:13)

In principle, I don't see any reason why we can't support this. One thing that would need fixing is pexprs.Apply.prototype.introduceParams (where the error is thrown). When we go to install the call rule into the grammar, we replace the Apply node in the body (the application of rule) with a Param node, and in doing so, discard the arguments.

One thing I'm not sure about is how we'd want to check that the rule application has the correct number of arguments. Some options:

  • Do it dynamically, à la Python
  • Do it at grammar creation time, through type inference.
  • Put type annotations on the parameters, e.g. call<rule/1, param> = rule<param>.
@alexwarth
Copy link
Contributor

I don't know about this -- seems complicated at first glance. Do you guys have a motivating example? The one above is a bit contrived.

@mroeder
Copy link
Contributor

mroeder commented Feb 20, 2016

Wait @alexwarth: You don't want to functionally program in Ohm??? We could write Ohm/Ohm (instead of JS or Smalltalk). :-D
Anyway, I am happy to not pursue but have a better error message and simply make rule a parameter:

(function() {
  return new this.newGrammar("G")
    .withDefaultStartRule("Start")
    .define("Start", ["rule"], this.param(0))
    .build();
});

(recipe for G { Start<rule> = rule })

@pdubroy
Copy link
Contributor Author

pdubroy commented Feb 20, 2016

I don't feel strongly about it, but on the other hand I could imagine some people being surprised that it doesn't work.

The best example I can come up with is something like: you write a rule that uses ListOf, but you want it to work in both semantic and lexical contexts. So you do something like this:

myRuleImpl<listExp> = foo bar+ blah? listExp<ident, ",">
MyRule = myRuleImpl<ListOf>
myRule = myRuleImpl<listOf>

@pdubroy pdubroy changed the title Parameterized rules as arguments Support parameterized rules as arguments Jul 4, 2021
@pdubroy pdubroy closed this as completed Nov 2, 2021
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

3 participants