{"action":"created","comment":{"url":"https://api.github.com/repos/bastikr/boolean.py/pulls/comments/57526643","id":57526643,"diff_hunk":"@@ -1032,55 +1094,61 @@ def start_operation(ast, operation):\n                 ast[0].append(ast[1](*ast[2:], eval=eval))\n                 ast = ast[0]\n \n-    expr = expr.replace(\" \", \"\")\n-    length = len(expr)\n+    if isinstance(expr, str):\n+        tokenized = tokenizer(expr)\n+    else:\n+        try:\n+            tokenized = list(expr)\n+        except:\n+            raise TypeError(\"Argument must be string or an iterable of tokens but it is %s.\" % type(expr))\n+\n     ast = [None, None]\n-    i = 0\n-    while i < length:\n-        char = expr[i]\n-        if char == \"1\":\n-            ast.append(TRUE)\n-        elif char == \"0\":\n-            ast.append(FALSE)\n-        elif char.isalpha():\n-            j = 1\n-            while i + j < length and expr[i + j].isalnum():\n-                j += 1\n-            ast.append(Symbol(expr[i:i + j]))\n-            i += j - 1\n-        elif char == \"(\":\n-            ast = [ast, \"(\"]\n-        elif char == \")\":\n-            while True:\n-                if ast[0] is None:\n-                    raise TypeError(\"Bad closing bracket at position %s.\" % i)\n-                if ast[1] is \"(\":\n-                    ast[0].append(ast[2])\n-                    ast = ast[0]\n-                    break\n-                ast[0].append(ast[1](*ast[2:], eval=eval))\n-                ast = ast[0]\n-        elif char == \"~\":\n-            ast = [ast, NOT]\n-        elif char == \"*\":\n-            ast = start_operation(ast, AND)\n-        elif char == \"+\":\n-            ast = start_operation(ast, OR)\n+    for is_symbol, tok, srow, scol in tokenized:\n+        if is_symbol:\n+            if tok == \"1\":\n+                ast.append(TRUE)\n+            elif tok == \"0\":\n+                ast.append(FALSE)\n+            else:\n+                # reuse Symbol as-is if provided\n+                if isinstance(tok, Symbol):\n+                    ast.append(tok)\n+                else:\n+                    ast.append(symbol(tok))","path":"boolean/boolean.py","position":146,"original_position":146,"commit_id":"1908bc01fc48f754f140b2ecab2b12e6806f8a26","original_commit_id":"1908bc01fc48f754f140b2ecab2b12e6806f8a26","user":{"login":"Kronuz","id":56894,"avatar_url":"https://avatars.githubusercontent.com/u/56894?v=3","gravatar_id":"","url":"https://api.github.com/users/Kronuz","html_url":"https://github.com/Kronuz","followers_url":"https://api.github.com/users/Kronuz/followers","following_url":"https://api.github.com/users/Kronuz/following{/other_user}","gists_url":"https://api.github.com/users/Kronuz/gists{/gist_id}","starred_url":"https://api.github.com/users/Kronuz/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Kronuz/subscriptions","organizations_url":"https://api.github.com/users/Kronuz/orgs","repos_url":"https://api.github.com/users/Kronuz/repos","events_url":"https://api.github.com/users/Kronuz/events{/privacy}","received_events_url":"https://api.github.com/users/Kronuz/received_events","type":"User","site_admin":false},"body":"Just seeing the diff, but isn't this supposed to be `Symbol(tok)` (uppercase \"S\")?","created_at":"2016-03-27T10:52:38Z","updated_at":"2016-03-27T10:52:38Z","html_url":"https://github.com/bastikr/boolean.py/pull/23#discussion_r57526643","pull_request_url":"https://api.github.com/repos/bastikr/boolean.py/pulls/23","_links":{"self":{"href":"https://api.github.com/repos/bastikr/boolean.py/pulls/comments/57526643"},"html":{"href":"https://github.com/bastikr/boolean.py/pull/23#discussion_r57526643"},"pull_request":{"href":"https://api.github.com/repos/bastikr/boolean.py/pulls/23"}}},"pull_request":{"url":"https://api.github.com/repos/bastikr/boolean.py/pulls/23","id":64249887,"html_url":"https://github.com/bastikr/boolean.py/pull/23","diff_url":"https://github.com/bastikr/boolean.py/pull/23.diff","patch_url":"https://github.com/bastikr/boolean.py/pull/23.patch","issue_url":"https://api.github.com/repos/bastikr/boolean.py/issues/23","number":23,"state":"open","locked":false,"title":"Alternative parser using a standard tokenizer with multiple customization possible","user":{"login":"pombredanne","id":675997,"avatar_url":"https://avatars.githubusercontent.com/u/675997?v=3","gravatar_id":"","url":"https://api.github.com/users/pombredanne","html_url":"https://github.com/pombredanne","followers_url":"https://api.github.com/users/pombredanne/followers","following_url":"https://api.github.com/users/pombredanne/following{/other_user}","gists_url":"https://api.github.com/users/pombredanne/gists{/gist_id}","starred_url":"https://api.github.com/users/pombredanne/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/pombredanne/subscriptions","organizations_url":"https://api.github.com/users/pombredanne/orgs","repos_url":"https://api.github.com/users/pombredanne/repos","events_url":"https://api.github.com/users/pombredanne/events{/privacy}","received_events_url":"https://api.github.com/users/pombredanne/received_events","type":"User","site_admin":false},"body":"This is rough proof of concept that supports more or less:\r\n* #11 and #18 (alternative operators) \r\n* #9  (feeding sequences to the parser with via custom tokenizers)\r\n* #19 (custom symbols)\r\n\r\nIt has these benefits IMHO:\r\n * Use the standard lib \"tokenize\" module\r\n * Accept arbitrary Python names as symbols\r\n * Support `and`, `not`, `or`, `!`, `~`, `+`, `*`, `&`, `|` as operators in any combination\r\n * Parse comments and multi-line expressions\r\n * Accept any white spaces\r\n * Errors are reported with row and columns\r\n * Accept alternative tokenizer, allowing to have custom \r\n   symbols and operators\r\n * Accept custom symbols class","created_at":"2016-03-26T21:44:43Z","updated_at":"2016-03-27T10:52:38Z","closed_at":null,"merged_at":null,"merge_commit_sha":"01177d0ee19b7c1af0a9b7c300d3cf0e25095ced","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/bastikr/boolean.py/pulls/23/commits","review_comments_url":"https://api.github.com/repos/bastikr/boolean.py/pulls/23/comments","review_comment_url":"https://api.github.com/repos/bastikr/boolean.py/pulls/comments{/number}","comments_url":"https://api.github.com/repos/bastikr/boolean.py/issues/23/comments","statuses_url":"https://api.github.com/repos/bastikr/boolean.py/statuses/1908bc01fc48f754f140b2ecab2b12e6806f8a26","head":{"label":"pombredanne:standard-tokenizer","ref":"standard-tokenizer","sha":"1908bc01fc48f754f140b2ecab2b12e6806f8a26","user":{"login":"pombredanne","id":675997,"avatar_url":"https://avatars.githubusercontent.com/u/675997?v=3","gravatar_id":"","url":"https://api.github.com/users/pombredanne","html_url":"https://github.com/pombredanne","followers_url":"https://api.github.com/users/pombredanne/followers","following_url":"https://api.github.com/users/pombredanne/following{/other_user}","gists_url":"https://api.github.com/users/pombredanne/gists{/gist_id}","starred_url":"https://api.github.com/users/pombredanne/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/pombredanne/subscriptions","organizations_url":"https://api.github.com/users/pombredanne/orgs","repos_url":"https://api.github.com/users/pombredanne/repos","events_url":"https://api.github.com/users/pombredanne/events{/privacy}","received_events_url":"https://api.github.com/users/pombredanne/received_events","type":"User","site_admin":false},"repo":{"id":44243980,"name":"boolean.py","full_name":"pombredanne/boolean.py","owner":{"login":"pombredanne","id":675997,"avatar_url":"https://avatars.githubusercontent.com/u/675997?v=3","gravatar_id":"","url":"https://api.github.com/users/pombredanne","html_url":"https://github.com/pombredanne","followers_url":"https://api.github.com/users/pombredanne/followers","following_url":"https://api.github.com/users/pombredanne/following{/other_user}","gists_url":"https://api.github.com/users/pombredanne/gists{/gist_id}","starred_url":"https://api.github.com/users/pombredanne/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/pombredanne/subscriptions","organizations_url":"https://api.github.com/users/pombredanne/orgs","repos_url":"https://api.github.com/users/pombredanne/repos","events_url":"https://api.github.com/users/pombredanne/events{/privacy}","received_events_url":"https://api.github.com/users/pombredanne/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/pombredanne/boolean.py","description":"Implements boolean algebra in one module.","fork":true,"url":"https://api.github.com/repos/pombredanne/boolean.py","forks_url":"https://api.github.com/repos/pombredanne/boolean.py/forks","keys_url":"https://api.github.com/repos/pombredanne/boolean.py/keys{/key_id}","collaborators_url":"https://api.github.com/repos/pombredanne/boolean.py/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/pombredanne/boolean.py/teams","hooks_url":"https://api.github.com/repos/pombredanne/boolean.py/hooks","issue_events_url":"https://api.github.com/repos/pombredanne/boolean.py/issues/events{/number}","events_url":"https://api.github.com/repos/pombredanne/boolean.py/events","assignees_url":"https://api.github.com/repos/pombredanne/boolean.py/assignees{/user}","branches_url":"https://api.github.com/repos/pombredanne/boolean.py/branches{/branch}","tags_url":"https://api.github.com/repos/pombredanne/boolean.py/tags","blobs_url":"https://api.github.com/repos/pombredanne/boolean.py/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/pombredanne/boolean.py/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/pombredanne/boolean.py/git/refs{/sha}","trees_url":"https://api.github.com/repos/pombredanne/boolean.py/git/trees{/sha}","statuses_url":"https://api.github.com/repos/pombredanne/boolean.py/statuses/{sha}","languages_url":"https://api.github.com/repos/pombredanne/boolean.py/languages","stargazers_url":"https://api.github.com/repos/pombredanne/boolean.py/stargazers","contributors_url":"https://api.github.com/repos/pombredanne/boolean.py/contributors","subscribers_url":"https://api.github.com/repos/pombredanne/boolean.py/subscribers","subscription_url":"https://api.github.com/repos/pombredanne/boolean.py/subscription","commits_url":"https://api.github.com/repos/pombredanne/boolean.py/commits{/sha}","git_commits_url":"https://api.github.com/repos/pombredanne/boolean.py/git/commits{/sha}","comments_url":"https://api.github.com/repos/pombredanne/boolean.py/comments{/number}","issue_comment_url":"https://api.github.com/repos/pombredanne/boolean.py/issues/comments{/number}","contents_url":"https://api.github.com/repos/pombredanne/boolean.py/contents/{+path}","compare_url":"https://api.github.com/repos/pombredanne/boolean.py/compare/{base}...{head}","merges_url":"https://api.github.com/repos/pombredanne/boolean.py/merges","archive_url":"https://api.github.com/repos/pombredanne/boolean.py/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/pombredanne/boolean.py/downloads","issues_url":"https://api.github.com/repos/pombredanne/boolean.py/issues{/number}","pulls_url":"https://api.github.com/repos/pombredanne/boolean.py/pulls{/number}","milestones_url":"https://api.github.com/repos/pombredanne/boolean.py/milestones{/number}","notifications_url":"https://api.github.com/repos/pombredanne/boolean.py/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/pombredanne/boolean.py/labels{/name}","releases_url":"https://api.github.com/repos/pombredanne/boolean.py/releases{/id}","deployments_url":"https://api.github.com/repos/pombredanne/boolean.py/deployments","created_at":"2015-10-14T11:42:13Z","updated_at":"2016-03-26T14:22:58Z","pushed_at":"2016-03-27T08:53:16Z","git_url":"git://github.com/pombredanne/boolean.py.git","ssh_url":"git@github.com:pombredanne/boolean.py.git","clone_url":"https://github.com/pombredanne/boolean.py.git","svn_url":"https://github.com/pombredanne/boolean.py","homepage":"","size":64,"stargazers_count":0,"watchers_count":0,"language":"Python","has_issues":false,"has_downloads":false,"has_wiki":false,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"bastikr:master","ref":"master","sha":"3ba3218be8d56a49be6076b63049cbb259b11f0a","user":{"login":"bastikr","id":102507,"avatar_url":"https://avatars.githubusercontent.com/u/102507?v=3","gravatar_id":"","url":"https://api.github.com/users/bastikr","html_url":"https://github.com/bastikr","followers_url":"https://api.github.com/users/bastikr/followers","following_url":"https://api.github.com/users/bastikr/following{/other_user}","gists_url":"https://api.github.com/users/bastikr/gists{/gist_id}","starred_url":"https://api.github.com/users/bastikr/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/bastikr/subscriptions","organizations_url":"https://api.github.com/users/bastikr/orgs","repos_url":"https://api.github.com/users/bastikr/repos","events_url":"https://api.github.com/users/bastikr/events{/privacy}","received_events_url":"https://api.github.com/users/bastikr/received_events","type":"User","site_admin":false},"repo":{"id":891231,"name":"boolean.py","full_name":"bastikr/boolean.py","owner":{"login":"bastikr","id":102507,"avatar_url":"https://avatars.githubusercontent.com/u/102507?v=3","gravatar_id":"","url":"https://api.github.com/users/bastikr","html_url":"https://github.com/bastikr","followers_url":"https://api.github.com/users/bastikr/followers","following_url":"https://api.github.com/users/bastikr/following{/other_user}","gists_url":"https://api.github.com/users/bastikr/gists{/gist_id}","starred_url":"https://api.github.com/users/bastikr/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/bastikr/subscriptions","organizations_url":"https://api.github.com/users/bastikr/orgs","repos_url":"https://api.github.com/users/bastikr/repos","events_url":"https://api.github.com/users/bastikr/events{/privacy}","received_events_url":"https://api.github.com/users/bastikr/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/bastikr/boolean.py","description":"Implements boolean algebra in one module.","fork":false,"url":"https://api.github.com/repos/bastikr/boolean.py","forks_url":"https://api.github.com/repos/bastikr/boolean.py/forks","keys_url":"https://api.github.com/repos/bastikr/boolean.py/keys{/key_id}","collaborators_url":"https://api.github.com/repos/bastikr/boolean.py/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/bastikr/boolean.py/teams","hooks_url":"https://api.github.com/repos/bastikr/boolean.py/hooks","issue_events_url":"https://api.github.com/repos/bastikr/boolean.py/issues/events{/number}","events_url":"https://api.github.com/repos/bastikr/boolean.py/events","assignees_url":"https://api.github.com/repos/bastikr/boolean.py/assignees{/user}","branches_url":"https://api.github.com/repos/bastikr/boolean.py/branches{/branch}","tags_url":"https://api.github.com/repos/bastikr/boolean.py/tags","blobs_url":"https://api.github.com/repos/bastikr/boolean.py/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/bastikr/boolean.py/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/bastikr/boolean.py/git/refs{/sha}","trees_url":"https://api.github.com/repos/bastikr/boolean.py/git/trees{/sha}","statuses_url":"https://api.github.com/repos/bastikr/boolean.py/statuses/{sha}","languages_url":"https://api.github.com/repos/bastikr/boolean.py/languages","stargazers_url":"https://api.github.com/repos/bastikr/boolean.py/stargazers","contributors_url":"https://api.github.com/repos/bastikr/boolean.py/contributors","subscribers_url":"https://api.github.com/repos/bastikr/boolean.py/subscribers","subscription_url":"https://api.github.com/repos/bastikr/boolean.py/subscription","commits_url":"https://api.github.com/repos/bastikr/boolean.py/commits{/sha}","git_commits_url":"https://api.github.com/repos/bastikr/boolean.py/git/commits{/sha}","comments_url":"https://api.github.com/repos/bastikr/boolean.py/comments{/number}","issue_comment_url":"https://api.github.com/repos/bastikr/boolean.py/issues/comments{/number}","contents_url":"https://api.github.com/repos/bastikr/boolean.py/contents/{+path}","compare_url":"https://api.github.com/repos/bastikr/boolean.py/compare/{base}...{head}","merges_url":"https://api.github.com/repos/bastikr/boolean.py/merges","archive_url":"https://api.github.com/repos/bastikr/boolean.py/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/bastikr/boolean.py/downloads","issues_url":"https://api.github.com/repos/bastikr/boolean.py/issues{/number}","pulls_url":"https://api.github.com/repos/bastikr/boolean.py/pulls{/number}","milestones_url":"https://api.github.com/repos/bastikr/boolean.py/milestones{/number}","notifications_url":"https://api.github.com/repos/bastikr/boolean.py/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/bastikr/boolean.py/labels{/name}","releases_url":"https://api.github.com/repos/bastikr/boolean.py/releases{/id}","deployments_url":"https://api.github.com/repos/bastikr/boolean.py/deployments","created_at":"2010-09-06T12:38:05Z","updated_at":"2016-03-25T10:03:52Z","pushed_at":"2016-03-27T10:43:44Z","git_url":"git://github.com/bastikr/boolean.py.git","ssh_url":"git@github.com:bastikr/boolean.py.git","clone_url":"https://github.com/bastikr/boolean.py.git","svn_url":"https://github.com/bastikr/boolean.py","homepage":"","size":80,"stargazers_count":9,"watchers_count":9,"language":"Python","has_issues":true,"has_downloads":false,"has_wiki":false,"has_pages":false,"forks_count":3,"mirror_url":null,"open_issues_count":8,"forks":3,"open_issues":8,"watchers":9,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/bastikr/boolean.py/pulls/23"},"html":{"href":"https://github.com/bastikr/boolean.py/pull/23"},"issue":{"href":"https://api.github.com/repos/bastikr/boolean.py/issues/23"},"comments":{"href":"https://api.github.com/repos/bastikr/boolean.py/issues/23/comments"},"review_comments":{"href":"https://api.github.com/repos/bastikr/boolean.py/pulls/23/comments"},"review_comment":{"href":"https://api.github.com/repos/bastikr/boolean.py/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/bastikr/boolean.py/pulls/23/commits"},"statuses":{"href":"https://api.github.com/repos/bastikr/boolean.py/statuses/1908bc01fc48f754f140b2ecab2b12e6806f8a26"}}}}