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

Case insensitive keywords? #46

Closed
mx-scissortail opened this issue May 1, 2017 · 4 comments
Closed

Case insensitive keywords? #46

mx-scissortail opened this issue May 1, 2017 · 4 comments
Labels

Comments

@mx-scissortail
Copy link

I've got a use case where the keywords in my language are case insensitive but other things (e.g. the contents of strings) aren't. Is there any way I can make a lexer that recognizes these? I tried keyword: [/foo/i, ...] but it complains that the "/i" flag isn't allowed.

@tjvr
Copy link
Collaborator

tjvr commented May 1, 2017

Right. Moo combines all the tokens into a single RegExp, so supporting both case-sensitive and insensitive tokens is difficult. Can you tell me more about the language? That might help :-)

One suggestion would be to do e.g. /[fF][oO][oO]/. You could write a function to generate such RegExps from strings, you needn't do it by hand. :-)

@mx-scissortail
Copy link
Author

Ah, yeah. It's a pretty simple DSL where each line starts with a case insensitive keyword, e.g.:

enter: (some-terrible-lisp-expression). ;comment
Enter: (another-terrible-lisp-expression).
delete: "string".

etc.

I think generating the individual cases won't be too hard, so that will probably work. Thanks.

@tjvr
Copy link
Collaborator

tjvr commented May 1, 2017

Glad I could help! :-)

Be aware that you might run into an edge case if you have identifiers too: https://github.com/tjvr/moo#keywords —moo only handles that if your keywords are specified as strings.

@deltaidea
Copy link
Contributor

Maybe it would be a good idea to add something like this:

moo.compile({
  evenOdd: { caseInsensitive: true, keyword: ['even', 'odd'] }
})

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants