{"id":17801516,"url":"https://github.com/yiminghe/kison","last_synced_at":"2025-10-10T00:05:33.408Z","repository":{"id":16345880,"uuid":"19095748","full_name":"yiminghe/kison","owner":"yiminghe","description":"A LALR(1)/LL(1)/LL(K) parser generator for javascript/typescript","archived":false,"fork":false,"pushed_at":"2024-10-10T22:07:36.000Z","size":5991,"stargazers_count":41,"open_issues_count":2,"forks_count":4,"subscribers_count":4,"default_branch":"master","last_synced_at":"2025-09-15T06:12:12.752Z","etag":null,"topics":["async-regexp","excel-formula","grammar","javascript","lalr","ll","parser","parser-generator","typescript","vba"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","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/yiminghe.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":"2014-04-24T04:31:57.000Z","updated_at":"2025-03-04T06:39:26.000Z","dependencies_parsed_at":"2024-10-22T22:54:18.396Z","dependency_job_id":null,"html_url":"https://github.com/yiminghe/kison","commit_stats":{"total_commits":540,"total_committers":2,"mean_commits":270.0,"dds":"0.0037037037037036535","last_synced_commit":"5a85cf3c5bdf45c3555378ebb1bd7831ecf806df"},"previous_names":[],"tags_count":104,"template":false,"template_full_name":null,"purl":"pkg:github/yiminghe/kison","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yiminghe%2Fkison","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yiminghe%2Fkison/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yiminghe%2Fkison/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yiminghe%2Fkison/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/yiminghe","download_url":"https://codeload.github.com/yiminghe/kison/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yiminghe%2Fkison/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":279002373,"owners_count":26083355,"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","status":"online","status_checked_at":"2025-10-09T02:00:07.460Z","response_time":59,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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":["async-regexp","excel-formula","grammar","javascript","lalr","ll","parser","parser-generator","typescript","vba"],"created_at":"2024-10-27T12:38:39.812Z","updated_at":"2025-10-10T00:05:33.374Z","avatar_url":"https://github.com/yiminghe.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# kison\n\n[![NPM version](https://badge.fury.io/js/kison.png)](http://badge.fury.io/js/kison)\n[![NPM downloads](http://img.shields.io/npm/dm/kison.svg)](https://npmjs.org/package/kison)\n[![Build Status](https://app.travis-ci.com/yiminghe/kison.svg?branch=master)](https://app.travis-ci.com/github/yiminghe/kison)\n\n[https://yiminghe.me/kison](https://yiminghe.me/kison)\n\n[https://github.com/yiminghe/kison](https://github.com/yiminghe/kison)\n\nA LALR(1)/LL(1)/LL(K) parser generator for `javascript`/`typescript`\n\n## examples\n\n[https://yiminghe.me/kison/examples/](https://yiminghe.me/kison/examples/)\n\n- [xtemplate](https://github.com/xtemplate/xtemplate): an extensible template engine\n\n[![npm version](https://badge.fury.io/js/xtemplate.svg)](https://badge.fury.io/js/xtemplate)\n[![NPM downloads](https://img.shields.io/npm/dm/xtemplate.svg)](https://npmjs.org/package/xtemplate)\n\n- [json](https://github.com/modulex/json): es5 compliant javascript implementation of JSON parser\n\n[![npm version](https://badge.fury.io/js/modulex-json.svg)](https://badge.fury.io/js/modulex-json)\n[![NPM downloads](https://img.shields.io/npm/dm/modulex-json.svg)](https://npmjs.org/package/modulex-json)\n\n- [excel formula engine](https://yiminghe.me/kison/examples/excel-formula-engine/): excel formula engine\n\n[![npm version](https://badge.fury.io/js/excel-formula-engine.svg)](https://badge.fury.io/js/excel-formula-engine)\n[![NPM downloads](https://img.shields.io/npm/dm/excel-formula-engine.svg)](https://npmjs.org/package/excel-formula-engine)\n\n\n- [regular expression engine](https://yiminghe.me/kison/examples/regular-expression-engine/): support [async stream match](https://medium.com/@yiminghe/match-stream-data-using-regular-expression-a1a08b17ca2e)\n\n[![npm version](https://badge.fury.io/js/regular-expression-engine.svg)](https://badge.fury.io/js/regular-expression-engine)\n[![NPM downloads](https://img.shields.io/npm/dm/regular-expression-engine.svg)](https://npmjs.org/package/regular-expression-engine)\n\n- [vba engine](https://yiminghe.me/kison/examples/vba/): [written in typescript/javascript](https://medium.com/@yiminghe/vba-engine-written-in-typescript-javascript-4ee8403777ec)\n\n[![npm version](https://badge.fury.io/js/vba.svg)](https://badge.fury.io/js/vba)\n[![NPM downloads](https://img.shields.io/npm/dm/vba.svg)](https://npmjs.org/package/vba)\n\n## run command\n\n```\nnpx kison@latest -g xx-grammar.js\n```\n\n## grammar and lexer definition\n\n### LALR\n\ncal-grammar.js: support operator precedence\n\n``` javascript\nmodule.exports = {\n  productions: [\n    {\n      symbol: 'exp',\n      rhs: ['primaryExpression'],\n    },\n\n    {\n      symbol: 'exp',\n      rhs: ['exp', '^', 'exp'],\n      action() {\n        return {\n          v: Math.pow(this.$1.v, this.$3.v),\n          l: this.$1,\n          r: this.$3,\n          op: '^',\n        };\n      },\n    },\n    {\n      symbol: 'exp',\n      rhs: ['exp', '-', 'exp'],\n      action() {\n        return { v: this.$1.v - this.$3.v, l: this.$1, r: this.$3, op: '-' };\n      },\n    },\n    {\n      symbol: 'exp',\n      rhs: ['exp', '*', 'exp'],\n      action() {\n        return { v: this.$1.v * this.$3.v, l: this.$1, r: this.$3, op: '*' };\n      },\n    },\n    {\n      symbol: 'exp',\n      rhs: ['exp', '/', 'exp'],\n      action() {\n        return { v: this.$1.v / this.$3.v, l: this.$1, r: this.$3, op: '/' };\n      },\n    },\n    {\n      symbol: 'exp',\n      precedence: 'UMINUS',\n      rhs: ['-', 'exp'],\n      action() {\n        return { v: -this.$2.v, op: 'UMINUS' };\n      },\n    },\n    {\n      symbol: 'exp',\n      rhs: ['exp', '+', 'exp'],\n      action() {\n        return { v: this.$1.v + this.$3.v, l: this.$1, r: this.$3, op: '+' };\n      },\n    },\n    {\n      symbol: 'primaryExpression',\n      rhs: ['(', 'exp', ')'],\n      action() {\n        return this.$2;\n      },\n    },\n    {\n      symbol: 'primaryExpression',\n      rhs: ['NUMBER'],\n      action() {\n        return { v: Number(this.$1) };\n      },\n    },\n  ],\n\n  operators: [\n    ['left', '+', '-'],\n    ['left', '*', '/'],\n    ['right', '^'],\n    ['right', 'UMINUS'],\n  ],\n\n  lexer: {\n    rules: [\n      {\n        regexp: /^\\s+/,\n        token: '$HIDDEN',\n      },\n      {\n        regexp: /^[0-9]+(\\.[0-9]+)?\\b/,\n        token: 'NUMBER'\n      }\n    ]\n  }\n};\n```\n### LL/LL(K)\n\ncal-grammar.js: \n\n- LL(1) and LL(K) support:\n  - direct left recursive \n  - operator precedence \n  - repeat notation(*/+) \n  - optional notation(?)\n  - group notation('('/')')\n  - alternative natation('|')\n- LL(K) extra support:\n  - lazy repeat notation(*?/+?)\n  - lazy optional notation(??). \n\n``` javascript\nconst startGroup = `'('`;\nconst endGroup = `')'`;\nconst alternative = `'|'`;\n\nmodule.exports = () =\u003e ({\n  productions: [\n    {\n      symbol: 'program',\n      rhs: ['statements'],\n    },\n    {\n      symbol: 'statements',\n      rhs: [startGroup, 'exp', 'NEW_LINE', endGroup + '*'],\n    },\n    {\n      symbol: 'exp',\n      rhs: [\n        'exp', '+', 'exp',\n        alternative,\n        'exp', '-', 'exp',\n        alternative,\n        'exp', '*', 'exp',\n        alternative,\n        'exp', '/', 'exp',\n        alternative,\n        'exp', '^', 'exp',\n      ],\n      label: 'binary-exp',\n    },\n    {\n      symbol: 'exp',\n      rhs: ['-', 'exp'],\n      precedence: 'UMINUS',\n    },\n    {\n      symbol: 'exp',\n      rhs: ['NUMBER'],\n    },\n    {\n      symbol: 'exp',\n      rhs: ['(', 'exp', ')'],\n    },\n  ],\n\n  operators: [\n    ['left', '+', '-'],\n    ['left', '*', '/'],\n    ['right', '^'],\n    ['right', 'UMINUS'],\n  ],\n\n  lexer: {\n    rules: [\n      {\n        regexp: /^\\n/,\n        token: 'NEW_LINE',\n      },\n      {\n        regexp: /^\\s+/,\n        token: '$HIDDEN',\n      },\n      {\n        regexp: /^[0-9]+(\\.[0-9]+)?\\b/,\n        token: 'NUMBER',\n      },\n    ],\n  },\n});\n```\n\n## command options\n\n- `--es`: generate es module\n- `-g`: grammar file\n- `-m`: ll or lalr or llk **(llk is powerful than ll but less performant!)**\n- `--babel`: use babel to transform code. need install @babel/core@7.x and @babel/preset-env manually\n- `--declaration`: generate d.ts type file for LL parser\n\n### LALR\n\n```\nnpx kison@latest -g cal-grammar.js\n```\n\n### LL\n\nll parser generator\n\n```\nnpx kison@latest -m ll -g cal-grammar.js\n```\n\n## changelog\n\n### 0.6.0 - 2022/12/31\n\n- support incremental parser\n\n### 0.5.0 - 2021/09/30\n\n- support '-m llk' support LL(K)\n\n### 0.4.35 - 2021/09/22\n\n- support `--declaration` to generate d.ts type for LL\n\n### 0.4.x - 2021/06/24\n\n* LL \u0026 LALR\n  * add $HIDDEN token type \n  * use js config file\n  * add excel formula demo\n  * support filter for lexer config\n  * support operator precedence\n\n* LL\n  * support LL parser\n  * support direct left recursive elimination and extract common prefix for LL\n  * support parser tree auto return even if partly error\n\n### 0.3.0 - 2014/08/25\n\n* optimize error debug info\n\n\n\n\u003clink rel=\"stylesheet\" href=\"https://cdnjs.cloudflare.com/ajax/libs/github-fork-ribbon-css/0.2.3/gh-fork-ribbon.min.css\" /\u003e\n\n\u003ca class=\"github-fork-ribbon\" href=\"https://github.com/yiminghe/kison\" data-ribbon=\"Fork me on GitHub\" title=\"Fork me on GitHub\"\u003eFork me on GitHub\u003c/a\u003e\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fyiminghe%2Fkison","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fyiminghe%2Fkison","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fyiminghe%2Fkison/lists"}