{"id":15915220,"url":"https://github.com/kevinhinterlong/jsonit","last_synced_at":"2025-04-03T04:26:44.706Z","repository":{"id":148848308,"uuid":"143443998","full_name":"kevinhinterlong/jsonit","owner":"kevinhinterlong","description":"A guide to setting up antlr4 grammar projects","archived":false,"fork":false,"pushed_at":"2018-08-03T21:55:52.000Z","size":61,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-02-08T18:32:25.204Z","etag":null,"topics":["antlr4","example","gradle","java"],"latest_commit_sha":null,"homepage":"","language":"Java","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/kevinhinterlong.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,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2018-08-03T15:29:00.000Z","updated_at":"2022-10-26T06:35:28.000Z","dependencies_parsed_at":null,"dependency_job_id":"610c79e3-29ec-4ef7-88db-b6313b85b301","html_url":"https://github.com/kevinhinterlong/jsonit","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kevinhinterlong%2Fjsonit","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kevinhinterlong%2Fjsonit/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kevinhinterlong%2Fjsonit/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kevinhinterlong%2Fjsonit/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/kevinhinterlong","download_url":"https://codeload.github.com/kevinhinterlong/jsonit/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246935730,"owners_count":20857484,"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":["antlr4","example","gradle","java"],"created_at":"2024-10-06T17:22:36.772Z","updated_at":"2025-04-03T04:26:44.682Z","avatar_url":"https://github.com/kevinhinterlong.png","language":"Java","readme":"# jsonit\n\n`jsonit` is a simple example of how to use [`Antlr`](https://www.antlr.org/) to define a grammar and use it in a Java (and gradle) based project\n\n\nThe project uses the [`JSON.g4`](https://github.com/antlr/grammars-v4/blob/master/json/JSON.g4) grammar from the  [antlr/grammars-v4](https://github.com/antlr/grammars-v4) repo\n\n\u003e NOTE: This project is _not_ meant to be a useful json parser.\n\n\n\n## Antlr setup with gradle\n\nThe following lines from [`build.gradle`](build.gradle) define how to set up the `antlr` plugin which will generate the Java sources for you Parser/Lexer\n\n```groovy\n// First we must pull in the antlr plugin\napply plugin: 'antlr'\n\n// then decide where to store the generated java code\ndef generatedSources = [\n    rootDir: 'generated-src/',\n    javaDir: 'generated-src/java'\n]\n\n// then add the generated sources to our project\nsourceSets {\n    main {\n        java {\n            srcDir generatedSources.javaDir\n        }\n    }\n}\n\ndependencies {\n    // pull in 'org.antlr:antlr4:4.7' for the `antlr` configuration\n    // (this is just for building the sources files)\n    antlr 'org.antlr:antlr4:4.7'\n    // add the antlr runtime so we can use the generated sources\n    implementation 'org.antlr:antlr4-runtime:4.7'\n}\n\n// configure the grammar generation\n// more info: https://docs.gradle.org/current/userguide/antlr_plugin.html\ngenerateGrammarSource {\n    arguments += ['-visitor', '-long-messages']\n    outputDirectory = file(generatedSources.javaDir)\n}\n// ensures the grammar source files are generated before building the project\ncompileJava.dependsOn generateGrammarSource\n\n// delete the generated sources as part of the 'clean' step\nclean {\n    delete generatedSources.rootDir\n}\n```\n\n\n\n## Working with IntelliJ\n\nIntelliJ by default will use it's own configuration for running Gradle project which is great for most cases; however it does not work with complex configurations.\n\nIf you try to run the project with IntelliJ it will fail because it does not run this step\n\n```groovy\ncompileJava.dependsOn generateGrammarSource\n```\n\nTo solve this you can set\n\n**Build, Execution, Deployment** → **Build Tools** → **Gradle** → **Runner** → `Delegate IDE build/run actions to gradle` to true\n\n\u003e NOTE: You could also manually generate the grammar once (or whenever you change it)\n\u003e ```bash\n\u003e $ ./gradlew generateGrammarSource \n\u003e ```\n\n\n\n## Build\n\nTo build the project, clone it then run\n\n```bash\n$ ./gradlew build\n```\n\n\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkevinhinterlong%2Fjsonit","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fkevinhinterlong%2Fjsonit","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkevinhinterlong%2Fjsonit/lists"}