Skip to content

Commit

Permalink
refactor(REPL): modify messages
Browse files Browse the repository at this point in the history
  • Loading branch information
GreasrySlug committed Feb 10, 2023
1 parent 7d015cf commit 2a40a5c
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 21 deletions.
16 changes: 10 additions & 6 deletions crates/erg_parser/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,7 @@ impl LexError {
pub fn invalid_seq_elems_error(errno: usize, loc: Location, hint: Option<&str>) -> LexError {
let hint = hint.map(|hint| hint.to_string());
let msg = switch_lang!(
"japanese" => "連続する要素の宣言が異なります",
"japanese" => "要素の列挙の仕方が不正です",
"simplified_chinese" => "无效的Sequential元素声明",
"traditional_chinese" => "無效的Sequential元素聲明",
"english" => "invalid sequential elements declaration",
Expand All @@ -268,7 +268,7 @@ impl LexError {

pub fn invalid_record_element_err(errno: usize, loc: Location) -> LexError {
let msg = switch_lang!(
"japanese" => "レコード型の要素が宣言が異なります",
"japanese" => "レコード型要素の列挙の仕方が不正です",
"simplified_chinese" => "无效的Record类型元素声明",
"traditional_chinese" => "無效的Record類型元素聲明",
"english" => "invalid record type element declarations",
Expand All @@ -279,25 +279,29 @@ impl LexError {
let record = StyledStr::new("レコード型", Some(HINT), Some(ATTR));
let var = StyledStr::new("属性", Some(HINT), Some(ATTR));
let def = StyledStr::new("属性=リテラル", Some(HINT), Some(ATTR));
format!("{record}では{var}か{def}のみ使うことができます")
let obj = StyledStr::new("属性=オブジェクト", Some(HINT), Some(ATTR));
format!("{record}では{var}か{def}、{obj}のみ宣言することができます")
},
"simplified_chinese" => {
let record = StyledStr::new("Record类型", Some(HINT), Some(ATTR));
let var = StyledStr::new("attr", Some(HINT), Some(ATTR));
let def = StyledStr::new("attr=lit", Some(HINT), Some(ATTR));
format!("只有{var}或{def}可以在{record}中使用")
let obj = StyledStr::new("attr=object", Some(HINT), Some(ATTR));
format!("{record}中只能声明 {var}、{def} 或 {obj}")
},
"traditional_chinese" => {
let record = StyledStr::new("Record類型", Some(HINT), Some(ATTR));
let var = StyledStr::new("attr", Some(HINT), Some(ATTR));
let def = StyledStr::new("attr=lit", Some(HINT), Some(ATTR));
format!("只有{var}或{def}可以在{record}中使用")
let obj = StyledStr::new("attr=object", Some(HINT), Some(ATTR));
format!("{record}中只能声明 {var}、{def} 或 {obj}")
},
"english" => {
let record = StyledStr::new("Record", Some(HINT), Some(ATTR));
let var = StyledStr::new("attr", Some(HINT), Some(ATTR));
let def = StyledStr::new("attr=lit", Some(HINT), Some(ATTR));
format!("only {var} or {def} can be used in {record}")
let obj = StyledStr::new("attr=object", Some(HINT), Some(ATTR));
format!("only {var}, {def} or {obj} can be declared in {record}")
},
);
Self::syntax_error(errno, loc, msg, Some(hint))
Expand Down
30 changes: 15 additions & 15 deletions crates/erg_parser/parse.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1071,9 +1071,9 @@ impl Parser {
} else {
let hint = switch_lang!(
"japanese" => "カンマの代わりに要素を追加してください",
"simplified_chinese" => "应该添加一个元素,而不是逗号",
"traditional_chinese" => "應該添加一個元素,而不是逗號",
"english" => "instead of comma, a element should be added",
"simplified_chinese" => "应该添加一个元素而不是逗号",
"traditional_chinese" => "應該添加一個元素而不是逗號",
"english" => "a element may be added instead of comma",
);
let err = self.skip_and_throw_invalid_seq_err(
caused_by!(),
Expand Down Expand Up @@ -2523,10 +2523,10 @@ impl Parser {
match self.peek() {
Some(t) if t.is(Semi) => {
let hint = switch_lang!(
"japanese" => "セミコロンの代わりに要素",
"japanese" => "セミコロンの代わりに要素を追加してください",
"simplified_chinese" => "不应该是分号,而应该是元素",
"traditional_chinese" => "不应该是分號,而应该是元素",
"english" => "instead of semicolon, element",
"english" => "a element may be added instead of semicolon",
);
let err = self.skip_and_throw_invalid_seq_err(
caused_by!(),
Expand Down Expand Up @@ -2634,9 +2634,9 @@ impl Parser {
Some(Comma) => {
let hint = switch_lang!(
"japanese" => "カンマの代わりに要素",
"simplified_chinese" => "一个元素",
"traditional_chinese" => "一個元素",
"english" => "a element",
"simplified_chinese" => "可以添加一个元素而不是逗号",
"traditional_chinese" => "可以添加一個元素而不是逗號",
"english" => "a element may be added instead of comma",
);
let err = self.skip_and_throw_invalid_seq_err(
caused_by!(),
Expand Down Expand Up @@ -2752,9 +2752,9 @@ impl Parser {
log!(err "error caused by: {caused_by}");
let hint = switch_lang!(
"japanese" => "カンマの代わりに要素",
"simplified_chinese" => "不应该是逗号,而应该是元素",
"traditional_chinese" => "不应该是逗號,而应该是元素",
"english" => "instead of comma, a element",
"simplified_chinese" => "可以添加一个元素而不是逗号",
"traditional_chinese" => "可以添加一個元素而不是逗號",
"english" => "a element may be added instead of comma",
);
let err = self.skip_and_throw_invalid_seq_err(
caused_by!(),
Expand Down Expand Up @@ -2815,10 +2815,10 @@ impl Parser {
}
Some(_) => {
let hint = switch_lang!(
"japanese" => "セミコロンか括弧",
"simplified_chinese" => "分号或右括号",
"traditional_chinese" => "分號或右括號",
"english" => "semicolon or right bracket",
"japanese" => "セミコロンか括弧を追加してください",
"simplified_chinese" => "可以添加分号或右括号",
"traditional_chinese" => "可以添加分號或右括號",
"english" => "semicolon or right bracket may be added",
);
let err = self.skip_and_throw_invalid_seq_err(
caused_by!(),
Expand Down

0 comments on commit 2a40a5c

Please sign in to comment.