Skip to content

Commit

Permalink
Merge branch 'dev'
Browse files Browse the repository at this point in the history
  • Loading branch information
limuy2022 committed Jan 20, 2024
2 parents a7d395d + be792e3 commit 016498a
Show file tree
Hide file tree
Showing 33 changed files with 1,047 additions and 194 deletions.
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

## Trc is a stack-based programming language

Trc's syntax is easy,and have full toolchain.It is easy to learn modern c++ and compiler,too.
Trc's syntax is easy,and have full toolchain. It is easy to learn modern c++ and compiler,too.

## language

Expand Down Expand Up @@ -81,6 +81,8 @@ Wechat:angelgel2020

QQ:3570249647

email: ```[email protected]```

## Referenced Open-source software

| Library |Usage |
Expand Down
116 changes: 100 additions & 16 deletions rust/Cargo.lock

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

4 changes: 3 additions & 1 deletion rust/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,7 @@ repository = "https://github.com/limuy2022/trc"

[dependencies]
rand = "0.8.5"
clap = { version = "4.4.12", features = ["derive"] }
clap = { version = "4.4.18", features = ["derive"] }
gettext-rs = "0.7.0"
colored = "2.1.0"
downcast-rs = "1.2.0"
24 changes: 24 additions & 0 deletions rust/docs/usage.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,16 @@ The next is the string value. To make you to write strings more easily:
|'hello_world'|another method that equals to "hello world"|
|"""hello world"""|this method is for code across multiple lines|

There are also many easape char in the string:

|escape char|meaning|
|:---|:---|
|\t|tab|
|\n|new line|
|\\\\|\|
|\'|'|
|\"|"|

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

Expand Down Expand Up @@ -100,3 +110,17 @@ if 1 == 1 {

}
```

## the comments of Trc

Trc support two kinds of comments

the first is use ```#```,from ```#``` to the end of the line belongs to the comment

the second is use ```/**/```,this kind can cross the line,like:

```cpp
/*
hello world!
*/
```
Binary file removed rust/locales/en/LC_MESSAGES/trans.mo
Binary file not shown.
2 changes: 0 additions & 2 deletions rust/locales/en/LC_MESSAGES/trans.po

This file was deleted.

Binary file modified rust/locales/zh_CN/LC_MESSAGES/trans.mo
Binary file not shown.
26 changes: 24 additions & 2 deletions rust/locales/zh_CN/LC_MESSAGES/trans.po
Original file line number Diff line number Diff line change
@@ -1,2 +1,24 @@
msgid "test"
msgstr "草"
msgid ""
msgstr ""
"Content-Type: text/plain; charset=UTF-8\n"

msgid "Welcome to tshell.Type help() to get more infomation"
msgstr "欢迎使用tshell。输入help()获取更多信息"

msgid "SyntaxError"
msgstr "语法错误"

msgid "OperatorError"
msgstr "操作符错误"

msgid "VmError"
msgstr "虚拟机错误"

msgid "this string should be ended with {}"
msgstr "这个字符串应当以{}结束"

msgid "operator {} is not supported for type {}"
msgstr "操作符{}不支持类型{}"

msgid "The number of data of vm stack is not correct, should have {} data"
msgstr "虚拟机栈中数据数量不正确,期望有{}个数据"
37 changes: 31 additions & 6 deletions rust/src/base/error.rs
Original file line number Diff line number Diff line change
@@ -1,17 +1,42 @@
enum ErrorType {
SyntaxError,
}
use gettextrs::gettext;
use std::process::exit;

const EXIT_FAILURE: i32 = 1;

pub const SYNTAX_ERROR: &str = "SyntaxError";
pub const OPERATOR_ERROR: &str = "OperatorError";
pub const VM_ERROR:&str = "VmError";

pub const STRING_WITHOUT_END: &str = "this string should be ended with {}";
pub const OPERATOR_IS_NOT_SUPPORT: &str = "operator {} is not supported for type {}";
pub const VM_DATA_NUMBER:&str = "The number of data of vm stack is not correct, should have {} data";

pub struct ErrorInfo {
pub message: String,
errot_type: ErrorType,
errot_type: &'static str,
}

impl ErrorInfo {
pub fn new(message: String) -> ErrorInfo {
pub fn new(message: String, error_type: &'static str) -> ErrorInfo {
ErrorInfo {
message,
errot_type: ErrorType::SyntaxError,
errot_type: error_type,
}
}
}

pub trait ErrorContent {
fn get_module_name(&self) -> &str;

fn get_line(&self) -> usize;
}

/// report error in vm or compiler
/// we will translate the error type to gettextrs
/// but you should translate the error messgae by caller
pub fn report_error(content: &impl ErrorContent, info: ErrorInfo) {
eprintln!("Error in line {}", content.get_line());
eprintln!("In module {}", content.get_module_name());
eprintln!("{}:{}", gettext(info.errot_type), info.message);
exit(EXIT_FAILURE);
}
3 changes: 3 additions & 0 deletions rust/src/cfg.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
//! some constant values and configurations in trc
pub const MAIN_MODULE_NAME: &str = "main";
Loading

0 comments on commit 016498a

Please sign in to comment.