From e5439847fd733a31423f9b02ce40b706f142acc4 Mon Sep 17 00:00:00 2001 From: Marijn Haverbeke Date: Tue, 25 Mar 2014 17:26:17 +0100 Subject: [PATCH] Rename remaining *_t constructors to something sane --- acorn.js | 22 +++++++++++----------- acorn_loose.js | 8 ++++---- index.html | 30 ++++++++++++++++-------------- 3 files changed, 31 insertions(+), 29 deletions(-) diff --git a/acorn.js b/acorn.js index fe56e3c92c..63abcce77f 100644 --- a/acorn.js +++ b/acorn.js @@ -466,7 +466,7 @@ // These are used when `options.locations` is on, for the // `tokStartLoc` and `tokEndLoc` properties. - function line_loc_t() { + function Position() { this.line = tokCurLine; this.column = tokPos - tokLineStart; } @@ -486,7 +486,7 @@ function finishToken(type, val) { tokEnd = tokPos; - if (options.locations) tokEndLoc = new line_loc_t; + if (options.locations) tokEndLoc = new Position; tokType = type; skipSpace(); tokVal = val; @@ -494,7 +494,7 @@ } function skipBlockComment() { - var startLoc = options.onComment && options.locations && new line_loc_t; + var startLoc = options.onComment && options.locations && new Position; var start = tokPos, end = input.indexOf("*/", tokPos += 2); if (end === -1) raise(tokPos - 2, "Unterminated comment"); tokPos = end + 2; @@ -508,12 +508,12 @@ } if (options.onComment) options.onComment(true, input.slice(start + 2, end), start, tokPos, - startLoc, options.locations && new line_loc_t); + startLoc, options.locations && new Position); } function skipLineComment() { var start = tokPos; - var startLoc = options.onComment && options.locations && new line_loc_t; + var startLoc = options.onComment && options.locations && new Position; var ch = input.charCodeAt(tokPos+=2); while (tokPos < inputLen && ch !== 10 && ch !== 13 && ch !== 8232 && ch !== 8233) { ++tokPos; @@ -521,7 +521,7 @@ } if (options.onComment) options.onComment(false, input.slice(start + 2, tokPos), start, tokPos, - startLoc, options.locations && new line_loc_t); + startLoc, options.locations && new Position); } // Called at the start of the parse and after every token. Skips @@ -724,7 +724,7 @@ function readToken(forceRegexp) { if (!forceRegexp) tokStart = tokPos; else tokPos = tokStart + 1; - if (options.locations) tokStartLoc = new line_loc_t; + if (options.locations) tokStartLoc = new Position; if (forceRegexp) return readRegexp(); if (tokPos >= inputLen) return finishToken(_eof); @@ -1005,7 +1005,7 @@ exports.Node = Node; - function node_loc_t() { + function SourceLocation() { this.start = tokStartLoc; this.end = null; if (sourceFile !== null) this.source = sourceFile; @@ -1014,7 +1014,7 @@ function startNode() { var node = new Node(); if (options.locations) - node.loc = new node_loc_t(); + node.loc = new SourceLocation(); if (options.directSourceFile) node.sourceFile = options.directSourceFile; if (options.ranges) @@ -1030,7 +1030,7 @@ var node = new Node(); node.start = other.start; if (options.locations) { - node.loc = new node_loc_t(); + node.loc = new SourceLocation(); node.loc.start = other.loc.start; } if (options.ranges) @@ -1115,7 +1115,7 @@ function parseTopLevel(program) { lastStart = lastEnd = tokPos; - if (options.locations) lastEndLoc = new line_loc_t; + if (options.locations) lastEndLoc = new Position; inFunction = strict = null; labels = []; readToken(); diff --git a/acorn_loose.js b/acorn_loose.js index 9d44df881d..5f3780b633 100644 --- a/acorn_loose.js +++ b/acorn_loose.js @@ -201,7 +201,7 @@ exports.Node = Node; - function node_loc_t(start) { + function SourceLocation(start) { this.start = start || token.startLoc || {line: 1, column: 0}; this.end = null; if (sourceFile !== null) this.source = sourceFile; @@ -210,7 +210,7 @@ function startNode() { var node = new Node(token.start); if (options.locations) - node.loc = new node_loc_t(); + node.loc = new SourceLocation(); if (options.directSourceFile) node.sourceFile = options.directSourceFile; return node; @@ -219,7 +219,7 @@ function startNodeFrom(other) { var node = new Node(other.start); if (options.locations) - node.loc = new node_loc_t(other.loc.start); + node.loc = new SourceLocation(other.loc.start); return node; } @@ -233,7 +233,7 @@ function getDummyLoc() { if (options.locations) { - var loc = new node_loc_t(); + var loc = new SourceLocation(); loc.end = loc.start; return loc; } diff --git a/index.html b/index.html index dc3f283cfc..edbc4ca823 100644 --- a/index.html +++ b/index.html @@ -278,7 +278,7 @@ line break). Used to count lines.

