Example grammars: Improve |parseInt| invocations

Instead of |parseInt("0x" + digits)| do |parseInt(digits, 16)|, which is
a bit cleaner.
redux
David Majda 11 years ago
parent 68c6452d8a
commit da9a32a5f3

@ -298,7 +298,7 @@ nonascii
unicode unicode
= "\\" digits:$(h h? h? h? h? h?) ("\r\n" / [ \t\r\n\f])? { = "\\" 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 escape

@ -231,7 +231,7 @@ SignedInteger
= [-+]? DecimalDigits = [-+]? DecimalDigits
HexIntegerLiteral HexIntegerLiteral
= "0" [xX] digits:$HexDigit+ { return parseInt("0x" + digits); } = "0" [xX] digits:$HexDigit+ { return parseInt(digits, 16); }
HexDigit HexDigit
= [0-9a-fA-F] = [0-9a-fA-F]
@ -292,12 +292,12 @@ EscapeCharacter
HexEscapeSequence HexEscapeSequence
= "x" digits:$(HexDigit HexDigit) { = "x" digits:$(HexDigit HexDigit) {
return String.fromCharCode(parseInt("0x" + digits)); return String.fromCharCode(parseInt(digits, 16));
} }
UnicodeEscapeSequence UnicodeEscapeSequence
= "u" digits:$(HexDigit HexDigit HexDigit HexDigit) { = "u" digits:$(HexDigit HexDigit HexDigit HexDigit) {
return String.fromCharCode(parseInt("0x" + digits)); return String.fromCharCode(parseInt(digits, 16));
} }
RegularExpressionLiteral "regular expression" RegularExpressionLiteral "regular expression"

@ -65,7 +65,7 @@ char
/ "\\r" { return "\r"; } / "\\r" { return "\r"; }
/ "\\t" { return "\t"; } / "\\t" { return "\t"; }
/ "\\u" digits:$(hexDigit hexDigit hexDigit hexDigit) { / "\\u" digits:$(hexDigit hexDigit hexDigit hexDigit) {
return String.fromCharCode(parseInt("0x" + digits)); return String.fromCharCode(parseInt(digits, 16));
} }
number "number" number "number"

Loading…
Cancel
Save