GitHub PullRequestReviewCommentEvent at 2014-02-24 14:09:03
Repository: zeroclickinfo-goodies
Actor: jagtalon
Payload: {"comment":{"url":"https://api.github.com/repos/duckduckgo/zeroclickinfo-goodies/pulls/comments/9991717","id":9991717,"diff_hunk":"@@ -0,0 +1,129 @@\n+# -*- coding: utf-8 -*-\n+\n+package DDG::Goodie::BinaryLogic;\n+\n+use DDG::Goodie;\n+use utf8;\n+\n+use Marpa::R2;\n+\n+# Regexp triggers are used to find cases where the logical symbol\n+# for 'not' is at the beginning of the query (e.g. the case '¬1')\n+triggers query_raw => qr/.*\\s+(and|or|xor|⊕|∧|∨)\\s+.*/;\n+triggers query_raw => qr/not\\s+.*/;\n+triggers query_raw => qr/¬.*/;\n+\n+# zci is_cached => 1;\n+zci answer_type => \"binary_logic\"; \n+\n+attribution\n+    github => ['https://github.com/MithrandirAgain', 'MithrandirAgain'],\n+    github => ['https://github.com/bpaschen', 'Bjoern Paschen'],\n+    twitter => ['https://twitter.com/Prypjat', 'Bjoern Paschen'];\n+\n+primary_example_queries '4 xor 5', '3 and 2', '1 or 1234';\n+secondary_example_queries \n+    '9489 xor 394 xor 9349 xor 39 xor 29 xor 4967 xor 3985', \n+    '10 and 12',\n+    '34 or 100',\n+    '10 and (30 or 128)',\n+    '0x01 or not 0X100';\n+description 'take two numbers and do bitwise logical operations (exclusive-or, or, and, not) on them';\n+code_url 'https://github.com/duckduckgo/zeroclickinfo-goodies/blob/master/lib/DDG/Goodie/BinaryLogic.pm';\n+category 'calculations';\n+topics 'math';\n+\n+# TODO: - add binary numbers. \n+#         the parser callback is already available but the \n+#         lexer grammar did not work.\n+#         (BinaryLogic_Actions::bin_number)\n+my $rules = <<'END_OF_GRAMMAR';\n+:default ::= action => ::first\n+:start ::= Expression\n+\n+Expression ::= Term\n+\n+Term ::=\n+       ('(') Term (')') assoc => group action => ::first\n+     | Number\n+    || Term 'xor' Term action => do_xor\n+     | Term 'and' Term action => do_and\n+     | Term 'or' Term action => do_or\n+     | 'not' Term action => do_not\n+\n+Number ::= \n+       '0x' HexDigits action => hex_number\n+     | '0X' HexDigits action => hex_number\n+     | DecimalDigits\n+\n+DecimalDigits ~ [\\d]+\n+HexDigits ~ [\\dA-Fa-f]+\n+\n+:discard ~ whitespace\n+whitespace ~ [\\s]+\n+END_OF_GRAMMAR\n+\n+sub BinaryLogic_Actions::hex_number {\n+    my (undef, undef, $t2) = @_;\n+    return hex($t2);\n+}\n+\n+sub BinaryLogic_Actions::bin_number {\n+    my (undef, undef, $t2) = @_;\n+    return oct \"0b$t2\";\n+}\n+\n+sub BinaryLogic_Actions::do_and {\n+    my (undef, $t1, undef, $t2) = @_;\n+    return int($t1) & int($t2);\n+}\n+\n+sub BinaryLogic_Actions::do_or {\n+    my (undef, $t1, undef, $t2) = @_;\n+    return int($t1) | int($t2);\n+}\n+\n+sub BinaryLogic_Actions::do_xor {\n+    my (undef, $t1, undef, $t2) = @_;\n+    return int($t1) ^ int($t2);\n+}\n+\n+sub BinaryLogic_Actions::do_not {\n+    my (undef, undef, $t1) = @_;\n+    return ~int($t1);","path":"lib/DDG/Goodie/BinaryLogic.pm","position":93,"original_position":93,"commit_id":"57151505d32277580d059517e626e13ec28a131d","original_commit_id":"57151505d32277580d059517e626e13ec28a131d","user":{"login":"jagtalon","id":81969,"avatar_url":"https://gravatar.com/avatar/d965329b8e3f75c32804f22f19c47834?d=https%3A%2F%2Fidenticons.github.com%2Fc2b9b2c416e6e64bebc29c99ba8abcb0.png&r=x","gravatar_id":"d965329b8e3f75c32804f22f19c47834","url":"https://api.github.com/users/jagtalon","html_url":"https://github.com/jagtalon","followers_url":"https://api.github.com/users/jagtalon/followers","following_url":"https://api.github.com/users/jagtalon/following{/other_user}","gists_url":"https://api.github.com/users/jagtalon/gists{/gist_id}","starred_url":"https://api.github.com/users/jagtalon/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jagtalon/subscriptions","organizations_url":"https://api.github.com/users/jagtalon/orgs","repos_url":"https://api.github.com/users/jagtalon/repos","events_url":"https://api.github.com/users/jagtalon/events{/privacy}","received_events_url":"https://api.github.com/users/jagtalon/received_events","type":"User","site_admin":false},"body":"![screen shot 2014-02-24 at 9 08 44 am](https://f.cloud.github.com/assets/81969/2246017/366f7d7a-9d5d-11e3-8bfb-8a25f10ba725.png)\r\n","created_at":"2014-02-24T14:09:03Z","updated_at":"2014-02-24T14:09:03Z","html_url":"https://github.com/duckduckgo/zeroclickinfo-goodies/pull/340#discussion_r9991717","pull_request_url":"https://api.github.com/repos/duckduckgo/zeroclickinfo-goodies/pulls/340","_links":{"self":{"href":"https://api.github.com/repos/duckduckgo/zeroclickinfo-goodies/pulls/comments/9991717"},"html":{"href":"https://github.com/duckduckgo/zeroclickinfo-goodies/pull/340#discussion_r9991717"},"pull_request":{"href":"https://api.github.com/repos/duckduckgo/zeroclickinfo-goodies/pulls/340"}}}}