Added support for hex float and double constants.
This commit is contained in:
parent
6a96a553cd
commit
094ffd52ec
|
|
@ -1784,6 +1784,8 @@ NUM_INT
|
|||
| (DOT)=>DOT {$setType(DOT);}
|
||||
| (DOUBLE_LITERAL)=>DOUBLE_LITERAL {$setType(NUM_DOUBLE);}
|
||||
| (FLOAT_LITERAL)=>FLOAT_LITERAL {$setType(NUM_FLOAT);}
|
||||
| (HEX_DOUBLE_LITERAL)=>HEX_DOUBLE_LITERAL {$setType(NUM_DOUBLE);}
|
||||
| (HEX_FLOAT_LITERAL)=>HEX_FLOAT_LITERAL {$setType(NUM_FLOAT);}
|
||||
| (LONG_LITERAL)=>LONG_LITERAL {$setType(NUM_LONG);}
|
||||
| (INT_LITERAL)=>INT_LITERAL {$setType(NUM_INT);}
|
||||
;
|
||||
|
|
@ -1834,6 +1836,32 @@ protected DOUBLE_LITERAL
|
|||
(EXPONENT)? ('d'|'D')
|
||||
;
|
||||
|
||||
protected HEX_FLOAT_LITERAL
|
||||
: '0' ('x'|'X')
|
||||
(
|
||||
((HEX_DIGIT)* '.')=>
|
||||
( (HEX_DIGIT)+ '.' (HEX_DIGIT)*
|
||||
| '.' (HEX_DIGIT)+
|
||||
)
|
||||
|
|
||||
(HEX_DIGIT)+
|
||||
)
|
||||
BINARY_EXPONENT ('f'|'F')?
|
||||
;
|
||||
|
||||
protected HEX_DOUBLE_LITERAL
|
||||
: '0' ('x'|'X')
|
||||
(
|
||||
((HEX_DIGIT)* '.')=>
|
||||
( (HEX_DIGIT)+ '.' (HEX_DIGIT)*
|
||||
| '.' (HEX_DIGIT)+
|
||||
)
|
||||
|
|
||||
(HEX_DIGIT)+
|
||||
)
|
||||
BINARY_EXPONENT ('d'|'D')
|
||||
;
|
||||
|
||||
protected ELLIPSIS
|
||||
: ".."
|
||||
;
|
||||
|
|
@ -1845,10 +1873,20 @@ protected DOT
|
|||
// a couple protected methods to assist in matching floating point numbers
|
||||
protected
|
||||
EXPONENT
|
||||
: ('e'|'E') ('+'|'-')? ('0'..'9')+
|
||||
: ('e'|'E') SIGNED_INTEGER
|
||||
;
|
||||
|
||||
protected
|
||||
SIGNED_INTEGER
|
||||
: ('+'|'-')? ('0'..'9')+
|
||||
;
|
||||
|
||||
protected
|
||||
FLOAT_SUFFIX
|
||||
: 'f'|'F'|'d'|'D'
|
||||
;
|
||||
|
||||
protected
|
||||
BINARY_EXPONENT
|
||||
: ('p'|'P') SIGNED_INTEGER
|
||||
;
|
||||
|
|
@ -0,0 +1,16 @@
|
|||
package com.puppycrawl.tools.checkstyle.grammars;
|
||||
|
||||
/**
|
||||
* Input for hex float and double test.
|
||||
*/
|
||||
public class InputHexFloat
|
||||
{
|
||||
float f1 = 0x.0P10;
|
||||
float f2 = 0x1.P-1;
|
||||
float f3 = 0Xab1P0;
|
||||
float f4 = 0Xab1ap+20;
|
||||
float f5 = 0Xab1ap+20D;
|
||||
float f6 = 0Xab1ap+20d;
|
||||
float f5 = 0Xab1ap+20f;
|
||||
float f6 = 0Xab1ap+20F;
|
||||
}
|
||||
|
|
@ -16,6 +16,7 @@ public class AllTests {
|
|||
//$JUnit-BEGIN$
|
||||
suite.addTest(new TestSuite(GeneratedJava14LexerTest.class));
|
||||
suite.addTest(new TestSuite(Post13KeywordsAsIdentifiersOKTest.class));
|
||||
suite.addTest(new TestSuite(HexFloatsTest.class));
|
||||
//$JUnit-END$
|
||||
return suite;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,23 @@
|
|||
package com.puppycrawl.tools.checkstyle.grammars;
|
||||
|
||||
import com.puppycrawl.tools.checkstyle.BaseCheckTestCase;
|
||||
import com.puppycrawl.tools.checkstyle.DefaultConfiguration;
|
||||
import com.puppycrawl.tools.checkstyle.checks.naming.MemberNameCheck;
|
||||
|
||||
/**
|
||||
* Tests hex floats and doubles can be parsed.
|
||||
* @author Michael Studman
|
||||
*/
|
||||
public class HexFloatsTest
|
||||
extends BaseCheckTestCase
|
||||
{
|
||||
public void testCanParse()
|
||||
throws Exception
|
||||
|
||||
{
|
||||
final DefaultConfiguration checkConfig =
|
||||
createCheckConfig(MemberNameCheck.class);
|
||||
final String[] expected = {};
|
||||
verify(checkConfig, getPath("grammars/InputHexFloat.java"), expected);
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue