ericbn / js-abstract-descent-parser Goto Github PK
View Code? Open in Web Editor NEWAbstract Descent Parser algorithm implemented in JavaScript
Abstract Descent Parser algorithm implemented in JavaScript
it is greatly appreciated.
I've rewritten your regexp() method a little but it is essentially the same. It goes:
parseRegExp(regexp) {
var parsed = false,
inputLength = this.input.length;
if (this.index < inputLength) {
var inputSubstring = this.input.substr(this.index),
matches = regexp.exec(inputSubstring);
if (matches && matches.index === 0) {
var firstMatch = first(matches),
firstMatchLength = firstMatch.length;
this.index += firstMatchLength;
parsed = true;
}
}
return parsed;
}
Here the index is only changed if there is a match. On the other hand, your char() method goes:
parseCharacter(character) {
var parsed = false,
inputLength = this.input.length;
if (this.index < inputLength) {
var inputCharacter = this.input.charAt(this.index);
this.index += 1;
if (inputCharacter === character) {
parsed = true;
}
}
return parsed;
}
Here the index is changed regardless of whether there is a match or not. I think it should be as follows:
parseCharacter(character) {
var parsed = false,
inputLength = this.input.length;
if (this.index < inputLength) {
var inputCharacter = this.input.charAt(this.index);
if (inputCharacter === character) {
this.index += 1;
parsed = true;
}
}
return parsed;
}
After all the char(...) method is a simplified regexp(...) method for all intents and purposes. Should it not behave in exactly the same way as far as the rest of the parse functionality is concerned? If I change the functionality, all your tests still pass.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.