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

Object syntax doesn't allow keywords (to, mod, in, etc) as keys #1645

Closed
WesleyKapow opened this issue Oct 8, 2019 · 4 comments
Closed

Object syntax doesn't allow keywords (to, mod, in, etc) as keys #1645

WesleyKapow opened this issue Oct 8, 2019 · 4 comments

Comments

@WesleyKapow
Copy link

math.parse('{from: 5, to: 7}')
fails with:
math.js:46660 Uncaught SyntaxError: Symbol or string expected as object key (char 11)

This fails for all of the keywords in the syntax: mod, and, not, or, xor, to, in.

Tested version: 6.2.2.

@josdejong
Copy link
Owner

Thanks for your suggestion Wesley, it would be nice indeed if we could use keywords as object properties. Should be possible I think.

@Veeloxfire
Copy link
Contributor

Veeloxfire commented Apr 3, 2020

Problem to me seems that, when assigning the toke type, all NAMED_DELIMITERS are assigned as TOKENTYPE.DELIMITER where they are actually usable as TOKENTYPE.SYMBOL in this context.
Maybe adding TOKENTYPE.NAMED_DELIMITER or having state.tokenType be an array instead so if there are more than one options then it could go through in order of priorty. If it would crash on a certain option it could revert to the second etc.
This would involve a lot of rewriting though so maybe just easier to have the extra option on TOKENTYPE

EDIT:
Another option is to do what is done elsewhere and use:
state.tokenType === TOKENTYPE.SYMBOL || (state.tokenType === TOKENTYPE.DELIMITER && state.token in NAMED_DELIMITERS)
This works and doesnt influence other cases

@josdejong
Copy link
Owner

This issue is fixed now in mathjs@6.6.3

@josdejong
Copy link
Owner

Thanks again @Veeloxfire

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