Code Monkey home page Code Monkey logo

jsparser's Introduction

jsparser

An ECMAScript 5.1 parser, written in JavaScript. The ECMAScript grammar was created using Jison.

A blog post describing the project is available here. You can also test the parser online here.

Node Usage

Require the jsparser module, then simply call the parser's parse() method on a string of JavaScript source code. On success, an AST is returned. On failure, an error is thown.

var parser = require("jsparser");
var source = "console.log('Hello World!');";
var ast;

try {
  ast = parser.parse(source);
  console.log(ast);
} catch (exception) {
  console.log("Parse Error:  " + exception.message);
}

jsparser's People

Contributors

cjihrig avatar jacobo221 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

jsparser's Issues

Parsing jquery.cloud9carousel.js fails

Parsing of jquery.cloud9carousel.js fails using the parser demo ( http://www.cjihrig.com/development/jsparser/ ) with error message:

SyntaxError:  Parse error on line 243:
...o rotate    //    this.go = function( 
---------------------^
Expecting ',', ';', got 'THIS'

I have been able to make the parser succeed with any of the following changes:

  • Remove all preceding // comments
@@ -242,9 +242,6 @@
       this.timer = 0;
     }

-    //
-    // Spin the carousel.  Count is the number (+-) of carousel items to rotate
-    //
     this.go = function( count ) {
       this.destRotation += (2 * Math.PI / this.items.length) * count;
       this.play();
  • Insert a comma: ,
@@ -240,7 +240,7 @@
     this.pause = function() {
       this.smooth && cancelFrame ? cancelFrame( this.timer ) : clearTimeout( this.timer );
       this.timer = 0;
-    }
+    },

     //
     // Spin the carousel.  Count is the number (+-) of carousel items to rotate
  • Insert a semicolon: ;
@@ -240,7 +240,7 @@
     this.pause = function() {
       this.smooth && cancelFrame ? cancelFrame( this.timer ) : clearTimeout( this.timer );
       this.timer = 0;
-    }
+    };

     //
     // Spin the carousel.  Count is the number (+-) of carousel items to rotate

Automatic Semicolon Insertion Bug

Semicolon is not properly inserted in the following code:

a={}//
 b

Note, the error only occurs when the second line begins with one or more whitespace characters. Adding an extra line in the middle, or removing the comment fixes the problem.

Way to execute the script?

It's pretty cool you can print it, but can you call it.
andwhat should be arguments array for the second param for the .parse method

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.