/*
* Copyright 2007 Sun Microsystems, Inc. All Rights Reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
* CA 95054 USA or visit www.sun.com if you need additional information or
* have any questions.
*/
fragment TIME_LITERAL : ;
fragment DECIMAL_LITERAL : ;
fragment OCTAL_LITERAL : ;
fragment HEX_LITERAL : ;
fragment DOTDOT : ;
fragment DOT : ;
FLOATING_POINT_LITERAL
@init
{
boolean rangeError = false;
int sPos = getCharIndex();
boolean negative = input.LT(-1) == '-';
}
:
'0'
(
('x'|'X')
{
$type = HEX_LITERAL;
}
(
(
('0'..'9'|'a'..'f'|'A'..'F') | ('g'..'z' |'G'..'Z')
{
rangeError = true; }
)+
{
setText(getText().substring(2, getText().length()));
if (rangeError)
{
log.error(sPos, MsgSym.MESSAGE_JAVAFX_HEX_MALFORMED);
setText("0");
}
else
{
if (! checkIntLiteralRange(getText(), getCharIndex(), 16, negative))
{
setText("0");
}
}
}
(
{ input.LA(2) != '.'}?=>
{ sPos = getCharIndex(); }
'.' (
('0'..'9'|'a'..'f'|'A'..'F') | ('g'..'z' |'G'..'Z')
)*
{
log.error(sPos, MsgSym.MESSAGE_JAVAFX_HEX_FLOAT);
setText("0");
}
|
)
| {
log.error(getCharIndex()-1, MsgSym.MESSAGE_JAVAFX_HEX_MISSING);
setText("0");
}
)
| (
'0'..'7'
| '8'..'9'
{
rangeError = true; }
)+
{
$type = OCTAL_LITERAL;
if (rangeError)
{
log.error(sPos, MsgSym.MESSAGE_JAVAFX_OCTAL_MALFORMED);
setText("0");
}
else
{
if (! checkIntLiteralRange(getText(), getCharIndex(), 8, negative))
{
setText("0");
}
}
}
(
{ input.LA(2) != '.'}?=>
{ sPos = getCharIndex(); }
'.' Digits?
{
log.error(sPos, MsgSym.MESSAGE_JAVAFX_OCTAL_FLOAT);
setText("0");
}
|
)
| ('m' 's'? | 's' | 'h')
{ $type = TIME_LITERAL; }
| { input.LA(2) != '.'}?=> '.'
(
Digits Exponent?
(
('m' 's'? | 's' | 'h')
{ $type = TIME_LITERAL; }
| { $type = FLOATING_POINT_LITERAL; }
)
| { $type = FLOATING_POINT_LITERAL; }
)
| {
$type = DECIMAL_LITERAL;
if (! checkIntLiteralRange(getText(), getCharIndex(), 10, negative))
{
setText("0");
}
}
)
| ('1'..'9') Digits?
(
{ input.LA(2) != '.'}?=>
'.' Digits? Exponent?
(
('m' 's'? | 's' | 'h')
{ $type = TIME_LITERAL; }
| { $type = FLOATING_POINT_LITERAL; }
)
| (
('m' 's'? | 's' | 'h')
{ $type = TIME_LITERAL; }
| Exponent
{
$type = FLOATING_POINT_LITERAL;
}
| {
$type = DECIMAL_LITERAL;
if (! checkIntLiteralRange(getText(), getCharIndex(), 10, negative))
{
setText("0");
}
}
)
)
|
'.'
( Digits Exponent?
(
('m' 's'? | 's' | 'h')
{ $type = TIME_LITERAL; }
| { $type = FLOATING_POINT_LITERAL; }
)
| '.'
{
$type = DOTDOT; }
|
{ $type = DOT; }
)
;
fragment
Digits
: ('0'..'9')+
;
fragment
Exponent
: ('e'|'E') ('+'|'-')?
(
Digits
| {
log.error(getCharIndex()-1, MsgSym.MESSAGE_JAVAFX_EXPONENT_MALFORMED);
setText("0.0");
}
)
;