Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

new files

  • Loading branch information...
commit df8ce32ce0251ccb67a98843b0d6c8fa21a90e78 1 parent 1e6fbaf
@zakdances authored
Showing with 314 additions and 0 deletions.
  1. +174 −0 .jsc/CSRange.js
  2. +140 −0 CSRange.coffee
View
174 .jsc/CSRange.js
@@ -0,0 +1,174 @@
+// Generated by CoffeeScript 1.6.3
+(function() {
+ var CSAttributedRange, CSRange, root,
+ __hasProp = {}.hasOwnProperty,
+ __extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; };
+
+ root = typeof exports !== "undefined" && exports !== null ? exports : this;
+
+ CSRange = (function() {
+ function CSRange(location, length, options) {
+ var k, o, v, _ref;
+ this.location = location != null ? location : NaN;
+ this.length = length != null ? length : NaN;
+ if (options == null) {
+ options = {};
+ }
+ if (typeof this.location === 'object') {
+ o = this.location;
+ _ref = this.length;
+ for (k in _ref) {
+ v = _ref[k];
+ if (typeof this.length === 'object') {
+ o[k] = v;
+ }
+ }
+ for (k in options) {
+ v = options[k];
+ if (typeof options === 'object') {
+ o[k] = v;
+ }
+ }
+ options = o;
+ }
+ this.location = typeof this.location === 'number' ? this.location : NaN;
+ this.length = typeof this.length === 'number' ? this.length : NaN;
+ for (k in options) {
+ v = options[k];
+ if (k === 'location') {
+ this.location = v;
+ } else if (k === 'length') {
+ this.length = v;
+ }
+ }
+ }
+
+ CSRange.newRangeFromArray = function(a, options) {
+ if (options == null) {
+ options = {};
+ }
+ return new CSRange(a[0], a.length, options);
+ };
+
+ CSRange.newRangeFromRange = function(range) {
+ var options;
+ if (range) {
+ options = {};
+ return new CSRange(range.location, range.length, options);
+ }
+ };
+
+ CSRange.prototype.range = function(a, b) {
+ if (a != null) {
+ if (typeof a === 'object' && (a.location != null) && (a.length != null)) {
+ this.location = a.location;
+ this.length = a.length;
+ } else if ((b != null) && typeof a === 'number' && typeof b === 'number') {
+ this.location = a;
+ this.length = b;
+ }
+ }
+ return {
+ location: this.location,
+ length: this.length
+ };
+ };
+
+ CSRange.prototype.maxEdge = function() {
+ return this.location + this.length;
+ };
+
+ CSRange.prototype.array = function(a) {
+ var _i, _ref, _ref1, _results;
+ if (a) {
+ this.range(a[0], a.length);
+ }
+ if (this.length) {
+ return (function() {
+ _results = [];
+ for (var _i = _ref = this.location, _ref1 = this.maxEdge(); _ref <= _ref1 ? _i < _ref1 : _i > _ref1; _ref <= _ref1 ? _i++ : _i--){ _results.push(_i); }
+ return _results;
+ }).apply(this);
+ } else {
+ return [];
+ }
+ };
+
+ CSRange.prototype.newJSON = function() {
+ var j, k, v, _ref;
+ j = {
+ location: this.location,
+ length: this.length
+ };
+ _ref = this.modes;
+ for (k in _ref) {
+ v = _ref[k];
+ if (k !== j.mode) {
+ j.modes[k] = {
+ location: v.location,
+ length: v.length
+ };
+ }
+ }
+ return j;
+ };
+
+ CSRange.newRangeFromJSON = function(j, options) {
+ var le, lo;
+ if (options == null) {
+ options = {};
+ }
+ lo = j.location;
+ le = j.length;
+ if ((lo != null) && (le != null)) {
+ return new CSRange(lo, le, options);
+ }
+ return null;
+ };
+
+ return CSRange;
+
+ })();
+
+ CSAttributedRange = (function(_super) {
+ __extends(CSAttributedRange, _super);
+
+ function CSAttributedRange(location, length, options) {
+ var o;
+ this.location = location != null ? location : NaN;
+ this.length = length != null ? length : NaN;
+ if (options == null) {
+ options = {};
+ }
+ o = typeof this.location === 'object' ? this.location : void 0;
+ CSAttributedRange.__super__.constructor.call(this, this.location, this.length, options);
+ this.attributes = {};
+ if (typeof o === 'object' && o.attributes) {
+ this.addAttributes(o.attributes);
+ }
+ if (options.attributes) {
+ this.addAttributes(options.attributes);
+ }
+ }
+
+ CSAttributedRange.prototype.addAttribute = function(k, v) {
+ this.attributes[k] = v;
+ };
+
+ CSAttributedRange.prototype.addAttributes = function(attributesToAdd) {
+ var k, v;
+ for (k in attributesToAdd) {
+ v = attributesToAdd[k];
+ this.addAttribute(k, v);
+ }
+ };
+
+ return CSAttributedRange;
+
+ })(CSRange);
+
+ root.CSRange = CSRange;
+
+ root.CSAttributedRange = CSAttributedRange;
+
+}).call(this);
View
140 CSRange.coffee
@@ -0,0 +1,140 @@
+root = exports ? this
+
+class CSRange
+ constructor: (@location=NaN, @length=NaN, options={}) ->
+ # initialOptions = initialOptions ? {}
+
+ if typeof @location is 'object'
+ o = @location
+ o[k] = v for k, v of @length when typeof @length is 'object'
+ o[k] = v for k, v of options when typeof options is 'object'
+ options = o
+
+ @location = if typeof @location is 'number' then @location else NaN
+ @length = if typeof @length is 'number' then @length else NaN
+
+ # defaultContextName = options['defaultContextName'] ? 'local'
+
+ # @contexts = {}
+
+ # @options = {}
+ for k, v of options
+ if k == 'location' then @location = v
+ else if k == 'length' then @length = v
+
+ # else @options[k] = v
+
+
+ # @c defaultContextName, default: true if not @c(defaultContextName)?
+
+ # @contexts[options['defaultContextName'] ? 'local'] = @
+
+ # @mode = @options.defaultContextName
+ # @classes = ['CSRange']
+ # @addMode: (modeName, range) ->
+ # @modes[modeName] = range
+
+ @newRangeFromArray: (a, options={}) ->
+ new CSRange a[0], a.length, options
+
+ @newRangeFromRange: (range) ->
+ if range
+ options = {}
+ # options.contexts = range.c()
+ new CSRange range.location, range.length, options
+
+
+
+ range: (a, b) ->
+
+ if a?
+ if typeof a == 'object' and a.location? and a.length?
+ @location = a.location
+ @length = a.length
+ else if b? and typeof a == 'number' and typeof b == 'number'
+ @location = a
+ @length = b
+
+ location : @location
+ length : @length
+ # TODO: Should this be recursive?
+ # locationOfMode: (modeName, newLocation) ->
+ # m = @mode[modeName]
+ # lo = if newLocation then m.location(newLocation) else m.location()
+ # lo
+
+ # lengthOfMode: (modeName, newLength) ->
+ # m = @mode[modeName]
+ # le = if newLocation then m.location(newLocation) else m.location()
+ # le
+
+ # TODO: fat arrow?
+ maxEdge: () ->
+ @location + @length
+
+ array: (a) ->
+ if a
+ @range a[0], a.length
+
+ if @length then [@location...@maxEdge()] else []
+
+ # nArray: () ->
+ # if @length > 0 then @array() else []
+
+ # TODO: This needs to be recursive.
+ newJSON: () ->
+ j =
+ location : @location
+ length : @length
+ # contexts : @contexts
+
+ # dmn = [@options.defaultModeName] # Default mode name.
+ # j.modes[dmn] = 'this'
+
+ for k, v of @modes when k != j.mode
+ j.modes[k] =
+ location: v.location
+ length : v.length
+ j
+
+ @newRangeFromJSON: (j, options={}) ->
+ lo = j.location
+ le = j.length
+ if lo? and le?
+ return new CSRange lo, le, options
+ null
+
+
+
+# class CSTextRange extends CSRange
+# constructor: (@location=0, @length=0, @lines=[]) ->
+
+
+class CSAttributedRange extends CSRange
+ constructor: (@location=NaN, @length=NaN, options={}) ->
+ o = if typeof @location is 'object' then @location
+ super @location, @length, options
+
+ # attributes = options.attributes ? {}
+ @attributes = {}
+ @addAttributes o.attributes if typeof o is 'object' and o.attributes
+ @addAttributes options.attributes if options.attributes
+ # for k, v of options.attributes ? {}
+ # @attributes[k] = v
+
+ # copy: () ->
+ # _shallowCopy CSAttributedRange
+ addAttribute: (k, v) ->
+ @attributes[k] = v
+ return
+
+ addAttributes: (attributesToAdd) ->
+ @addAttribute k, v for k, v of attributesToAdd
+ return
+# class CSSingleTextLineRange extends CSRange
+# constructor: (@location=0, @length=0, @lineNumber=0) ->
+
+root.CSRange = CSRange
+# root.CSTextRange = CSTextRange
+root.CSAttributedRange = CSAttributedRange
+# root.CSSingleTextLineRange = CSSingleTextLineRange
Please sign in to comment.
Something went wrong with that request. Please try again.