Browse Source

StateBlock cleanup

pull/14/head
Vitaly Puzrin 10 years ago
parent
commit
7ea9c2cffb
  1. 29
      lib/rules_block/state_block.js

29
lib/rules_block/state_block.js

@ -3,7 +3,7 @@
'use strict';
function State(src, parser, tokens, options, env) {
function StateBlock(src, parser, tokens, options, env) {
var ch, s, start, pos, len, indent, indent_found;
// Prepare string to parse:
@ -62,20 +62,15 @@ function State(src, parser, tokens, options, env) {
}
}
if (ch === 0x0A || ch === 0x0D) {
if (ch === 0x0A) {
this.bMarks.push(start);
this.eMarks.push(pos);
indent_found = false;
indent = 0;
start = pos + 1;
if (ch === 0x0D && pos + 1 < len && s.charCodeAt(pos + 1) === 0x0A) {
pos++;
start++;
}
}
}
if (ch !== 0x0D || ch !== 0x0A) {
if (ch !== 0x0A) {
this.bMarks.push(start);
this.eMarks.push(len);
if (!indent_found) { this.tShift.push(indent); }
@ -89,11 +84,11 @@ function State(src, parser, tokens, options, env) {
this.lineMax = this.bMarks.length - 1; // don't count last fake line
}
State.prototype.isEmpty = function isEmpty(line) {
StateBlock.prototype.isEmpty = function isEmpty(line) {
return this.bMarks[line] + this.tShift[line] >= this.eMarks[line];
};
State.prototype.skipEmptyLines = function skipEmptyLines(from) {
StateBlock.prototype.skipEmptyLines = function skipEmptyLines(from) {
for (var max = this.lineMax; from < max; from++) {
if (this.bMarks[from] + this.tShift[from] < this.eMarks[from]) {
break;
@ -103,7 +98,7 @@ State.prototype.skipEmptyLines = function skipEmptyLines(from) {
};
// Skip spaces from given position.
State.prototype.skipSpaces = function skipSpaces(pos) {
StateBlock.prototype.skipSpaces = function skipSpaces(pos) {
for (var max = this.src.length; pos < max; pos++) {
if (this.src.charCodeAt(pos) !== 0x20/* space */) { break; }
}
@ -111,7 +106,7 @@ State.prototype.skipSpaces = function skipSpaces(pos) {
};
// Skip char codes from given position
State.prototype.skipChars = function skipChars(pos, code) {
StateBlock.prototype.skipChars = function skipChars(pos, code) {
for (var max = this.src.length; pos < max; pos++) {
if (this.src.charCodeAt(pos) !== code) { break; }
}
@ -119,7 +114,7 @@ State.prototype.skipChars = function skipChars(pos, code) {
};
// Skip char codes reverse from given position - 1
State.prototype.skipCharsBack = function skipCharsBack(pos, code, min) {
StateBlock.prototype.skipCharsBack = function skipCharsBack(pos, code, min) {
if (pos <= min) { return pos; }
while (pos > min) {
@ -129,7 +124,7 @@ State.prototype.skipCharsBack = function skipCharsBack(pos, code, min) {
};
// cut lines range from source.
State.prototype.getLines = function getLines(begin, end, indent, keepLastLF) {
StateBlock.prototype.getLines = function getLines(begin, end, indent, keepLastLF) {
var i, first, last, queue, shift,
line = begin;
@ -167,8 +162,8 @@ State.prototype.getLines = function getLines(begin, end, indent, keepLastLF) {
};
// Create shadow clone of curent state with new input data
State.prototype.clone = function clone(src) {
return new State(
StateBlock.prototype.clone = function clone(src) {
return new StateBlock(
src,
this.parser,
this.tokens,
@ -176,4 +171,4 @@ State.prototype.clone = function clone(src) {
);
};
module.exports = State;
module.exports = StateBlock;

Loading…
Cancel
Save