{"id":17841354,"url":"https://github.com/shybovycha/configscript","last_synced_at":"2025-04-02T14:09:26.018Z","repository":{"id":136382839,"uuid":"563722235","full_name":"shybovycha/configscript","owner":"shybovycha","description":"Configuration language parser in ANTLR4","archived":false,"fork":false,"pushed_at":"2023-09-27T07:28:02.000Z","size":36,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-02-08T05:14:53.995Z","etag":null,"topics":["antlr","antlr4","config","cpp","language"],"latest_commit_sha":null,"homepage":"","language":"C++","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/shybovycha.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,"governance":null}},"created_at":"2022-11-09T07:37:40.000Z","updated_at":"2022-11-09T07:39:01.000Z","dependencies_parsed_at":"2023-09-27T08:35:28.094Z","dependency_job_id":"429227c9-86e0-4c15-b329-da349e10006d","html_url":"https://github.com/shybovycha/configscript","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/shybovycha%2Fconfigscript","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/shybovycha%2Fconfigscript/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/shybovycha%2Fconfigscript/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/shybovycha%2Fconfigscript/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/shybovycha","download_url":"https://codeload.github.com/shybovycha/configscript/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246828500,"owners_count":20840474,"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":["antlr","antlr4","config","cpp","language"],"created_at":"2024-10-27T21:02:46.605Z","updated_at":"2025-04-02T14:09:26.001Z","avatar_url":"https://github.com/shybovycha.png","language":"C++","funding_links":[],"categories":[],"sub_categories":[],"readme":"# ConfigScript\n\n## Overview\n\nThis is a grammar in ANTLR for a config markup language, similar to [OGRE Scripts](https://ogrecave.github.io/ogre/api/latest/_scripts.html):\n\n```\n// This is a comment\nobject_keyword \"Example/ObjectName\"\n{\n    attribute_name \"some value\"\n\n    list_of_strings_attribute [\n        \"item #1\" \"item #2\"\n        \"item #3\" \"item #4\" \"item #5\"\n    ]\n\n    object_keyword2 \"Nested Object\"\n    {\n        other_attribute 1 2 3\n        /* block comment */\n    }\n}\n```\n\nThis repo includes a parser implementation in C++, so grammar is spiced up with the C++-specific [actions](https://github.com/antlr/antlr4/blob/master/doc/actions.md).\n\n## Building\n\nFirst, generate the C++ sources for the grammar parser using [ANTLR 4.13.0 JAR](https://www.antlr.org/download/antlr-4.13.0-complete.jar):\n\n```bash\njava -jar antlr-4.13.0-complete.jar -o gen_parser -Dlanguage=Cpp ConfigScript.g4\n```\n\n**NOTE:** it is important to keep ANTLR4 generator version in sync with what is [provided by the vcpkg](https://github.com/microsoft/vcpkg/blob/master/ports/antlr4/portfile.cmake).\n\nRun CMake specifying [vcpkg](https://github.com/microsoft/vcpkg) as a toolchain:\n\n```bash\ncmake -B build -S . -DCMAKE_TOOLCHAIN_FILE=\"[path to vcpkg]/scripts/buildsystems/vcpkg.cmake\"\n```\n\nThen, build the project:\n\n```bash\ncmake --build build\n```\n\n## Usage\n\nFirst, add the necessary headers to your code:\n\n```cpp\n#include \"parser.hpp\"\n```\n\nParse the code:\n\n```cpp\nconst auto configSource = R\"(\n// This is a comment\nmy_object_1 \"Example/ObjectName\" // \u003c--- this can not be just Example/ObjectName (no quotes)\n{\n    some_attribute \"some value\"\n\n    list_of_strings_attribute [\n        \"item #1\" \"item #2\"\n        \"item #3\" \"item #4\" \"item #5\"\n    ]\n\n    my_object_2 \"Nested Object\"\n    {\n        other_attribute 1 2 3\n        // and so on..\n        /* block comment */\n    }\n}\n)\";\n\n// parse the source\nauto config = ConfigScript::Parser::parse(configSource);\n```\n\nThe `config` variable would then contain a list (`std::vector`) of top-level objects from the config.\n\nTo access the top-level object properties, use\n\n```cpp\nstd::map\u003cstd::string, ConfigScript::PropertyType\u003e properties = config[0].properties;\n```\n\n`ConfigScripr::PropertyType` is an alias for `std::variant` containing all possible value types:\n\n* `int` and `float` vectors of 2, 3 or 4 components: `Vec2i`, `Vec3i`, `Vec4i`, `Vec2f`, `Vec3f`, `Vec4f`\n* `std::string`\n* `bool`\n* `int`\n* `float`\n* lists of strings (`std::vector\u003cstd::string\u003e`)\n* objects, represented as \n  ```cpp\n  ConfigScript::Object {\n    std::string name;\n    std::string classifier;\n    std::map\u003cstd::string, ConfigScript::PropertyType\u003e properties;\n  }\n  ```\n\nSince `PropertyType` is alias for `std::variant`, you would have to cast it to whatever it is underneath in order to access a specific property value:\n\n```cpp\nauto property1 = std::get\u003cstd::string\u003e(propertyValue1); // string values\nauto property2 = std::get\u003cConfigScript::Vec3f\u003e(propertyValue2); // 4-component float vector\n```\n\nObjects can have a _classifier_, which is a string following the object _name_:\n\n```\nobject_name \"object classifier\"\n{\n  // properties\n}\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fshybovycha%2Fconfigscript","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fshybovycha%2Fconfigscript","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fshybovycha%2Fconfigscript/lists"}