{"id":19620593,"url":"https://github.com/cjhdev/contrived_json","last_synced_at":"2025-04-28T03:32:06.554Z","repository":{"id":56843823,"uuid":"82427834","full_name":"cjhdev/contrived_json","owner":"cjhdev","description":"A JSON parser implemented using Flex, Bison, and Ruby","archived":false,"fork":false,"pushed_at":"2018-11-13T11:25:34.000Z","size":60,"stargazers_count":19,"open_issues_count":0,"forks_count":0,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-04-05T05:51:09.436Z","etag":null,"topics":["bison","flex","json"],"latest_commit_sha":null,"homepage":null,"language":"C","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/cjhdev.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-02-19T01:39:10.000Z","updated_at":"2022-01-21T11:34:29.000Z","dependencies_parsed_at":"2022-09-05T15:31:47.287Z","dependency_job_id":null,"html_url":"https://github.com/cjhdev/contrived_json","commit_stats":null,"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cjhdev%2Fcontrived_json","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cjhdev%2Fcontrived_json/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cjhdev%2Fcontrived_json/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cjhdev%2Fcontrived_json/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/cjhdev","download_url":"https://codeload.github.com/cjhdev/contrived_json/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":251246151,"owners_count":21558759,"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":["bison","flex","json"],"created_at":"2024-11-11T11:19:23.171Z","updated_at":"2025-04-28T03:32:06.228Z","avatar_url":"https://github.com/cjhdev.png","language":"C","readme":"ContrivedJSON\n=============\n\nA Ruby JSON parser implemented using Flex and Bison.\n\nThis project is an example of how to use Flex and Bison with Ruby to produce LALR based parsers.\n\n[![Build Status](https://travis-ci.org/cjhdev/contrived_json.svg?branch=master)](https://travis-ci.org/cjhdev/contrived_json)\n[![Gem Version](https://badge.fury.io/rb/contrived_json.svg)](https://badge.fury.io/rb/contrived_json)\n\n## ContrivedJSON Highlights\n\n- Can read from a stream or a string\n- Big number support\n    - Fractions and exponents are captured using `BigDecimal::new`\n    - Integers are captured using `String#to_i`\n- Syntax error reporting with location and token information\n- Bulk of implementation within ~200 lines of configuration ([parser.l](etc/contrived_json/ext_parser/parser.l) and [parser.y](etc/contrived_json/ext_parser/parser.y))\n- Works on MRI Ruby 1.9.3 and up\n\n## The Interface\n\nContrivedJSON implements a parse method similar to the standard library\n`JSON.parse`. It looks like this:\n\n~~~ ruby\nmodule ContrivedJSON\n\n    class JSON\n\n        # @param source [String,#readpartial] JSON string or a stream\n        # @param opts   [Hash]\n        #\n        # @return [Hash,Array]\n        #\n        # @raise [ArgumentError]\n        # @raise [TypeError]\n        # @raise [ContrivedJSON::ParseError]\n        #\n        def self.parse(source, opts={})\n        end    \n\n    end\n\nend\n~~~\n\n## Usage\n\nInstalling:\n\n~~~\n$ gem install contrived_json\n~~~\n\nHello world:\n\n~~~\n$ irb\n2.3.3 :001 \u003e require 'contrived_json'\n =\u003e true \n2.3.3 :002 \u003e ContrivedJSON::JSON.parse('{\"hello\":\"world\"}')\n =\u003e {\"hello\"=\u003e\"world\"} \n~~~\n\nSyntax error:\n\n~~~\n$ irb\n2.3.3 :001 \u003e require 'contrived_json'\n =\u003e true \n2.3.3 :002 \u003e ContrivedJSON::JSON.parse('{\"hello\":\"world\"')\n1:10: error: syntax error, unexpected EOF, expecting ',' or '}'\nContrivedJSON::ParseError: parse error\n    from (irb):2:in `parse'\n    from (irb):2\n    from /home/cjh/.rvm/rubies/ruby-2.3.3/bin/irb:11:in `\u003cmain\u003e'\n~~~\n\n## Under The Hood\n\nIn this project the lexer is configured in [parser.l](etc/contrived_json/ext_parser/parser.l) and the parser is configured in [parser.y](etc/contrived_json/ext_parser/parser.y).\n\nThe rake task `:flexbison` is used by the developer to convert configuration into source:\n~~~\ntask :flexbison do    \n    system \"flex --outfile=#{DIR_SRC}/lexer.c --header-file=#{DIR_SRC}/lexer.h #{DIR_ETC}/parser.l\"\n    system \"bison -d #{DIR_ETC}/parser.y --output=#{DIR_SRC}/parser.c\"\nend\n~~~\n\nThe result is checked into Git:\n\n- [lexer.c](ext/contrived_json/ext_parser/lexer.c) \n- [lexer.h](ext/contrived_json/ext_parser/lexer.h) \n- [parser.c](ext/contrived_json/ext_parser/parser.c) \n- [parser.h](ext/contrived_json/ext_parser/parser.h) \n\nThe remainder of the code and structure in the repository is for packaging\nup the project as a Gem which will handle compilation of the parser\nsource on installation.\n  \n## Further Reading\n\n- [Bison user manual](https://www.gnu.org/software/bison/manual/)\n- The Flex user manual is included with the distribution and can be accessed from the terminal via the command `$ info flex`\n- [A Flex/Bison tutorial](http://aquamentus.com/flex_bison.html)\n\n## License\n\nContrivedJSON has an MIT license\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcjhdev%2Fcontrived_json","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcjhdev%2Fcontrived_json","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcjhdev%2Fcontrived_json/lists"}