{"id":19151845,"url":"https://github.com/zhs007/jison-demo","last_synced_at":"2026-03-14T13:22:22.785Z","repository":{"id":94328447,"uuid":"45098682","full_name":"zhs007/jison-demo","owner":"zhs007","description":null,"archived":false,"fork":false,"pushed_at":"2015-11-05T10:46:19.000Z","size":192,"stargazers_count":9,"open_issues_count":0,"forks_count":1,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-05-07T05:47:56.009Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","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/zhs007.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":"2015-10-28T08:27:21.000Z","updated_at":"2022-04-08T08:18:50.000Z","dependencies_parsed_at":"2023-03-08T07:26:12.394Z","dependency_job_id":null,"html_url":"https://github.com/zhs007/jison-demo","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/zhs007/jison-demo","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zhs007%2Fjison-demo","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zhs007%2Fjison-demo/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zhs007%2Fjison-demo/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zhs007%2Fjison-demo/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/zhs007","download_url":"https://codeload.github.com/zhs007/jison-demo/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zhs007%2Fjison-demo/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":262962838,"owners_count":23391700,"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-09T08:15:49.806Z","updated_at":"2026-03-14T13:22:22.713Z","avatar_url":"https://github.com/zhs007.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# jison-demo\n自己折腾jison的一些例子，对我来说，比现在在网上找的一些例子好用些，基本上是按一条线走下去的，也许对其他人也有点用处吧。\n\n我本来对语法解析这块没啥兴趣的，手头上做个东西，需要自动解析protobuf协议，其实开源的实现很多，但我要能得到注释内容，没找到合适的项目，只能自己来折腾了。\n\nnodejs项目，拉到本地后别忘了下载依赖（后来发现其实不需要依赖jison......）。\n\n```\nnpm install\n```\n\n具体的例子在子目录里面，每个例子都有一个jison的文件，同名的.js就是jison生成的，具体的使用看demo.js就好了。\n\ncalc\n---\n\n这就是网上能找到的最简单的calc例子了，解析纯数学运算，传入\n\n```\n(3 + 9) * 5\n```\n\n得到\n\n```\n60\n```\n\n这个是最基础的了。\n\ncalc2\n---\n\n在上面的例子上前进了一小步，传入\n\n```\na = (3 + 9) * 5\n```\n\n得到\n\n```\n{name: 'abc', val: 60}\n```\n\ncalc3\n---\n\n增加了注释的识别\n\n```\nabc = (3+9)*5 //我是注释\n```\n\n得到\n\n```\n{ name: 'abc', val: 60, comment: '//我是注释' }\n```\n\ncfgfile\n---\n配置文件的解析，这个例子稍微像点样子了，支持变量赋值，支持字符串，支持行注释等。样例配置文件如下\n\n```\nname = 'zhs007' // name\nhp = 100\nmaxhp = hp * 2\ninfo = \"haha\"\n```\n\n输出\n\n```\n[\n{name: 'name', val: 'zhs007', comment: 'name'},\n{name: 'hp', val: 100},\n{name: 'maxhp', val: 200},\n{name: 'info', val: 'haha'}\n]\n```\n\nstruct\n---\n类C++语法的结构体，强注释的，只支持行注释。样例配置文件如下\n\n```\n\nint a = 100;    // a is 100\n\n\n// B is haha\nstruct B {\n\n  int aa = a + 100; //aa is 200\n\n  string bb;\n};\n```\n\n输出\n\n```\n[\n  {\n    \"type\": \"struct\",\n    \"val\": [\n      {\n        \"type\": \"string\",\n        \"name\": \"bb\",\n        \"val\": \"\"\n      },\n      {\n        \"type\": \"int\",\n        \"name\": \"aa\",\n        \"val\": 200,\n        \"comment\": \"//aa is 200\"\n      }\n    ],\n    \"name\": \"B\",\n    \"comment\": \"// B is haha\"\n  },\n  {\n    \"type\": \"int\",\n    \"name\": \"a\",\n    \"val\": 100,\n    \"comment\": \"// a is xixi\"\n  }\n]\n```","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzhs007%2Fjison-demo","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fzhs007%2Fjison-demo","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzhs007%2Fjison-demo/lists"}