From: Jay Freeman (saurik) Date: Sat, 12 Dec 2015 23:45:22 +0000 (-0800) Subject: Support Infinity (syntax highlighting and output). X-Git-Tag: v0.9.590~221 X-Git-Url: https://git.saurik.com/cycript.git/commitdiff_plain/5f6902c29e9bba2538e729694ec7c8ced38bf9ec?hp=23111dca236b4e9ef5351abb990b1e489edf9e05 Support Infinity (syntax highlighting and output). --- diff --git a/Library.cpp b/Library.cpp index 59decd8..7203225 100644 --- a/Library.cpp +++ b/Library.cpp @@ -172,6 +172,13 @@ void CYStringify(std::ostringstream &str, const char *data, size_t size) { } void CYNumerify(std::ostringstream &str, double value) { + if (std::isinf(value)) { + if (value < 0) + str << '-'; + str << "Infinity"; + return; + } + char string[32]; // XXX: I want this to print 1e3 rather than 1000 sprintf(string, "%.17g", value); diff --git a/Parser.ypp.in b/Parser.ypp.in index e453814..d18903c 100644 --- a/Parser.ypp.in +++ b/Parser.ypp.in @@ -323,6 +323,7 @@ _finline int yylex(cy::parser::semantic_type *semantic, CYLocation *location, CY %token _import_ "import" %token _in_ "in" %token _in__ "!in" +%token _Infinity_ "Infinity" %token _instanceof_ "instanceof" %token _new_ "new" %token _return_ "return" @@ -703,6 +704,7 @@ IdentifierName : Word { $$ = $1; } | "for" { $$ = CYNew CYWord("for"); } | "in" { $$ = CYNew CYWord("in"); } + | "Infinity" { $$ = CYNew CYIdentifier("Infinity"); } | "instanceof" { $$ = CYNew CYWord("instanceof"); } ; @@ -907,6 +909,7 @@ Literal : NullLiteral { $$ = $1; } | BooleanLiteral { $$ = $1; } | NumericLiteral { $$ = $1; } + | "Infinity" { $$ = CYNew CYNumber(std::numeric_limits::infinity()); } | StringLiteral { $$ = $1; } ; /* }}} */ diff --git a/Scanner.lpp.in b/Scanner.lpp.in index 7201198..e34f675 100644 --- a/Scanner.lpp.in +++ b/Scanner.lpp.in @@ -475,6 +475,7 @@ XMLName {XMLNameStart}{XMLNamePart}* "implements" L /*FSS*/ F(tk::_implements_, hi::Meta); "import" L /*FFK*/ F(tk::_import_, hi::Meta); "in" L /*KKK*/ F(yyextra->in_.top() ? tk::_in__ : tk::_in_, hi::Operator); +"Infinity" L /*III*/ F(tk::_Infinity_, hi::Constant); "instanceof" L /*KKK*/ F(tk::_instanceof_, hi::Operator); "int" L /*FII*/ F(tk::_int_, hi::Type); "interface" L /*FSS*/ F(tk::_interface_, hi::Meta);