{"id":13694440,"url":"https://github.com/shockerli/spiker","last_synced_at":"2025-04-10T00:07:46.977Z","repository":{"id":57555102,"uuid":"310472592","full_name":"shockerli/spiker","owner":"shockerli","description":"A Go package implementation of real-time computing","archived":false,"fork":false,"pushed_at":"2025-01-11T12:49:28.000Z","size":139,"stargazers_count":5,"open_issues_count":0,"forks_count":2,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-04-10T00:07:40.357Z","etag":null,"topics":["ast","go","golang","golang-library","realtime-compute","rule-engine","rules-engine","tdop"],"latest_commit_sha":null,"homepage":"","language":"Go","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/shockerli.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":"2020-11-06T02:38:56.000Z","updated_at":"2025-01-11T12:49:32.000Z","dependencies_parsed_at":"2025-02-16T03:31:52.968Z","dependency_job_id":"35b8200e-c8fc-488a-90c3-c6a72e5e73ad","html_url":"https://github.com/shockerli/spiker","commit_stats":null,"previous_names":[],"tags_count":4,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/shockerli%2Fspiker","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/shockerli%2Fspiker/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/shockerli%2Fspiker/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/shockerli%2Fspiker/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/shockerli","download_url":"https://codeload.github.com/shockerli/spiker/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248131317,"owners_count":21052819,"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":["ast","go","golang","golang-library","realtime-compute","rule-engine","rules-engine","tdop"],"created_at":"2024-08-02T17:01:32.082Z","updated_at":"2025-04-10T00:07:46.954Z","avatar_url":"https://github.com/shockerli.png","language":"Go","readme":"# Spiker\n[![PkgGoDev](https://pkg.go.dev/badge/github.com/shockerli/spiker)](https://pkg.go.dev/github.com/shockerli/spiker)\n[![Go Report Card](https://goreportcard.com/badge/github.com/shockerli/spiker)](https://goreportcard.com/report/github.com/shockerli/spiker)\n[![codecov](https://codecov.io/gh/shockerli/spiker/branch/master/graph/badge.svg)](https://codecov.io/gh/shockerli/spiker)\n![GitHub top language](https://img.shields.io/github/languages/top/shockerli/spiker)\n\n\u003e A Go package implementation of real-time computing\n\u003e\n\u003e lexer is inspired by [tdop](https://github.com/cristiandima/tdop)\n\nEnglish | [中文](README_ZH.md)\n\n## Install\n```sh\ngo get -u github.com/shockerli/spiker\n```\n\n\n## Usage\n\n- Execute\n\n\n```go\nspiker.Execute(`1 + 2 * 3 / 4`)\n```\n\n- ExecuteWithScope\n\n```go\nvar scopes = spiker.NewScopeTable(\"demo\", 1, nil)\nscopes.Set(\"a\", 3)\nscopes.Set(\"b\", 4)\n\nspiker.ExecuteWithScope(`a * 2 + b`, )\n```\n\n- Format\n\n```go\nspiker.Format(`a + b * 3`)\n```\n\n## Architecture\n![architecture](architecture.png)\n\n\n## Examples\n\n### Keywords\n```js\ntrue/false/if/else/in/...\n```\n\n### Instruction separation\nSpiker requires instructions to be terminated with a semicolon at the end of each statement\n\n### Data type\n- Number\n\u003e Integer, Float\n```js\n123;\n-123;\n12.34;\n-12.34;\n```\n\n- String\n```js\n\"abc\"\n```\n\n- Boolean\n```js\ntrue;\nfalse;\n```\n\n- Array\n```js\n[];\n[1, 2, \"a\"];\n[1, [], [2,], [3, 4,], 5];\n```\n\n- Dict\n```js\nv = [9:99, 8:8.8, \"hello\":12.02];\nv = [\"name\":\"jioby\", \"age\":18, \"log\":[1:2, 3:4]];\nv = [1, 9:9.9, 3];\n```\n\n### Arithmetic Operators\n```js\n1 + 2 - 3 * 4 / 5 % 6;\n-0.19 + 3.2983;\n3 ** 2;\n```\n\n### Bitwise Operators\n```js\n1 \u0026 2;\n1 | 2;\n1 ^ 2;\n1 \u003e\u003e 2;\n1 \u003c\u003c 2;\n```\n\n### Comparison Operators\n```js\n3 == 2;\n3 != 2;\n3 \u003e 2;\n3 \u003e= 2;\n3 \u003c 2;\n3 \u003c= 2;\n```\n\n### Logical Operators\n```js\n!2;\n1 \u0026\u0026 2;\n1 || 2;\n```\n\n### Assignment Operators\n```js\nv = 2;\nv += 2;\nv -= 2;\nv *= 2;\nv /= 2;\nv %= 2;\n\na = b = c = 100;\n```\n\n### In Operator\n```js\n\"john\" in [\"joy\", \"john\"]; // true\n100 in [100, 200, 300]; // true\n9 in [9:\"999\", 8:\"888\"]; // true\n9 in \"123456789\"; // true\n```\n\n### Build-in functions\n- export\n\u003e return the expression value and interrupt script\n```js\nexport(v);\nexport(v[i]);\n```\n\n- exist\n\u003e determines whether a variable or index exists\n```js\nexist(v);\nexist(v[i]);\n```\n\n- len\n\u003e return the length of a value\n```js\nlen(\"123\");\nlen(v);\nlen(v[i]);\n```\n\n- del\n\u003e delete one or more variable or index\n```js\ndel(a)\ndel(a, b)\ndel(a, b[1])\ndel(a[i], b[i])\n```\n\n### Custom function\n- single\n\n```js\nsum = (a, b) -\u003e a + b;\n\nexport(sum(1, 2)); # 3\n```\n\n```js\npow2 = x -\u003e x ** 2;\n\nexport(pow2(5)); # 25\n```\n\n- block\n\n```js\nmax = (a, b) -\u003e {\n    if (a \u003e b) {\n        return a;\n    } else {\n        return b;\n    }\n};\n\nexport(max(1, 2)); # 2\n```\n\n### Control structures\n\n- if/else\n\n```js\nif (a \u003e b \u0026\u0026 c != d) {\n    a = b;\n} else if (c \u003e b) {\n    a = c;\n} else {\n    export(c + d);\n}\n```\n\n- while\n\n```js\nwhile (true) {\n  a = 0;\n  while (a \u003c 10) {\n    print(a, \"\\n\");\n    a += 1;\n  }\n}\n```\n\n\n### More\n```js\na = 101;\nb = 102;\nc = \"103\";\nd = [1, 2, a, b, c+b, \"abc\"];\n\nif (a \u003e b) {\n    export(len(d));\n} else if (a \u003c b) {\n    if (c) {\n        d = -1000;\n    } else {\n        d = 0;\n    }\n\n    d += len(c);\n    export(d);\n}\n\nexport(d[2]);\n```\n\n\n## License\nThis project is licensed under the terms of the [MIT](LICENSE) license.\n","funding_links":[],"categories":["开源类库","Open source library"],"sub_categories":["解释器","Interpreter"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fshockerli%2Fspiker","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fshockerli%2Fspiker","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fshockerli%2Fspiker/lists"}