Skip to content

Commit c31667f

Browse files
authored
Merge pull request #1479 from vim-jp/hh-update-vim9class
Update vim9class.{txt,jax}
2 parents 9d47ad7 + 505e454 commit c31667f

File tree

2 files changed

+231
-20
lines changed

2 files changed

+231
-20
lines changed

doc/vim9class.jax

Lines changed: 115 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
*vim9class.txt* For Vim バージョン 9.1. Last change: 2024 Mar 03
1+
*vim9class.txt* For Vim バージョン 9.1. Last change: 2024 Mar 28
22

33

44
VIMリファレンスマニュアル by Bram Moolenaar
@@ -891,19 +891,124 @@ Note メソッド名は "new" で始まる必要があることに注意。"new(
891891

892892
8. 列挙型 *Vim9-enum* *:enum* *:endenum*
893893

894-
{not implemented yet (まだ実装されていない)}
894+
*enum* *E1418* *E1419* *E1420*
895+
列挙型は、値のリストの 1 つを持つことができる型である。例: >
895896
896-
enum は、値のリストの 1 つを持つことができる型である。例: >
897+
:enum Color
898+
White,
899+
Red,
900+
Green, Blue, Black
901+
:endenum
902+
<
903+
*enumvalue* *E1422*
904+
列挙値はコンマで区切られる。複数の列挙値を 1 行にリストできる。最後の列挙値の
905+
後にコンマを付けてはならない。
906+
907+
列挙値には、列挙名に続いて値の名前を使用してアクセスする: >
908+
909+
var a: Color = Color.Blue
910+
<
911+
列挙型はクラスとして扱われ、各列挙値は本質的にそのクラスのインスタンスである。
912+
|new()| メソッドを使用した一般的なオブジェクトのインスタンス化とは異なり、この
913+
方法では列挙型インスタンスを作成できない。
914+
915+
列挙型は |Vim9| script ファイルでのみ定義できる。 *E1414*
916+
列挙型は関数内で定義できない。
917+
918+
*E1415*
919+
列挙名は大文字で始めなければならない。列挙型内の列挙値の名前は、大文字または小
920+
文字で始めることができる。
921+
922+
*E1416*
923+
列挙型はインターフェイスを実装できるが、クラスを拡張することはできない: >
897924
898-
:enum Color
899-
White
900-
Red
901-
Green
902-
Blue
903-
Black
904-
:endenum
925+
enum MyEnum implements MyIntf
926+
Value1,
927+
Value2
905928
929+
def SomeMethod()
930+
enddef
931+
endenum
932+
<
933+
*enum-constructor*
934+
列挙型内の列挙値値オブジェクトは、|new()| メソッドを使用する他のオブジェクトと
935+
同じように構築される。関数を呼び出すのと同じように、引数を列挙値名の後に指定す
936+
ることで、列挙型コンストラクタに引数を渡すことができる。デフォルトのコンストラ
937+
クタには引数がない。
938+
939+
*E1417*
940+
列挙型には、クラス変数、クラスメソッド、オブジェクト変数、およびオブジェクトメ
941+
ソッドを含めることができる。列挙型内のメソッドを |:abstract| メソッドにするこ
942+
とはできない。
943+
944+
次の例は、オブジェクト変数とオブジェクトメソッドを含む列挙型を示している: >
906945
946+
vim9script
947+
enum Planet
948+
Earth(1, false),
949+
Jupiter(95, true),
950+
Saturn(146, true)
951+
952+
var moons: number
953+
var has_rings: bool
954+
def GetMoons(): number
955+
return this.moons
956+
enddef
957+
endenum
958+
echo Planet.Jupiter.GetMoons()
959+
echo Planet.Earth.has_rings
960+
<
961+
*E1421* *E1423* *E1424* *E1425*
962+
列挙型とその値は不変である。宣言後に変更したり、数値型または文字列型として使用
963+
したりすることはできない。
964+
965+
*enum-name*
966+
各列挙値オブジェクトには、列挙値の名前を含む "name" インスタンス変数がある。こ
967+
れは読み取り専用の変数である。
968+
969+
*enum-ordinal* *E1426*
970+
各列挙値には、0 から始まる序数が関連付けられている。列挙値の序数には、インスタ
971+
ンス変数 "ordinal" を使用してアクセスできる。これは読み取り専用の変数である。
972+
Note 列挙型内の列挙値の順序が変更されると、その序数の値も変更されることに注意。
973+
974+
*enum-values*
975+
列挙型内のすべての値には、列挙型オブジェクトのリストである "values" クラス変数
976+
を使用してアクセスできる。これは読み取り専用の変数である。
977+
978+
例: >
979+
enum Planet
980+
Mercury,
981+
Venus,
982+
Earth
983+
endenum
984+
985+
echo Planet.Mercury
986+
echo Planet.Venus.name
987+
echo Planet.Venus.ordinal
988+
for p in Planet.values
989+
# ...
990+
endfor
991+
<
992+
列挙型は、列挙値オブジェクトのクラス変数と、列挙値の名前と列挙値の序数のオブ
993+
ジェクト変数を持つクラスである: >
994+
995+
enum Planet
996+
Mercury,
997+
Venus
998+
endenum
999+
<
1000+
上記の列挙型定義は、以下のクラス定義と同等である: >
1001+
1002+
class Planet
1003+
public static final Mercury: Planet = Planet.new('Mercury', 0)
1004+
public static final Venus: Planet = Planet.new('Venus', 1)
1005+
1006+
public static const values: list<Planet> = [Planet.Mercury, Planet.Venus]
1007+
1008+
public const name: string
1009+
public const ordinal: number
1010+
endclass
1011+
<
9071012
==============================================================================
9081013

