nadesiko3go

module
v0.0.0-...-097477c Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 11, 2026 License: MIT

README

日本語プログラミング言語「なでしこ3(Go版)」

日本語プログラミング言語「なでしこ3」のGo言語実装です。基本ライブラリを含めて、本家(TypeScript版)と同じように動きます。 ランタイムのインストール不要で配布しやすい、CUI/GUIバックエンドを目標にしています。

ランタイム兼開発エディタで、ファイル1つだけで動く、gonako-guiと、コマンドラインから使うgonakoを提供しています。


インストール方法

コマンドラインでコマンドを貼り付けて実行するとスムーズにインストールできます。

コマンド一発でインストール (ワンライナー)

macOS / Linux (ターミナル):

curl -fsSL https://nadesi.com/install/gonako | bash

Windows (PowerShell):

irm https://nadesi.com/install/gonako | iex
Homebrew (macOS) でインストールする方法
# Homebrewでtapを追加して、CLI/GUI版をインストール
brew tap kujirahand/nadesiko3 && brew trust kujirahand/nadesiko3
brew install gonako && brew install --cask gonako-gui

※ Linuxで gonako-gui を実行するには、ソースコードからビルドして利用してください。


インストールした後は?

上記の手順でインストールすると、gonako-gui というコマンドが使えるようになります。

ターミナル(PowerShell/ターミナル.app)上で、gonako-gui とタイプすると、開発用エディタが起動します。 プログラムを書いて、実行ボタンを押せば実行できます。例えば、以下のようなプログラムを書いて実行してみると良いでしょう。

# hello.nako3
名前=「お名前は? 」と尋ねる
「お名前は、『{名前}』さんで良いでしょうか?」と二択
もし、それがはいならば:
  「こんにちは、{名前}さん!」と言う
違えば:
  「処理を中止します」と表示。

また、開発用エディタの左側には、「ひな形」というタブがあるので、そこで「ひな形」を選んで実行してみてください。 なでしこの雰囲気を掴むことができます。

なでしこ3を学ぶには?

ターミナルから gonako を使う方法

gonakoは、コマンドラインから使うCLIツールです。なでしこのプログラムを実行したり、配布ファイルを作ったりできます。

# ファイルを実行する
gonako hello.nako3
gonako run hello.nako3 引数    # 引数は『コマンドライン』で受け取れる
# その場で実行する
gonako -e '「こんにちは」と表示'
cat hello.nako3 | gonako run - # 標準入力から読む

命令やマニュアルを検索する

gonako doc で、なでしこの命令を調べられます。命令一覧はgonakoに埋め込まれているので、 ネットにつながっていなくても検索できます。

gonako doc 秒待              # 命令一覧から検索する
gonako doc ファイル 読む      # キーワードを複数書くと、そのすべてに一致する命令を探す
gonako doc 秒待 --web        # Webのマニュアル(https://nadesi.com/v3/doc/)も検索する
gonako doc 秒待 --json       # 結果をJSONで出力する(AIエージェント向け)
オプション 説明
--command, -c 命令一覧(JSON)から検索する(既定の動作)
--web, -w Webのマニュアルも検索する
--json 結果をJSONで出力する
--limit N 表示する件数の上限(既定: 20、0で全件)

