-
Notifications
You must be signed in to change notification settings - Fork 65
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
Refer to specific grammar rule #386
Comments
Yes, see the
|
Also of note: you can specify I'm going to keep this open in order to make sure the CLI docs say that. |
Alright, I've managed to see it with the cli, you need to specify startRule on options arg of the function parse. |
"use strict";
const peggy = require("./");
const { parse } = peggy.generate(`
false = "false" { return false; }
true = "true" { return true; }
boolean = true / false`, {
allowedStartRules: ["*"],
});
console.log(parse("true", { startRule: "boolean" })); |
Understood, this is basically the equivalent of the CLI but when generating the grammar at runtime. I hoped there was some way to flag rules in the grammar itself to tell the generator (CLI or peggy.generate) what default starting rules to have. Let's say I have mygrammar.peggy *false = "false" { return false; }
true = "true" { return true; }
*boolean = true / false And I want the starting rule to be either boolean or false. But as I understand this is not currently supported. |
You are correct there is currently no mechanism inside the grammar for this, although that's a good idea. When we do rule importing (see #292 for initial work), some rules might be marked as public and others as private, for instance. There are other bits of metadata that might be interesting about rules, such as anticipated types for Typescript output, enabling tracing per-rule, example inputs that get automatically tested, etc. We could come up with something like ECMAscript/Typescript decorators, have a syntax for comments like JSdoc, or decide that all of this is too complicated for the benefits that might accrue. In the meantime, just keep an array of the rules you want to be made visible whenver you would have generated a |
* main: Update deps, CHANGELOG, version. Rebuild. Fix typos. Move parens to correct place. Rebuilt patch from scratch, incorporating comments Update dependencies Remove --optimize. Fixes peggyjs#392. --allowed-start-rule=\* documented for CLI. Fixes peggyjs#386. Put parens around integer conversions in repetition. Fixes peggyjs#381. Tweaking the error format() documentation Authors and small grammar fix Change silver to hex Update to [email protected] Update CHANGELOG Make online version work in old browsers. Fixes peggyjs#371. Updating grammarSource documentation Add Marcel Bolten to authors Remove redundant options variants in behavior test Handle null and undefined explicitly Fixes peggyjs#374. CLI was throwing exception on grammar errors without a CLI test also being specified. Stub out new CHANGELOG.md section
Is it possible to have one single grammar and decide to parse a specific text using one rule of this grammar which is not the main one?
Let's say I have the following, very simple grammar, boolean is my start rule.
But sometimes I would like to access in the generated file, no only boolean but maybe I just need to parse false or true, is that possible? I mean to export them separately through cli.
The text was updated successfully, but these errors were encountered: