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 modern ECMAScript regexp syntax #1670

Open
Tracked by #1739
bd82 opened this issue Oct 15, 2021 · 3 comments
Open
Tracked by #1739

Support modern ECMAScript regexp syntax #1670

bd82 opened this issue Oct 15, 2021 · 3 comments

Comments

@bd82
Copy link
Member

bd82 commented Oct 15, 2021

For example:

  • unicode flag
  • lookbehind assertions.

The biggest question is to decide if to update regexp-to-ast to the newst spec
or replace it with regexpp.

At the moment I am leaning towards updating regexp-to-ast as it seems regexpp is only minimally maintained.

@likern
Copy link

likern commented Dec 7, 2021

@bd82 Hello, I've started using this awesome parser in React Native environment. Please, consider also supporting React Native Hermes engine, it probably has some limitations in RegEx compared to V8.

More information is on Hermes site.

@0xThiebaut
Copy link

0xThiebaut commented Dec 27, 2021

For anyone ending up here and needing modern ECMAScript syntax, here is a quick workaround (in TypeScript) wrapping a RegExp into a Custom Token Pattern.

import { createToken, CustomPatternMatcherFunc } from "chevrotain"

function wrap(regex: RegExp): CustomPatternMatcherFunc {
    return (text: string, offset: number): RegExpExecArray | null => {
        const re = new RegExp(regex, 'y');
        re.lastIndex = offset
        return re.exec(text)
    }
}

export const ComplexIdentifier = createToken({
    name: 'variable.other.identifier.complex',
    pattern: wrap(/(?<=\[['"])[\w. -]{1,1024}(?=['"]\])/), // Wrap the modern ECMAScript RegExp syntax in the function
    line_breaks: false // A Custom Token Pattern should specify the <line_breaks> option
})

@bd82
Copy link
Member Author

bd82 commented Dec 29, 2021

I've started using this awesome parser in React Native environment. Please, consider also supporting React Native Hermes engine, it probably has some limitations in RegEx compared to V8.

Hello @likern

Chevrotain is a JavaScript library, so it should not need any special support to run inside of hermes.
Generally it should run on any ES6 compatible JavaScript engine which I assume Hermes is...

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