[Feature request] Decorators / attributes

オープン
#199 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

評価

難易度
5/5
見積もり時間
1週間以上
初心者へのやさしさ
25/100
issue の種類
機能追加
明瞭さ
おおむね明確
活発さ
停滞
技術スタック
lua
領域
compilers

調査の方向性

まず、YueScript のコンパイラとパーサーのエントリーポイントを調べます。issue にはファイル名やテスト名がありません。要求されているデコレーターと属性マクロの例を、既存のクラス、関数、マクロの処理と比較します。構文、名前束縛、マクロ呼び出し、生成される Lua の動作が実装され、テストでカバーされれば完了です。

索引モデルが issue の本文から書いたものです。

説明

It would be nice if we could write something like this:

add_class_tostring = (target, name) ->
    target.<tostring> = () => "<class '#{name}'>"
    target


#[add_class_tostring]
class FooBar
    -- ...


print(FooBar) --> <class 'FooBar'>

It would be equivalent to this:

FooBar = add_class_tostring(class FooBar
    -- ...
"FooBar")

The name parameter would be statically determined from the declaration. This has the advantage that a statement like

#[wrap_func]
local x = () -> print("...")

would also have access to the name (x in this case). That would be equal to:

local x = wrap_func((() -> print("...")), "x")

Of course, name would have to be nil if the statement doesn't have a name (like a name-less class).


Additionally, macros should also be invocable as attributes:

macro example = (target, name) ->
    target


#[$example]
class FooBar
    -- ...

That would be equivalent to:

FooBar = $example(class FooBar
    -- ...
FooBar)

Note that, unlike a regular macro, the output of an attribute macro would not need to be wrapped in a do-expression.

主要言語
Lua
スター
620
フォーク
45
平均マージ
9時間 5分
マージ済み PR(30日)
1

環境構築

このプロジェクトには開発コンテナ、Dockerfile、コントリビューションガイドがありません。まず README を読み、一般的な手順ははじめてのコントリビューションガイドを参照してください。

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

IppClub/YueScript のほかの issue

IppClub/YueScript の issue をすべて見る

似ている issue

Lua の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。