命令名・読みがな・説明・分類のいずれかに一致した命令を、一致度の高い順に表示します。 各命令には、マニュアルの解説ページ(https://nadesi.com/v3/doc/index.php?gonako/命令名)と、 Go版の実装場所も表示されます。


作ったものをそのまま渡す

プログラムとリソースを1つの実行ファイルに固められます。

gonako build かんたんゲーム.nako3 --resource ./images --out かんたんゲーム

できあがった かんたんゲーム を渡すだけで動きます。 受け取る側にはランタイムもインストールも要りません。

同梱したリソースは、開発中と同じ書き方で読めます。

設定=「images/setting.txt」を開く

開発中(gonako run)は実ファイルを、固めた後は同梱したものを読むので、 プログラムを書き換える必要はありません。

他のOS向けに固めるときは、そのOS向けのランタイムを土台に指定します。 バイト列を後ろに足すだけなので、固める側にGoツールチェインは要りません。

gonako build ゲーム.nako3 --runtime ./gonako-linux-amd64 --out ゲーム-linux

macOSの署名済みバイナリは末尾追記で署名が壊れます。 配布時は codesign し直してください。


Go言語でソースコードからインストール

gonako / gonako-gui をソースコードからコンパイルするのも簡単です。以下のコマンドを実行すると、/binフォルダ以下にgonako/gonako-guiが作成されます。

タスクランナーにはjustを使っています。 brew install just(またはお使いのOSのパッケージマネージャ)で導入してください。

# ビルド
git clone https://github.com/kujirahand/nadesiko3go.git
cd nadesiko3go
just build
# もしリリースファイルを生成するなら(実行中のOS向けのみ。just release-darwin 等でOS指定も可)
just release

「gnako-gui」「gonako」で実現できること

分野 内容
言語 変数・定数・演算子・制御構文・ユーザー定義関数・クロージャ・エラー監視
標準命令 文字列・配列・辞書・JSON・正規表現・タイマー(plugin_system 相当)
OS連携 ファイル読み書き・フォルダ操作・パス操作・環境変数・外部コマンド実行(plugin_node 相当)
SQLite DB開閉・切替・SQL実行・単一行/全行取得・位置/名前付きパラメータ・コールバック
配布 プログラムとリソースを単一の実行ファイルに梱包

※ 完全な互換性を保証するのは 標準ライブラリ(plugin_systemの範囲だけ)です。

gonako-gui に関して

gonako-guiは、GUI(WebView)を持ったなでしこ3の実行ランタイムですが、開発エディタを同梱しています。 gonako-guiを実行すると、デフォルトエディタが表示されます。

SQLite

SQLiteはgonako本体に組み込まれているため、取り込む文や外部ライブラリは不要です。

「books.sqlite3」をSQLITE3開く
「CREATE TABLE IF NOT EXISTS books(id INTEGER PRIMARY KEY, name TEXT)」を[]でSQLITE3実行
「INSERT INTO books(name) VALUES(?)」を[「クジラ」]でSQLITE3実行

行一覧=「SELECT id,name FROM books ORDER BY id」を[]でSQLITE3全取得
行一覧をJSONエンコード整形して表示
SQLITE3閉じる

SQLITE3開くの戻り値はDBハンドルです。複数開いた場合は、ハンドルを SQLITE3切替に渡して操作対象を変更できます。SQLite実装はpure Goなので、 CGOや別配布のSQLiteライブラリは不要です。

実行速度

代表的なアルゴリズム7本で、本家(cnako3 / Node.js)とVM実行(gonako)、 Goコード生成(gogen)を比較しています。結果と考察は benchmark/README.md にあります。

合計 対 cnako3
cnako3 (Node.js) 2713.6 ms 1.00x
gonako (VM実行) 1921.1 ms 1.41x
gogen (Goネイティブ) 880.1 ms 3.08x

VM実行は得意・不得意が分かれます。起動の軽さ・文字列処理・辞書・関数呼び出しは 本家より速い(文字列は約5倍、再帰は約2.6倍)一方、数値ループはV8のJITに負けます。

gogen(gonako gengo → go build)は7本すべてで本家より速く、 数値計算では3〜4倍です。生成コードは、型推論で数値と証明できた場所を 生の float64 で計算します(→ docs/gogen.md)。

ベンチマークは自分の環境でも回せます。

just cmd                      # gonako本体をビルド
go run ./benchmark/runner.go  # 測定してbenchmark/README.mdを再生成

開発

必要なGoバージョンとSQLiteドライバはgo.modで固定しています。 現在はGo 1.27.0、modernc.org/sqlite v1.57.0です。Go 1.21以降を導入済みで GOTOOLCHAIN=autoなら、リポジトリ内でgoを実行した際にGo 1.27.0が 自動取得・選択されます。

go version          # go version go1.27.0 ... を確認
just test           # テスト
just doctest        # manualとtestdata/doctestのサンプルを実行
just sync-compat    # 本家の差分fixtureをGo側へ同期
just compat-run     # 全ケースを実行して out/ へ出力
just compat-check   # 本家のoracleと照合して通過率を出す

将来、GoとSQLiteを新しい確定版へ更新する場合は、バージョンを明示して実行します。

go get go@1.27.0
go get modernc.org/sqlite@v1.57.0
go mod tidy
go test ./...

参考

Directories

Path Synopsis
cmd
gonako command
gonako-cui command
gonako-gui command
gonako-wasm command
gonako-wasm は、なでしこ3のコア機能をブラウザで動かすWebAssembly版です。
gonako-wasm は、なでしこ3のコア機能をブラウザで動かすWebAssembly版です。
internal
ast
Package ast defines the syntax tree the parser builds (nako_ast.mts equivalent).
Package ast defines the syntax tree the parser builds (nako_ast.mts equivalent).
bundle
Package bundle packs a compiled program and its resources onto the end of the runtime executable, so that the result is one file to hand over (AGENTS.md §10).
Package bundle packs a compiled program and its resources onto the end of the runtime executable, so that the result is one file to hand over (AGENTS.md §10).
commanddiff
Package commanddiff compares plugin_system command names with gonako's parser command table.
Package commanddiff compares plugin_system command names with gonako's parser command table.
commanddoc
Package commanddoc は、なでしこの命令一覧(JSON)からの検索と、 マニュアルサイトの検索を提供する。
Package commanddoc は、なでしこの命令一覧(JSON)からの検索と、 マニュアルサイトの検索を提供する。
compat
Package compat reads language-independent compatibility fixtures and writes results that can be consumed by nadesiko3's compat:check command.
Package compat reads language-independent compatibility fixtures and writes results that can be consumed by nadesiko3's compat:check command.
compiler
Package compiler turns the syntax tree into IR (AGENTS.md §6).
Package compiler turns the syntax tree into IR (AGENTS.md §6).
csvlib
Package csvlib implements the TypeScript plugin_csv commands used by the command-line runtime.
Package csvlib implements the TypeScript plugin_csv commands used by the command-line runtime.
dncl
Package dncl converts DNCL source into nadesiko source.
Package dncl converts DNCL source into nadesiko source.
doctest
Package doctest runs sample code from the manual and fixed test data, then checks that it prints the documented result.
Package doctest runs sample code from the manual and fixed test data, then checks that it prints the documented result.
errs
Package errs defines nadesiko-compatible error kinds and source locations.
Package errs defines nadesiko-compatible error kinds and source locations.
event
Package event holds the timer queue that makes asynchronous execution deterministic (AGENTS.md §8).
Package event holds the timer queue that makes asynchronous execution deterministic (AGENTS.md §8).
format
Package format はなでしこ3のソースコードを整形する(→ docs/format.md)。
Package format はなでしこ3のソースコードを整形する(→ docs/format.md)。
gogen
Package gogen emits Go source from versioned IR (AGENTS.md §12).
Package gogen emits Go source from versioned IR (AGENTS.md §12).
host
Package host defines the boundary between the language runtime and its execution environment.
Package host defines the boundary between the language runtime and its execution environment.
imagelib
Package imagelib implements deterministic raster image creation commands.
Package imagelib implements deterministic raster image creation commands.
indent
Package indent converts indentation syntax into parser input.
Package indent converts indentation syntax into parser input.
ir
Package ir defines the versioned, serializable boundary between compiler and execution backends.
Package ir defines the versioned, serializable boundary between compiler and execution backends.
lexer
Package lexer tokenizes prepared nadesiko source text.
Package lexer tokenizes prepared nadesiko source text.
lexer/josi
Package josi defines the particles (助詞) recognized by the lexer.
Package josi defines the particles (助詞) recognized by the lexer.
mathlib
Package mathlib implements commands from the separate TypeScript plugin_math.
Package mathlib implements commands from the separate TypeScript plugin_math.
nodelib
Package nodelib holds the commands that reach outside the program: files, the operating system, and the process itself (plugin_node's territory).
Package nodelib holds the commands that reach outside the program: files, the operating system, and the process itself (plugin_node's territory).
officelib
Package officelib implements spreadsheet commands for the CUI runtime.
Package officelib implements spreadsheet commands for the CUI runtime.
ops
Package ops holds what なでしこ's operators actually do, in one place.
Package ops holds what なでしこ's operators actually do, in one place.
parser
Package parser turns a token stream into a syntax tree (nako_parser3.mts / nako_parser_base.mts equivalent).
Package parser turns a token stream into a syntax tree (nako_parser3.mts / nako_parser_base.mts equivalent).
pdflib
Package pdflib implements PDF creation commands for the CUI runtime.
Package pdflib implements PDF creation commands for the CUI runtime.
prepare
Package prepare normalizes source text before lexical analysis.
Package prepare normalizes source text before lexical analysis.
re
Package re abstracts the regular-expression engine used by the nadesiko regexp commands.
Package re abstracts the regular-expression engine used by the nadesiko regexp commands.
safepath
Package safepath は os.Root(Go 1.24+)を使った安全なZIP展開ヘルパを提供する。
Package safepath は os.Root(Go 1.24+)を使った安全なZIP展開ヘルパを提供する。
sqlitelib
Package sqlitelib implements the commands from nadesiko3-sqlite3 for the command-line runtime.
Package sqlitelib implements the commands from nadesiko3-sqlite3 for the command-line runtime.
stdlib
Package stdlib contains the plugin_system-compatible command registry.
Package stdlib contains the plugin_system-compatible command registry.
tomllib
Package tomllib は本家の外部プラグイン nadesiko3-toml (plugin_toml) 相当の 命令を実装する。
Package tomllib は本家の外部プラグイン nadesiko3-toml (plugin_toml) 相当の 命令を実装する。
value
Package value defines the runtime value model shared by the compiler, VM, standard library, and host boundary.
Package value defines the runtime value model shared by the compiler, VM, standard library, and host boundary.
value/text
Package text provides rune-based string operations.
Package text provides rune-based string operations.
version
Package version は gonako のバージョン番号を一元管理する。
Package version は gonako のバージョン番号を一元管理する。
vm
Package vm executes versioned IR.
Package vm executes versioned IR.
wasmrt
Package wasmrt は、ブラウザ(WebAssembly)でなでしこのコア機能だけを動かす実行環境です。
Package wasmrt は、ブラウザ(WebAssembly)でなでしこのコア機能だけを動かす実行環境です。
pkg
nako3package
Package nako3package はランタイムへ埋め込むなでしこパッケージを持つ。
Package nako3package はランタイムへ埋め込むなでしこパッケージを持つ。
runtime
Package runtime is the public facade the gogen backend generates Go source against (AGENTS.md §12).
Package runtime is the public facade the gogen backend generates Go source against (AGENTS.md §12).
scripts
versionupdate
Package versionupdate は version-update スクリプトの引数解析ロジックを提供する。
Package versionupdate は version-update スクリプトの引数解析ロジックを提供する。

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL