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

Pattern generators #1495

Open
RunDevelopment opened this issue Jul 22, 2018 · 1 comment
Open

Pattern generators #1495

RunDevelopment opened this issue Jul 22, 2018 · 1 comment

Comments

@RunDevelopment
Copy link
Member

RunDevelopment commented Jul 22, 2018

This is based on the idea of @LeaVerou (#1479 (comment))

We could also have factory helpers, e.g. Prism.keywords("foo", "bar", ...) that generate regexes for common things

The only difference is that Prism.keywords will not generate a regex but an array with a method/property generate. This method will be called when the pattern is used for the first time and returns a regex.
Like this, we can have lists of keywords which can be used and modified by other languages.

Thoughts?

@RunDevelopment
Copy link
Member Author

The keywords function could then look like this:

function keywords(keywords, caseInsensitive) {
	keywords.generate = function (keywords) {
		return RegExp('\\b(?:' + keywords.join('|') + ')\\b', caseInsensitive ? 'i' : '');
	};
	return keywords;
}

@RunDevelopment RunDevelopment changed the title Objects as patterns Pattern generators Jul 27, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants