Skip to content

Commit 12d2681

Browse files
authored
Merge pull request #49 from codefuse-ai/lhk_dev
[doc] Fix error & delete description about `trait` in documents
2 parents 2eccd87 + 0d0a3a8 commit 12d2681

File tree

2 files changed

+12
-128
lines changed

2 files changed

+12
-128
lines changed

doc/4_godelscript_language.en.md

+6-64
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
- [Statements](#statements)
1111
- [Schema](#schema)
1212
- [Database](#database)
13-
- [Trait](#trait)
1413
- [Import](#import)
1514
- [Query](#query)
1615
- [Ungrounded Error: Unassigned/Unbound Error](#ungrounded-error-unassignedunbound-error)
@@ -59,7 +58,6 @@ A GödelScript program may include:
5958
- [Module and symbol import statements](#import)
6059
- [Schema type declarations](#schema)
6160
- [Database type declarations](#database)
62-
- [Trait declarations](#trait)
6361
- [Method implementations](#method-implementation)
6462
- [Function declarations and implementations](#function)
6563
- [Query declarations](#query)
@@ -87,22 +85,10 @@ database NewDB {
8785
file: *File
8886
}
8987

90-
// Trait declaration
91-
trait FileTrait {
92-
fn getId(self) -> int;
93-
}
94-
95-
// Impl trait for
96-
impl FileTrait for File {
97-
fn getId(self) -> int {
98-
return self.id
99-
}
100-
}
101-
10288
// Impl
10389
impl File {
10490
@data_constraint
105-
fn all() -> *File {
91+
fn __all__() -> *File {
10692
yield File {id: 1}
10793
yield File {id: 2}
10894
}
@@ -639,22 +625,9 @@ fn out() -> bool {
639625
}
640626
```
641627

642-
##### Custom Full Set Method
643-
644-
A `schema` allows using static methods with different names than `__all__` to indicate that some sets also exist within its full set. This method must also contain the special annotation `@data_constraint`. This method is generally used to manually add some data to the full set of that type.
645-
646-
```rust
647-
impl File {
648-
@data_constraint
649-
fn extend_example() -> *File {
650-
yield File {id: 1234567}
651-
}
652-
}
653-
```
654-
655628
#### Constructing Anonymous Instances
656629

657-
GödelScript allows for the creation of anonymous instances with a specific syntax. The creation of anonymous instances is contingent on the instance existing within the full set of the `schema`, unless this usage appears within a `@data_constraint` method, in which case the result will be empty.
630+
GödelScript allows for the creation of anonymous instances with a specific syntax. The creation of anonymous instances is contingent on the instance existing within the full set of the `schema`, unless this usage appears within a `__all__` method, in which case the result will be empty.
658631

659632
```rust
660633
schema A {
@@ -713,6 +686,7 @@ schema MyFile extends File {}
713686
##### Method Override
714687

715688
If the subclass implementation contains a method with the same name as the parent class, the parent method will be **overridden** by the subclass method.
689+
The overridden method can use different parameter and return type. There's no need to use the same parameter and return type of parent class method.
716690

717691
```rust
718692
schema File {
@@ -799,38 +773,6 @@ fn getAnnotation() -> Annotation {
799773
}
800774
```
801775

802-
### Trait
803-
804-
#### Trait Declaration
805-
806-
The syntax for declaring a `trait` is as follows:
807-
808-
```rust
809-
trait Example {
810-
fn getId(self) -> int;
811-
fn getName(self) -> string;
812-
fn getValueByName(self, name: string) -> string;
813-
}
814-
```
815-
816-
#### Impl Trait
817-
818-
The syntax is similar to `impl`, but you must implement all the functions declared in the `trait` to pass compilation.
819-
820-
```rust
821-
impl Example for XmlElement {
822-
fn getId(self) -> int {return self.id}
823-
fn getName(self) -> int {return self.name}
824-
fn getValueByName(self, name: string) -> int {
825-
for(attr in XmlAttribute(XmlDB::load("...")) {
826-
if (attr.getName() = name && attr.id = self.getAttribute().id) {
827-
return attr.getValue()
828-
}
829-
}
830-
}
831-
}
832-
```
833-
834776
### Import
835777

836778
GödelScript uses the `use` keyword to import symbols from other files:
@@ -996,7 +938,7 @@ Query is used for simple queries and is guaranteed to be output even without dec
996938

997939
```rust
998940
query name from
999-
variable in initial value,
941+
variable in initial value,
1000942
variable in initial value,
1001943
variable in initial value
1002944
where condition
@@ -1044,8 +986,8 @@ fn db() -> JavaDB {
1044986
}
1045987

1046988
query class_method from
1047-
Callable m in Callable(db()),
1048-
Class c in Class(db())
989+
m in Callable(db()),
990+
c in Class(db())
1049991
where
1050992
c.id = m.getBelongedClass().id
1051993
select

doc/4_godelscript_language.md

+6-64
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
- [语句](#语句)
1111
- [Schema](#schema)
1212
- [数据库](#数据库)
13-
- [Trait](#trait)
1413
- [Import](#import)
1514
- [Query](#query)
1615
- [Ungrounded Error: 未赋值/未绑定错误](#ungrounded-error-未赋值未绑定错误)
@@ -59,7 +58,6 @@ GödelScript 程序可能包含:
5958
- [模块和符号引用](#import)
6059
- [Schema 类型声明](#schema)
6160
- [数据库类型声明](#数据库)
62-
- [Trait 声明](#trait)
6361
- [Schema 方法实现](#方法实现)
6462
- [函数声明和实现](#函数)
6563
- [Query 声明](#query)
@@ -87,22 +85,10 @@ database NewDB {
8785
file: *File
8886
}
8987

90-
// trait 声明
91-
trait FileTrait {
92-
fn getId(self) -> int;
93-
}
94-
95-
// impl trait for
96-
impl FileTrait for File {
97-
fn getId(self) -> int {
98-
return self.id
99-
}
100-
}
101-
10288
// impl
10389
impl File {
10490
@data_constraint
105-
fn all() -> *File {
91+
fn __all__() -> *File {
10692
yield File {id: 1}
10793
yield File {id: 2}
10894
}
@@ -621,7 +607,7 @@ impl File {
621607

622608
这种方法必须包含特殊注解`@data_constraint`,表明该方法专用于加载,如果不写该注解,则该方法的返回为**空集合**。该方法返回类型必须为其本身的集合。
623609

624-
包含了该方法的`schema`可以使用一个语法糖来获取其全集:
610+
包含该方法的`schema`可以使用一个语法糖来获取其全集:
625611

626612
```rust
627613
fn out() -> bool {
@@ -639,22 +625,9 @@ fn out() -> bool {
639625
}
640626
```
641627

642-
##### 自定义全集方法
643-
644-
`schema`允许使用不同于`__all__`名称的**静态方法**来表明一些集合也存在于该类型的全集中。该方法也必须包含特殊注解`@data_constraint`。该方法一般用于手动添加一些数据到该类型的全集中。
645-
646-
```rust
647-
impl File {
648-
@data_constraint
649-
fn extend_example() -> *File {
650-
yield File {id: 1234567}
651-
}
652-
}
653-
```
654-
655628
#### 构造匿名实例
656629

657-
GödelScript 允许用一个特定语法生成匿名实例。生成匿名实例的前提是该实例存在于该`schema`的全集中,除非该用法出现在`@data_constraint`方法中,否则结果为空。
630+
GödelScript 允许用一个特定语法生成匿名实例。生成匿名实例的前提是该实例存在于该`schema`的全集中,除非该用法出现在`__all__`方法中,否则结果为空。
658631

659632
```rust
660633
schema A {
@@ -713,6 +686,7 @@ schema MyFile extends File {}
713686
##### Method Override
714687

715688
如果子类的实现中存在与父类同名的方法,则父类的方法会被子类方法**覆盖**
689+
覆盖方法的参数和返回值类型没有限制,不需要与父类保持一致。
716690

717691
```rust
718692
schema File {
@@ -799,38 +773,6 @@ fn getAnnotation() -> Annotation {
799773
}
800774
```
801775

802-
### Trait
803-
804-
#### Trait 声明
805-
806-
`trait`声明语法如下:
807-
808-
```rust
809-
trait Example {
810-
fn getId(self) -> int;
811-
fn getName(self) -> string;
812-
fn getValueByName(self, name: string) -> string;
813-
}
814-
```
815-
816-
#### Impl Trait
817-
818-
写法与`impl`类似,但是必须要将`trait`中声明的所有函数都实现出来,否则无法通过编译。
819-
820-
```rust
821-
impl Example for XmlElement {
822-
fn getId(self) -> int {return self.id}
823-
fn getName(self) -> int {return self.name}
824-
fn getValueByName(self, name: string) -> int {
825-
for(attr in XmlAttribute(XmlDB::load("...")) {
826-
if (attr.getName() = name && attr.id = self.getAttribute().id) {
827-
return attr.getValue()
828-
}
829-
}
830-
}
831-
}
832-
```
833-
834776
### Import
835777

836778
GödelScript 使用`use`关键字来引入其他文件的符号:
@@ -1044,8 +986,8 @@ fn db() -> JavaDB {
1044986
}
1045987

1046988
query class_method from
1047-
Callable m in Callable(db()),
1048-
Class c in Class(db())
989+
m in Callable(db()),
990+
c in Class(db())
1049991
where
1050992
c.id = m.getBelongedClass().id
1051993
select

0 commit comments

Comments
 (0)