cleaning up the previous merge -- moving it out to helpers.invertLiterate
This commit is contained in:
parent
51b1affbc5
commit
1b573412d3
|
@ -1,6 +1,6 @@
|
|||
// Generated by CoffeeScript 1.6.1
|
||||
(function() {
|
||||
var BANNER, CoffeeScript, EventEmitter, SWITCHES, compileJoin, compileOptions, compilePath, compileScript, compileStdio, exec, exists, forkNode, fs, helpers, hidden, joinTimeout, lint, notSources, optionParser, optparse, opts, outputPath, parseOptions, path, printLine, printTokens, printWarn, removeSource, rewriteLiterate, sourceCode, sources, spawn, timeLog, unwatchDir, usage, version, wait, watch, watchDir, watchers, writeJs, _ref;
|
||||
var BANNER, CoffeeScript, EventEmitter, SWITCHES, compileJoin, compileOptions, compilePath, compileScript, compileStdio, exec, exists, forkNode, fs, helpers, hidden, joinTimeout, lint, notSources, optionParser, optparse, opts, outputPath, parseOptions, path, printLine, printTokens, printWarn, removeSource, sourceCode, sources, spawn, timeLog, unwatchDir, usage, version, wait, watch, watchDir, watchers, writeJs, _ref;
|
||||
|
||||
fs = require('fs');
|
||||
|
||||
|
@ -12,8 +12,6 @@
|
|||
|
||||
CoffeeScript = require('./coffee-script');
|
||||
|
||||
rewriteLiterate = require('./lexer').rewriteLiterate;
|
||||
|
||||
_ref = require('child_process'), spawn = _ref.spawn, exec = _ref.exec;
|
||||
|
||||
EventEmitter = require('events').EventEmitter;
|
||||
|
@ -167,7 +165,10 @@
|
|||
} else if (o.run) {
|
||||
return CoffeeScript.run(t.input, t.options);
|
||||
} else if (o.join && t.file !== o.join) {
|
||||
sourceCode[sources.indexOf(t.file)] = helpers.isLiterate(file) ? rewriteLiterate(t.input) : t.input;
|
||||
if (helpers.isLiterate(file)) {
|
||||
t.input = helpers.invertLiterate(t.input);
|
||||
}
|
||||
sourceCode[sources.indexOf(t.file)] = t.input;
|
||||
return compileJoin();
|
||||
} else {
|
||||
compiled = CoffeeScript.compile(t.input, t.options);
|
||||
|
|
|
@ -85,6 +85,25 @@
|
|||
return false;
|
||||
};
|
||||
|
||||
exports.invertLiterate = function(code) {
|
||||
var line, lines, match;
|
||||
lines = (function() {
|
||||
var _i, _len, _ref1, _results;
|
||||
_ref1 = code.split('\n');
|
||||
_results = [];
|
||||
for (_i = 0, _len = _ref1.length; _i < _len; _i++) {
|
||||
line = _ref1[_i];
|
||||
if (match = /^([ ]{4}|\t)/.exec(line)) {
|
||||
_results.push(line.slice(match[0].length));
|
||||
} else {
|
||||
_results.push('# ' + line);
|
||||
}
|
||||
}
|
||||
return _results;
|
||||
})();
|
||||
return lines.join('\n');
|
||||
};
|
||||
|
||||
buildLocationData = function(first, last) {
|
||||
if (!last) {
|
||||
return first;
|
||||
|
|
|
@ -1,30 +1,11 @@
|
|||
// Generated by CoffeeScript 1.6.1
|
||||
(function() {
|
||||
var BOM, BOOL, CALLABLE, CODE, COFFEE_ALIASES, COFFEE_ALIAS_MAP, COFFEE_KEYWORDS, COMMENT, COMPARE, COMPOUND_ASSIGN, HEREDOC, HEREDOC_ILLEGAL, HEREDOC_INDENT, HEREGEX, HEREGEX_OMIT, IDENTIFIER, INDEXABLE, INVERSES, JSTOKEN, JS_FORBIDDEN, JS_KEYWORDS, LINE_BREAK, LINE_CONTINUER, LITERATE, LOGIC, Lexer, MATH, MULTILINER, MULTI_DENT, NOT_REGEX, NOT_SPACED_REGEX, NUMBER, OPERATOR, REGEX, RELATION, RESERVED, Rewriter, SHIFT, SIMPLESTR, STRICT_PROSCRIBED, TRAILING_SPACES, UNARY, WHITESPACE, compact, count, key, last, locationDataToString, rewriteLiterate, starts, _ref, _ref1,
|
||||
var BOM, BOOL, CALLABLE, CODE, COFFEE_ALIASES, COFFEE_ALIAS_MAP, COFFEE_KEYWORDS, COMMENT, COMPARE, COMPOUND_ASSIGN, HEREDOC, HEREDOC_ILLEGAL, HEREDOC_INDENT, HEREGEX, HEREGEX_OMIT, IDENTIFIER, INDEXABLE, INVERSES, JSTOKEN, JS_FORBIDDEN, JS_KEYWORDS, LINE_BREAK, LINE_CONTINUER, LOGIC, Lexer, MATH, MULTILINER, MULTI_DENT, NOT_REGEX, NOT_SPACED_REGEX, NUMBER, OPERATOR, REGEX, RELATION, RESERVED, Rewriter, SHIFT, SIMPLESTR, STRICT_PROSCRIBED, TRAILING_SPACES, UNARY, WHITESPACE, compact, count, invertLiterate, key, last, locationDataToString, starts, _ref, _ref1,
|
||||
__indexOf = [].indexOf || function(item) { for (var i = 0, l = this.length; i < l; i++) { if (i in this && this[i] === item) return i; } return -1; };
|
||||
|
||||
_ref = require('./rewriter'), Rewriter = _ref.Rewriter, INVERSES = _ref.INVERSES;
|
||||
|
||||
_ref1 = require('./helpers'), count = _ref1.count, starts = _ref1.starts, compact = _ref1.compact, last = _ref1.last, locationDataToString = _ref1.locationDataToString;
|
||||
|
||||
exports.rewriteLiterate = rewriteLiterate = function(code) {
|
||||
var line, lines, match;
|
||||
lines = (function() {
|
||||
var _i, _len, _ref2, _results;
|
||||
_ref2 = code.split('\n');
|
||||
_results = [];
|
||||
for (_i = 0, _len = _ref2.length; _i < _len; _i++) {
|
||||
line = _ref2[_i];
|
||||
if (match = LITERATE.exec(line)) {
|
||||
_results.push(line.slice(match[0].length));
|
||||
} else {
|
||||
_results.push('# ' + line);
|
||||
}
|
||||
}
|
||||
return _results;
|
||||
})();
|
||||
return lines.join('\n');
|
||||
};
|
||||
_ref1 = require('./helpers'), count = _ref1.count, starts = _ref1.starts, compact = _ref1.compact, last = _ref1.last, invertLiterate = _ref1.invertLiterate, locationDataToString = _ref1.locationDataToString;
|
||||
|
||||
exports.Lexer = Lexer = (function() {
|
||||
|
||||
|
@ -71,7 +52,7 @@
|
|||
this.chunkLine--;
|
||||
}
|
||||
if (this.literate) {
|
||||
code = rewriteLiterate(code);
|
||||
code = invertLiterate(code);
|
||||
}
|
||||
return code;
|
||||
};
|
||||
|
@ -854,8 +835,6 @@
|
|||
|
||||
COMMENT = /^###([^#][\s\S]*?)(?:###[^\n\S]*|(?:###)$)|^(?:\s*#(?!##[^#]).*)+/;
|
||||
|
||||
LITERATE = /^([ ]{4}|\t)/;
|
||||
|
||||
CODE = /^[-=]>/;
|
||||
|
||||
MULTI_DENT = /^(?:\n[^\n\S]*)+/;
|
||||
|
|
|
@ -10,7 +10,6 @@ path = require 'path'
|
|||
helpers = require './helpers'
|
||||
optparse = require './optparse'
|
||||
CoffeeScript = require './coffee-script'
|
||||
{rewriteLiterate} = require './lexer'
|
||||
{spawn, exec} = require 'child_process'
|
||||
{EventEmitter} = require 'events'
|
||||
|
||||
|
@ -123,7 +122,8 @@ compileScript = (file, input, base) ->
|
|||
else if o.nodes then printLine CoffeeScript.nodes(t.input, t.options).toString().trim()
|
||||
else if o.run then CoffeeScript.run t.input, t.options
|
||||
else if o.join and t.file isnt o.join
|
||||
sourceCode[sources.indexOf(t.file)] = if helpers.isLiterate file then rewriteLiterate t.input else t.input
|
||||
t.input = helpers.invertLiterate t.input if helpers.isLiterate file
|
||||
sourceCode[sources.indexOf(t.file)] = t.input
|
||||
compileJoin()
|
||||
else
|
||||
compiled = CoffeeScript.compile t.input, t.options
|
||||
|
|
|
@ -60,6 +60,17 @@ exports.some = Array::some ? (fn) ->
|
|||
return true for e in this when fn e
|
||||
false
|
||||
|
||||
# Simple function for inverting Literate CoffeeScript code by putting the
|
||||
# documentation in comments, and bumping the actual code back out to the edge ...
|
||||
# producing a string of CoffeeScript code that can be compiled "normally".
|
||||
exports.invertLiterate = (code) ->
|
||||
lines = for line in code.split('\n')
|
||||
if match = (/^([ ]{4}|\t)/).exec line
|
||||
line[match[0].length..]
|
||||
else
|
||||
'# ' + line
|
||||
lines.join '\n'
|
||||
|
||||
# Merge two jison-style location data objects together.
|
||||
# If `last` is not provided, this will simply return `first`.
|
||||
buildLocationData = (first, last) ->
|
||||
|
|
|
@ -12,16 +12,7 @@
|
|||
{Rewriter, INVERSES} = require './rewriter'
|
||||
|
||||
# Import the helpers we need.
|
||||
{count, starts, compact, last, locationDataToString} = require './helpers'
|
||||
|
||||
# Rewrite literate CoffeeScript code, converting Markdown text into inline comments.
|
||||
exports.rewriteLiterate = rewriteLiterate = (code) ->
|
||||
lines = for line in code.split('\n')
|
||||
if match = LITERATE.exec line
|
||||
line[match[0].length..]
|
||||
else
|
||||
'# ' + line
|
||||
lines.join '\n'
|
||||
{count, starts, compact, last, invertLiterate, locationDataToString} = require './helpers'
|
||||
|
||||
# The Lexer Class
|
||||
# ---------------
|
||||
|
@ -93,7 +84,7 @@ exports.Lexer = class Lexer
|
|||
if WHITESPACE.test code
|
||||
code = "\n#{code}"
|
||||
@chunkLine--
|
||||
code = rewriteLiterate code if @literate
|
||||
code = invertLiterate code if @literate
|
||||
code
|
||||
|
||||
# Tokenizers
|
||||
|
@ -782,8 +773,6 @@ WHITESPACE = /^[^\n\S]+/
|
|||
|
||||
COMMENT = /^###([^#][\s\S]*?)(?:###[^\n\S]*|(?:###)$)|^(?:\s*#(?!##[^#]).*)+/
|
||||
|
||||
LITERATE = /^([ ]{4}|\t)/
|
||||
|
||||
CODE = /^[-=]>/
|
||||
|
||||
MULTI_DENT = /^(?:\n[^\n\S]*)+/
|
||||
|
|
Loading…
Reference in New Issue