diff options
m--------- | dhall-lang | 0 | ||||
-rw-r--r-- | dhall/src/syntax/text/parser.rs | 28 |
2 files changed, 18 insertions, 10 deletions
diff --git a/dhall-lang b/dhall-lang -Subproject 9f248138f69ee5e22192dc3d0417d5c77b189e0 +Subproject c7dd51ec433e07433243cf1a1134655dbab6cc9 diff --git a/dhall/src/syntax/text/parser.rs b/dhall/src/syntax/text/parser.rs index 27e0382..0e3e97a 100644 --- a/dhall/src/syntax/text/parser.rs +++ b/dhall/src/syntax/text/parser.rs @@ -383,19 +383,27 @@ impl DhallParser { } fn natural_literal(input: ParseInput) -> ParseResult<Natural> { - input - .as_str() - .trim() - .parse() - .map_err(|e| input.error(format!("{}", e))) + let s = input.as_str().trim(); + if s.starts_with("0x") { + let without_prefix = s.trim_start_matches("0x"); + usize::from_str_radix(without_prefix, 16) + .map_err(|e| input.error(format!("{}", e))) + } else { + s.parse().map_err(|e| input.error(format!("{}", e))) + } } fn integer_literal(input: ParseInput) -> ParseResult<Integer> { - input - .as_str() - .trim() - .parse() - .map_err(|e| input.error(format!("{}", e))) + let s = input.as_str().trim(); + let (sign, rest) = (&s[0..1], &s[1..]); + if rest.starts_with("0x") { + let without_prefix = + sign.to_owned() + rest.trim_start_matches("0x"); + isize::from_str_radix(&without_prefix, 16) + .map_err(|e| input.error(format!("{}", e))) + } else { + s.parse().map_err(|e| input.error(format!("{}", e))) + } } #[alias(expression, shortcut = true)] |