[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] master 2b8bc05 052/271: Remove buggy tail optimization. Move stdi
From: |
Jackson Ray Hamilton |
Subject: |
[elpa] master 2b8bc05 052/271: Remove buggy tail optimization. Move stdin cruft to cli. |
Date: |
Thu, 05 Feb 2015 18:29:43 +0000 |
branch: master
commit 2b8bc0540394f1b72148c8fbdaeacfe8d9d749d5
Author: Jackson Ray Hamilton <address@hidden>
Commit: Jackson Ray Hamilton <address@hidden>
Remove buggy tail optimization. Move stdin cruft to cli.
---
bin/cli.js | 23 ++++++++++++++
bin/scopifier | 3 ++
context-coloring.el | 5 +--
scopifier.js | 80 ++++++++++++++++++++------------------------------
4 files changed, 60 insertions(+), 51 deletions(-)
diff --git a/bin/cli.js b/bin/cli.js
new file mode 100644
index 0000000..4b2b90e
--- /dev/null
+++ b/bin/cli.js
@@ -0,0 +1,23 @@
+/*jslint node: true */
+
+// Reads a JavaScript file from stdin.
+
+// Writes an array of `[level, start, end]' tokens to stdout.
+
+'use strict';
+
+var scopifier = require('../scopifier'),
+ whole = '';
+
+process.stdin.setEncoding('utf8');
+
+process.stdin.on('readable', function () {
+ var chunk = process.stdin.read();
+ if (chunk !== null) {
+ whole += chunk;
+ }
+});
+
+process.stdin.on('end', function () {
+ console.log(JSON.stringify(scopifier(whole)));
+});
diff --git a/bin/scopifier b/bin/scopifier
new file mode 100755
index 0000000..9610016
--- /dev/null
+++ b/bin/scopifier
@@ -0,0 +1,3 @@
+#!/usr/bin/env node
+'use strict';
+require('./cli.js');
\ No newline at end of file
diff --git a/context-coloring.el b/context-coloring.el
index 7d1fb02..3b871a8 100644
--- a/context-coloring.el
+++ b/context-coloring.el
@@ -127,7 +127,7 @@ For example: \"context-coloring-depth-1-face\"."
"This file's directory.")
(defconst context-coloring-scopifier-path
- (expand-file-name "./scopifier.js" context-coloring-path)
+ (expand-file-name "./bin/scopifier" context-coloring-path)
"Path to the external scopifier executable.")
(defconst context-coloring-delay 0.25
@@ -171,8 +171,7 @@ calling FUNCTION with the parsed list of tokens."
;; Start the process.
(setq context-coloring-scopifier-process
- (start-process-shell-command "scopifier" nil
- (concat "node "
context-coloring-scopifier-path)))
+ (start-process-shell-command "scopifier" nil
context-coloring-scopifier-path))
(let ((output "")
(buffer context-coloring-buffer)
diff --git a/scopifier.js b/scopifier.js
index 3b2338d..7bdbe37 100644
--- a/scopifier.js
+++ b/scopifier.js
@@ -4,36 +4,31 @@
var escope = require('escope'),
esprima = require('esprima'),
+
+ // Given an array of definitions, determines if a definition already exists
+ // for a given range. (escope detects variables twice if they are declared
+ // and initialized simultaneously; this filters them.)
isDefined = function (definitions, range) {
return definitions.some(function (definition) {
// Check for identical definitions.
return definition[1] === range[0] &&
definition[2] === range[1];
});
- },
- whole = '';
-
-process.stdin.setEncoding('utf8');
-
-process.stdin.on('readable', function () {
- var chunk = process.stdin.read();
- if (chunk !== null) {
- whole += chunk;
- }
-});
+ };
-process.stdin.on('end', function () {
+// Given code, returns an array of `[level, start, end]' tokens for
+// context-coloring.
+module.exports = function (code) {
var ast,
analyzedScopes,
scopes = [],
symbols = [],
- comments = [],
- continuous,
+ comments,
emacsified;
// Gracefully handle parse errors by doing nothing.
try {
- ast = esprima.parse(whole, {
+ ast = esprima.parse(code, {
comment: true,
range: true
});
@@ -107,38 +102,27 @@ process.stdin.on('end', function () {
}
});
- ast.comments.forEach(function (comment) {
- var range = comment.range;
- comments.push([
- -1,
- range[0],
- range[1]
- ]);
- });
-
- continuous = symbols.concat(comments).sort(function (a, b) {
- return a[1] - b[1];
- });
-
- continuous = continuous.slice(1).reduce(function (soFar, token) {
- var previous = soFar[soFar.length - 1];
- // Detect same-color exact tail ends (nothing else is safe to join).
- if (previous[0] === token[0] &&
- previous[2] === token[1] - 1) {
- previous[2] = token[2];
- return soFar;
- }
- soFar.push(token);
- return soFar;
- }, continuous.slice(0, 1));
-
- emacsified = scopes.concat(continuous);
+ comments = ast.comments
+ .map(function (comment) {
+ var range = comment.range;
+ return [
+ -1,
+ range[0],
+ range[1]
+ ];
+ });
- emacsified.forEach(function (instruction) {
- // Emacs starts counting from 1.
- instruction[1] += 1;
- instruction[2] += 1;
- });
+ emacsified = scopes
+ .concat(symbols)
+ .concat(comments)
+ .map(function (token) {
+ // Emacs starts counting from 1.
+ return [
+ token[0],
+ token[1] + 1,
+ token[2] + 1
+ ];
+ });
- console.log(JSON.stringify(emacsified));
-});
+ return emacsified;
+};
- [elpa] master fef44f5 038/271: Fix broken link., (continued)
- [elpa] master fef44f5 038/271: Fix broken link., Jackson Ray Hamilton, 2015/02/05
- [elpa] master e4ee2ec 042/271: Catch parse errors., Jackson Ray Hamilton, 2015/02/05
- [elpa] master d372de1 029/271: Clean up cruft., Jackson Ray Hamilton, 2015/02/05
- [elpa] master b1b7f9d 032/271: Optimize tokens by connecting tail ends., Jackson Ray Hamilton, 2015/02/05
- [elpa] master 2cdd91e 043/271: Write new scopifier with comment detection., Jackson Ray Hamilton, 2015/02/05
- [elpa] master eb14005 041/271: Rename scopify to scopifier. Use vectors., Jackson Ray Hamilton, 2015/02/05
- [elpa] master f482c62 035/271: Use remove-text-properties as a temporary comment fix., Jackson Ray Hamilton, 2015/02/05
- [elpa] master 615163a 045/271: Update screenshot., Jackson Ray Hamilton, 2015/02/05
- [elpa] master f4e075f 047/271: Readme updates., Jackson Ray Hamilton, 2015/02/05
- [elpa] master 6cd2827 044/271: Cleanup old scopifier., Jackson Ray Hamilton, 2015/02/05
- [elpa] master 2b8bc05 052/271: Remove buggy tail optimization. Move stdin cruft to cli.,
Jackson Ray Hamilton <=
- [elpa] master f75af43 036/271: Fix installation instructions., Jackson Ray Hamilton, 2015/02/05
- [elpa] master d881130 049/271: Rename test., Jackson Ray Hamilton, 2015/02/05
- [elpa] master 40c9d93 048/271: Readme updates., Jackson Ray Hamilton, 2015/02/05
- [elpa] master 348b4ca 056/271: Teeny., Jackson Ray Hamilton, 2015/02/05
- [elpa] master c9a7a2d 050/271: Add tail-end optimization., Jackson Ray Hamilton, 2015/02/05
- [elpa] master d2114ae 053/271: Remove indentation level., Jackson Ray Hamilton, 2015/02/05
- [elpa] master 028370d 054/271: Refactor to be more functional., Jackson Ray Hamilton, 2015/02/05
- [elpa] master 0e64e85 055/271: Simplify to 2 arrays., Jackson Ray Hamilton, 2015/02/05
- [elpa] master ff988f3 051/271: Fix duplicate tokens and tail-end bug., Jackson Ray Hamilton, 2015/02/05
- [elpa] master 0143a29 058/271: Leverage .jslintrc files., Jackson Ray Hamilton, 2015/02/05