cucapra/dahlia

Parse issue for hexadecimal literals in cast expressions

Closed this issue · 0 comments

The following fails with a strange message

let x = (0x9e3779b9 as ubit<32>);

Error message

[Error] For input string: "779b9 a" under radix 16

Issue seems to be the way hex literals are parsed

def hex[K: P]: P[Expr] =
positioned(
P("0x" ~/ CharIn("0-9a-fA-F").rep(1)).!.map((n: String) =>
EInt(BigInt(n.substring(2), 16), 16)
).opaque("hexademical")
)
def octal[K: P]: P[Expr] =
positioned(
P("0" ~ CharsWhileIn("0-7")).!.map((n: String) =>
EInt(BigInt(n.substring(1), 8), 8)
).opaque("ocatal")

A fix would be to handle it in the same way as Octal literals with the CharsWhileIn("0-9a-fA-F") instead of CharIn("0-9a-fA-F").rep(1)

Interestingly it seems to work on the online example editor in https://capra.cs.cornell.edu/dahlia/