{"action":"created","comment":{"url":"https://api.github.com/repos/kaitai-io/kaitai_struct_compiler/pulls/comments/86108373","pull_request_review_id":6782344,"id":86108373,"diff_hunk":"@@ -0,0 +1,121 @@\n+package io.kaitai.struct.format\n+\n+import io.kaitai.struct.Utils\n+\n+object ParseUtils {\n+  def ensureLegalKeys(src: Map[String, Any], legalKeys: Set[String], path: List[String]) = {\n+    src.keys.foreach((key) =>\n+      if (!legalKeys.contains(key))\n+        throw new YAMLParseException(s\"unknown key found, expected: ${legalKeys.toList.sorted.mkString(\", \")}\", path ++ List(key))\n+    )\n+  }\n+\n+  // Unfortunately, these can't be parameterized with [T] - for some reason, `case Some(value: T)`\n+  // doesn't seem to work properly, checking that value is indeed of type T. Besides, there are some\n+  // variations when we need to do implicit type conversions.\n+\n+  def getValueStr(src: Map[String, Any], field: String, path: List[String]): String = {\n+    src.get(field) match {\n+      case Some(value: String) =>\n+        value\n+      case unknown =>\n+        throw YAMLParseException.badType(\"string\", unknown, path ++ List(field))\n+    }\n+  }\n+\n+  def getOptValueStr(src: Map[String, Any], field: String, path: List[String]): Option[String] = {\n+    src.get(field) match {\n+      case None =>\n+        None\n+      case Some(value: String) =>\n+        Some(value)\n+      case Some(value: Int) =>\n+        Some(value.toString)\n+      case unknown =>\n+        throw YAMLParseException.badType(\"string\", unknown, path ++ List(field))\n+    }\n+  }\n+\n+  def getOptValueBool(src: Map[String, Any], field: String, path: List[String]): Option[Boolean] = {\n+    src.get(field) match {\n+      case None =>\n+        None\n+      case Some(value: Boolean) =>\n+        Some(value)\n+      case unknown =>\n+        throw YAMLParseException.badType(\"boolean\", unknown, path ++ List(field))\n+    }\n+  }\n+\n+  def getOptValueInt(src: Map[String, Any], field: String, path: List[String]): Option[Int] = {\n+    src.get(field) match {\n+      case None =>\n+        None\n+      case Some(value: Int) =>\n+        Some(value)\n+      case unknown =>\n+        throw YAMLParseException.badType(\"int\", unknown, path ++ List(field))\n+    }\n+  }\n+\n+  def asStr(src: Any, path: List[String]): String = {\n+    src match {\n+      case str: String =>\n+        str\n+      case n: Int =>\n+        n.toString\n+      case unknown =>\n+        throw YAMLParseException.badType(\"string\", unknown, path)\n+    }\n+  }\n+\n+  def asLong(src: Any, path: List[String]): Long = {\n+    src match {\n+      case n: Long =>\n+        n\n+      case n: Int =>\n+        n\n+      case str: String =>\n+        // Generally should not happen, but when the data comes from JavaScript,\n+        // all object keys are forced to be strings.\n+        try {","path":"shared/src/main/scala/io/kaitai/struct/format/ParseUtils.scala","position":81,"original_position":81,"commit_id":"809cfb894751352d9b6346b1b60c6df911a10a48","original_commit_id":"809cfb894751352d9b6346b1b60c6df911a10a48","user":{"login":"codacy-bot","id":19940114,"avatar_url":"https://avatars.githubusercontent.com/u/19940114?v=3","gravatar_id":"","url":"https://api.github.com/users/codacy-bot","html_url":"https://github.com/codacy-bot","followers_url":"https://api.github.com/users/codacy-bot/followers","following_url":"https://api.github.com/users/codacy-bot/following{/other_user}","gists_url":"https://api.github.com/users/codacy-bot/gists{/gist_id}","starred_url":"https://api.github.com/users/codacy-bot/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/codacy-bot/subscriptions","organizations_url":"https://api.github.com/users/codacy-bot/orgs","repos_url":"https://api.github.com/users/codacy-bot/repos","events_url":"https://api.github.com/users/codacy-bot/events{/privacy}","received_events_url":"https://api.github.com/users/codacy-bot/received_events","type":"User","site_admin":false},"body":"![Codacy](https://www.codacy.com/assets/images/favicon.png) Issue found: [Consider using util.Try instead of a try-catch block](https://www.codacy.com/app/greycat-na-kor/kaitai_struct_compiler/file/4345013340/issues/source?bid=3217973&fileBranchId=3870090#l81)","created_at":"2016-11-02T10:12:21Z","updated_at":"2016-11-02T10:12:21Z","html_url":"https://github.com/kaitai-io/kaitai_struct_compiler/pull/27#discussion_r86108373","pull_request_url":"https://api.github.com/repos/kaitai-io/kaitai_struct_compiler/pulls/27","_links":{"self":{"href":"https://api.github.com/repos/kaitai-io/kaitai_struct_compiler/pulls/comments/86108373"},"html":{"href":"https://github.com/kaitai-io/kaitai_struct_compiler/pull/27#discussion_r86108373"},"pull_request":{"href":"https://api.github.com/repos/kaitai-io/kaitai_struct_compiler/pulls/27"}}},"pull_request":{"url":"https://api.github.com/repos/kaitai-io/kaitai_struct_compiler/pulls/27","id":91940604,"html_url":"https://github.com/kaitai-io/kaitai_struct_compiler/pull/27","diff_url":"https://github.com/kaitai-io/kaitai_struct_compiler/pull/27.diff","patch_url":"https://github.com/kaitai-io/kaitai_struct_compiler/pull/27.patch","issue_url":"https://api.github.com/repos/kaitai-io/kaitai_struct_compiler/issues/27","number":27,"state":"open","locked":false,"title":"Unified YAML parsing","user":{"login":"GreyCat","id":157154,"avatar_url":"https://avatars.githubusercontent.com/u/157154?v=3","gravatar_id":"","url":"https://api.github.com/users/GreyCat","html_url":"https://github.com/GreyCat","followers_url":"https://api.github.com/users/GreyCat/followers","following_url":"https://api.github.com/users/GreyCat/following{/other_user}","gists_url":"https://api.github.com/users/GreyCat/gists{/gist_id}","starred_url":"https://api.github.com/users/GreyCat/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/GreyCat/subscriptions","organizations_url":"https://api.github.com/users/GreyCat/orgs","repos_url":"https://api.github.com/users/GreyCat/repos","events_url":"https://api.github.com/users/GreyCat/events{/privacy}","received_events_url":"https://api.github.com/users/GreyCat/received_events","type":"User","site_admin":false},"body":"This is a somewhat complete re-implementation that addresses issue https://github.com/kaitai-io/kaitai_struct/issues/42. All internal structures are re-implemented to accommodate raw SnakeYAML + objects coming from JavaScript YAML parser. Jackson mapping library that we've used previously, is removed.\r\n\r\nAs far as I see, all tests pass, new compiler generates the same code as old one. As a bonus, we've got much nicer error messages.","created_at":"2016-11-02T10:09:49Z","updated_at":"2016-11-02T10:12:21Z","closed_at":null,"merged_at":null,"merge_commit_sha":"82b32375ec1fe2eb016144270697d8cdb251ecd0","assignee":null,"assignees":[],"milestone":null,"commits_url":"https://api.github.com/repos/kaitai-io/kaitai_struct_compiler/pulls/27/commits","review_comments_url":"https://api.github.com/repos/kaitai-io/kaitai_struct_compiler/pulls/27/comments","review_comment_url":"https://api.github.com/repos/kaitai-io/kaitai_struct_compiler/pulls/comments{/number}","comments_url":"https://api.github.com/repos/kaitai-io/kaitai_struct_compiler/issues/27/comments","statuses_url":"https://api.github.com/repos/kaitai-io/kaitai_struct_compiler/statuses/809cfb894751352d9b6346b1b60c6df911a10a48","head":{"label":"kaitai-io:unified-yaml","ref":"unified-yaml","sha":"809cfb894751352d9b6346b1b60c6df911a10a48","user":{"login":"kaitai-io","id":17322584,"avatar_url":"https://avatars.githubusercontent.com/u/17322584?v=3","gravatar_id":"","url":"https://api.github.com/users/kaitai-io","html_url":"https://github.com/kaitai-io","followers_url":"https://api.github.com/users/kaitai-io/followers","following_url":"https://api.github.com/users/kaitai-io/following{/other_user}","gists_url":"https://api.github.com/users/kaitai-io/gists{/gist_id}","starred_url":"https://api.github.com/users/kaitai-io/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/kaitai-io/subscriptions","organizations_url":"https://api.github.com/users/kaitai-io/orgs","repos_url":"https://api.github.com/users/kaitai-io/repos","events_url":"https://api.github.com/users/kaitai-io/events{/privacy}","received_events_url":"https://api.github.com/users/kaitai-io/received_events","type":"Organization","site_admin":false},"repo":{"id":52196052,"name":"kaitai_struct_compiler","full_name":"kaitai-io/kaitai_struct_compiler","owner":{"login":"kaitai-io","id":17322584,"avatar_url":"https://avatars.githubusercontent.com/u/17322584?v=3","gravatar_id":"","url":"https://api.github.com/users/kaitai-io","html_url":"https://github.com/kaitai-io","followers_url":"https://api.github.com/users/kaitai-io/followers","following_url":"https://api.github.com/users/kaitai-io/following{/other_user}","gists_url":"https://api.github.com/users/kaitai-io/gists{/gist_id}","starred_url":"https://api.github.com/users/kaitai-io/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/kaitai-io/subscriptions","organizations_url":"https://api.github.com/users/kaitai-io/orgs","repos_url":"https://api.github.com/users/kaitai-io/repos","events_url":"https://api.github.com/users/kaitai-io/events{/privacy}","received_events_url":"https://api.github.com/users/kaitai-io/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/kaitai-io/kaitai_struct_compiler","description":"Kaitai Struct: compiler to translate .ksy => .cpp / .cs / .java / .js / .py / .rb","fork":false,"url":"https://api.github.com/repos/kaitai-io/kaitai_struct_compiler","forks_url":"https://api.github.com/repos/kaitai-io/kaitai_struct_compiler/forks","keys_url":"https://api.github.com/repos/kaitai-io/kaitai_struct_compiler/keys{/key_id}","collaborators_url":"https://api.github.com/repos/kaitai-io/kaitai_struct_compiler/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/kaitai-io/kaitai_struct_compiler/teams","hooks_url":"https://api.github.com/repos/kaitai-io/kaitai_struct_compiler/hooks","issue_events_url":"https://api.github.com/repos/kaitai-io/kaitai_struct_compiler/issues/events{/number}","events_url":"https://api.github.com/repos/kaitai-io/kaitai_struct_compiler/events","assignees_url":"https://api.github.com/repos/kaitai-io/kaitai_struct_compiler/assignees{/user}","branches_url":"https://api.github.com/repos/kaitai-io/kaitai_struct_compiler/branches{/branch}","tags_url":"https://api.github.com/repos/kaitai-io/kaitai_struct_compiler/tags","blobs_url":"https://api.github.com/repos/kaitai-io/kaitai_struct_compiler/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/kaitai-io/kaitai_struct_compiler/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/kaitai-io/kaitai_struct_compiler/git/refs{/sha}","trees_url":"https://api.github.com/repos/kaitai-io/kaitai_struct_compiler/git/trees{/sha}","statuses_url":"https://api.github.com/repos/kaitai-io/kaitai_struct_compiler/statuses/{sha}","languages_url":"https://api.github.com/repos/kaitai-io/kaitai_struct_compiler/languages","stargazers_url":"https://api.github.com/repos/kaitai-io/kaitai_struct_compiler/stargazers","contributors_url":"https://api.github.com/repos/kaitai-io/kaitai_struct_compiler/contributors","subscribers_url":"https://api.github.com/repos/kaitai-io/kaitai_struct_compiler/subscribers","subscription_url":"https://api.github.com/repos/kaitai-io/kaitai_struct_compiler/subscription","commits_url":"https://api.github.com/repos/kaitai-io/kaitai_struct_compiler/commits{/sha}","git_commits_url":"https://api.github.com/repos/kaitai-io/kaitai_struct_compiler/git/commits{/sha}","comments_url":"https://api.github.com/repos/kaitai-io/kaitai_struct_compiler/comments{/number}","issue_comment_url":"https://api.github.com/repos/kaitai-io/kaitai_struct_compiler/issues/comments{/number}","contents_url":"https://api.github.com/repos/kaitai-io/kaitai_struct_compiler/contents/{+path}","compare_url":"https://api.github.com/repos/kaitai-io/kaitai_struct_compiler/compare/{base}...{head}","merges_url":"https://api.github.com/repos/kaitai-io/kaitai_struct_compiler/merges","archive_url":"https://api.github.com/repos/kaitai-io/kaitai_struct_compiler/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/kaitai-io/kaitai_struct_compiler/downloads","issues_url":"https://api.github.com/repos/kaitai-io/kaitai_struct_compiler/issues{/number}","pulls_url":"https://api.github.com/repos/kaitai-io/kaitai_struct_compiler/pulls{/number}","milestones_url":"https://api.github.com/repos/kaitai-io/kaitai_struct_compiler/milestones{/number}","notifications_url":"https://api.github.com/repos/kaitai-io/kaitai_struct_compiler/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/kaitai-io/kaitai_struct_compiler/labels{/name}","releases_url":"https://api.github.com/repos/kaitai-io/kaitai_struct_compiler/releases{/id}","deployments_url":"https://api.github.com/repos/kaitai-io/kaitai_struct_compiler/deployments","created_at":"2016-02-21T07:36:26Z","updated_at":"2016-11-02T04:17:03Z","pushed_at":"2016-11-02T10:09:49Z","git_url":"git://github.com/kaitai-io/kaitai_struct_compiler.git","ssh_url":"git@github.com:kaitai-io/kaitai_struct_compiler.git","clone_url":"https://github.com/kaitai-io/kaitai_struct_compiler.git","svn_url":"https://github.com/kaitai-io/kaitai_struct_compiler","homepage":"http://kaitai.io/","size":943,"stargazers_count":24,"watchers_count":24,"language":"Scala","has_issues":true,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":6,"mirror_url":null,"open_issues_count":4,"forks":6,"open_issues":4,"watchers":24,"default_branch":"master"}},"base":{"label":"kaitai-io:master","ref":"master","sha":"b85c0408bb56a28f7a694ec961e8d64c1fe7fb86","user":{"login":"kaitai-io","id":17322584,"avatar_url":"https://avatars.githubusercontent.com/u/17322584?v=3","gravatar_id":"","url":"https://api.github.com/users/kaitai-io","html_url":"https://github.com/kaitai-io","followers_url":"https://api.github.com/users/kaitai-io/followers","following_url":"https://api.github.com/users/kaitai-io/following{/other_user}","gists_url":"https://api.github.com/users/kaitai-io/gists{/gist_id}","starred_url":"https://api.github.com/users/kaitai-io/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/kaitai-io/subscriptions","organizations_url":"https://api.github.com/users/kaitai-io/orgs","repos_url":"https://api.github.com/users/kaitai-io/repos","events_url":"https://api.github.com/users/kaitai-io/events{/privacy}","received_events_url":"https://api.github.com/users/kaitai-io/received_events","type":"Organization","site_admin":false},"repo":{"id":52196052,"name":"kaitai_struct_compiler","full_name":"kaitai-io/kaitai_struct_compiler","owner":{"login":"kaitai-io","id":17322584,"avatar_url":"https://avatars.githubusercontent.com/u/17322584?v=3","gravatar_id":"","url":"https://api.github.com/users/kaitai-io","html_url":"https://github.com/kaitai-io","followers_url":"https://api.github.com/users/kaitai-io/followers","following_url":"https://api.github.com/users/kaitai-io/following{/other_user}","gists_url":"https://api.github.com/users/kaitai-io/gists{/gist_id}","starred_url":"https://api.github.com/users/kaitai-io/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/kaitai-io/subscriptions","organizations_url":"https://api.github.com/users/kaitai-io/orgs","repos_url":"https://api.github.com/users/kaitai-io/repos","events_url":"https://api.github.com/users/kaitai-io/events{/privacy}","received_events_url":"https://api.github.com/users/kaitai-io/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/kaitai-io/kaitai_struct_compiler","description":"Kaitai Struct: compiler to translate .ksy => .cpp / .cs / .java / .js / .py / .rb","fork":false,"url":"https://api.github.com/repos/kaitai-io/kaitai_struct_compiler","forks_url":"https://api.github.com/repos/kaitai-io/kaitai_struct_compiler/forks","keys_url":"https://api.github.com/repos/kaitai-io/kaitai_struct_compiler/keys{/key_id}","collaborators_url":"https://api.github.com/repos/kaitai-io/kaitai_struct_compiler/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/kaitai-io/kaitai_struct_compiler/teams","hooks_url":"https://api.github.com/repos/kaitai-io/kaitai_struct_compiler/hooks","issue_events_url":"https://api.github.com/repos/kaitai-io/kaitai_struct_compiler/issues/events{/number}","events_url":"https://api.github.com/repos/kaitai-io/kaitai_struct_compiler/events","assignees_url":"https://api.github.com/repos/kaitai-io/kaitai_struct_compiler/assignees{/user}","branches_url":"https://api.github.com/repos/kaitai-io/kaitai_struct_compiler/branches{/branch}","tags_url":"https://api.github.com/repos/kaitai-io/kaitai_struct_compiler/tags","blobs_url":"https://api.github.com/repos/kaitai-io/kaitai_struct_compiler/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/kaitai-io/kaitai_struct_compiler/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/kaitai-io/kaitai_struct_compiler/git/refs{/sha}","trees_url":"https://api.github.com/repos/kaitai-io/kaitai_struct_compiler/git/trees{/sha}","statuses_url":"https://api.github.com/repos/kaitai-io/kaitai_struct_compiler/statuses/{sha}","languages_url":"https://api.github.com/repos/kaitai-io/kaitai_struct_compiler/languages","stargazers_url":"https://api.github.com/repos/kaitai-io/kaitai_struct_compiler/stargazers","contributors_url":"https://api.github.com/repos/kaitai-io/kaitai_struct_compiler/contributors","subscribers_url":"https://api.github.com/repos/kaitai-io/kaitai_struct_compiler/subscribers","subscription_url":"https://api.github.com/repos/kaitai-io/kaitai_struct_compiler/subscription","commits_url":"https://api.github.com/repos/kaitai-io/kaitai_struct_compiler/commits{/sha}","git_commits_url":"https://api.github.com/repos/kaitai-io/kaitai_struct_compiler/git/commits{/sha}","comments_url":"https://api.github.com/repos/kaitai-io/kaitai_struct_compiler/comments{/number}","issue_comment_url":"https://api.github.com/repos/kaitai-io/kaitai_struct_compiler/issues/comments{/number}","contents_url":"https://api.github.com/repos/kaitai-io/kaitai_struct_compiler/contents/{+path}","compare_url":"https://api.github.com/repos/kaitai-io/kaitai_struct_compiler/compare/{base}...{head}","merges_url":"https://api.github.com/repos/kaitai-io/kaitai_struct_compiler/merges","archive_url":"https://api.github.com/repos/kaitai-io/kaitai_struct_compiler/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/kaitai-io/kaitai_struct_compiler/downloads","issues_url":"https://api.github.com/repos/kaitai-io/kaitai_struct_compiler/issues{/number}","pulls_url":"https://api.github.com/repos/kaitai-io/kaitai_struct_compiler/pulls{/number}","milestones_url":"https://api.github.com/repos/kaitai-io/kaitai_struct_compiler/milestones{/number}","notifications_url":"https://api.github.com/repos/kaitai-io/kaitai_struct_compiler/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/kaitai-io/kaitai_struct_compiler/labels{/name}","releases_url":"https://api.github.com/repos/kaitai-io/kaitai_struct_compiler/releases{/id}","deployments_url":"https://api.github.com/repos/kaitai-io/kaitai_struct_compiler/deployments","created_at":"2016-02-21T07:36:26Z","updated_at":"2016-11-02T04:17:03Z","pushed_at":"2016-11-02T10:09:49Z","git_url":"git://github.com/kaitai-io/kaitai_struct_compiler.git","ssh_url":"git@github.com:kaitai-io/kaitai_struct_compiler.git","clone_url":"https://github.com/kaitai-io/kaitai_struct_compiler.git","svn_url":"https://github.com/kaitai-io/kaitai_struct_compiler","homepage":"http://kaitai.io/","size":943,"stargazers_count":24,"watchers_count":24,"language":"Scala","has_issues":true,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":6,"mirror_url":null,"open_issues_count":4,"forks":6,"open_issues":4,"watchers":24,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/kaitai-io/kaitai_struct_compiler/pulls/27"},"html":{"href":"https://github.com/kaitai-io/kaitai_struct_compiler/pull/27"},"issue":{"href":"https://api.github.com/repos/kaitai-io/kaitai_struct_compiler/issues/27"},"comments":{"href":"https://api.github.com/repos/kaitai-io/kaitai_struct_compiler/issues/27/comments"},"review_comments":{"href":"https://api.github.com/repos/kaitai-io/kaitai_struct_compiler/pulls/27/comments"},"review_comment":{"href":"https://api.github.com/repos/kaitai-io/kaitai_struct_compiler/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/kaitai-io/kaitai_struct_compiler/pulls/27/commits"},"statuses":{"href":"https://api.github.com/repos/kaitai-io/kaitai_struct_compiler/statuses/809cfb894751352d9b6346b1b60c6df911a10a48"}}}}
{"actor":{"display_login":"codacy-bot"}}