From da9a32a5f3f939eb04aab54400f28159cc567d85 Mon Sep 17 00:00:00 2001 From: David Majda Date: Sat, 7 Dec 2013 15:23:12 +0100 Subject: [PATCH] Example grammars: Improve |parseInt| invocations Instead of |parseInt("0x" + digits)| do |parseInt(digits, 16)|, which is a bit cleaner. --- examples/css.pegjs | 2 +- examples/javascript.pegjs | 6 +++--- examples/json.pegjs | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/examples/css.pegjs b/examples/css.pegjs index 798f3d5..45e21b9 100644 --- a/examples/css.pegjs +++ b/examples/css.pegjs @@ -298,7 +298,7 @@ nonascii unicode = "\\" digits:$(h h? h? h? h? h?) ("\r\n" / [ \t\r\n\f])? { - return String.fromCharCode(parseInt("0x" + digits)); + return String.fromCharCode(parseInt(digits, 16)); } escape diff --git a/examples/javascript.pegjs b/examples/javascript.pegjs index 13206ad..0da7c28 100644 --- a/examples/javascript.pegjs +++ b/examples/javascript.pegjs @@ -231,7 +231,7 @@ SignedInteger = [-+]? DecimalDigits HexIntegerLiteral - = "0" [xX] digits:$HexDigit+ { return parseInt("0x" + digits); } + = "0" [xX] digits:$HexDigit+ { return parseInt(digits, 16); } HexDigit = [0-9a-fA-F] @@ -292,12 +292,12 @@ EscapeCharacter HexEscapeSequence = "x" digits:$(HexDigit HexDigit) { - return String.fromCharCode(parseInt("0x" + digits)); + return String.fromCharCode(parseInt(digits, 16)); } UnicodeEscapeSequence = "u" digits:$(HexDigit HexDigit HexDigit HexDigit) { - return String.fromCharCode(parseInt("0x" + digits)); + return String.fromCharCode(parseInt(digits, 16)); } RegularExpressionLiteral "regular expression" diff --git a/examples/json.pegjs b/examples/json.pegjs index 43b2314..0729c4a 100644 --- a/examples/json.pegjs +++ b/examples/json.pegjs @@ -65,7 +65,7 @@ char / "\\r" { return "\r"; } / "\\t" { return "\t"; } / "\\u" digits:$(hexDigit hexDigit hexDigit hexDigit) { - return String.fromCharCode(parseInt("0x" + digits)); + return String.fromCharCode(parseInt(digits, 16)); } number "number"