if (code < 123)return true; return code >= 0xaa && nonASCIIidentifier.test(String.fromCharCode(code)); };

Tokenizer

These are used when options.locations is on, for the -tokStartLoc and tokEndLoc properties.

  function line_loc_t() {
+tokStartLoc and tokEndLoc properties.

  function Position() {
     this.line = tokCurLine;
     this.column = tokPos - tokLineStart;
   }

Reset the token state. Used at the start of a parse.

  function initTokenState() {
@@ -290,7 +290,7 @@ line break). Used to count lines.

  function finishToken(type, val) {
     tokEnd = tokPos;
-    if (options.locations) tokEndLoc = new line_loc_t;
+    if (options.locations) tokEndLoc = new Position;
     tokType = type;
     skipSpace();
     tokVal = val;
@@ -298,7 +298,7 @@ the next one's tokStart will point at the right position.

} function skipBlockComment() { - var startLoc = options.onComment && options.locations && new line_loc_t; + var startLoc = options.onComment && options.locations && new Position; var start = tokPos, end = input.indexOf("*/", tokPos += 2); if (end === -1) raise(tokPos - 2, "Unterminated comment"); tokPos = end + 2; @@ -312,12 +312,12 @@ the next one's tokStart will point at the right position.

} if (options.onComment) options.onComment(true, input.slice(start + 2, end), start, tokPos, - startLoc, options.locations && new line_loc_t); + startLoc, options.locations && new Position); } function skipLineComment() { var start = tokPos; - var startLoc = options.onComment && options.locations && new line_loc_t; + var startLoc = options.onComment && options.locations && new Position; var ch = input.charCodeAt(tokPos+=2); while (tokPos < inputLen && ch !== 10 && ch !== 13 && ch !== 8232 && ch !== 8233) { ++tokPos; @@ -325,7 +325,7 @@ the next one's tokStart will point at the right position.

} if (options.onComment) options.onComment(false, input.slice(start + 2, tokPos), start, tokPos, - startLoc, options.locations && new line_loc_t); + startLoc, options.locations && new Position); }

Called at the start of the parse and after every token. Skips whitespace and comments, and.

  function skipSpace() {
     while (tokPos < inputLen) {
@@ -497,7 +497,7 @@ of the type given by its first argument.

function readToken(forceRegexp) { if (!forceRegexp) tokStart = tokPos; else tokPos = tokStart + 1; - if (options.locations) tokStartLoc = new line_loc_t; + if (options.locations) tokStartLoc = new Position; if (forceRegexp) return readRegexp(); if (tokPos >= inputLen) return finishToken(_eof); @@ -712,22 +712,24 @@ tests ("use strict"; 010; -- should fail).

} skipSpace(); readToken(); - }

Start an AST node, attaching a start offset.

  function node_t() {
+  }

Start an AST node, attaching a start offset.

  function Node() {
     this.type = null;
     this.start = tokStart;
     this.end = null;
   }
+  
+  exports.Node = Node;
 
-  function node_loc_t() {
+  function SourceLocation() {
     this.start = tokStartLoc;
     this.end = null;
     if (sourceFile !== null) this.source = sourceFile;
   }
 
   function startNode() {
-    var node = new node_t();
+    var node = new Node();
     if (options.locations)
-      node.loc = new node_loc_t();
+      node.loc = new SourceLocation();
     if (options.directSourceFile)
       node.sourceFile = options.directSourceFile;
     if (options.ranges)
@@ -736,10 +738,10 @@ tests ("use strict"; 010; -- should fail).

}

Start a node whose start offset information should be based on the start of another node. For example, a binary operator node is only started after its left-hand side has already been parsed.

  function startNodeFrom(other) {
-    var node = new node_t();
+    var node = new Node();
     node.start = other.start;
     if (options.locations) {
-      node.loc = new node_loc_t();
+      node.loc = new SourceLocation();
       node.loc.start = other.loc.start;
     }
     if (options.ranges)
@@ -786,7 +788,7 @@ statements, and wraps them in a Program node.  Optionally takes a
 program argument.  If present, the statements will be appended
 to its body instead of creating a new node.

  function parseTopLevel(program) {
     lastStart = lastEnd = tokPos;
-    if (options.locations) lastEndLoc = new line_loc_t;
+    if (options.locations) lastEndLoc = new Position;
     inFunction = strict = null;
     labels = [];
     readToken();