I'm working on editing features for a web spreadsheet where I need to identify the cell references, range references and then coloring them as per my requirement. I'm able to identify and color the cell references but failed to identify the fixed cell references ($a$1, $a1, a$1 etc...) as it is throwing an error after entering dollar ('$') symbol.Can anyone help me on this.
When I try to enter the cell reference as "$A$1", it is throwing no viable exception after entering second dollar symbol for row reference and i'm not sure why. How to read the "$" symbol to recognize the fixed cell reference?
FYI, I've extended the grammar found @ antlr3 - Generating a Parse Tree
I'm using the grammar for cell/range reference as below
CELLREFERENCE
: '$'?('a'..'z'|'A'..'Z')+'$'?('0'..'9')+
;
RANGEREFERENCE
: '$'?('a'..'z'|'A'..'Z')+'$'?('0'..'9')+ ':' '$'?('a'..'z'|'A'..'Z')+'$'?('0'..'9')+
;
This will work for identifying the colon,
RANGEREFERENCE : CELLREFERENCE ((':' CELLREFERENCE)=> ':' CELLREFERENCE)?;
Still not sure about the '$' issue in cell reference.
Please find the complete grammar here:
grammar Excel;
options {
output=AST;
language=JavaScript;
}
tokens {
// define pseudo-operations
FUNC;
CALL;
NEGATE;
}
parse
: exp EOF -> exp
;
exp
: orExp
;
orExp
: andExp (OR^ andExp)*
;
andExp
: eqExp (AND^ eqExp)*
;
eqExp
: relExp (( EQUALS | NOTEQUALS)^ relExp)*
;
relExp
: addExp ( (LT^|LTEQ^|GT^|GTEQ^) addExp)*
;
addExp
: multExp ( (PLUS^| MINUS^) multExp)*
;
multExp
: unaryExp (( MULT^ | DIV^ | MOD^ |POW^| IS^) unaryExp)*
;
unaryExp
: NOT atom -> ^(NOT atom)
| MINUS atom -> ^(NEGATE atom)
| ASSIGN atom -> ^(ASSIGN atom)
| atom
;
atom
: TRUE
| FALSE
| INT
| FLOAT
| function
| CELLREFERENCE
| RANGEREFERENCE
| '(' exp ')' -> exp
;
POW : '^';
DIV : '/';
MOD : '%';
MULT : '*';
PLUS : '+';
MINUS : '-';
LT : '<';
LTEQ : '<=';
GT : '>';
GTEQ : '>=';
EQUALS : '==';
ASSIGN: '=';
NOTEQUALS : '<>';
INT : '0'..'9'+;
FLOAT : ('0'..'9')* '.' ('0'..'9')+;
OR : 'or' ;
AND : 'and' ;
IS : 'is' ;
NOT : 'not' ;
TRUE : 'true' ;
FALSE : 'false' ;
function
: IDENT '(' ( exp (',' exp)* )? ')' -> ^(FUNC IDENT (exp)*)
;
CELLREFERENCE
: '$'?('a'..'z'|'A'..'Z')+'$'?('0'..'9')+
;
RANGEREFERENCE
: '$'?('a'..'z'|'A'..'Z')+'$'?('0'..'9')+ ':' '$'?('a'..'z'|'A'..'Z')+'$'?('0'..'9')+
;
IDENT
: ('a'..'z' | 'A'..'Z') ('a'..'z' | 'A'..'Z' |'0'..'9')*
;
SPACE : (' ' | '\t' | '\r' | '\n') {$channel=HIDDEN;} ;
ERRCHAR : Err =. { /*console.log($Err);*/ } ;