OW2 Consortium spagobi

Compare Revisions

Ignore whitespace Rev 18052 → Rev 18053

/V_3.x/Server/trunk/SpagoBIQbeEngine/WebContent/js/spagobi/qbe/filterwizard/parser.js
1,3 → 1,49
/*
Default template driver for JS/CC generated parsers running as
browser-based JavaScript/ECMAScript applications.
This class parses a InLineCalculated field. If an error occurs than the
expression is not well formed.
The LALR grammar:
 
/~ --- Token definitions --- ~/
 
 
/~ Characters to be ignored ~/
! ' |\r|\n|\t'
/~ Non-associative tokens ~/
"AND"
"GROUP"
"OR"
'$F{[ÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖØþÙÚÛÜÝàáâãäåæçèéêëìíîïðñòóôõöøÞùúûüýA-Za-z0-9_ ]+}' Identifier
;
/~ Left-associative tokens, lowest precedence ~/
 
/~ Left-associative tokens, highest precedence ~/
 
##
/~ --- Grammar specification --- ~/
p: ex;
ex: ex 'OR' ex
| ex 'AND' ex
| ex 'GROUP' ex
| Identifier
;
 
 
 
*/
 
// create namespace
boolstaf = {};
 
11,23 → 57,46
// =============================================================================================
 
 
var _dbg_withtrace = false;
var _dbg_string = new String();
 
 
 
var _dbg_withtrace = false;
var _dbg_string = new String();
 
function __dbg_print( text )
{ _dbg_string += text + "\n";}
{
_dbg_string += text + "\n";
}
 
