-
-
Notifications
You must be signed in to change notification settings - Fork 115
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
37 changed files
with
5,420 additions
and
1 deletion.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
"use strict"; | ||
|
||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
exports.addCommentBefore = addCommentBefore; | ||
exports.default = addComment; | ||
|
||
function addCommentBefore(str, indent, comment) { | ||
if (!comment) return str; | ||
var cc = comment.replace(/[\s\S]^/gm, "$&".concat(indent, "#")); | ||
return "#".concat(cc, "\n").concat(indent).concat(str); | ||
} | ||
|
||
function addComment(str, indent, comment) { | ||
return !comment ? str : comment.indexOf('\n') === -1 ? "".concat(str, " #").concat(comment) : "".concat(str, "\n") + comment.replace(/^/gm, "".concat(indent || '', "#")); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
"use strict"; | ||
|
||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
exports.default = void 0; | ||
|
||
var _Node2 = _interopRequireDefault(require("./Node")); | ||
|
||
var _Range = _interopRequireDefault(require("./Range")); | ||
|
||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
|
||
function _typeof(obj) { if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); } | ||
|
||
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } | ||
|
||
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } _setPrototypeOf(subClass.prototype, superClass && superClass.prototype); if (superClass) _setPrototypeOf(subClass, superClass); } | ||
|
||
function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); } | ||
|
||
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } | ||
|
||
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; } | ||
|
||
function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); } | ||
|
||
function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; } | ||
|
||
function _getPrototypeOf(o) { _getPrototypeOf = Object.getPrototypeOf || function _getPrototypeOf(o) { return o.__proto__; }; return _getPrototypeOf(o); } | ||
|
||
var Alias = | ||
/*#__PURE__*/ | ||
function (_Node) { | ||
function Alias() { | ||
_classCallCheck(this, Alias); | ||
|
||
return _possibleConstructorReturn(this, _getPrototypeOf(Alias).apply(this, arguments)); | ||
} | ||
|
||
_createClass(Alias, [{ | ||
key: "parse", | ||
|
||
/** | ||
* Parses an *alias from the source | ||
* | ||
* @param {ParseContext} context | ||
* @param {number} start - Index of first character | ||
* @returns {number} - Index of the character after this scalar | ||
*/ | ||
value: function parse(context, start) { | ||
this.context = context; | ||
var src = context.src; | ||
|
||
var offset = _Node2.default.endOfIdentifier(src, start + 1); | ||
|
||
this.valueRange = new _Range.default(start + 1, offset); | ||
offset = _Node2.default.endOfWhiteSpace(src, offset); | ||
offset = this.parseComment(offset); | ||
return offset; | ||
} | ||
}]); | ||
|
||
_inherits(Alias, _Node); | ||
|
||
return Alias; | ||
}(_Node2.default); | ||
|
||
exports.default = Alias; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,255 @@ | ||
"use strict"; | ||
|
||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
exports.default = exports.Chomp = void 0; | ||
|
||
var _Node2 = _interopRequireWildcard(require("./Node")); | ||
|
||
var _Range = _interopRequireDefault(require("./Range")); | ||
|
||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
|
||
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = Object.defineProperty && Object.getOwnPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : {}; if (desc.get || desc.set) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } } newObj.default = obj; return newObj; } } | ||
|
||
function _typeof(obj) { if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); } | ||
|
||
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } | ||
|
||
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } _setPrototypeOf(subClass.prototype, superClass && superClass.prototype); if (superClass) _setPrototypeOf(subClass, superClass); } | ||
|
||
function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); } | ||
|
||
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } | ||
|
||
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; } | ||
|
||
function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); } | ||
|
||
function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; } | ||
|
||
function _getPrototypeOf(o) { _getPrototypeOf = Object.getPrototypeOf || function _getPrototypeOf(o) { return o.__proto__; }; return _getPrototypeOf(o); } | ||
|
||
var Chomp = { | ||
CLIP: 'CLIP', | ||
KEEP: 'KEEP', | ||
STRIP: 'STRIP' | ||
}; | ||
exports.Chomp = Chomp; | ||
|
||
var BlockValue = | ||
/*#__PURE__*/ | ||
function (_Node) { | ||
function BlockValue(type, props) { | ||
var _this; | ||
|
||
_classCallCheck(this, BlockValue); | ||
|
||
_this = _possibleConstructorReturn(this, _getPrototypeOf(BlockValue).call(this, type, props)); | ||
_this.blockIndent = null; | ||
_this.chomping = Chomp.CLIP; | ||
_this.header = null; | ||
return _this; | ||
} | ||
|
||
_createClass(BlockValue, [{ | ||
key: "parseBlockHeader", | ||
value: function parseBlockHeader(start) { | ||
var src = this.context.src; | ||
var offset = start + 1; | ||
var bi = ''; | ||
|
||
while (true) { | ||
var ch = src[offset]; | ||
|
||
switch (ch) { | ||
case '-': | ||
this.chomping = Chomp.STRIP; | ||
break; | ||
|
||
case '+': | ||
this.chomping = Chomp.KEEP; | ||
break; | ||
|
||
case '0': | ||
case '1': | ||
case '2': | ||
case '3': | ||
case '4': | ||
case '5': | ||
case '6': | ||
case '7': | ||
case '8': | ||
case '9': | ||
bi += ch; | ||
break; | ||
|
||
default: | ||
this.blockIndent = Number(bi) || null; | ||
this.header = new _Range.default(start, offset); | ||
return offset; | ||
} | ||
|
||
offset += 1; | ||
} | ||
} | ||
}, { | ||
key: "parseBlockValue", | ||
value: function parseBlockValue(start) { | ||
var _this$context = this.context, | ||
indent = _this$context.indent, | ||
inFlow = _this$context.inFlow, | ||
src = _this$context.src; | ||
var offset = start; | ||
var bi = this.blockIndent ? indent + this.blockIndent - 1 : indent; | ||
var minBlockIndent = 1; | ||
|
||
for (var ch = src[offset]; ch === '\n'; ch = src[offset]) { | ||
offset += 1; | ||
if (_Node2.default.atDocumentBoundary(src, offset)) break; | ||
|
||
var end = _Node2.default.endOfBlockIndent(src, bi, offset); // should not include tab? | ||
|
||
|
||
if (end === null) break; | ||
|
||
if (!this.blockIndent) { | ||
// no explicit block indent, none yet detected | ||
var lineIndent = end - (offset + indent); | ||
|
||
if (src[end] !== '\n') { | ||
// first line with non-whitespace content | ||
if (lineIndent < minBlockIndent) { | ||
offset -= 1; | ||
break; | ||
} | ||
|
||
this.blockIndent = lineIndent; | ||
bi = indent + this.blockIndent - 1; | ||
} else if (lineIndent > minBlockIndent) { | ||
// empty line with more whitespace | ||
minBlockIndent = lineIndent; | ||
} | ||
} | ||
|
||
offset = _Node2.default.endOfLine(src, end); | ||
} | ||
|
||
this.valueRange = new _Range.default(start + 1, offset); | ||
return offset; | ||
} | ||
/** | ||
* Parses a block value from the source | ||
* | ||
* Accepted forms are: | ||
* ``` | ||
* BS | ||
* block | ||
* lines | ||
* | ||
* BS #comment | ||
* block | ||
* lines | ||
* ``` | ||
* where the block style BS matches the regexp `[|>][-+1-9]*` and block lines | ||
* are empty or have an indent level greater than `indent`. | ||
* | ||
* @param {ParseContext} context | ||
* @param {number} start - Index of first character | ||
* @returns {number} - Index of the character after this block | ||
*/ | ||
|
||
}, { | ||
key: "parse", | ||
value: function parse(context, start) { | ||
this.context = context; | ||
var src = context.src; | ||
var offset = this.parseBlockHeader(start); | ||
offset = _Node2.default.endOfWhiteSpace(src, offset); | ||
offset = this.parseComment(offset); | ||
offset = this.parseBlockValue(offset); | ||
return offset; | ||
} | ||
}, { | ||
key: "strValue", | ||
get: function get() { | ||
if (!this.valueRange || !this.context) return null; | ||
var _this$valueRange = this.valueRange, | ||
start = _this$valueRange.start, | ||
end = _this$valueRange.end; | ||
var _this$context2 = this.context, | ||
indent = _this$context2.indent, | ||
src = _this$context2.src; | ||
if (this.valueRange.isEmpty) return ''; | ||
var lastNewLine = null; | ||
var ch = src[end - 1]; | ||
|
||
while (ch === '\n' || ch === '\t' || ch === ' ') { | ||
end -= 1; | ||
|
||
if (end <= start) { | ||
if (this.chomping === Chomp.KEEP) break;else return ''; | ||
} | ||
|
||
if (ch === '\n') lastNewLine = end; | ||
ch = src[end - 1]; | ||
} | ||
|
||
var keepStart = end + 1; | ||
|
||
if (lastNewLine) { | ||
if (this.chomping === Chomp.KEEP) { | ||
keepStart = lastNewLine; | ||
end = this.valueRange.end; | ||
} else { | ||
end = lastNewLine; | ||
} | ||
} | ||
|
||
var bi = indent + this.blockIndent; | ||
var folded = this.type === _Node2.Type.BLOCK_FOLDED; | ||
var str = ''; | ||
var sep = ''; | ||
var prevMoreIndented = false; | ||
|
||
for (var i = start; i < end; ++i) { | ||
for (var j = 0; j < bi; ++j) { | ||
if (src[i] !== ' ') break; | ||
i += 1; | ||
} | ||
|
||
var _ch = src[i]; | ||
|
||
if (_ch === '\n') { | ||
if (sep === '\n') str += '\n';else sep = '\n'; | ||
} else { | ||
var lineEnd = _Node2.default.endOfLine(src, i); | ||
|
||
var line = src.slice(i, lineEnd); | ||
i = lineEnd; | ||
|
||
if (folded && (_ch === ' ' || _ch === '\t') && i < keepStart) { | ||
if (sep === ' ') sep = '\n';else if (!prevMoreIndented && sep === '\n') sep = '\n\n'; | ||
str += sep + line; //+ ((lineEnd < end && src[lineEnd]) || '') | ||
|
||
sep = lineEnd < end && src[lineEnd] || ''; | ||
prevMoreIndented = true; | ||
} else { | ||
str += sep + line; | ||
sep = folded && i < keepStart ? ' ' : '\n'; | ||
prevMoreIndented = false; | ||
} | ||
} | ||
} | ||
|
||
return this.chomping === Chomp.STRIP ? str : str + '\n'; | ||
} | ||
}]); | ||
|
||
_inherits(BlockValue, _Node); | ||
|
||
return BlockValue; | ||
}(_Node2.default); | ||
|
||
exports.default = BlockValue; |
Oops, something went wrong.