otofune / sinfer Goto Github PK
View Code? Open in Web Editor NEW:boat: Infer types from structures like JSON and convert into Go source code
License: MIT License
:boat: Infer types from structures like JSON and convert into Go source code
License: MIT License
力技すぎて壊れそうなのでやめたい
これをやるには Go のエコシステムに出ていく必要がありそうな気はする
package main
import "encoding/json"
// 型名のうしろには1文字スペースが必要
type GeneratedType
例えば struct の slice に代入するときなど Go ではしばしば型を明示する必要がある場面に出会うことがある
匿名型だと常に append(slice, struct{A: string json:"a"
}{"aaa"}) のようにしなければならず、定義が変更されたタイミングで様々な箇所を修正しなければならなくなって面倒
よって、型として独立した名前がつけられるようにしたい
Go に起こす部分でユニークなのは any にしなければならないという点でしかない。
情報量が落ちる処理のみが言語系に合わせる部分であり、その表現力を失わない範囲で併合することは問題がない。
その処理だけを切り出せば綺麗にまとまるのでは?
利点としては
欠点としては
具体的には3つに分解する
IRUnion
を情報量を減らさない範囲で併合する方針: 同じ型のみ合成する
IRUnion
を子として含むなら、その内容を自身に併合する
IRUnion
を含まなくなるまで繰り返すIRUnion
をそれらの型にしてしまう
IRPrimitive
なら条件はないのでそのまま外に出すIRSlice
なら of
同士を合成した IRUnion
を作成し、併合処理を繰り返すIRStruct
なら field
毎に IRUnion
を作成し、併合処理を繰り返す。このとき合計 struct 数より少ないフィールドには optional を付与IRUnion
とするIRIgnore
を IRUnion
から消し去る[注意]
この処理を行うと IRAny
になってしまう可能性があるので破壊的である。
最終成果物を生成する際にのみ、必要な処理。
IRAny
が含まれる IRUnion
を常に IRAny
にするIRStruct
のフィールドが IRUnion
であった場合に限り、フィールドを optional 扱いにする役割を果す。その IRUnion
からは IRAny
を消し去った上で併合処理を繰り返すIRUnion
を消し去るIRIgnore
を削除されているものとする。されていなければ、することIRAny
にする
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.