Rain: changed integer literals to allow negative literals

This commit is contained in:
Neil Brown 2007-08-28 20:40:41 +00:00
parent 96fc3a9983
commit 005dbd4d87
2 changed files with 5 additions and 4 deletions

View File

@ -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 :-

View File

@ -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)