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
Consider switching to iterative parser #263
Comments
While we are discussing a new parser, I feel that I should point out Jison. It's a parser generator for JavaScript that powers CoffeeScript and some other pretty big JavaScript libraries. With Jison you can generate the parser and the generated code has no dependencies. It might not be the right thing for our use case, and it might not support switching out the tokens because of internationalization, but I feel that it would be wrong not to bring it up at least. |
Now that I've at least brought Jison up, I can actually comment on this parser idea. I think that it provides a couple of advantages that we cannot get from the regex parsing method:
A couple questions:
|
I'll look into Jison more in depth, thanks for mentioning it. re:questions
|
I've started working on this in the feature/parser branch. |
Well, I've got all the old unit tests up and passing for this, plus some new tests added here. Now I'll make a jsperf test and see how it compares... |
Results are in: http://jsperf.com/moment-iterative-parser ~25% slower on Chrome, ~50% slower on Firefox.
It's not that bad, considering other parsers like DateJS are 95% slower than moment. http://jsperf.com/underscore-date-vs-datejs/2
|
This has been merged into the develop branch and will go out in the 1.6.0 release |
Currently, moment parses by converting strings to arrays based on regexes.
Then, the parser loops through each item in the array and converts it to the correct argument for parsing an array to a date.
Instead, perhaps the parser should only chuck up the tokens, then loop through them, tearing chunks of the input string apart.
This could solve both the ISO8601 "T" problem/CJK number/month name problem, and the "YYYYMMDD" problem as well.
The text was updated successfully, but these errors were encountered: