Permalink
Browse files

fixed subexpressions formatting for formatFormula

  • Loading branch information...
1 parent 574390b commit 5c0338b06f5cedcc852773bc9e6ddbea12caf64c @joshbtn committed Oct 25, 2012
View
9 excelFormulaUtilities-0.9.4.js
@@ -187,7 +187,8 @@
* http://jquery.org/license
*
* Based on Ewbi's Go Calc Prototype Excel Formula Parser. [http://ewbi.blogs.com/develops/2004/12/excel_formula_p.html]
- */ (function () {
+ */
+(function () {
if (typeof window === 'undefined') {
window = root;
}
@@ -1002,7 +1003,7 @@
var formatFormula = excelFormulaUtilities.formatFormula = function (formula, options) {
var isFirstToken = true,
defaultOptions = {
- tmplFunctionStart: '\n{{autoindent}}{{token}}(\n',
+ tmplFunctionStart: '{{autoindent}}{{token}}(\n',
tmplFunctionStop: '\n{{autoindent}}{{token}})',
tmplOperandError: ' {{token}}',
tmplOperandRange: '{{autoindent}}{{token}}',
@@ -1014,8 +1015,8 @@
tmplFunctionStartArrayRow: '{',
tmplFunctionStopArrayRow: '}',
tmplFunctionStopArray: '',
- tmplSubexpressionStart: '{{autoindent}}(',
- tmplSubexpressionStop: ' )',
+ tmplSubexpressionStart: '{{autoindent}}(\n',
+ tmplSubexpressionStop: '\n)',
tmplIndentTab: '\t',
tmplIndentSpace: ' ',
autoLineBreak: 'TOK_TYPE_FUNCTION | TOK_TYPE_ARGUMENT | TOK_SUBTYPE_LOGICAL | TOK_TYPE_OP_IN ',
View
4 excelFormulaUtilities-0.9.4.min.js
@@ -15,8 +15,8 @@ f,c,d);break;case "argument":f=h(a(b.tmplArgument),f,c,d);break;case "subexpress
j.TOK_TYPE_FUNCTION="function",s=j.TOK_TYPE_SUBEXPR="subexpression",z=j.TOK_TYPE_ARGUMENT="argument",E=j.TOK_TYPE_OP_PRE="operator-prefix",t=j.TOK_TYPE_OP_IN="operator-infix",B=j.TOK_TYPE_OP_POST="operator-postfix",D=j.TOK_TYPE_WSPACE="white-space",y=j.TOK_TYPE_UNKNOWN="unknown",q=j.TOK_SUBTYPE_START="start",p=j.TOK_SUBTYPE_STOP="stop",H=j.TOK_SUBTYPE_TEXT="text",M=j.TOK_SUBTYPE_NUMBER="number",A=j.TOK_SUBTYPE_LOGICAL="logical",I=j.TOK_SUBTYPE_ERROR="error",F=j.TOK_SUBTYPE_RANGE="range",C=j.TOK_SUBTYPE_MATH=
"math",L=j.TOK_SUBTYPE_CONCAT="concatenate",K=j.TOK_SUBTYPE_INTERSECT="intersect",J=j.TOK_SUBTYPE_UNION="union";i.parseFormula=function(g,b){var c=0,d=document.getElementById(g),e=v(d.value),a;for(a="<table cellspacing='0' style='border-top: 1px #cecece solid; margin-top: 5px; margin-bottom: 5px'><tr><td class='token' style='font-weight: bold; width: 50px'>index</td><td class='token' style='font-weight: bold; width: 125px'>type</td><td class='token' style='font-weight: bold; width: 125px'>subtype</td><td class='token' style='font-weight: bold; width: 150px'>token</td><td class='token' style='font-weight: bold; width: 300px'>token tree</td></tr>";e.moveNext();){var f=
e.current();f.subtype===p&&(c-=0<c?1:0);a+="<tr>";a+="<td class='token'>"+(e.index+1)+"</td>";a+="<td class='token'>"+f.type+"</td>";a+="<td class='token'>"+(0===f.subtype.length?"&nbsp;":f.subtype.toString())+"</td>";a+="<td class='token'>"+(0===f.value.length?"&nbsp;":f.value).split(" ").join("&nbsp;")+"</td>";for(var i="|",h=0;h<c;h+=1)i+="&nbsp;&nbsp;&nbsp;|";a+="<td class='token'>"+i+(0===f.value.length?"&nbsp;":f.value).split(" ").join("&nbsp;")+"</td>";a+="</tr>";f.subtype===q&&(c+=1)}document.getElementById(b).innerHTML=
-a+"</table>";d.select();d.focus()};var G=i.formatFormula=function(g,b){for(var c={tmplFunctionStart:"\n{{autoindent}}{{token}}(\n",tmplFunctionStop:"\n{{autoindent}}{{token}})",tmplOperandError:" {{token}}",tmplOperandRange:"{{autoindent}}{{token}}",tmplOperandLogical:" {{token}}{{autolinebreak}}",tmplOperandNumber:"{{autoindent}}{{token}}",tmplOperandText:'{{autoindent}}"{{token}}"',tmplArgument:"{{token}}\n",tmplFunctionStartArray:"",tmplFunctionStartArrayRow:"{",tmplFunctionStopArrayRow:"}",tmplFunctionStopArray:"",
-tmplSubexpressionStart:"{{autoindent}}(",tmplSubexpressionStop:" )",tmplIndentTab:"\t",tmplIndentSpace:" ",autoLineBreak:"TOK_TYPE_FUNCTION | TOK_TYPE_ARGUMENT | TOK_SUBTYPE_LOGICAL | TOK_TYPE_OP_IN ",newLine:"\n",customTokenRender:null,prefix:"",postfix:""},b=b?m.extend(!0,c,b):c,c=0,d=v(g),e="",a=b.autoLineBreak.replace(/\s/gi,"").split("|"),f=!0;d.moveNext();){var i=d.current(),h=d.next();i.subtype.toString()===p&&(c-=0<c?1:0);var l=RegExp(b.newLine+"$","");a:{for(var k=0;k<a.length;k+=1)if(null!==
+a+"</table>";d.select();d.focus()};var G=i.formatFormula=function(g,b){for(var c={tmplFunctionStart:"{{autoindent}}{{token}}(\n",tmplFunctionStop:"\n{{autoindent}}{{token}})",tmplOperandError:" {{token}}",tmplOperandRange:"{{autoindent}}{{token}}",tmplOperandLogical:" {{token}}{{autolinebreak}}",tmplOperandNumber:"{{autoindent}}{{token}}",tmplOperandText:'{{autoindent}}"{{token}}"',tmplArgument:"{{token}}\n",tmplFunctionStartArray:"",tmplFunctionStartArrayRow:"{",tmplFunctionStopArrayRow:"}",tmplFunctionStopArray:"",
+tmplSubexpressionStart:"{{autoindent}}(\n",tmplSubexpressionStop:"\n)",tmplIndentTab:"\t",tmplIndentSpace:" ",autoLineBreak:"TOK_TYPE_FUNCTION | TOK_TYPE_ARGUMENT | TOK_SUBTYPE_LOGICAL | TOK_TYPE_OP_IN ",newLine:"\n",customTokenRender:null,prefix:"",postfix:""},b=b?m.extend(!0,c,b):c,c=0,d=v(g),e="",a=b.autoLineBreak.replace(/\s/gi,"").split("|"),f=!0;d.moveNext();){var i=d.current(),h=d.next();i.subtype.toString()===p&&(c-=0<c?1:0);var l=RegExp(b.newLine+"$","");a:{for(var k=0;k<a.length;k+=1)if(null!==
h&&"undefined"!==typeof h&&(j[a[k]]===h.type.toString()||j[a[k]]===h.subtype.toString())){h=!0;break a}h=!1}if(f){f="";for(k=0;k<c;k+=1)f+=b.tmplIndentTab}else f=b.tmplIndentSpace;e+=x(i,b,f,h?b.newLine:"",b.customTokenRender);i.subtype.toString()===q&&(c+=1);f=h||l.test(e)}return e=b.prefix+o(e)+b.postfix};i.formatFormulaHTML=function(g){return G(g,{tmplFunctionStart:'{{autoindent}}<span class="function">{{token}}</span><span class="function_start">(</span><br />',tmplFunctionStop:'<br />{{autoindent}}{{token}}<span class="function_stop">)</span>',
tmplOperandError:"{{token}}",tmplOperandRange:"{{autoindent}}{{token}}",tmplOperandLogical:" {{token}}{{autolinebreak}}",tmplOperandNumber:"{{autoindent}}{{token}}",tmplOperandText:'{{autoindent}}<span class="quote_mark">"</span><span class="text">{{token}}</span><span class="quote_mark">"</span>',tmplArgument:"{{token}}<br />",tmplFunctionStartArray:"",tmplFunctionStartArrayRow:"{",tmplFunctionStopArrayRow:"}",tmplFunctionStopArray:"",tmplSubexpressionStart:"{{autoindent}}(",tmplSubexpressionStop:" )",
tmplIndentTab:'<span class="tabbed">&nbsp;&nbsp;&nbsp;&nbsp;</span>',tmplIndentSpace:"&nbsp;",newLine:"<br />",autoLineBreak:"TOK_TYPE_FUNCTION | TOK_TYPE_ARGUMENT | TOK_SUBTYPE_LOGICAL | TOK_TYPE_OP_IN ",trim:!0,prefix:"=",customTokenRender:null})};var N=i.formula2CSharp=function(g){var b=[];return G(g,{tmplFunctionStart:"{{token}}(",tmplFunctionStop:"{{token}})",tmplOperandError:"{{token}}",tmplOperandRange:"{{token}}",tmplOperandLogical:"{{token}}",tmplOperandNumber:"{{token}}",tmplOperandText:'"{{token}}"',
View
6 src/ExcelFormulaUtilities.js
@@ -828,7 +828,7 @@
var formatFormula = excelFormulaUtilities.formatFormula = function (formula, options) {
var isFirstToken = true,
defaultOptions = {
- tmplFunctionStart: '\n{{autoindent}}{{token}}(\n',
+ tmplFunctionStart: '{{autoindent}}{{token}}(\n',
tmplFunctionStop: '\n{{autoindent}}{{token}})',
tmplOperandError: ' {{token}}',
tmplOperandRange: '{{autoindent}}{{token}}',
@@ -840,8 +840,8 @@
tmplFunctionStartArrayRow: '{',
tmplFunctionStopArrayRow: '}',
tmplFunctionStopArray: '',
- tmplSubexpressionStart: '{{autoindent}}(',
- tmplSubexpressionStop: ' )',
+ tmplSubexpressionStart: '{{autoindent}}(\n',
+ tmplSubexpressionStop: '\n)',
tmplIndentTab: '\t',
tmplIndentSpace: ' ',
autoLineBreak: 'TOK_TYPE_FUNCTION | TOK_TYPE_ARGUMENT | TOK_SUBTYPE_LOGICAL | TOK_TYPE_OP_IN ',
View
9 test/dev.parse.debug.html
@@ -9,7 +9,7 @@
</head>
<body>
<input type="text" id="txtInput" />
-
+ <button id="parse">parse</button>
<div id="results">
</div>
@@ -21,13 +21,12 @@
/*<![CDATA[*/
jQuery(function(){
var $input = $('#txtInput')
+ ,$parse = $('#parse')
,$results = $('#results');
-
-
- $input.bind('keyup', function(){
-
+ $parse.bind('click', function(){
window.excelFormulaUtilities.parseFormula('txtInput', 'results')
+ return false;
});
})
/*]]>*/

0 comments on commit 5c0338b

Please sign in to comment.