{"id":18909129,"url":"https://github.com/jruby/jruby-parser","last_synced_at":"2025-04-06T22:10:18.093Z","repository":{"id":56879411,"uuid":"1729999","full_name":"jruby/jruby-parser","owner":"jruby","description":"JRuby's parser customized for IDE usage","archived":false,"fork":false,"pushed_at":"2023-02-01T23:13:07.000Z","size":1745,"stargazers_count":44,"open_issues_count":11,"forks_count":21,"subscribers_count":22,"default_branch":"master","last_synced_at":"2024-09-19T18:07:15.977Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"Java","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/jruby.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2011-05-10T20:35:44.000Z","updated_at":"2024-03-31T14:12:06.000Z","dependencies_parsed_at":"2023-02-09T13:30:27.534Z","dependency_job_id":null,"html_url":"https://github.com/jruby/jruby-parser","commit_stats":null,"previous_names":[],"tags_count":12,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jruby%2Fjruby-parser","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jruby%2Fjruby-parser/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jruby%2Fjruby-parser/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jruby%2Fjruby-parser/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/jruby","download_url":"https://codeload.github.com/jruby/jruby-parser/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247557767,"owners_count":20958047,"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-11-08T09:31:06.508Z","updated_at":"2025-04-06T22:10:18.073Z","avatar_url":"https://github.com/jruby.png","language":"Java","readme":"# JRubyParser.jar and jruby-parser.gem\n\nJRuby once had a parser which kept track of all sorts of extra information when it built it's Abstract Syntax Tree (AST).  Stuff like character offsets where a particular element started or ended.  The impact of this extra information was a more than noticeable amount of memory and a bit of a perf impact.  At the time we decided to discontinue having this sort of parser in JRuby we created JRubyParser.\n\nJRubyParser.java is just the Java code which is slowly evolving into everything a Ruby IDE project could want.  Ability to know where source elements are; whether a syntax is correct; source re-writing....\n\nNetbeans and Eclipse are two users of JRubyParser.  We have a vested interest in making parsing Ruby a convenient and simple task for Java programmers.\n\n# Basic Usage\n\n## Java\n\n```java\nimport org.jrubyparser.CompatVersion;\nimport org.jrubyparser.Parser;\nimport org.jrubyparser.ast.*;\nimport org.jrubyparser.parser.ParserConfiguration;\nimport java.io.StringReader;\n\npublic class ParseSomething {\n\n    public static void main(String[] args) {\n        String codeString = \"def foo(bar)\\n bar\\n end\\n foo('astring')\";\n\n        Node node = parseContents(codeString);\n        System.out.println(node);\n    }\n\n    public static Node parseContents(String string) {\n        Parser rubyParser = new Parser();\n        StringReader in = new StringReader(string);\n        CompatVersion version = CompatVersion.RUBY1_8;\n        ParserConfiguration config = new ParserConfiguration(0, version);\n        return rubyParser.parse(\"\u003ccode\u003e\", in, config);\n    }\n}\n\n```\nIn the above code, `CompatVersion` is an enum which can be `RUBY1_8`,`RUBY1_9`, `RUBY2_0`, or `RUBY2_3`. ParserConfiguration takes\nseveral options, including linenumber, version, and optionally a static scope and can be configured with additional information about syntax gathering if necessary. \n\n## Ruby\n\njruby-parser.gem is a gem which bundles JRubyParser.jar and also provides a thin Ruby layer around the Java API to follow Ruby programming idioms better.  Here is a simple example of parsing and rewriting using jruby-parser.rb:\n\n```ruby\nrequire 'jruby-parser'\n\nroot = JRubyParser.parse(\"b = foo(1)\")\nfcall = root.find_node(:fcall)\nfcall.name = 'bar'\nfcall.args[0] = true\n\n# Write out the new source \nroot.to_source # b = bar(true)\n```\n\n# Building\n\n## Generate new parser code (only needed on hacking .y files):\n\nAssume: [jay 1.0.2](https://github.com/jruby/jay) installed\n\n```sh\n./bin/generate_parser Ruby18Parser Ruby18\n./bin/generate_parser Ruby19Parser Ruby19\n./bin/generate_parser Ruby20Parser Ruby20\n```\n\n# Build and test using Rake\n\nCompiles .java files, builds jar, copies jar to lib directory and runs the specs:\n\n`jruby -S rake`\n\nBuilds gemfile:\n\n`jruby -S rake build`\n\nRuns specs:\n\n`jruby -S rake spec`\n\n## Build and package using Maven to get a JAR\n\n```sh\nmvn compile\nmvn package\n```\n\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjruby%2Fjruby-parser","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjruby%2Fjruby-parser","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjruby%2Fjruby-parser/lists"}