9091014
9. 論理的根拠

en/vim9class.txt

Lines changed: 116 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
*vim9class.txt* For Vim version 9.1. Last change: 2024 Mar 03
1+
*vim9class.txt* For Vim version 9.1. Last change: 2024 Mar 28
22

33

44
VIM REFERENCE MANUAL by Bram Moolenaar
@@ -904,19 +904,125 @@ aliased: >
904904

905905
8. Enum *Vim9-enum* *:enum* *:endenum*
906906

907-
{not implemented yet}
908-
907+
*enum* *E1418* *E1419* *E1420*
909908
An enum is a type that can have one of a list of values. Example: >
910909
911-
:enum Color
912-
White
913-
Red
914-
Green
915-
Blue
916-
Black
917-
:endenum
910+
:enum Color
911+
White,
912+
Red,
913+
Green, Blue, Black
914+
:endenum
915+
<
916+
*enumvalue* *E1422*
917+
The enum values are separated by commas. More than one enum value can be
918+
listed in a single line. The final enum value should not be followed by a
919+
comma.
920+
921+
An enum value is accessed using the enum name followed by the value name: >
922+
923+
var a: Color = Color.Blue
924+
<
925+
Enums are treated as classes, where each enum value is essentially an instance
926+
of that class. Unlike typical object instantiation with the |new()| method,
927+
enum instances cannot be created this way.
928+
929+
An enum can only be defined in a |Vim9| script file. *E1414*
930+
An enum cannot be defined inside a function.
931+
932+
*E1415*
933+
An enum name must start with an uppercase letter. The name of an enum value
934+
in an enum can start with an upper or lowercase letter.
935+
936+
*E1416*
937+
An enum can implement an interface but cannot extend a class: >
938+
939+
enum MyEnum implements MyIntf
940+
Value1,
941+
Value2
942+
943+
def SomeMethod()
944+
enddef
945+
endenum
946+
<
947+
*enum-constructor*
948+
The enum value objects in an enum are constructed like any other objects using
949+
the |new()| method. Arguments can be passed to the enum constructor by
950+
specifying them after the enum value name, just like calling a function. The
951+
default constructor doesn't have any arguments.
952+
953+
*E1417*
954+
An enum can contain class variables, class methods, object variables and
955+
object methods. The methods in an enum cannot be |:abstract| methods.
956+
957+
The following example shows an enum with object variables and methods: >
958+
959+
vim9script
960+
enum Planet
961+
Earth(1, false),
962+
Jupiter(95, true),
963+
Saturn(146, true)
964+
965+
var moons: number
966+
var has_rings: bool
967+
def GetMoons(): number
968+
return this.moons
969+
enddef
970+
endenum
971+
echo Planet.Jupiter.GetMoons()
972+
echo Planet.Earth.has_rings
973+
<
974+
*E1421* *E1423* *E1424* *E1425*
975+
Enums and their values are immutable. They cannot be modified after
976+
declaration and cannot be utilized as numerical or string types.
977+
978+
*enum-name*
979+
Each enum value object has a "name" instance variable which contains the name
980+
of the enum value. This is a readonly variable.
981+
982+
*enum-ordinal* *E1426*
983+
Each enum value has an associated ordinal number starting with 0. The ordinal
984+
number of an enum value can be accessed using the "ordinal" instance variable.
985+
This is a readonly variable. Note that if the ordering of the enum values in
986+
an enum is changed, then their ordinal values will also change.
987+
988+
*enum-values*
989+
All the values in an enum can be accessed using the "values" class variable
990+
which is a List of the enum objects. This is a readonly variable.
991+
992+
Example: >
993+
enum Planet
994+
Mercury,
995+
Venus,
996+
Earth
997+
endenum
998+
999+
echo Planet.Mercury
1000+
echo Planet.Venus.name
1001+
echo Planet.Venus.ordinal
1002+
for p in Planet.values
1003+
# ...
1004+
endfor
1005+
<
1006+
An enum is a class with class variables for the enum value objects and object
1007+
variables for the enum value name and the enum value ordinal: >
1008+
1009+
enum Planet
1010+
Mercury,
1011+
Venus
1012+
endenum
1013+
<
1014+
The above enum definition is equivalent to the following class definition: >
1015+
1016+
class Planet
1017+
public static final Mercury: Planet = Planet.new('Mercury', 0)
1018+
public static final Venus: Planet = Planet.new('Venus', 1)
9181019
1020+
public static const values: list<Planet> = [Planet.Mercury, Planet.Venus]
9191021
1022+
public const name: string
1023+
public const ordinal: number
1024+
endclass
1025+
<
9201026
==============================================================================
9211027

9221028
9. Rationale

0 commit comments

Comments
 (0)