GithubHelp home page GithubHelp logo

ericbn / js-abstract-descent-parser Goto Github PK

View Code? Open in Web Editor NEW
12.0 12.0 2.0 111 KB

Abstract Descent Parser algorithm implemented in JavaScript

JavaScript 80.92% HTML 19.08%
grammar javascript parser parsing

js-abstract-descent-parser's People

Contributors

ericbn avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

Forkers

jrvlima kilokon

js-abstract-descent-parser's Issues

The index is handled differently when handling characters as opposed to regular expressions

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.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.