This repository has been archived by the owner. It is now read-only.
Permalink
Browse files

Initial commit of parser using esprima.

  • Loading branch information...
csnover committed Mar 29, 2012
1 parent dec38c5 commit 3e9dbafb2a24ef820ad95396945f02a979f0853a
Showing with 306 additions and 29 deletions.
  1. +3 −3 .gitmodules
  2. +0 −1 bdParse
  3. +1 −1 dojo
  4. +1 −0 esprima
  5. +17 −16 lib/Scope.js
  6. +5 −2 lib/Value.js
  7. +1 −1 lib/callHandlers.js
  8. +4 −0 lib/console.js
  9. +20 −3 lib/env.js
  10. +251 −0 lib/esprimaParser.js
  11. +3 −2 parse.js
View
@@ -1,6 +1,6 @@
[submodule "dojo"]
path = dojo
url = https://github.com/dojo/dojo.git
-[submodule "bdParse"]
- path = bdParse
- url = https://github.com/csnover/bdParse
+[submodule "esprima"]
+ path = esprima
+ url = https://github.com/ariya/esprima.git
Submodule bdParse deleted from 65c028
2 dojo
Submodule dojo updated from d29d3f to 2e1e84
Submodule esprima added at 7d82d3
View
@@ -36,24 +36,29 @@ define([ 'dojo/_base/lang', './env', './Value', './node!util' ], function (lang,
throw new Error('Scope is a constructor');
}
- if (!relatedFunction && env.globalScope) {
- throw new Error('All scopes except global scope must have a related function value');
- }
-
if (!parent) {
parent = env.scope;
}
this.parent = parent;
this.children = [];
this.vars = {};
+
+ this.isFunctionScope = !!relatedFunction;
this.relatedFunction = relatedFunction;
return this; // strict mode
}
Scope.prototype = {
constructor: Scope,
+ /**
+ * Whether or not this is a function scope (as opposed
+ * to a block scope).
+ * @type boolean
+ */
+ isFunctionScope: false,
+
/**
* If a scope has no parent, it is the global scope.
* @type Scope?
@@ -214,24 +219,20 @@ define([ 'dojo/_base/lang', './env', './Value', './node!util' ], function (lang,
}
return variable;
- }
- };
-
- // TODO: Using defineProperty until bdParse supports ES5 get/set
+ },
- /**
- * The function value to which this scope belongs. Undefined if it is the global scope.
- * @type Value?
- */
- Object.defineProperty(Scope.prototype, 'relatedFunction', {
- get: function () {
+ /**
+ * The function value to which this scope belongs. Undefined if it is the global scope.
+ * @type Value?
+ */
+ get relatedFunction() {
return this.vars['this'];
},
- set: function (/** Value */ value) {
+ set relatedFunction(/**Value*/ value) {
this.vars['this'] = value;
}
- });
+ };
return Scope;
});
View
@@ -15,9 +15,12 @@ define([ 'dojo/_base/lang', './env' ], function (lang, env) {
this.file = env.file;
lang.mixin(this, kwArgs);
-
- return this; // strict mode
}
+
+ lang.mixin(Value, {
+ TYPE_FUNCTION: 'function'
+ });
+
Value.prototype = {
constructor: Value,
View
@@ -64,7 +64,7 @@ define([ 'dojo/_base/lang', 'dojo/AdapterRegistry', './env', './Module', './Pars
dependency = Module.get(env.file.resolveRelativeId(dependencyIds[i].value));
}
// Keep parser from ignoring this error as being one that is coming from the AdapterRegistry
- catch(error) {
+ catch (error) {
throw new ParseError(error);
}
View
@@ -1,3 +1,7 @@
+/**
+ * A module that improves the standard console logging mechanism
+ * by adding details about the execution state of the parser.
+ */
define([ 'dojo/_base/kernel', './env', './node!util' ], function (dojo, env, util) {
var oldConsole = this.console;
View
@@ -33,11 +33,17 @@ define([ 'dojo/_base/kernel', './Scope', './File', './Value', './Module', 'expor
globalScope: globalScope,
/**
- * The current scope of the parser environment.
+ * The current block scope of the parser environment.
* @type Scope
*/
scope: globalScope,
+ /**
+ * The current function scope of the parser environment.
+ * @type Scope
+ */
+ functionScope: globalScope,
+
/**
* The current file being processed.
* @type File
@@ -60,12 +66,18 @@ define([ 'dojo/_base/kernel', './Scope', './File', './Value', './Module', 'expor
/**
* Pushes a new variable scope to the environment.
- * @param functionValue The function to which the new scope belongs.
+ * @param relatedFunction The function to which the new scope belongs.
+ * If undefined, the new scope is a block scope.
* @returns {Scope} The new scope.
*/
- pushScope: function (/**Value*/ relatedFunction) {
+ pushScope: function (/**Value?*/ relatedFunction) {
var parentScope = this.scope;
this.scope = new Scope(parentScope, relatedFunction);
+
+ if (relatedFunction) {
+ this.functionScope = this.scope;
+ }
+
parentScope.children.push(this.scope);
return this.scope;
@@ -83,6 +95,11 @@ define([ 'dojo/_base/kernel', './Scope', './File', './Value', './Module', 'expor
}
this.scope = this.scope.parent;
+
+ if (this.scope.isFunctionScope) {
+ this.functionScope = this.scope;
+ }
+
return childScope;
},
Oops, something went wrong.

0 comments on commit 3e9dbaf

Please sign in to comment.