{"id":13798031,"url":"https://github.com/soutaro/ast_utils","last_synced_at":"2025-04-13T11:21:27.252Z","repository":{"id":53693772,"uuid":"100060106","full_name":"soutaro/ast_utils","owner":"soutaro","description":"Utility over parser gem AST","archived":false,"fork":false,"pushed_at":"2021-03-19T04:46:43.000Z","size":47,"stargazers_count":3,"open_issues_count":0,"forks_count":1,"subscribers_count":4,"default_branch":"master","last_synced_at":"2025-04-11T17:51:47.122Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Ruby","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/soutaro.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-08-11T18:27:35.000Z","updated_at":"2021-03-19T04:46:46.000Z","dependencies_parsed_at":"2022-09-04T10:40:56.530Z","dependency_job_id":null,"html_url":"https://github.com/soutaro/ast_utils","commit_stats":null,"previous_names":[],"tags_count":4,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/soutaro%2Fast_utils","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/soutaro%2Fast_utils/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/soutaro%2Fast_utils/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/soutaro%2Fast_utils/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/soutaro","download_url":"https://codeload.github.com/soutaro/ast_utils/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248703736,"owners_count":21148219,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-08-04T00:00:38.088Z","updated_at":"2025-04-13T11:21:27.220Z","avatar_url":"https://github.com/soutaro.png","language":"Ruby","readme":"# ASTUtils\n\nASTUtils provides some utility over parser gem AST, which aims to help analyzing Ruby programs.\n\n## Installation\n\nAdd this line to your application's Gemfile:\n\n```ruby\ngem 'ast_utils'\n```\n\nAnd then execute:\n\n    $ bundle\n\nOr install it yourself as:\n\n    $ gem install ast_utils\n\n## Usage\n\n### ASTUtils::Labeling\n\n`ASTUTils::Labeling` implements local variables labeling.\n\nIn Ruby, local variable scope can be nested, and identification on local variables is not trivial.\nThis utility give labels to identify local variables.\n\n```rb\nrequire \"parser/current\"\nrequire \"ast_utils\"\n\nnode = Parser::CurrentRuby.parse(source)\nlabeled = ASTUtils::Labeling.translate(node: node)\n```\n\n### ASTUTils::Navigation\n\n`AST` has `children` but no pointer to its parent.\n\n```rb\nrequire \"parser/current\"\nrequire \"ast_utils\"\n\nnode = Parser::CurrentRuby.parse(source)\nnavigation = ASTUtils::Navigation.from(node: node)\n\nparent = navigation.parent(child_node)\n```\n\n### ASTUtils::Scope\n\n`Scope` is about *scope* in Ruby.\n\nIt associates outer scope and its inner scope.\n\n```rb\nrequire \"parser/current\"\nrequire \"ast_utils\"\n\nnode = Parser::CurrentRuby.parse(source)\nlabeled = ASTUtils::Labeling.translate(node: node)\nscope = ASTUtils::Scope.from(node: labeled)\n\nscope.root\nscope.children(root)\nscope.subs(root)\n```\n\n`children` includes `def` and iterator block, but `subs` only includes blocks.\n\nIt also defines `assignments` and `references` to refere assignments and references for local variables in the scope.\n\n`assignments` returns pair of:\n\n* Node which implements assignment\n* Labeled local variable name which is assigned\n\n## Contributing\n\nBug reports and pull requests are welcome on GitHub at https://github.com/soutaro/ast_utils.\n\n","funding_links":[],"categories":["Tools"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsoutaro%2Fast_utils","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsoutaro%2Fast_utils","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsoutaro%2Fast_utils/lists"}