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

Add new "verbose" mode #55

Open
jviereck opened this issue Jul 1, 2014 · 5 comments
Open

Add new "verbose" mode #55

jviereck opened this issue Jul 1, 2014 · 5 comments

Comments

@jviereck
Copy link
Owner

jviereck commented Jul 1, 2014

This was brought up before and also arises in #54. The idea is to have a verbose mode, which splits out the current from of the AST. If the verbose mode is turned off, following properties are omitted from the AST:

  • range
  • raw
  • kind

The current parse function accepts as second argument flags:

  function parse(str, flags) {

to turn on verbose mode, I think the flags string could just contain a v, like:

  parse('/hello/', 'v')

Thoughts?

@bnjmnt4n
Copy link
Contributor

bnjmnt4n commented Jul 2, 2014

Verbose mode seems great, but I’m using node.kind quite a lot especially for "value" nodes, and I’m not too sure how to generate some values without using kind.

@jviereck
Copy link
Owner Author

jviereck commented Jul 2, 2014

@D10, if kind is not given, you have to make a "guess" and take a look at the codePoint property. E.g. if you can figure out, that the codePoint corresponds to an ASCII character, then just use an ASCII char, if you figure out it is the codePoint for a newline, then use \n.

So yes, this is a little bit painful, but as raised by @mathiasbynens in #54 (comment), there is no free lunch: either modifying the AST is easier or regenerating it is easier. I do not see how we can have both at the same time.

@D10, does that sounds reasonable to you?

@bnjmnt4n
Copy link
Contributor

bnjmnt4n commented Jul 2, 2014

In that case there will be some conflicts such as controlLetter which returns a number from 1 to 26, which could be mistaken for the Unicode value U+0001.

@jviereck
Copy link
Owner Author

jviereck commented Jul 2, 2014

In that case there will be some conflicts such as controlLetter which returns a number from 1 to 26, which could be mistaken for the Unicode value U+0001.

Yes, the generated RegExp is then no longer unique determined. The code to regenerate the AST has then to make a good choice.

To ensure there is one unique output (and reading @mathiasbynens comment here #54 (comment) once more), I am happy to have two kind of verbose modes:

  • full-verbose mode: adds like what we have right now
  • verbose mode: adds raw and kind properties only to value AST nodes

How does this sound?

@mathiasbynens
Copy link
Collaborator

I think the flags string could just contain a v, like […]

I dislike the idea of reserving v in the flags for verbose mode. I’d prefer something like regjsparser.parse(regex, { verbose: true, flags: 'gim' }).

full-verbose mode: adds like what we have right now
verbose mode: adds raw and kind properties only to value AST nodes

Two verbose modes sounds a bit excessive IMHO. At this point I’d prefer just a single verbose mode, that adds raw and kind properties only to value AST nodes.

Yes, the generated RegExp is then no longer unique determined. The code to regenerate the AST has then to make a good choice.

That is not necessarily a bad thing, though. (Note that this is true for Escodegen to some extent.)

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

3 participants