function __lex( info )
{ var state = 0; var match = -1; var match_pos = 0; var start = 0; var pos = info.offset + 1; do
{ pos--; state = 0; match = -2; start = pos; if( info.src.length <= start )
return 9; do
{ switch( state )
{
var state = 0;
var match = -1;
var match_pos = 0;
var start = 0;
var pos = info.offset + 1;
 
do
{
pos--;
state = 0;
match = -2;
start = pos;
 
if( info.src.length <= start )
return 8;
 
do
{
 
switch( state )
{
case 0:
if( info.src.charCodeAt( pos ) == 9 || info.src.charCodeAt( pos ) == 32 ) state = 1;
else if( info.src.charCodeAt( pos ) == 40 ) state = 2;
else if( info.src.charCodeAt( pos ) == 41 ) state = 3;
else if( info.src.charCodeAt( pos ) == 36 ) state = 7;
else if( info.src.charCodeAt( pos ) == 65 ) state = 8;
else if( info.src.charCodeAt( pos ) == 79 ) state = 9;
if( ( info.src.charCodeAt( pos ) >= 9 && info.src.charCodeAt( pos ) <= 10 ) || info.src.charCodeAt( pos ) == 13 || info.src.charCodeAt( pos ) == 32 ) state = 1;
else if( info.src.charCodeAt( pos ) == 36 ) state = 6;
else if( info.src.charCodeAt( pos ) == 65 || info.src.charCodeAt( pos ) == 97 ) state = 7;
else if( info.src.charCodeAt( pos ) == 71 || info.src.charCodeAt( pos ) == 103 ) state = 8;
else if( info.src.charCodeAt( pos ) == 79 || info.src.charCodeAt( pos ) == 111 ) state = 9;
else state = -1;
break;
 
39,13 → 108,13
 
case 2:
state = -1;
match = 2;
match = 4;
match_pos = pos;
break;
 
case 3:
state = -1;
match = 3;
match = 2;
match_pos = pos;
break;
 
57,184 → 126,308
 
case 5:
state = -1;
match = 6;
match = 3;
match_pos = pos;
break;
 
case 6:
state = -1;
match = 4;
match_pos = pos;
if( info.src.charCodeAt( pos ) == 70 ) state = 10;
else state = -1;
break;
 
case 7:
if( info.src.charCodeAt( pos ) == 70 ) state = 10;
if( info.src.charCodeAt( pos ) == 78 || info.src.charCodeAt( pos ) == 110 ) state = 11;
else state = -1;
break;
 
case 8:
if( info.src.charCodeAt( pos ) == 78 ) state = 11;
if( info.src.charCodeAt( pos ) == 82 || info.src.charCodeAt( pos ) == 114 ) state = 12;
else state = -1;
break;
 
case 9:
if( info.src.charCodeAt( pos ) == 82 ) state = 4;
if( info.src.charCodeAt( pos ) == 82 || info.src.charCodeAt( pos ) == 114 ) state = 2;
else state = -1;
break;
 
case 10:
if( info.src.charCodeAt( pos ) == 123 ) state = 12;
if( info.src.charCodeAt( pos ) == 123 ) state = 13;
else state = -1;
break;
 
case 11:
if( info.src.charCodeAt( pos ) == 68 ) state = 5;
if( info.src.charCodeAt( pos ) == 68 || info.src.charCodeAt( pos ) == 100 ) state = 3;
else state = -1;
break;
 
case 12:
if( ( info.src.charCodeAt( pos ) >= 65 && info.src.charCodeAt( pos ) <= 90 ) || info.src.charCodeAt( pos ) == 95 || ( info.src.charCodeAt( pos ) >= 97 && info.src.charCodeAt( pos ) <= 122 ) ) state = 13;
if( info.src.charCodeAt( pos ) == 79 || info.src.charCodeAt( pos ) == 111 ) state = 14;
else state = -1;
break;
 
case 13:
if( info.src.charCodeAt( pos ) == 125 ) state = 6;
else if( ( info.src.charCodeAt( pos ) >= 48 && info.src.charCodeAt( pos ) <= 57 ) || ( info.src.charCodeAt( pos ) >= 65 && info.src.charCodeAt( pos ) <= 90 ) || info.src.charCodeAt( pos ) == 95 || ( info.src.charCodeAt( pos ) >= 97 && info.src.charCodeAt( pos ) <= 122 ) ) state = 13;
if( info.src.charCodeAt( pos ) == 32 || ( info.src.charCodeAt( pos ) >= 48 && info.src.charCodeAt( pos ) <= 57 ) || ( info.src.charCodeAt( pos ) >= 65 && info.src.charCodeAt( pos ) <= 90 ) || info.src.charCodeAt( pos ) == 95 || ( info.src.charCodeAt( pos ) >= 97 && info.src.charCodeAt( pos ) <= 122 ) || ( info.src.charCodeAt( pos ) >= 192 && info.src.charCodeAt( pos ) <= 214 ) || ( info.src.charCodeAt( pos ) >= 216 && info.src.charCodeAt( pos ) <= 222 ) || ( info.src.charCodeAt( pos ) >= 224 && info.src.charCodeAt( pos ) <= 246 ) || ( info.src.charCodeAt( pos ) >= 248 && info.src.charCodeAt( pos ) <= 254 ) ) state = 15;
else state = -1;
break;
 
}
case 14:
if( info.src.charCodeAt( pos ) == 85 || info.src.charCodeAt( pos ) == 117 ) state = 16;
else state = -1;
break;
 
case 15:
if( info.src.charCodeAt( pos ) == 125 ) state = 4;
else if( info.src.charCodeAt( pos ) == 32 || ( info.src.charCodeAt( pos ) >= 48 && info.src.charCodeAt( pos ) <= 57 ) || ( info.src.charCodeAt( pos ) >= 65 && info.src.charCodeAt( pos ) <= 90 ) || info.src.charCodeAt( pos ) == 95 || ( info.src.charCodeAt( pos ) >= 97 && info.src.charCodeAt( pos ) <= 122 ) || ( info.src.charCodeAt( pos ) >= 192 && info.src.charCodeAt( pos ) <= 214 ) || ( info.src.charCodeAt( pos ) >= 216 && info.src.charCodeAt( pos ) <= 222 ) || ( info.src.charCodeAt( pos ) >= 224 && info.src.charCodeAt( pos ) <= 246 ) || ( info.src.charCodeAt( pos ) >= 248 && info.src.charCodeAt( pos ) <= 254 ) ) state = 15;
else state = -1;
break;
 
pos++;}
while( state > -1 );}
while( 1 > -1 && match == 1 ); if( match > -1 )
{ info.att = info.src.substr( start, match_pos - start ); info.offset = match_pos; switch( match )
{
case 4:
{
info.att = info.att;
}
case 16:
if( info.src.charCodeAt( pos ) == 80 || info.src.charCodeAt( pos ) == 112 ) state = 5;
else state = -1;
break;
 
}
 
 
}
else
{ info.att = new String(); match = -1;}
return match;};
pos++;
 
}
while( state > -1 );
 
}
while( 1 > -1 && match == 1 );
 
if( match > -1 )
{
info.att = info.src.substr( start, match_pos - start );
info.offset = match_pos;
 
}
else
{
info.att = new String();
match = -1;
}
 
return match;
}
 
 
 
 
 
