Merge pull request #2405 from webzwo0i/fix-lineassembler-not-finished
Fix lineassembler not finished
This commit is contained in:
commit
19c78212e8
|
@ -507,6 +507,10 @@ exports.opAssembler = function () {
|
||||||
*/
|
*/
|
||||||
exports.stringIterator = function (str) {
|
exports.stringIterator = function (str) {
|
||||||
var curIndex = 0;
|
var curIndex = 0;
|
||||||
|
var newLines = str.split("\n").length - 1
|
||||||
|
function getnewLines(){
|
||||||
|
return newLines
|
||||||
|
}
|
||||||
|
|
||||||
function assertRemaining(n) {
|
function assertRemaining(n) {
|
||||||
exports.assert(n <= remaining(), "!(", n, " <= ", remaining(), ")");
|
exports.assert(n <= remaining(), "!(", n, " <= ", remaining(), ")");
|
||||||
|
@ -515,6 +519,7 @@ exports.stringIterator = function (str) {
|
||||||
function take(n) {
|
function take(n) {
|
||||||
assertRemaining(n);
|
assertRemaining(n);
|
||||||
var s = str.substr(curIndex, n);
|
var s = str.substr(curIndex, n);
|
||||||
|
newLines -= s.split("\n").length - 1
|
||||||
curIndex += n;
|
curIndex += n;
|
||||||
return s;
|
return s;
|
||||||
}
|
}
|
||||||
|
@ -537,7 +542,8 @@ exports.stringIterator = function (str) {
|
||||||
take: take,
|
take: take,
|
||||||
skip: skip,
|
skip: skip,
|
||||||
remaining: remaining,
|
remaining: remaining,
|
||||||
peek: peek
|
peek: peek,
|
||||||
|
newlines: getnewLines
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -910,6 +916,8 @@ exports.applyToText = function (cs, str) {
|
||||||
var csIter = exports.opIterator(unpacked.ops);
|
var csIter = exports.opIterator(unpacked.ops);
|
||||||
var bankIter = exports.stringIterator(unpacked.charBank);
|
var bankIter = exports.stringIterator(unpacked.charBank);
|
||||||
var strIter = exports.stringIterator(str);
|
var strIter = exports.stringIterator(str);
|
||||||
|
var newlines = 0
|
||||||
|
var newlinefail = false
|
||||||
var assem = exports.stringAssembler();
|
var assem = exports.stringAssembler();
|
||||||
while (csIter.hasNext()) {
|
while (csIter.hasNext()) {
|
||||||
var op = csIter.next();
|
var op = csIter.next();
|
||||||
|
@ -919,16 +927,24 @@ exports.applyToText = function (cs, str) {
|
||||||
break;
|
break;
|
||||||
case '-':
|
case '-':
|
||||||
removedLines += op.lines;
|
removedLines += op.lines;
|
||||||
|
newlines = strIter.newlines()
|
||||||
strIter.skip(op.chars);
|
strIter.skip(op.chars);
|
||||||
|
if(!(newlines - strIter.newlines() == 0) && (newlines - strIter.newlines() != op.lines)){
|
||||||
|
newlinefail = true
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
case '=':
|
case '=':
|
||||||
|
newlines = strIter.newlines()
|
||||||
assem.append(strIter.take(op.chars));
|
assem.append(strIter.take(op.chars));
|
||||||
|
if(!(newlines - strIter.newlines() == op.lines)){
|
||||||
|
newlinefail = true
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
exports.assert(totalNrOfLines >= removedLines,"cannot remove ", removedLines, " lines from text with ", totalNrOfLines, " lines");
|
exports.assert(totalNrOfLines >= removedLines,"cannot remove ", removedLines, " lines from text with ", totalNrOfLines, " lines");
|
||||||
assem.append(strIter.take(strIter.remaining()));
|
assem.append(strIter.take(strIter.remaining()));
|
||||||
return assem.toString();
|
return [assem.toString(),newlinefail];
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -1599,8 +1615,12 @@ exports.makeAText = function (text, attribs) {
|
||||||
* @param pool {AttribPool} Attribute Pool to add to
|
* @param pool {AttribPool} Attribute Pool to add to
|
||||||
*/
|
*/
|
||||||
exports.applyToAText = function (cs, atext, pool) {
|
exports.applyToAText = function (cs, atext, pool) {
|
||||||
|
var text = exports.applyToText(cs, atext.text)
|
||||||
|
if(text[1]){
|
||||||
|
throw new Error()
|
||||||
|
}
|
||||||
return {
|
return {
|
||||||
text: exports.applyToText(cs, atext.text),
|
text: text[0],
|
||||||
attribs: exports.applyToAttribution(cs, atext.attribs, pool)
|
attribs: exports.applyToAttribution(cs, atext.attribs, pool)
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in New Issue