diff --git a/LexRain.x b/LexRain.x index cc4a8d5..da870e3 100644 --- a/LexRain.x +++ b/LexRain.x @@ -54,12 +54,10 @@ $escapeChar = [cnrts \" \' \\ \n] @stringLiteral = \" ( @escape | [^\\\"] )* \" @charLiteral = \' ( @escape | [^\'] ) \' --- Note that occam number literals don't include their signs -- if you say --- "-3", then that's the operator "-" applied to the literal "3". -@decimalLiteral = $decimalDigit+ +@decimalLiteral = ("-")? $decimalDigit+ @hexLiteral = "#" $hexDigit+ @exponent = ("+" | "-") $decimalDigit+ -@realLiteral = ( $decimalDigit+ "." $decimalDigit+ "E" @exponent ) +@realLiteral = ("-")? ( $decimalDigit+ "." $decimalDigit+ "E" @exponent ) | ( $decimalDigit+ "." $decimalDigit+ ) occam :- diff --git a/RainParseTest.hs b/RainParseTest.hs index 186cc29..a62d643 100644 --- a/RainParseTest.hs +++ b/RainParseTest.hs @@ -183,6 +183,9 @@ testLiteral = ,pass ("18446744073709551616", RP.literal, assertEqual "testLiteral 2" (intLiteral 18446744073709551616)) --2^100: We should be able to parse this, but it will be rejected at a later stage: ,pass ("1267650600228229401496703205376", RP.literal, assertEqual "testLiteral 3" (intLiteral 1267650600228229401496703205376)) + --Test that both literal and expression parse -3 the same way: + ,pass ("-3", RP.literal, assertEqual "testLiteral 4" (intLiteral (-3))) + ,pass ("-3", RP.expression, assertEqual "testLiteral 5" (intLiteral (-3))) --Non-integers currently unsupported: ,fail ("0.",RP.literal)