Commit 0cb36154 authored by Dmitry.Shahtanov's avatar Dmitry.Shahtanov

добавлен оператор intersection(" ") в формулах spreadsheets

git-svn-id: svn://192.168.3.15/activex/AVS/Sources/TeamlabOffice/trunk/OfficeWeb@68690 954022d7-b5bf-4e40-9824-e11837661b57
parent b289fb04
...@@ -1147,13 +1147,13 @@ parserHelper.prototype.is3DRef = function ( formula, start_pos ) { ...@@ -1147,13 +1147,13 @@ parserHelper.prototype.is3DRef = function ( formula, start_pos ) {
} }
return [false, null, null]; return [false, null, null];
}; };
parserHelper.prototype.isNextPtg = function ( formula, start_pos ) { parserHelper.prototype.isNextPtg = function ( formula, start_pos, digitDelim ) {
if ( this instanceof parserHelper ) { if ( this instanceof parserHelper ) {
this._reset(); this._reset();
} }
var subSTR = formula.substring( start_pos ), match; var subSTR = formula.substring( start_pos ), match;
if( subSTR.match( rx_before_operators ) == null && (match = subSTR.match( rx_intersect )) != null ){ if( subSTR.match( rx_RightParentheses ) == null && subSTR.match( digitDelim?rx_Comma:rx_CommaDef ) == null && subSTR.match( rx_operators ) == null && (match = subSTR.match( rx_intersect )) != null ){
this.pCurrPos += match[0].length; this.pCurrPos += match[0].length;
this.operand_str = match[0][0]; this.operand_str = match[0][0];
return true; return true;
...@@ -1181,7 +1181,7 @@ parserHelper.prototype.isLeftParentheses = function ( formula, start_pos ) { ...@@ -1181,7 +1181,7 @@ parserHelper.prototype.isLeftParentheses = function ( formula, start_pos ) {
var match = (formula.substring( start_pos )).match( rx_LeftParentheses ); var match = (formula.substring( start_pos )).match( rx_LeftParentheses );
if (match != null) { if (match != null) {
this.operand_str = match[0].replace( rx_space, "" ); this.operand_str = match[0].replace( rx_space_g, "" );
this.pCurrPos += match[0].length; this.pCurrPos += match[0].length;
return true; return true;
} }
...@@ -1194,7 +1194,7 @@ parserHelper.prototype.isRightParentheses = function ( formula, start_pos ) { ...@@ -1194,7 +1194,7 @@ parserHelper.prototype.isRightParentheses = function ( formula, start_pos ) {
var match = (formula.substring( start_pos )).match( rx_RightParentheses ); var match = (formula.substring( start_pos )).match( rx_RightParentheses );
if (match != null) { if (match != null) {
this.operand_str = match[0].replace( rx_space, "" ); this.operand_str = match[0].replace( rx_space_g, "" );
this.pCurrPos += match[0].length; this.pCurrPos += match[0].length;
return true; return true;
} }
......
...@@ -437,6 +437,35 @@ ...@@ -437,6 +437,35 @@
strictEqual( oParser.calculate().getValue(), 6 ); strictEqual( oParser.calculate().getValue(), 6 );
} ) } )
test( "Test: \"Parse intersection\"", function () {
ws.getRange2( "A7" ).setValue( "1" );
ws.getRange2( "A8" ).setValue( "2" );
ws.getRange2( "A9" ).setValue( "3" );
oParser = new parserFormula( '1 + ( A7 +A8 ) * 2', "A1", ws );
ok( oParser.parse() );
strictEqual( oParser.assemble(), "1+(A7+A8)*2" );
strictEqual( oParser.calculate().getValue(), 7 );
oParser = new parserFormula( 'sum A1:A5', "A1", ws );
ok( oParser.parse() );
strictEqual( oParser.assemble(), "sum A1:A5" );
strictEqual( oParser.calculate().getValue(), "#VALUE!" );
oParser = new parserFormula( 'sum( A1:A5 , B1:B5 ) ', "A1", ws );
ok( oParser.parse() );
strictEqual( oParser.assemble(), "SUM(A1:A5,B1:B5)" );
strictEqual( oParser.calculate().getValue(), 0 );
oParser = new parserFormula( 'sum( A1:A5 , B1:B5 , " 3 , 14 15 92 6 " ) ', "A1", ws );
ok( oParser.parse() );
strictEqual( oParser.assemble(), 'SUM(A1:A5,B1:B5," 3 , 14 15 92 6 ")' );
strictEqual( oParser.calculate().getValue(), "#VALUE!" );
} )
test( "Test: \"Arithmetical operations\"", function () { test( "Test: \"Arithmetical operations\"", function () {
oParser = new parserFormula( '1+3', "A1", ws ); oParser = new parserFormula( '1+3', "A1", ws );
ok( oParser.parse() ); ok( oParser.parse() );
......
...@@ -4020,7 +4020,7 @@ parserFormula.prototype = { ...@@ -4020,7 +4020,7 @@ parserFormula.prototype = {
}*/ }*/
/* Operators*/ /* Operators*/
if ( parserHelp.isOperator.call( this, this.Formula, this.pCurrPos ) /*|| parserHelp.isNextPtg.call( this, this.Formula, this.pCurrPos )*/ ) { if ( parserHelp.isOperator.call( this, this.Formula, this.pCurrPos ) || parserHelp.isNextPtg.call( this, this.Formula, this.pCurrPos ) ) {
wasLeftParentheses = false; wasLeftParentheses = false;
wasRigthParentheses = false; wasRigthParentheses = false;
found_operator = null; found_operator = null;
...@@ -4034,6 +4034,9 @@ parserFormula.prototype = { ...@@ -4034,6 +4034,9 @@ parserFormula.prototype = {
this.operand_expected = true; this.operand_expected = true;
found_operator = new cFormulaOperators['un_plus'](); found_operator = new cFormulaOperators['un_plus']();
} }
else if( this.operand_str == " " ){
continue;
}
else { else {
this.error.push( c_oAscError.ID.FrmlWrongOperator ); this.error.push( c_oAscError.ID.FrmlWrongOperator );
this.outStack = []; this.outStack = [];
...@@ -4058,6 +4061,9 @@ parserFormula.prototype = { ...@@ -4058,6 +4061,9 @@ parserFormula.prototype = {
this.operand_expected = false; this.operand_expected = false;
found_operator = new cFormulaOperators['%'](); found_operator = new cFormulaOperators['%']();
} }
else if ( this.operand_str == " " && this.pCurrPos == this.Formula.length) {
continue;
}
else { else {
if ( this.operand_str in cFormulaOperators ) { if ( this.operand_str in cFormulaOperators ) {
found_operator = new cFormulaOperators[this.operand_str](); found_operator = new cFormulaOperators[this.operand_str]();
...@@ -4218,7 +4224,7 @@ parserFormula.prototype = { ...@@ -4218,7 +4224,7 @@ parserFormula.prototype = {
var arr = new cArray(), operator = { isOperator: false, operatorName: ""}; var arr = new cArray(), operator = { isOperator: false, operatorName: ""};
while ( this.pCurrPos < this.Formula.length && !parserHelp.isRightBrace.call(this, this.Formula, this.pCurrPos) ) { while ( this.pCurrPos < this.Formula.length && !parserHelp.isRightBrace.call(this, this.Formula, this.pCurrPos) ) {
if ( parserHelp.isArraySeparator.call( this, this.Formula, this.pCurrPos, digitDelim ) ) { if ( parserHelp.isArraySeparator.call( this, this.Formula, this.pCurrPos, digitDelim ) ) {
if ( this.operand_str == (digitDelim ? arrayRowSeparator : arrayRowSeparatorDef) ) { if ( digitDelim ? rx_arraySeparators.test(this.operand_str) : rx_arraySeparatorsDef.test(this.operand_str) ) {
arr.addRow(); arr.addRow();
} }
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment