Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Support of float literals

* Includes hexadecimal, octal and binary representation
* Adds unit tests
* Fixes #42
  • Loading branch information...
commit 1a0e9dd0e54358d160db747ac88e16d456acd5cc 1 parent 83c1db8
Denis Ok OkayX6 authored
12 src/fsharper/Psi.FSharp/src/Parsing/FSharpLexer.gen.lex
View
@@ -97,7 +97,10 @@ UNFINISHED_VERBATIM_STRING_LITERAL=(@\"{VERBATIM_STRING_LITERAL_CHARACTER}*)
ERROR_REGULAR_STRING_LITERAL=(\"{REGULAR_STRING_LITERAL_CHARACTER}*{BAD_ESCAPE_SEQUENCE}({BAD_ESCAPE_SEQUENCE}|{REGULAR_STRING_LITERAL_CHARACTER})*\"?)
ERROR_STRING_LITERAL=({UNFINISHED_REGULAR_STRING_LITERAL}|{UNFINISHED_VERBATIM_STRING_LITERAL}|{ERROR_REGULAR_STRING_LITERAL})
-UINT_LITERAL = (({DECIMAL_DIGIT}+)|(0[xX]{HEX_DIGIT}+)|(0[oO]{OCT_DIGIT}+)|(0[bB]{BIN_DIGIT}+))
+HEX_LITERAL=(0[xX]{HEX_DIGIT}+)
+OCT_LITERAL=(0[oO]{OCT_DIGIT}+)
+BIN_LITERAL=(0[bB]{BIN_DIGIT}+)
+UINT_LITERAL = (({DECIMAL_DIGIT}+)|{HEX_LITERAL}|{OCT_LITERAL}|{BIN_LITERAL})
INT_LITERAL = -?{UINT_LITERAL}
INT8_LITERAL = {INT_LITERAL}y
@@ -114,8 +117,8 @@ UINT64_LITERAL = {UINT_LITERAL}[uU]L
FLOAT_LITERAL = ((-?{DECIMAL_DIGIT}+"."{DECIMAL_DIGIT}*)|(-?{DECIMAL_DIGIT}+("."{DECIMAL_DIGIT}*)?([eE])(([+-])?){DECIMAL_DIGIT}+))
-FLOAT32_LITERAL = {FLOAT_LITERAL}F
-FLOAT64_LITERAL = {FLOAT_LITERAL}
+FLOAT32_LITERAL = (({FLOAT_LITERAL}[fF])|({HEX_LITERAL}lf)|({OCT_LITERAL}lf)|({BIN_LITERAL}lf))
+FLOAT64_LITERAL = (({FLOAT_LITERAL})|({HEX_LITERAL}LF)|({OCT_LITERAL}LF)|({BIN_LITERAL}LF))
NOT_NUMBER_SIGN=[^#]
PP_NUMBER_SIGN=#
@@ -147,6 +150,9 @@ END_LINE={NOT_NEW_LINE}*(({PP_NEW_LINE_PAIR})|({PP_NEW_LINE_CHAR}))
<YYINITIAL> {INT64_LITERAL} { currTokenType = makeToken (FSharpTokenType.INT64_LITERAL); return currTokenType; }
<YYINITIAL> {UINT64_LITERAL} { currTokenType = makeToken (FSharpTokenType.UINT64_LITERAL); return currTokenType; }
+<YYINITIAL> {FLOAT32_LITERAL} { currTokenType = makeToken (FSharpTokenType.FLOAT_LITERAL); return currTokenType; }
+<YYINITIAL> {FLOAT64_LITERAL} { currTokenType = makeToken (FSharpTokenType.FLOAT_LITERAL); return currTokenType; }
+
<YYINITIAL> {NEW_LINE_PAIR} { yybegin(YYINITIAL); return makeToken(FSharpTokenType.NEW_LINE); }
<YYINITIAL> {NEW_LINE_CHAR} { yybegin(YYINITIAL); return makeToken(FSharpTokenType.NEW_LINE); }
14,834 src/fsharper/Psi.FSharp/src/Parsing/FSharpLexer.gen_lex.cs
View
7,482 additions, 7,352 deletions not shown
1  src/fsharper/Tests/FSharpLexerTest.cs
View
@@ -15,6 +15,7 @@ public void TestLexer(string file)
private readonly string[] files = new[]
{
"do-bang",
+ "float-literals",
"int-literals",
"let-arith-1",
"let-array-1",
11 test/data/lexing/fsharp/float-literals.fs
View
@@ -0,0 +1,11 @@
+1.23F
+1.23f
+1.F
+1.f
+-1.23F
+-1.23f
+-1.F
+-1.f
+0x0000lf
+0o0000lf
+0b0000lf
21 test/data/lexing/fsharp/float-literals.fs.gold
View
@@ -0,0 +1,21 @@
+FLOAT_LITERAL
+NEW_LINE
+FLOAT_LITERAL
+NEW_LINE
+FLOAT_LITERAL
+NEW_LINE
+FLOAT_LITERAL
+NEW_LINE
+FLOAT_LITERAL
+NEW_LINE
+FLOAT_LITERAL
+NEW_LINE
+FLOAT_LITERAL
+NEW_LINE
+FLOAT_LITERAL
+NEW_LINE
+FLOAT_LITERAL
+NEW_LINE
+FLOAT_LITERAL
+NEW_LINE
+FLOAT_LITERAL
Please sign in to comment.
Something went wrong with that request. Please try again.