Skip to content

Commit

Permalink
save
Browse files Browse the repository at this point in the history
  • Loading branch information
limuy2022 committed Jan 1, 2024
1 parent 622575b commit 088a9c1
Show file tree
Hide file tree
Showing 21 changed files with 219 additions and 72 deletions.
45 changes: 27 additions & 18 deletions rust/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 2 additions & 9 deletions rust/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,10 +1,3 @@
[package]
name = "rust"
version = "0.1.0"
edition = "2021"
[workspace]

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
rand = "0.8.5"
clap = { version = "4.4.11", features = ["derive"] }
members = ["trc", "Chinese", "English"]
8 changes: 8 additions & 0 deletions rust/Chinese/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
[package]
name = "Chinese"
version = "0.1.0"
edition = "2021"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
14 changes: 14 additions & 0 deletions rust/Chinese/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
pub fn add(left: usize, right: usize) -> usize {
left + right
}

#[cfg(test)]
mod tests {
use super::*;

#[test]
fn it_works() {
let result = add(2, 2);
assert_eq!(result, 4);
}
}
8 changes: 8 additions & 0 deletions rust/English/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
[package]
name = "English"
version = "0.1.0"
edition = "2021"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
14 changes: 14 additions & 0 deletions rust/English/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
pub fn add(left: usize, right: usize) -> usize {
left + right
}

#[cfg(test)]
mod tests {
use super::*;

#[test]
fn it_works() {
let result = add(2, 2);
assert_eq!(result, 4);
}
}
43 changes: 40 additions & 3 deletions rust/docs/usage.md
Original file line number Diff line number Diff line change
@@ -1,21 +1,58 @@
# The usage of Rust version Trc

## Hello world

Writing a hello world is the beginning of learning Trc.

```rust
println("Hello World!")
```

Great!Now you are saying "Hello" to the programming world!

## First written value for Trc

you can write integer value in the following ways:
you can write integer or float value in the following ways:
|Way|Explain|
|:---|:---|
|12321312|commom value|
|122_32432_4324324|use underline to split the number to read more easily|
|0b32132|number in 2 radix|
|0o324243|number in 8 radix|
|0x324324|number in 16 radix|
|1e9+7 or 2E9+7|Scientific notation|

Tip:No matter how large is your number.Trc compiler will take it into enough type to store!Don't worry!
Tip1:No matter how large is your number.Trc compiler will take it into enough type to store!Don't worry!

Tip2:The form like 0x3.4 isn't supported

Tip3:The form like 001 is supported

The next is the string value. To make you to write strings more easily:

|Way|Explain|
|:---|:---|
|"hello world"|commom value|
|"hello_world"|use underline to split the number to read more easily|
|'hello_world'|another method that equals to "hello world"|
|"""hello world"""|this method is for code across multiple lines|

If you add ```r``` or ```R``` in front of the string.Trc will treat it as a raw string.
Yes.These rules are from Python.I love its grammar rules

ok.now you know how to write value in Trc.Then let's go to the next part.

## the control flow of Trc

First,you can use ```if ... else if ... else``` statements

An example:

```python
if 1 == 1 {

} else if 2 != 1 {

} else {

}
```
Empty file removed rust/src/base.rs
Empty file.
Empty file removed rust/src/base/error.rs
Empty file.
Empty file removed rust/tests/test_compiler.rs
Empty file.
16 changes: 16 additions & 0 deletions rust/trc/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
[package]
name = "trc"
version = "0.1.0"
edition = "2021"
license = "GPL3"
authors = ["limuy"]
description = "a easy-learn programming language"
homepage = "https://github.com/limuy2022/trc"
repository = "https://github.com/limuy2022/trc"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
rand = "0.8.5"
clap = { version = "4.4.11", features = ["derive"] }
English = { path = "../English" }
1 change: 1 addition & 0 deletions rust/trc/src/base.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
pub mod error;
17 changes: 17 additions & 0 deletions rust/trc/src/base/error.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
enum ErrorType {
SyntaxError
}

pub struct ErrorInfo {
pub message: String,
errot_type: ErrorType
}

impl ErrorInfo {
pub fn new(message: String) -> ErrorInfo {
ErrorInfo {
message,
errot_type: ErrorType::SyntaxError
}
}
}
File renamed without changes.
Loading

0 comments on commit 088a9c1

Please sign in to comment.