{"action":"created","comment":{"url":"https://api.github.com/repos/andrewjensen/blockly-parser-rs/pulls/comments/223550725","pull_request_review_id":162699787,"id":223550725,"node_id":"MDI0OlB1bGxSZXF1ZXN0UmV2aWV3Q29tbWVudDIyMzU1MDcyNQ==","diff_hunk":"@@ -0,0 +1,450 @@\n+extern crate sxd_document;\n+\n+use std::str;\n+use std::string::String;\n+use std::collections::HashMap;\n+\n+use sxd_document::{\n+    parser,\n+    Package,\n+};\n+use sxd_document::dom::{\n+    Document,\n+    Root,\n+    ChildOfRoot,\n+    Element,\n+    ChildOfElement,\n+};\n+\n+#[derive(Debug)]\n+pub struct Program {\n+    pub groups: Vec<StatementBody>\n+}\n+\n+#[derive(PartialEq, Debug)]\n+pub struct StatementBody {\n+    pub blocks: Vec<Block>\n+}\n+\n+#[derive(PartialEq, Debug)]\n+pub struct Block {\n+    pub block_type: String,\n+    pub id: String,\n+    pub fields: Option<HashMap<String, FieldValue>>,\n+    pub statements: Option<HashMap<String, StatementBody>>,\n+}\n+\n+#[derive(PartialEq, Debug)]\n+pub enum FieldValue {\n+    SimpleField(String),\n+    ExpressionField(Block),\n+}\n+\n+impl Program {\n+    pub fn new() -> Self {\n+        Self {\n+            groups: Vec::new()\n+        }\n+    }\n+}\n+\n+impl StatementBody {\n+    pub fn new() -> Self {\n+        Self {\n+            blocks: Vec::new()\n+        }\n+    }\n+}\n+\n+impl Block {\n+    pub fn new() -> Self {\n+        Self {\n+            block_type: \"\".to_string(),\n+            id: \"\".to_string(),\n+            fields: None,\n+            statements: None\n+        }\n+    }\n+\n+    pub fn add_field(&mut self, name: String, value: FieldValue) {\n+        match self.fields {\n+            Some(ref mut f) => {\n+                f.insert(name.to_owned(), value);\n+            },\n+            None => {\n+                let mut new_map: HashMap<String, FieldValue> = HashMap::new();\n+                new_map.insert(name.to_owned(), value);\n+                self.fields = Some(new_map);\n+            }\n+        }\n+    }\n+\n+    pub fn get_field(&self, name: &str) -> Option<&FieldValue> {\n+        match self.fields {\n+            Some(ref fields) => {\n+                fields.get(name)\n+            },\n+            None => None\n+        }\n+    }\n+\n+    pub fn add_statement_body(&mut self, name: String, body: StatementBody) {\n+        match self.statements {\n+            Some(ref mut s) => {\n+                s.insert(name.to_owned(), body);\n+            },\n+            None => {\n+                let mut new_map: HashMap<String, StatementBody> = HashMap::new();\n+                new_map.insert(name.to_owned(), body);\n+                self.statements = Some(new_map);\n+            }\n+        };\n+    }\n+\n+    pub fn get_statement(&self, name: &str) -> Option<&StatementBody> {\n+        match self.statements {\n+            Some(ref statements) => {\n+                statements.get(name)\n+            },\n+            None => None\n+        }\n+    }\n+}\n+\n+\n+// Utilities for creating Blockly data structures\n+\n+pub fn program_from_xml(xml: &str) -> Program {","path":"src/lib.rs","position":117,"original_position":117,"commit_id":"a1915a6cbb4b09af6636c5e65746035eaa5eb866","original_commit_id":"a1915a6cbb4b09af6636c5e65746035eaa5eb866","user":{"login":"z2oh","id":385684,"node_id":"MDQ6VXNlcjM4NTY4NA==","avatar_url":"https://avatars3.githubusercontent.com/u/385684?v=4","gravatar_id":"","url":"https://api.github.com/users/z2oh","html_url":"https://github.com/z2oh","followers_url":"https://api.github.com/users/z2oh/followers","following_url":"https://api.github.com/users/z2oh/following{/other_user}","gists_url":"https://api.github.com/users/z2oh/gists{/gist_id}","starred_url":"https://api.github.com/users/z2oh/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/z2oh/subscriptions","organizations_url":"https://api.github.com/users/z2oh/orgs","repos_url":"https://api.github.com/users/z2oh/repos","events_url":"https://api.github.com/users/z2oh/events{/privacy}","received_events_url":"https://api.github.com/users/z2oh/received_events","type":"User","site_admin":false},"body":"Just calling attention to the fact that `xml` is of type `&str`, which it should be. This function does not need to take ownership of the actual xml in memory. This is likely owned by something else in your program.\r\n\r\nIf you are reading xml in from a file, then the data is likely owned by some buffer that you passed into a file reading function.\r\n\r\nIf you are reading xml in from a string literal (like in your tests below) then the data is owned by the binary itself (and are loaded into memory when the actual binary is; since this data lives for the duration of the entire binary, the reference to it has `'static` lifetime).","created_at":"2018-10-09T03:20:46Z","updated_at":"2018-10-09T03:34:26Z","html_url":"https://github.com/andrewjensen/blockly-parser-rs/pull/1#discussion_r223550725","pull_request_url":"https://api.github.com/repos/andrewjensen/blockly-parser-rs/pulls/1","author_association":"NONE","_links":{"self":{"href":"https://api.github.com/repos/andrewjensen/blockly-parser-rs/pulls/comments/223550725"},"html":{"href":"https://github.com/andrewjensen/blockly-parser-rs/pull/1#discussion_r223550725"},"pull_request":{"href":"https://api.github.com/repos/andrewjensen/blockly-parser-rs/pulls/1"}}},"pull_request":{"url":"https://api.github.com/repos/andrewjensen/blockly-parser-rs/pulls/1","id":221287963,"node_id":"MDExOlB1bGxSZXF1ZXN0MjIxMjg3OTYz","html_url":"https://github.com/andrewjensen/blockly-parser-rs/pull/1","diff_url":"https://github.com/andrewjensen/blockly-parser-rs/pull/1.diff","patch_url":"https://github.com/andrewjensen/blockly-parser-rs/pull/1.patch","issue_url":"https://api.github.com/repos/andrewjensen/blockly-parser-rs/issues/1","number":1,"state":"open","locked":false,"title":"Initial library code","user":{"login":"andrewjensen","id":3885955,"node_id":"MDQ6VXNlcjM4ODU5NTU=","avatar_url":"https://avatars2.githubusercontent.com/u/3885955?v=4","gravatar_id":"","url":"https://api.github.com/users/andrewjensen","html_url":"https://github.com/andrewjensen","followers_url":"https://api.github.com/users/andrewjensen/followers","following_url":"https://api.github.com/users/andrewjensen/following{/other_user}","gists_url":"https://api.github.com/users/andrewjensen/gists{/gist_id}","starred_url":"https://api.github.com/users/andrewjensen/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/andrewjensen/subscriptions","organizations_url":"https://api.github.com/users/andrewjensen/orgs","repos_url":"https://api.github.com/users/andrewjensen/repos","events_url":"https://api.github.com/users/andrewjensen/events{/privacy}","received_events_url":"https://api.github.com/users/andrewjensen/received_events","type":"User","site_admin":false},"body":"This is the initial commit of library code. This is the first time I am attempting to publish a crate, so I'm enthusiastically accepting public reviews on this PR!","created_at":"2018-10-09T02:03:45Z","updated_at":"2018-10-09T03:34:26Z","closed_at":null,"merged_at":null,"merge_commit_sha":"76a9bbab8843830c3968e8ca0989b4ee0c02c78d","assignee":null,"assignees":[],"requested_reviewers":[],"requested_teams":[],"labels":[],"milestone":null,"commits_url":"https://api.github.com/repos/andrewjensen/blockly-parser-rs/pulls/1/commits","review_comments_url":"https://api.github.com/repos/andrewjensen/blockly-parser-rs/pulls/1/comments","review_comment_url":"https://api.github.com/repos/andrewjensen/blockly-parser-rs/pulls/comments{/number}","comments_url":"https://api.github.com/repos/andrewjensen/blockly-parser-rs/issues/1/comments","statuses_url":"https://api.github.com/repos/andrewjensen/blockly-parser-rs/statuses/a1915a6cbb4b09af6636c5e65746035eaa5eb866","head":{"label":"andrewjensen:feat/initial-library","ref":"feat/initial-library","sha":"a1915a6cbb4b09af6636c5e65746035eaa5eb866","user":{"login":"andrewjensen","id":3885955,"node_id":"MDQ6VXNlcjM4ODU5NTU=","avatar_url":"https://avatars2.githubusercontent.com/u/3885955?v=4","gravatar_id":"","url":"https://api.github.com/users/andrewjensen","html_url":"https://github.com/andrewjensen","followers_url":"https://api.github.com/users/andrewjensen/followers","following_url":"https://api.github.com/users/andrewjensen/following{/other_user}","gists_url":"https://api.github.com/users/andrewjensen/gists{/gist_id}","starred_url":"https://api.github.com/users/andrewjensen/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/andrewjensen/subscriptions","organizations_url":"https://api.github.com/users/andrewjensen/orgs","repos_url":"https://api.github.com/users/andrewjensen/repos","events_url":"https://api.github.com/users/andrewjensen/events{/privacy}","received_events_url":"https://api.github.com/users/andrewjensen/received_events","type":"User","site_admin":false},"repo":{"id":152172225,"node_id":"MDEwOlJlcG9zaXRvcnkxNTIxNzIyMjU=","name":"blockly-parser-rs","full_name":"andrewjensen/blockly-parser-rs","private":false,"owner":{"login":"andrewjensen","id":3885955,"node_id":"MDQ6VXNlcjM4ODU5NTU=","avatar_url":"https://avatars2.githubusercontent.com/u/3885955?v=4","gravatar_id":"","url":"https://api.github.com/users/andrewjensen","html_url":"https://github.com/andrewjensen","followers_url":"https://api.github.com/users/andrewjensen/followers","following_url":"https://api.github.com/users/andrewjensen/following{/other_user}","gists_url":"https://api.github.com/users/andrewjensen/gists{/gist_id}","starred_url":"https://api.github.com/users/andrewjensen/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/andrewjensen/subscriptions","organizations_url":"https://api.github.com/users/andrewjensen/orgs","repos_url":"https://api.github.com/users/andrewjensen/repos","events_url":"https://api.github.com/users/andrewjensen/events{/privacy}","received_events_url":"https://api.github.com/users/andrewjensen/received_events","type":"User","site_admin":false},"html_url":"https://github.com/andrewjensen/blockly-parser-rs","description":"Deserialize XML generated by the Google Blockly UI into Rust data structures.","fork":false,"url":"https://api.github.com/repos/andrewjensen/blockly-parser-rs","forks_url":"https://api.github.com/repos/andrewjensen/blockly-parser-rs/forks","keys_url":"https://api.github.com/repos/andrewjensen/blockly-parser-rs/keys{/key_id}","collaborators_url":"https://api.github.com/repos/andrewjensen/blockly-parser-rs/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/andrewjensen/blockly-parser-rs/teams","hooks_url":"https://api.github.com/repos/andrewjensen/blockly-parser-rs/hooks","issue_events_url":"https://api.github.com/repos/andrewjensen/blockly-parser-rs/issues/events{/number}","events_url":"https://api.github.com/repos/andrewjensen/blockly-parser-rs/events","assignees_url":"https://api.github.com/repos/andrewjensen/blockly-parser-rs/assignees{/user}","branches_url":"https://api.github.com/repos/andrewjensen/blockly-parser-rs/branches{/branch}","tags_url":"https://api.github.com/repos/andrewjensen/blockly-parser-rs/tags","blobs_url":"https://api.github.com/repos/andrewjensen/blockly-parser-rs/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/andrewjensen/blockly-parser-rs/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/andrewjensen/blockly-parser-rs/git/refs{/sha}","trees_url":"https://api.github.com/repos/andrewjensen/blockly-parser-rs/git/trees{/sha}","statuses_url":"https://api.github.com/repos/andrewjensen/blockly-parser-rs/statuses/{sha}","languages_url":"https://api.github.com/repos/andrewjensen/blockly-parser-rs/languages","stargazers_url":"https://api.github.com/repos/andrewjensen/blockly-parser-rs/stargazers","contributors_url":"https://api.github.com/repos/andrewjensen/blockly-parser-rs/contributors","subscribers_url":"https://api.github.com/repos/andrewjensen/blockly-parser-rs/subscribers","subscription_url":"https://api.github.com/repos/andrewjensen/blockly-parser-rs/subscription","commits_url":"https://api.github.com/repos/andrewjensen/blockly-parser-rs/commits{/sha}","git_commits_url":"https://api.github.com/repos/andrewjensen/blockly-parser-rs/git/commits{/sha}","comments_url":"https://api.github.com/repos/andrewjensen/blockly-parser-rs/comments{/number}","issue_comment_url":"https://api.github.com/repos/andrewjensen/blockly-parser-rs/issues/comments{/number}","contents_url":"https://api.github.com/repos/andrewjensen/blockly-parser-rs/contents/{+path}","compare_url":"https://api.github.com/repos/andrewjensen/blockly-parser-rs/compare/{base}...{head}","merges_url":"https://api.github.com/repos/andrewjensen/blockly-parser-rs/merges","archive_url":"https://api.github.com/repos/andrewjensen/blockly-parser-rs/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/andrewjensen/blockly-parser-rs/downloads","issues_url":"https://api.github.com/repos/andrewjensen/blockly-parser-rs/issues{/number}","pulls_url":"https://api.github.com/repos/andrewjensen/blockly-parser-rs/pulls{/number}","milestones_url":"https://api.github.com/repos/andrewjensen/blockly-parser-rs/milestones{/number}","notifications_url":"https://api.github.com/repos/andrewjensen/blockly-parser-rs/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/andrewjensen/blockly-parser-rs/labels{/name}","releases_url":"https://api.github.com/repos/andrewjensen/blockly-parser-rs/releases{/id}","deployments_url":"https://api.github.com/repos/andrewjensen/blockly-parser-rs/deployments","created_at":"2018-10-09T01:59:27Z","updated_at":"2018-10-09T01:59:47Z","pushed_at":"2018-10-09T02:03:46Z","git_url":"git://github.com/andrewjensen/blockly-parser-rs.git","ssh_url":"git@github.com:andrewjensen/blockly-parser-rs.git","clone_url":"https://github.com/andrewjensen/blockly-parser-rs.git","svn_url":"https://github.com/andrewjensen/blockly-parser-rs","homepage":null,"size":4,"stargazers_count":0,"watchers_count":0,"language":null,"has_issues":true,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"archived":false,"open_issues_count":1,"license":null,"forks":0,"open_issues":1,"watchers":0,"default_branch":"master"}},"base":{"label":"andrewjensen:master","ref":"master","sha":"c12799c61100a6123548361e3321f37deeee0c5a","user":{"login":"andrewjensen","id":3885955,"node_id":"MDQ6VXNlcjM4ODU5NTU=","avatar_url":"https://avatars2.githubusercontent.com/u/3885955?v=4","gravatar_id":"","url":"https://api.github.com/users/andrewjensen","html_url":"https://github.com/andrewjensen","followers_url":"https://api.github.com/users/andrewjensen/followers","following_url":"https://api.github.com/users/andrewjensen/following{/other_user}","gists_url":"https://api.github.com/users/andrewjensen/gists{/gist_id}","starred_url":"https://api.github.com/users/andrewjensen/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/andrewjensen/subscriptions","organizations_url":"https://api.github.com/users/andrewjensen/orgs","repos_url":"https://api.github.com/users/andrewjensen/repos","events_url":"https://api.github.com/users/andrewjensen/events{/privacy}","received_events_url":"https://api.github.com/users/andrewjensen/received_events","type":"User","site_admin":false},"repo":{"id":152172225,"node_id":"MDEwOlJlcG9zaXRvcnkxNTIxNzIyMjU=","name":"blockly-parser-rs","full_name":"andrewjensen/blockly-parser-rs","private":false,"owner":{"login":"andrewjensen","id":3885955,"node_id":"MDQ6VXNlcjM4ODU5NTU=","avatar_url":"https://avatars2.githubusercontent.com/u/3885955?v=4","gravatar_id":"","url":"https://api.github.com/users/andrewjensen","html_url":"https://github.com/andrewjensen","followers_url":"https://api.github.com/users/andrewjensen/followers","following_url":"https://api.github.com/users/andrewjensen/following{/other_user}","gists_url":"https://api.github.com/users/andrewjensen/gists{/gist_id}","starred_url":"https://api.github.com/users/andrewjensen/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/andrewjensen/subscriptions","organizations_url":"https://api.github.com/users/andrewjensen/orgs","repos_url":"https://api.github.com/users/andrewjensen/repos","events_url":"https://api.github.com/users/andrewjensen/events{/privacy}","received_events_url":"https://api.github.com/users/andrewjensen/received_events","type":"User","site_admin":false},"html_url":"https://github.com/andrewjensen/blockly-parser-rs","description":"Deserialize XML generated by the Google Blockly UI into Rust data structures.","fork":false,"url":"https://api.github.com/repos/andrewjensen/blockly-parser-rs","forks_url":"https://api.github.com/repos/andrewjensen/blockly-parser-rs/forks","keys_url":"https://api.github.com/repos/andrewjensen/blockly-parser-rs/keys{/key_id}","collaborators_url":"https://api.github.com/repos/andrewjensen/blockly-parser-rs/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/andrewjensen/blockly-parser-rs/teams","hooks_url":"https://api.github.com/repos/andrewjensen/blockly-parser-rs/hooks","issue_events_url":"https://api.github.com/repos/andrewjensen/blockly-parser-rs/issues/events{/number}","events_url":"https://api.github.com/repos/andrewjensen/blockly-parser-rs/events","assignees_url":"https://api.github.com/repos/andrewjensen/blockly-parser-rs/assignees{/user}","branches_url":"https://api.github.com/repos/andrewjensen/blockly-parser-rs/branches{/branch}","tags_url":"https://api.github.com/repos/andrewjensen/blockly-parser-rs/tags","blobs_url":"https://api.github.com/repos/andrewjensen/blockly-parser-rs/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/andrewjensen/blockly-parser-rs/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/andrewjensen/blockly-parser-rs/git/refs{/sha}","trees_url":"https://api.github.com/repos/andrewjensen/blockly-parser-rs/git/trees{/sha}","statuses_url":"https://api.github.com/repos/andrewjensen/blockly-parser-rs/statuses/{sha}","languages_url":"https://api.github.com/repos/andrewjensen/blockly-parser-rs/languages","stargazers_url":"https://api.github.com/repos/andrewjensen/blockly-parser-rs/stargazers","contributors_url":"https://api.github.com/repos/andrewjensen/blockly-parser-rs/contributors","subscribers_url":"https://api.github.com/repos/andrewjensen/blockly-parser-rs/subscribers","subscription_url":"https://api.github.com/repos/andrewjensen/blockly-parser-rs/subscription","commits_url":"https://api.github.com/repos/andrewjensen/blockly-parser-rs/commits{/sha}","git_commits_url":"https://api.github.com/repos/andrewjensen/blockly-parser-rs/git/commits{/sha}","comments_url":"https://api.github.com/repos/andrewjensen/blockly-parser-rs/comments{/number}","issue_comment_url":"https://api.github.com/repos/andrewjensen/blockly-parser-rs/issues/comments{/number}","contents_url":"https://api.github.com/repos/andrewjensen/blockly-parser-rs/contents/{+path}","compare_url":"https://api.github.com/repos/andrewjensen/blockly-parser-rs/compare/{base}...{head}","merges_url":"https://api.github.com/repos/andrewjensen/blockly-parser-rs/merges","archive_url":"https://api.github.com/repos/andrewjensen/blockly-parser-rs/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/andrewjensen/blockly-parser-rs/downloads","issues_url":"https://api.github.com/repos/andrewjensen/blockly-parser-rs/issues{/number}","pulls_url":"https://api.github.com/repos/andrewjensen/blockly-parser-rs/pulls{/number}","milestones_url":"https://api.github.com/repos/andrewjensen/blockly-parser-rs/milestones{/number}","notifications_url":"https://api.github.com/repos/andrewjensen/blockly-parser-rs/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/andrewjensen/blockly-parser-rs/labels{/name}","releases_url":"https://api.github.com/repos/andrewjensen/blockly-parser-rs/releases{/id}","deployments_url":"https://api.github.com/repos/andrewjensen/blockly-parser-rs/deployments","created_at":"2018-10-09T01:59:27Z","updated_at":"2018-10-09T01:59:47Z","pushed_at":"2018-10-09T02:03:46Z","git_url":"git://github.com/andrewjensen/blockly-parser-rs.git","ssh_url":"git@github.com:andrewjensen/blockly-parser-rs.git","clone_url":"https://github.com/andrewjensen/blockly-parser-rs.git","svn_url":"https://github.com/andrewjensen/blockly-parser-rs","homepage":null,"size":4,"stargazers_count":0,"watchers_count":0,"language":null,"has_issues":true,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"archived":false,"open_issues_count":1,"license":null,"forks":0,"open_issues":1,"watchers":0,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/andrewjensen/blockly-parser-rs/pulls/1"},"html":{"href":"https://github.com/andrewjensen/blockly-parser-rs/pull/1"},"issue":{"href":"https://api.github.com/repos/andrewjensen/blockly-parser-rs/issues/1"},"comments":{"href":"https://api.github.com/repos/andrewjensen/blockly-parser-rs/issues/1/comments"},"review_comments":{"href":"https://api.github.com/repos/andrewjensen/blockly-parser-rs/pulls/1/comments"},"review_comment":{"href":"https://api.github.com/repos/andrewjensen/blockly-parser-rs/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/andrewjensen/blockly-parser-rs/pulls/1/commits"},"statuses":{"href":"https://api.github.com/repos/andrewjensen/blockly-parser-rs/statuses/a1915a6cbb4b09af6636c5e65746035eaa5eb866"}},"author_association":"OWNER"}}
{"actor":{"display_login":"z2oh"}}