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 support for RegExp literals #78

Closed
wants to merge 1 commit into from
Closed

Add support for RegExp literals #78

wants to merge 1 commit into from

Conversation

ianchi
Copy link

@ianchi ianchi commented Jan 2, 2018

No description provided.

@LeaVerou
Copy link
Collaborator

LeaVerou commented Jan 3, 2018

I think this may be out of scope. What do you think, @EricSmekens?

src/jsep.js Outdated
ch === 105 || // i
ch === 109 || // m
ch === 117 || // u
ch === 121 // y
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

123 |                            ch === 121 // y
                                           ^ Missing semicolon.

src/jsep.js Outdated
try {
re = new RegExp(pattern, flags);
} catch (e) {
throwError(e.message, start)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

422 |                        throwError(e.message, start)
                                                         ^ Missing semicolon.

@EricSmekens
Copy link
Owner

EricSmekens commented Jan 3, 2018

@ianchi Could you add a test so it demonstrates the use of this feature and it will not break use of multiple divide operators. We're still thinking of the use of regexp in this library however, if you can convince us but use-cases, go ahead :)

@EricSmekens
Copy link
Owner

EricSmekens commented Jan 3, 2018

@LeaVerou Yes, I'm not sure yet. I think it would be a nice feature, but if we keep adding nice features it will become more complex and turns into a more advanced parser. See http://esprima.org/demo/parse.html?code=%2F123*(w)%2Fg%0D%0A

@ianchi
Copy link
Author

ianchi commented Jan 4, 2018

fixed linting problems,
added tests,
fixed case to handle '/' in a class group

Signed-off-by: Adrian Panella <ianchi74@outlook.com>
@ianchi
Copy link
Author

ianchi commented Jan 4, 2018

Regarding the scope, I'm not sure of your goal.
I congratulate you on your work to have a light parser to handle expressions.
I need just that for a project I'm working on. But I need it to handle the full range of operators / literals, in an expression.
I already have another branch to add the comma/sequence expression, and was planning an additional with the minimum changes needed to add the missing operators: typeof / instanceof.
The last missing feature are object expressions, for which there is already an old PR.

Please tell me if you are interested in these PR, or you prefer that I fork the project.
Anyway, perhaps I'll end up needing to fork it, as for my project I need a light jsonPath implementation, and jsep provides a great starting point for adding the few custom types needed to parse also those expressions.

@LeaVerou
Copy link
Collaborator

LeaVerou commented Jan 4, 2018

@EricSmekens Because different people have different needs and different definitions of what an "expression" is and we'll keep running into such dilemmas, I think we should instead support plugins.
I did this 5 years ago with PrismJS, and it has worked out great and created an entire ecosystem around the project while allowing us to keep the core very small.

The main idea is:

  • Public data structures whenever it makes sense, so that people can modify them from third-party code
  • A hooks system, so that people can run arbitrary code at certain pre-selected parts of our codebase. I can get into more detail about API & implementation of this if you want, but the main idea looks like this.

If you agree with the idea, I can work towards it.

@ianchi
Copy link
Author

ianchi commented Jan 19, 2018

I ended up writing a new expression parser, inspired by jsep. It's designed to be completely configurable, so that it can be made to parse the same way as jsep, add additional operators to complete the ES5 expressions (except for function expressions, which would require parsing statements) and output compatible to current esprima, and also to parse jsonPath syntax.
It also includes an optional static-eval ( es5 and jsonPath flavors presets).
It is in ESpression, and any help/suggestions are welcomed.

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

Successfully merging this pull request may close these issues.

None yet

3 participants