Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[doc] Fix error & delete description about trait in documents #49

Merged
merged 5 commits into from
May 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
70 changes: 6 additions & 64 deletions doc/4_godelscript_language.en.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
- [Statements](#statements)
- [Schema](#schema)
- [Database](#database)
- [Trait](#trait)
- [Import](#import)
- [Query](#query)
- [Ungrounded Error: Unassigned/Unbound Error](#ungrounded-error-unassignedunbound-error)
Expand Down Expand Up @@ -59,7 +58,6 @@ A GödelScript program may include:
- [Module and symbol import statements](#import)
- [Schema type declarations](#schema)
- [Database type declarations](#database)
- [Trait declarations](#trait)
- [Method implementations](#method-implementation)
- [Function declarations and implementations](#function)
- [Query declarations](#query)
Expand Down Expand Up @@ -87,22 +85,10 @@ database NewDB {
file: *File
}

// Trait declaration
trait FileTrait {
fn getId(self) -> int;
}

// Impl trait for
impl FileTrait for File {
fn getId(self) -> int {
return self.id
}
}

// Impl
impl File {
@data_constraint
fn all() -> *File {
fn __all__() -> *File {
yield File {id: 1}
yield File {id: 2}
}
Expand Down Expand Up @@ -639,22 +625,9 @@ fn out() -> bool {
}
```

##### Custom Full Set Method

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.

```rust
impl File {
@data_constraint
fn extend_example() -> *File {
yield File {id: 1234567}
}
}
```

#### Constructing Anonymous Instances

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.
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.

```rust
schema A {
Expand Down Expand Up @@ -713,6 +686,7 @@ schema MyFile extends File {}
##### Method Override

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.
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.

```rust
schema File {
Expand Down Expand Up @@ -799,38 +773,6 @@ fn getAnnotation() -> Annotation {
}
```

### Trait

#### Trait Declaration

The syntax for declaring a `trait` is as follows:

```rust
trait Example {
fn getId(self) -> int;
fn getName(self) -> string;
fn getValueByName(self, name: string) -> string;
}
```

#### Impl Trait

The syntax is similar to `impl`, but you must implement all the functions declared in the `trait` to pass compilation.

```rust
impl Example for XmlElement {
fn getId(self) -> int {return self.id}
fn getName(self) -> int {return self.name}
fn getValueByName(self, name: string) -> int {
for(attr in XmlAttribute(XmlDB::load("...")) {
if (attr.getName() = name && attr.id = self.getAttribute().id) {
return attr.getValue()
}
}
}
}
```

### Import

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

```rust
query name from
variable in initial value,
variable in initial value,
variable in initial value,
variable in initial value
where condition
Expand Down Expand Up @@ -1044,8 +986,8 @@ fn db() -> JavaDB {
}

query class_method from
Callable m in Callable(db()),
Class c in Class(db())
m in Callable(db()),
c in Class(db())
where
c.id = m.getBelongedClass().id
select
Expand Down
70 changes: 6 additions & 64 deletions doc/4_godelscript_language.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
- [语句](#语句)
- [Schema](#schema)
- [数据库](#数据库)
- [Trait](#trait)
- [Import](#import)
- [Query](#query)
- [Ungrounded Error: 未赋值/未绑定错误](#ungrounded-error-未赋值未绑定错误)
Expand Down Expand Up @@ -59,7 +58,6 @@ GödelScript 程序可能包含:
- [模块和符号引用](#import)
- [Schema 类型声明](#schema)
- [数据库类型声明](#数据库)
- [Trait 声明](#trait)
- [Schema 方法实现](#方法实现)
- [函数声明和实现](#函数)
- [Query 声明](#query)
Expand Down Expand Up @@ -87,22 +85,10 @@ database NewDB {
file: *File
}

// trait 声明
trait FileTrait {
fn getId(self) -> int;
}

// impl trait for
impl FileTrait for File {
fn getId(self) -> int {
return self.id
}
}

// impl
impl File {
@data_constraint
fn all() -> *File {
fn __all__() -> *File {
yield File {id: 1}
yield File {id: 2}
}
Expand Down Expand Up @@ -621,7 +607,7 @@ impl File {

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

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

```rust
fn out() -> bool {
Expand All @@ -639,22 +625,9 @@ fn out() -> bool {
}
```

##### 自定义全集方法

`schema`允许使用不同于`__all__`名称的**静态方法**来表明一些集合也存在于该类型的全集中。该方法也必须包含特殊注解`@data_constraint`。该方法一般用于手动添加一些数据到该类型的全集中。

```rust
impl File {
@data_constraint
fn extend_example() -> *File {
yield File {id: 1234567}
}
}
```

#### 构造匿名实例

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

```rust
schema A {
Expand Down Expand Up @@ -713,6 +686,7 @@ schema MyFile extends File {}
##### Method Override

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

```rust
schema File {
Expand Down Expand Up @@ -799,38 +773,6 @@ fn getAnnotation() -> Annotation {
}
```

### Trait

#### Trait 声明

`trait`声明语法如下:

```rust
trait Example {
fn getId(self) -> int;
fn getName(self) -> string;
fn getValueByName(self, name: string) -> string;
}
```

#### Impl Trait

写法与`impl`类似,但是必须要将`trait`中声明的所有函数都实现出来,否则无法通过编译。

```rust
impl Example for XmlElement {
fn getId(self) -> int {return self.id}
fn getName(self) -> int {return self.name}
fn getValueByName(self, name: string) -> int {
for(attr in XmlAttribute(XmlDB::load("...")) {
if (attr.getName() = name && attr.id = self.getAttribute().id) {
return attr.getValue()
}
}
}
}
```

### Import

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

query class_method from
Callable m in Callable(db()),
Class c in Class(db())
m in Callable(db()),
c in Class(db())
where
c.id = m.getBelongedClass().id
select
Expand Down