{"action":"created","comment":{"url":"https://api.github.com/repos/elementary/vala-lint/pulls/comments/167951483","pull_request_review_id":96240912,"id":167951483,"diff_hunk":"@@ -0,0 +1,132 @@\n+/*\n+ * Copyright (c) 2018 elementary LLC. (https://github.com/elementary/Vala-Lint)\n+ *\n+ * This program is free software; you can redistribute it and/or\n+ * modify it under the terms of the GNU General Public\n+ * License as published by the Free Software Foundation; either\n+ * version 2 of the License, or (at your option) any later version.\n+ *\n+ * This program is distributed in the hope that it will be useful,\n+ * but WITHOUT ANY WARRANTY; without even the implied warranty of\n+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU\n+ * General Public License for more details.\n+ *\n+ * You should have received a copy of the GNU General Public\n+ * License along with this program; if not, write to the\n+ * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,\n+ * Boston, MA 02110-1301 USA.\n+ */\n+\n+public class ValaLint.Parser : Object {\n+\n+    // For ParseDetailType\n+    string[] start_patterns = {\n+        \"\"\"(\\/\\/)\"\"\",\n+        \"\"\"(\\/\\*)\"\"\",\n+        \"\"\"(\\\"\\\"\\\")\"\"\",\n+        \"\"\"(@\")\"\"\",\n+        \"\"\"(\")\"\"\",\n+        \"\"\"(')\"\"\"\n+    };\n+    string[] close_patterns = {\n+        \"\"\"(\\n)\"\"\",\n+        \"\"\"(\\*\\/)\"\"\",\n+        \"\"\"((?<!\\\\)(\\\\\\\\)*\\\"\\\"\\\")\"\"\",\n+        \"\"\"((?<!\\\\)(\\\\\\\\)*\")\"\"\",\n+        \"\"\"((?<!\\\\)(\\\\\\\\)*\")\"\"\",\n+        \"\"\"((?<!\\\\)(\\\\\\\\)*')\"\"\"\n+    };\n+    ParseType[] parse_types = {\n+        ParseType.Comment,\n+        ParseType.Comment,\n+        ParseType.String,\n+        ParseType.String,\n+        ParseType.String,\n+        ParseType.String,\n+        ParseType.Default\n+    };\n+\n+    struct MatchTypeInfo {\n+        MatchInfo match_info;\n+        ParseDetailType type;\n+        int start_pos;\n+        int end_pos;\n+    }\n+\n+    public Gee.ArrayList<ParseResult?> parse (string input) {\n+        var result = new Gee.ArrayList<ParseResult?> ();\n+\n+        int search_pos = 0;\n+        int current_line = 0;\n+\n+        MatchTypeInfo info = match_type (input, start_patterns, search_pos);\n+        while (info.match_info.matches ()) {\n+            if (info.start_pos > search_pos) {\n+                add_result (input, search_pos, info.start_pos, ParseDetailType.Code, result, ref current_line);\n+            }\n+            search_pos = info.start_pos;\n+\n+            MatchTypeInfo info_close = match_type (input, {close_patterns[info.type]}, info.end_pos);\n+            if (info_close.match_info.matches ()) {\n+                add_result (input, search_pos, info_close.end_pos, info.type, result, ref current_line);\n+            } else {\n+                add_result (input, search_pos, input.length, info.type, result, ref current_line);\n+                search_pos = input.length;\n+                break;\n+            }\n+\n+            search_pos = info_close.end_pos;\n+            info = match_type (input, start_patterns, info_close.end_pos);\n+        }\n+\n+        if (input.length > search_pos) {\n+            add_result (input, search_pos, input.length, ParseDetailType.Code, result, ref current_line);\n+        }\n+        return result;\n+    }\n+\n+    /**\n+     * Matches one of multiple regex patterns.\n+     *\n+     * @param input The input string.\n+     * @param patterns The array of regex patterns.\n+     * @param start_search_pos The start position for searching in the input string.\n+     * @param info The output, including which pattern was matched and the exact position.\n+     */\n+    MatchTypeInfo match_type (string input, string[] patterns, int start_search_pos) {\n+        string entire_pattern = string.joinv (\"|\", patterns); // Join regex patterns\n+        var info = MatchTypeInfo ();\n+\n+        try {\n+            var regex = new Regex (entire_pattern);\n+            if (regex.match_full (input, -1, start_search_pos, 0, out info.match_info)) {\n+                info.match_info.fetch_pos (0, out info.start_pos, out info.end_pos);\n+                for (int i = 0; i < info.match_info.get_match_count (); i++) {\n+                    if (info.match_info.fetch (i + 1).length > 0) {\n+                        info.type = (ParseDetailType)i;\n+                        return info;;\n+                    }\n+                }\n+            }\n+        } catch {\n+            error (_(\"Regex error in parser: %s\"), entire_pattern);","path":"lib/Parser.vala","position":112,"original_position":112,"commit_id":"fd661ce3848f9cec2f523fd16777d1b6576c65c3","original_commit_id":"fd661ce3848f9cec2f523fd16777d1b6576c65c3","user":{"login":"davidmhewitt","id":3372394,"avatar_url":"https://avatars0.githubusercontent.com/u/3372394?v=4","gravatar_id":"","url":"https://api.github.com/users/davidmhewitt","html_url":"https://github.com/davidmhewitt","followers_url":"https://api.github.com/users/davidmhewitt/followers","following_url":"https://api.github.com/users/davidmhewitt/following{/other_user}","gists_url":"https://api.github.com/users/davidmhewitt/gists{/gist_id}","starred_url":"https://api.github.com/users/davidmhewitt/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/davidmhewitt/subscriptions","organizations_url":"https://api.github.com/users/davidmhewitt/orgs","repos_url":"https://api.github.com/users/davidmhewitt/repos","events_url":"https://api.github.com/users/davidmhewitt/events{/privacy}","received_events_url":"https://api.github.com/users/davidmhewitt/received_events","type":"User","site_admin":false},"body":"This doesn't need to be translatable","created_at":"2018-02-13T18:06:51Z","updated_at":"2018-02-13T18:09:14Z","html_url":"https://github.com/elementary/vala-lint/pull/31#discussion_r167951483","pull_request_url":"https://api.github.com/repos/elementary/vala-lint/pulls/31","author_association":"MEMBER","_links":{"self":{"href":"https://api.github.com/repos/elementary/vala-lint/pulls/comments/167951483"},"html":{"href":"https://github.com/elementary/vala-lint/pull/31#discussion_r167951483"},"pull_request":{"href":"https://api.github.com/repos/elementary/vala-lint/pulls/31"}}},"pull_request":{"url":"https://api.github.com/repos/elementary/vala-lint/pulls/31","id":165560435,"html_url":"https://github.com/elementary/vala-lint/pull/31","diff_url":"https://github.com/elementary/vala-lint/pull/31.diff","patch_url":"https://github.com/elementary/vala-lint/pull/31.patch","issue_url":"https://api.github.com/repos/elementary/vala-lint/issues/31","number":31,"state":"open","locked":false,"title":"Implement Parser","user":{"login":"pantor","id":1885260,"avatar_url":"https://avatars3.githubusercontent.com/u/1885260?v=4","gravatar_id":"","url":"https://api.github.com/users/pantor","html_url":"https://github.com/pantor","followers_url":"https://api.github.com/users/pantor/followers","following_url":"https://api.github.com/users/pantor/following{/other_user}","gists_url":"https://api.github.com/users/pantor/gists{/gist_id}","starred_url":"https://api.github.com/users/pantor/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/pantor/subscriptions","organizations_url":"https://api.github.com/users/pantor/orgs","repos_url":"https://api.github.com/users/pantor/repos","events_url":"https://api.github.com/users/pantor/events{/privacy}","received_events_url":"https://api.github.com/users/pantor/received_events","type":"User","site_admin":false},"body":"This PR makes some changes to the Linter class. Instead of checking each line on its own, the entire input string is first parsed for comments, strings and other (default) code. This information is used by the checks, fixing #17 and #19 (and outdating branch inside-string-check). Each check can now find multiple mistakes in a single line. Additionally, mistakes are now ordered by line and character position.","created_at":"2018-01-28T10:19:37Z","updated_at":"2018-02-13T18:09:14Z","closed_at":null,"merged_at":null,"merge_commit_sha":"6de6217693aff6d02537f5d2702f45687cf2e93d","assignee":null,"assignees":[],"requested_reviewers":[],"requested_teams":[],"labels":[],"milestone":null,"commits_url":"https://api.github.com/repos/elementary/vala-lint/pulls/31/commits","review_comments_url":"https://api.github.com/repos/elementary/vala-lint/pulls/31/comments","review_comment_url":"https://api.github.com/repos/elementary/vala-lint/pulls/comments{/number}","comments_url":"https://api.github.com/repos/elementary/vala-lint/issues/31/comments","statuses_url":"https://api.github.com/repos/elementary/vala-lint/statuses/fd661ce3848f9cec2f523fd16777d1b6576c65c3","head":{"label":"elementary:parser","ref":"parser","sha":"fd661ce3848f9cec2f523fd16777d1b6576c65c3","user":{"login":"elementary","id":1978534,"avatar_url":"https://avatars0.githubusercontent.com/u/1978534?v=4","gravatar_id":"","url":"https://api.github.com/users/elementary","html_url":"https://github.com/elementary","followers_url":"https://api.github.com/users/elementary/followers","following_url":"https://api.github.com/users/elementary/following{/other_user}","gists_url":"https://api.github.com/users/elementary/gists{/gist_id}","starred_url":"https://api.github.com/users/elementary/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/elementary/subscriptions","organizations_url":"https://api.github.com/users/elementary/orgs","repos_url":"https://api.github.com/users/elementary/repos","events_url":"https://api.github.com/users/elementary/events{/privacy}","received_events_url":"https://api.github.com/users/elementary/received_events","type":"Organization","site_admin":false},"repo":{"id":70204293,"name":"vala-lint","full_name":"elementary/vala-lint","owner":{"login":"elementary","id":1978534,"avatar_url":"https://avatars0.githubusercontent.com/u/1978534?v=4","gravatar_id":"","url":"https://api.github.com/users/elementary","html_url":"https://github.com/elementary","followers_url":"https://api.github.com/users/elementary/followers","following_url":"https://api.github.com/users/elementary/following{/other_user}","gists_url":"https://api.github.com/users/elementary/gists{/gist_id}","starred_url":"https://api.github.com/users/elementary/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/elementary/subscriptions","organizations_url":"https://api.github.com/users/elementary/orgs","repos_url":"https://api.github.com/users/elementary/repos","events_url":"https://api.github.com/users/elementary/events{/privacy}","received_events_url":"https://api.github.com/users/elementary/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/elementary/vala-lint","description":"Check code-style of Vala code files","fork":false,"url":"https://api.github.com/repos/elementary/vala-lint","forks_url":"https://api.github.com/repos/elementary/vala-lint/forks","keys_url":"https://api.github.com/repos/elementary/vala-lint/keys{/key_id}","collaborators_url":"https://api.github.com/repos/elementary/vala-lint/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/elementary/vala-lint/teams","hooks_url":"https://api.github.com/repos/elementary/vala-lint/hooks","issue_events_url":"https://api.github.com/repos/elementary/vala-lint/issues/events{/number}","events_url":"https://api.github.com/repos/elementary/vala-lint/events","assignees_url":"https://api.github.com/repos/elementary/vala-lint/assignees{/user}","branches_url":"https://api.github.com/repos/elementary/vala-lint/branches{/branch}","tags_url":"https://api.github.com/repos/elementary/vala-lint/tags","blobs_url":"https://api.github.com/repos/elementary/vala-lint/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/elementary/vala-lint/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/elementary/vala-lint/git/refs{/sha}","trees_url":"https://api.github.com/repos/elementary/vala-lint/git/trees{/sha}","statuses_url":"https://api.github.com/repos/elementary/vala-lint/statuses/{sha}","languages_url":"https://api.github.com/repos/elementary/vala-lint/languages","stargazers_url":"https://api.github.com/repos/elementary/vala-lint/stargazers","contributors_url":"https://api.github.com/repos/elementary/vala-lint/contributors","subscribers_url":"https://api.github.com/repos/elementary/vala-lint/subscribers","subscription_url":"https://api.github.com/repos/elementary/vala-lint/subscription","commits_url":"https://api.github.com/repos/elementary/vala-lint/commits{/sha}","git_commits_url":"https://api.github.com/repos/elementary/vala-lint/git/commits{/sha}","comments_url":"https://api.github.com/repos/elementary/vala-lint/comments{/number}","issue_comment_url":"https://api.github.com/repos/elementary/vala-lint/issues/comments{/number}","contents_url":"https://api.github.com/repos/elementary/vala-lint/contents/{+path}","compare_url":"https://api.github.com/repos/elementary/vala-lint/compare/{base}...{head}","merges_url":"https://api.github.com/repos/elementary/vala-lint/merges","archive_url":"https://api.github.com/repos/elementary/vala-lint/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/elementary/vala-lint/downloads","issues_url":"https://api.github.com/repos/elementary/vala-lint/issues{/number}","pulls_url":"https://api.github.com/repos/elementary/vala-lint/pulls{/number}","milestones_url":"https://api.github.com/repos/elementary/vala-lint/milestones{/number}","notifications_url":"https://api.github.com/repos/elementary/vala-lint/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/elementary/vala-lint/labels{/name}","releases_url":"https://api.github.com/repos/elementary/vala-lint/releases{/id}","deployments_url":"https://api.github.com/repos/elementary/vala-lint/deployments","created_at":"2016-10-07T00:44:02Z","updated_at":"2018-01-25T19:33:32Z","pushed_at":"2018-02-13T12:36:54Z","git_url":"git://github.com/elementary/vala-lint.git","ssh_url":"git@github.com:elementary/vala-lint.git","clone_url":"https://github.com/elementary/vala-lint.git","svn_url":"https://github.com/elementary/vala-lint","homepage":null,"size":282,"stargazers_count":20,"watchers_count":20,"language":"Vala","has_issues":true,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":3,"mirror_url":null,"archived":false,"open_issues_count":13,"license":null,"forks":3,"open_issues":13,"watchers":20,"default_branch":"master"}},"base":{"label":"elementary:master","ref":"master","sha":"1dc2fdeb1b829e9ff57b3782c429500075d2ef32","user":{"login":"elementary","id":1978534,"avatar_url":"https://avatars0.githubusercontent.com/u/1978534?v=4","gravatar_id":"","url":"https://api.github.com/users/elementary","html_url":"https://github.com/elementary","followers_url":"https://api.github.com/users/elementary/followers","following_url":"https://api.github.com/users/elementary/following{/other_user}","gists_url":"https://api.github.com/users/elementary/gists{/gist_id}","starred_url":"https://api.github.com/users/elementary/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/elementary/subscriptions","organizations_url":"https://api.github.com/users/elementary/orgs","repos_url":"https://api.github.com/users/elementary/repos","events_url":"https://api.github.com/users/elementary/events{/privacy}","received_events_url":"https://api.github.com/users/elementary/received_events","type":"Organization","site_admin":false},"repo":{"id":70204293,"name":"vala-lint","full_name":"elementary/vala-lint","owner":{"login":"elementary","id":1978534,"avatar_url":"https://avatars0.githubusercontent.com/u/1978534?v=4","gravatar_id":"","url":"https://api.github.com/users/elementary","html_url":"https://github.com/elementary","followers_url":"https://api.github.com/users/elementary/followers","following_url":"https://api.github.com/users/elementary/following{/other_user}","gists_url":"https://api.github.com/users/elementary/gists{/gist_id}","starred_url":"https://api.github.com/users/elementary/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/elementary/subscriptions","organizations_url":"https://api.github.com/users/elementary/orgs","repos_url":"https://api.github.com/users/elementary/repos","events_url":"https://api.github.com/users/elementary/events{/privacy}","received_events_url":"https://api.github.com/users/elementary/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/elementary/vala-lint","description":"Check code-style of Vala code files","fork":false,"url":"https://api.github.com/repos/elementary/vala-lint","forks_url":"https://api.github.com/repos/elementary/vala-lint/forks","keys_url":"https://api.github.com/repos/elementary/vala-lint/keys{/key_id}","collaborators_url":"https://api.github.com/repos/elementary/vala-lint/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/elementary/vala-lint/teams","hooks_url":"https://api.github.com/repos/elementary/vala-lint/hooks","issue_events_url":"https://api.github.com/repos/elementary/vala-lint/issues/events{/number}","events_url":"https://api.github.com/repos/elementary/vala-lint/events","assignees_url":"https://api.github.com/repos/elementary/vala-lint/assignees{/user}","branches_url":"https://api.github.com/repos/elementary/vala-lint/branches{/branch}","tags_url":"https://api.github.com/repos/elementary/vala-lint/tags","blobs_url":"https://api.github.com/repos/elementary/vala-lint/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/elementary/vala-lint/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/elementary/vala-lint/git/refs{/sha}","trees_url":"https://api.github.com/repos/elementary/vala-lint/git/trees{/sha}","statuses_url":"https://api.github.com/repos/elementary/vala-lint/statuses/{sha}","languages_url":"https://api.github.com/repos/elementary/vala-lint/languages","stargazers_url":"https://api.github.com/repos/elementary/vala-lint/stargazers","contributors_url":"https://api.github.com/repos/elementary/vala-lint/contributors","subscribers_url":"https://api.github.com/repos/elementary/vala-lint/subscribers","subscription_url":"https://api.github.com/repos/elementary/vala-lint/subscription","commits_url":"https://api.github.com/repos/elementary/vala-lint/commits{/sha}","git_commits_url":"https://api.github.com/repos/elementary/vala-lint/git/commits{/sha}","comments_url":"https://api.github.com/repos/elementary/vala-lint/comments{/number}","issue_comment_url":"https://api.github.com/repos/elementary/vala-lint/issues/comments{/number}","contents_url":"https://api.github.com/repos/elementary/vala-lint/contents/{+path}","compare_url":"https://api.github.com/repos/elementary/vala-lint/compare/{base}...{head}","merges_url":"https://api.github.com/repos/elementary/vala-lint/merges","archive_url":"https://api.github.com/repos/elementary/vala-lint/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/elementary/vala-lint/downloads","issues_url":"https://api.github.com/repos/elementary/vala-lint/issues{/number}","pulls_url":"https://api.github.com/repos/elementary/vala-lint/pulls{/number}","milestones_url":"https://api.github.com/repos/elementary/vala-lint/milestones{/number}","notifications_url":"https://api.github.com/repos/elementary/vala-lint/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/elementary/vala-lint/labels{/name}","releases_url":"https://api.github.com/repos/elementary/vala-lint/releases{/id}","deployments_url":"https://api.github.com/repos/elementary/vala-lint/deployments","created_at":"2016-10-07T00:44:02Z","updated_at":"2018-01-25T19:33:32Z","pushed_at":"2018-02-13T12:36:54Z","git_url":"git://github.com/elementary/vala-lint.git","ssh_url":"git@github.com:elementary/vala-lint.git","clone_url":"https://github.com/elementary/vala-lint.git","svn_url":"https://github.com/elementary/vala-lint","homepage":null,"size":282,"stargazers_count":20,"watchers_count":20,"language":"Vala","has_issues":true,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":3,"mirror_url":null,"archived":false,"open_issues_count":13,"license":null,"forks":3,"open_issues":13,"watchers":20,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/elementary/vala-lint/pulls/31"},"html":{"href":"https://github.com/elementary/vala-lint/pull/31"},"issue":{"href":"https://api.github.com/repos/elementary/vala-lint/issues/31"},"comments":{"href":"https://api.github.com/repos/elementary/vala-lint/issues/31/comments"},"review_comments":{"href":"https://api.github.com/repos/elementary/vala-lint/pulls/31/comments"},"review_comment":{"href":"https://api.github.com/repos/elementary/vala-lint/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/elementary/vala-lint/pulls/31/commits"},"statuses":{"href":"https://api.github.com/repos/elementary/vala-lint/statuses/fd661ce3848f9cec2f523fd16777d1b6576c65c3"}},"author_association":"COLLABORATOR"}}
{"actor":{"display_login":"davidmhewitt"}}