{"id":13615009,"url":"https://github.com/chai2010/gotlang","last_synced_at":"2025-04-14T09:40:42.581Z","repository":{"id":51333106,"uuid":"219361313","full_name":"chai2010/gotlang","owner":"chai2010","description":":dog::dog::dog: 狗头语言（gotlang） :dog::dog::dog:","archived":false,"fork":false,"pushed_at":"2024-07-22T13:35:28.000Z","size":322,"stargazers_count":38,"open_issues_count":0,"forks_count":6,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-04-06T07:37:26.656Z","etag":null,"topics":["gotlang","language","programming-language"],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/chai2010.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":"2019-11-03T20:29:53.000Z","updated_at":"2024-07-22T13:35:32.000Z","dependencies_parsed_at":"2024-10-19T05:39:26.428Z","dependency_job_id":null,"html_url":"https://github.com/chai2010/gotlang","commit_stats":{"total_commits":12,"total_committers":1,"mean_commits":12.0,"dds":0.0,"last_synced_commit":"022b765c92ecdcb7d448f54fcc6f0ffff8d55614"},"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chai2010%2Fgotlang","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chai2010%2Fgotlang/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chai2010%2Fgotlang/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chai2010%2Fgotlang/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/chai2010","download_url":"https://codeload.github.com/chai2010/gotlang/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248855579,"owners_count":21172601,"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":["gotlang","language","programming-language"],"created_at":"2024-08-01T20:01:08.104Z","updated_at":"2025-04-14T09:40:42.550Z","avatar_url":"https://github.com/chai2010.png","language":"Go","funding_links":[],"categories":["Go"],"sub_categories":[],"readme":"\n- *凹语言™: https://github.com/wa-lang/wa*\n\n----\n\n# 狗头语言(Go Template Language)\n\n![](gotlang-logo.png)\n\n狗头语言是“柴树杉(chai2010)”于2019年11月基于Go语言标准库`text/template`包定制的图灵完备的玩具语言。\n\n## 安装\n\n```\n$ go get github.com/chai2010/gotlang/got\n```\n\n## 例子1：输出命令行参数\n\n创建`hello.gotmpl`程序，输出命令行参数：\n\n```gotmpl\n{{/* 狗头语 版权 @2019 柴树杉 */}}}\n\n{{template \"main\" .}}\n\n{{define \"main\"}}\n\t{{range $i, $v := . }}\n\t\t{{println $i $v}}\n\t{{end}}\n{{end}}\n```\n\n其中\"{{}}\"中间的是程序的语句，语句支持传统C语言风格的注释。然后通过`{{template \"main\" .}}`执行名字为\"main\"的模板，执行的参数是`.`表示的当前对象。这里的main模板可以看作是宏或者是函数，`template`指令会展开对应的宏函数，因此就产生了类似函数调用的效果（不过这个函数没有返回值）。然后通过`range`指令执行循环，每次循环打印相关信息。\n\n运行脚本：\n\n```\n$ got hello.gotmpl aa bb cc\n0 aa\n1 bb\n2 cc\n```\n\n执行时第一个参数是程序的路径，后面的参数是传递给狗头语脚本的命令行参数，也就是之前提到的`.`表示的当前对象。然后就可以输出命令行参数了。\n\n## 例子2：打印斐波那契数列\n\n创建`./examples/fib.gotmpl`程序，输出斐波那契数列：\n\n```\n{{/* 狗头语 版权 @2019 柴树杉 */}}}\n\n{{template_call \"main\" .}}\n\n{{define \"main\"}}\n\t{{range $_, $i := (xrange 10) }}\n\t\t{{printf \"%d: %d\\n\" $i (template_call \"fib\" $i)}}\n\t{{end}}\n{{end}}}\n\n{{define \"fib\"}}\n\t{{if (le . 0)}}\n\t\t{{template_ret 0}}\n\t\t{{/*return fib(0)*/}}\n\t{{else if (eq . 1)}}\n\t\t{{template_ret 1}}\n\t\t{{/*return fib(1)*/}}\n\t{{else}}\n\t\t{{template_ret (add (template_call \"fib\" (sub . 1)) (template_call \"fib\" (sub . 2)))}}\n\t\t{{/*return fib(n-1) + fib(n-2)*/}}\n\t{{end}}\n{{end}}\n```\n\n这个例子更为复杂：其中涉及到了通过递归函数计算斐波那契数列，然后将数列的前10个值打印出来。\n\n运行脚本：\n\n```\n$ got ./examples/fib.gotmpl\n0: 0\n1: 1\n2: 1\n3: 2\n4: 3\n5: 5\n6: 8\n7: 13\n8: 21\n9: 34\n```\n\n## 语法高亮（VS Code）\n\n安装 [gotemplate-syntax](https://marketplace.visualstudio.com/items?itemName=casualjim.gotemplate) 插件，效果如下：\n\n![](gotlang-logo-02.png)\n\n\n## 版权\n\n狗头语 版权 @2019 柴树杉。\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fchai2010%2Fgotlang","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fchai2010%2Fgotlang","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fchai2010%2Fgotlang/lists"}