function __parse( src, err_off, err_la )
{ var sstack = new Array(); var vstack = new Array(); var err_cnt = 0; var act; var go; var la; var rval; var parseinfo = new Function( "", "var offset; var src; var att;" ); var info = new parseinfo(); /* Pop-Table */
{
var sstack = new Array();
var vstack = new Array();
var err_cnt = 0;
var act;
var go;
var la;
var rval;
var parseinfo = new Function( "", "var offset; var src; var att;" );
var info = new parseinfo();
/* Pop-Table */
var pop_tab = new Array(
new Array( 0/* p' */, 1 ),
new Array( 8/* p */, 1 ),
new Array( 7/* e */, 3 ),
new Array( 7/* e */, 3 ),
new Array( 7/* e */, 3 ),
new Array( 7/* e */, 1 )
new Array( 7/* p */, 1 ),
new Array( 6/* ex */, 3 ),
new Array( 6/* ex */, 3 ),
new Array( 6/* ex */, 3 ),
new Array( 6/* ex */, 1 )
);
 
/* Action-Table */
var act_tab = new Array(
/* State 0 */ new Array( 2/* "(" */,3 , 4/* "FILTER" */,4 ),
/* State 1 */ new Array( 9/* "$" */,0 ),
/* State 2 */ new Array( 6/* "AND" */,5 , 5/* "OR" */,6 , 9/* "$" */,-1 ),
/* State 3 */ new Array( 2/* "(" */,3 , 4/* "FILTER" */,4 ),
/* State 4 */ new Array( 9/* "$" */,-5 , 5/* "OR" */,-5 , 6/* "AND" */,-5 , 3/* ")" */,-5 ),
/* State 5 */ new Array( 2/* "(" */,3 , 4/* "FILTER" */,4 ),
/* State 6 */ new Array( 2/* "(" */,3 , 4/* "FILTER" */,4 ),
/* State 7 */ new Array( 6/* "AND" */,5 , 5/* "OR" */,6 , 3/* ")" */,10 ),
/* State 8 */ new Array( 6/* "AND" */,-3 , 5/* "OR" */,-3 , 9/* "$" */,-3 , 3/* ")" */,-3 ),
/* State 9 */ new Array( 6/* "AND" */,5 , 5/* "OR" */,-2 , 9/* "$" */,-2 , 3/* ")" */,-2 ),
/* State 10 */ new Array( 9/* "$" */,-4 , 5/* "OR" */,-4 , 6/* "AND" */,-4 , 3/* ")" */,-4 )
/* State 0 */ new Array( 5/* "Identifier" */,3 ),
/* State 1 */ new Array( 8/* "$" */,0 ),
/* State 2 */ new Array( 3/* "GROUP" */,4 , 2/* "AND" */,5 , 4/* "OR" */,6 , 8/* "$" */,-1 ),
/* State 3 */ new Array( 8/* "$" */,-5 , 4/* "OR" */,-5 , 2/* "AND" */,-5 , 3/* "GROUP" */,-5 ),
/* State 4 */ new Array( 5/* "Identifier" */,3 ),
/* State 5 */ new Array( 5/* "Identifier" */,3 ),
/* State 6 */ new Array( 5/* "Identifier" */,3 ),
/* State 7 */ new Array( 3/* "GROUP" */,4 , 2/* "AND" */,5 , 4/* "OR" */,6 , 8/* "$" */,-4 ),
/* State 8 */ new Array( 3/* "GROUP" */,4 , 2/* "AND" */,5 , 4/* "OR" */,6 , 8/* "$" */,-3 ),
/* State 9 */ new Array( 3/* "GROUP" */,4 , 2/* "AND" */,5 , 4/* "OR" */,6 , 8/* "$" */,-2 )
);
 
/* Goto-Table */
var goto_tab = new Array(
/* State 0 */ new Array( 8/* p */,1 , 7/* e */,2 ),
/* State 0 */ new Array( 7/* p */,1 , 6/* ex */,2 ),
/* State 1 */ new Array( ),
/* State 2 */ new Array( ),
/* State 3 */ new Array( 7/* e */,7 ),
/* State 4 */ new Array( ),
/* State 5 */ new Array( 7/* e */,8 ),
/* State 6 */ new Array( 7/* e */,9 ),
/* State 3 */ new Array( ),
/* State 4 */ new Array( 6/* ex */,7 ),
/* State 5 */ new Array( 6/* ex */,8 ),
/* State 6 */ new Array( 6/* ex */,9 ),
/* State 7 */ new Array( ),
/* State 8 */ new Array( ),
/* State 9 */ new Array( ),
/* State 10 */ new Array( )
/* State 9 */ new Array( )
);
 
 
 
/* Symbol labels */
var labels = new Array(
"p'" /* Non-terminal symbol */,
"^" /* Terminal symbol */,
"(" /* Terminal symbol */,
")" /* Terminal symbol */,
"FILTER" /* Terminal symbol */,
"WHITESPACE" /* Terminal symbol */,
"AND" /* Terminal symbol */,
"GROUP" /* Terminal symbol */,
"OR" /* Terminal symbol */,
"AND" /* Terminal symbol */,
"e" /* Non-terminal symbol */,
"Identifier" /* Terminal symbol */,
"ex" /* Non-terminal symbol */,
"p" /* Non-terminal symbol */,
"$" /* Terminal symbol */
);
 
 
info.offset = 0; info.src = src; info.att = new String(); if( !err_off )
err_off = new Array(); if( !err_la )
err_la = new Array(); sstack.push( 0 ); vstack.push( 0 ); la = __lex( info ); while( true )
{ act = 12; for( var i = 0; i < act_tab[sstack[sstack.length-1]].length; i+=2 )
{ if( act_tab[sstack[sstack.length-1]][i] == la )
{ act = act_tab[sstack[sstack.length-1]][i+1]; break;}
}
if( _dbg_withtrace && sstack.length > 0 )
{ __dbg_print( "\nState " + sstack[sstack.length-1] + "\n" + "\tLookahead: " + labels[la] + " (\"" + info.att + "\")\n" + "\tAction: " + act + "\n" + "\tSource: \"" + info.src.substr( info.offset, 30 ) + ( ( info.offset + 30 < info.src.length ) ?
"..." : "" ) + "\"\n" + "\tStack: " + sstack.join() + "\n" + "\tValue stack: " + vstack.join() + "\n" );}
if( act == 12 )
{ if( _dbg_withtrace )
__dbg_print( "Error detected: There is no reduce or shift on the symbol " + labels[la] ); err_cnt++; err_off.push( info.offset - info.att.length ); err_la.push( new Array() ); for( var i = 0; i < act_tab[sstack[sstack.length-1]].length; i+=2 )
err_la[err_la.length-1].push( labels[act_tab[sstack[sstack.length-1]][i]] ); var rsstack = new Array(); var rvstack = new Array(); for( var i = 0; i < sstack.length; i++ )
{ rsstack[i] = sstack[i]; rvstack[i] = vstack[i];}
while( act == 12 && la != 9 )
{ if( _dbg_withtrace )
__dbg_print( "\tError recovery\n" + "Current lookahead: " + labels[la] + " (" + info.att + ")\n" + "Action: " + act + "\n\n" ); if( la == -1 )
info.offset++; while( act == 12 && sstack.length > 0 )
{ sstack.pop(); vstack.pop(); if( sstack.length == 0 )
break; act = 12; for( var i = 0; i < act_tab[sstack[sstack.length-1]].length; i+=2 )
{ if( act_tab[sstack[sstack.length-1]][i] == la )
{ act = act_tab[sstack[sstack.length-1]][i+1]; break;}
}
}
if( act != 12 )
break; for( var i = 0; i < rsstack.length; i++ )
{ sstack.push( rsstack[i] ); vstack.push( rvstack[i] );}
la = __lex( info );}
if( act == 12 )
{ if( _dbg_withtrace )
__dbg_print( "\tError recovery failed, terminating parse process..." ); break;}
if( _dbg_withtrace )
__dbg_print( "\tError recovery succeeded, continuing" );}
if( act > 0 )
{ if( _dbg_withtrace )
__dbg_print( "Shifting symbol: " + labels[la] + " (" + info.att + ")" ); sstack.push( act ); vstack.push( info.att ); la = __lex( info ); if( _dbg_withtrace )
__dbg_print( "\tNew lookahead symbol: " + labels[la] + " (" + info.att + ")" );}
else
{ act *= -1; if( _dbg_withtrace )
__dbg_print( "Reducing by producution: " + act ); rval = void(0); if( _dbg_withtrace )
__dbg_print( "\tPerforming semantic action..." ); switch( act )
info.offset = 0;
info.src = src;
info.att = new String();
if( !err_off )
err_off = new Array();
if( !err_la )
err_la = new Array();
sstack.push( 0 );
vstack.push( 0 );
la = __lex( info );
 
while( true )
{
act = 11;
for( var i = 0; i < act_tab[sstack[sstack.length-1]].length; i+=2 )
{
if( act_tab[sstack[sstack.length-1]][i] == la )
{
act = act_tab[sstack[sstack.length-1]][i+1];
break;
}
}
 
if( _dbg_withtrace && sstack.length > 0 )
{
__dbg_print( "\nState " + sstack[sstack.length-1] + "\n" +
"\tLookahead: " + labels[la] + " (\"" + info.att + "\")\n" +
"\tAction: " + act + "\n" +
"\tSource: \"" + info.src.substr( info.offset, 30 ) + ( ( info.offset + 30 < info.src.length ) ?
"..." : "" ) + "\"\n" +
"\tStack: " + sstack.join() + "\n" +
"\tValue stack: " + vstack.join() + "\n" );
}
//Panic-mode: Try recovery when parse-error occurs!
if( act == 11 )
{
if( _dbg_withtrace )
__dbg_print( "Error detected: There is no reduce or shift on the symbol " + labels[la] );
err_cnt++;
err_off.push( info.offset - info.att.length );
err_la.push( new Array() );
for( var i = 0; i < act_tab[sstack[sstack.length-1]].length; i+=2 )
err_la[err_la.length-1].push( labels[act_tab[sstack[sstack.length-1]][i]] );
//Remember the original stack!
var rsstack = new Array();
var rvstack = new Array();
for( var i = 0; i < sstack.length; i++ )
{
rsstack[i] = sstack[i];
rvstack[i] = vstack[i];
}
while( act == 11 && la != 8 )
{
if( _dbg_withtrace )
__dbg_print( "\tError recovery\n" +
"Current lookahead: " + labels[la] + " (" + info.att + ")\n" +
"Action: " + act + "\n\n" );
if( la == -1 )
info.offset++;
while( act == 11 && sstack.length > 0 )
{
sstack.pop();
vstack.pop();
if( sstack.length == 0 )
break;
act = 11;
for( var i = 0; i < act_tab[sstack[sstack.length-1]].length; i+=2 )
{
if( act_tab[sstack[sstack.length-1]][i] == la )
{
act = act_tab[sstack[sstack.length-1]][i+1];
break;
}
}
}
if( act != 11 )
break;
for( var i = 0; i < rsstack.length; i++ )
{
sstack.push( rsstack[i] );
vstack.push( rvstack[i] );
}
la = __lex( info );
}
if( act == 11 )
{
if( _dbg_withtrace )
__dbg_print( "\tError recovery failed, terminating parse process..." );
break;
}
 
 
if( _dbg_withtrace )
__dbg_print( "\tError recovery succeeded, continuing" );
}
/*
if( act == 11 )
break;
*/
//Shift
if( act > 0 )
{
if( _dbg_withtrace )
__dbg_print( "Shifting symbol: " + labels[la] + " (" + info.att + ")" );
sstack.push( act );
vstack.push( info.att );
la = __lex( info );
if( _dbg_withtrace )
__dbg_print( "\tNew lookahead symbol: " + labels[la] + " (" + info.att + ")" );
}
//Reduce
else
{
act *= -1;
if( _dbg_withtrace )
__dbg_print( "Reducing by producution: " + act );
rval = void(0);
if( _dbg_withtrace )
__dbg_print( "\tPerforming semantic action..." );
switch( act )
{
case 0:
case 0:
{
rval = vstack[ vstack.length - 1 ];
}
267,22 → 460,52
}
 
 
if( _dbg_withtrace )
__dbg_print( "\tPopping " + pop_tab[act][1] + " off the stack..." ); for( var i = 0; i < pop_tab[act][1]; i++ )
{ sstack.pop(); vstack.pop();}
go = -1; for( var i = 0; i < goto_tab[sstack[sstack.length-1]].length; i+=2 )
{ if( goto_tab[sstack[sstack.length-1]][i] == pop_tab[act][0] )
{ go = goto_tab[sstack[sstack.length-1]][i+1]; break;}
 
if( _dbg_withtrace )
__dbg_print( "\tPopping " + pop_tab[act][1] + " off the stack..." );
for( var i = 0; i < pop_tab[act][1]; i++ )
{
sstack.pop();
vstack.pop();
}
go = -1;
for( var i = 0; i < goto_tab[sstack[sstack.length-1]].length; i+=2 )
{
if( goto_tab[sstack[sstack.length-1]][i] == pop_tab[act][0] )
{
go = goto_tab[sstack[sstack.length-1]][i+1];
break;
}
}
if( act == 0 )
break;
if( _dbg_withtrace )
__dbg_print( "\tPushing non-terminal " + labels[ pop_tab[act][0] ] );
sstack.push( go );
vstack.push( rval );
}
if( _dbg_withtrace )
{
alert( _dbg_string );
_dbg_string = new String();
}
}
 
if( _dbg_withtrace )
{
__dbg_print( "\nParse complete." );
alert( _dbg_string );
}
return err_cnt;
}
if( act == 0 )
break; if( _dbg_withtrace )
__dbg_print( "\tPushing non-terminal " + labels[ pop_tab[act][0] ] ); sstack.push( go ); vstack.push( rval );}
if( _dbg_withtrace )
{ alert( _dbg_string ); _dbg_string = new String();}
}
if( _dbg_withtrace )
{ __dbg_print( "\nParse complete." ); alert( _dbg_string );}
return err_cnt;}
 
// =============================================================================================