refactor: Equal -> Assign

This commit is contained in:
Shunsuke Shibayama 2023-03-30 01:27:51 +09:00
parent 3f66981c5c
commit 6f334b6bcc
6 changed files with 29 additions and 29 deletions

View file

@ -42,7 +42,7 @@ pub fn token_kind_to_op_kind(kind: TokenKind) -> Option<OpKind> {
TokenKind::PrePlus => Some(OpKind::Pos), TokenKind::PrePlus => Some(OpKind::Pos),
TokenKind::PreMinus => Some(OpKind::Neg), TokenKind::PreMinus => Some(OpKind::Neg),
TokenKind::PreBitNot => Some(OpKind::Invert), TokenKind::PreBitNot => Some(OpKind::Invert),
TokenKind::Equal => Some(OpKind::Eq), TokenKind::DblEq => Some(OpKind::Eq),
TokenKind::NotEq => Some(OpKind::Ne), TokenKind::NotEq => Some(OpKind::Ne),
TokenKind::Less => Some(OpKind::Lt), TokenKind::Less => Some(OpKind::Lt),
TokenKind::LessEq => Some(OpKind::Le), TokenKind::LessEq => Some(OpKind::Le),

View file

@ -652,7 +652,7 @@ impl Desugarer {
}; };
let id = DefId(get_hash(&(&acc, buf_name))); let id = DefId(get_hash(&(&acc, buf_name)));
let block = Block::new(vec![Expr::Accessor(acc)]); let block = Block::new(vec![Expr::Accessor(acc)]);
let op = Token::from_str(TokenKind::Equal, "="); let op = Token::from_str(TokenKind::Assign, "=");
let body = DefBody::new(op, block, id); let body = DefBody::new(op, block, id);
match &sig.pat { match &sig.pat {
VarPattern::Tuple(tup) => { VarPattern::Tuple(tup) => {
@ -753,7 +753,7 @@ impl Desugarer {
let var = VarSignature::new(VarPattern::Ident(ident.clone()), None); let var = VarSignature::new(VarPattern::Ident(ident.clone()), None);
let sig = Signature::Var(var); let sig = Signature::Var(var);
let body = DefBody::new( let body = DefBody::new(
Token::from_str(TokenKind::Equal, "="), Token::from_str(TokenKind::Assign, "="),
Block::new(vec![Expr::local( Block::new(vec![Expr::local(
ident.inspect(), ident.inspect(),
ident.ln_begin().unwrap_or(1), ident.ln_begin().unwrap_or(1),
@ -1027,7 +1027,7 @@ impl Desugarer {
}; };
let id = DefId(get_hash(&(&acc, buf_name))); let id = DefId(get_hash(&(&acc, buf_name)));
let block = Block::new(vec![Expr::Accessor(acc)]); let block = Block::new(vec![Expr::Accessor(acc)]);
let op = Token::from_str(TokenKind::Equal, "="); let op = Token::from_str(TokenKind::Assign, "=");
let body = DefBody::new(op, block, id); let body = DefBody::new(op, block, id);
let line = sig.ln_begin().unwrap_or(1); let line = sig.ln_begin().unwrap_or(1);
match &mut sig.pat { match &mut sig.pat {

View file

@ -1265,7 +1265,7 @@ impl Iterator for Lexer /*<'a>*/ {
self.consume(); self.consume();
self.accept(ProcArrow, "=>") self.accept(ProcArrow, "=>")
} }
_ => self.accept(Equal, "="), _ => self.accept(Assign, "="),
}, },
Some('!') => { Some('!') => {
if let Some('=') = self.peek_cur_ch() { if let Some('=') = self.peek_cur_ch() {

View file

@ -2093,7 +2093,7 @@ impl Parser {
debug_exit_info!(self); debug_exit_info!(self);
return Ok(BraceContainer::Set(Set::Normal(set))); return Ok(BraceContainer::Set(Set::Normal(set)));
} }
Some(Equal) => { Some(Assign) => {
let _eq = self.lpop(); let _eq = self.lpop();
if let Some(t) = self.peek() { if let Some(t) = self.peek() {
if t.is(RBrace) { if t.is(RBrace) {

View file

@ -23,7 +23,7 @@ fn test_lexer_for_basic() -> ParseResult<()> {
(Newline, newline), (Newline, newline),
(Newline, newline), (Newline, newline),
(Symbol, "_a"), (Symbol, "_a"),
(Equal, "="), (Assign, "="),
(NatLit, "1_234"), (NatLit, "1_234"),
(Plus, "+"), (Plus, "+"),
(RatioLit, "1113."), (RatioLit, "1113."),
@ -39,14 +39,14 @@ fn test_lexer_for_basic() -> ParseResult<()> {
(UBar, "_"), (UBar, "_"),
(Comma, ","), (Comma, ","),
(Symbol, "b"), (Symbol, "b"),
(Equal, "="), (Assign, "="),
(Symbol, "tuple"), (Symbol, "tuple"),
(Newline, newline), (Newline, newline),
(Symbol, "f"), (Symbol, "f"),
(Symbol, "x"), (Symbol, "x"),
(Comma, ","), (Comma, ","),
(Symbol, "y"), (Symbol, "y"),
(Equal, "="), (Assign, "="),
(Newline, newline), (Newline, newline),
(Indent, " "), (Indent, " "),
(Symbol, "x"), (Symbol, "x"),
@ -88,7 +88,7 @@ fn test_lexer_for_basic() -> ParseResult<()> {
(Newline, newline), (Newline, newline),
(Dedent, ""), (Dedent, ""),
(Symbol, "Hello"), (Symbol, "Hello"),
(Equal, "="), (Assign, "="),
(Symbol, "S2c"), (Symbol, "S2c"),
(StrLit, "\"hello\""), (StrLit, "\"hello\""),
(Newline, newline), (Newline, newline),
@ -97,7 +97,7 @@ fn test_lexer_for_basic() -> ParseResult<()> {
(Dedent, ""), (Dedent, ""),
(Dedent, ""), (Dedent, ""),
(Symbol, "aあ아"), (Symbol, "aあ아"),
(Equal, "="), (Assign, "="),
(Newline, newline), (Newline, newline),
(Indent, " "), (Indent, " "),
(Newline, newline), (Newline, newline),
@ -140,12 +140,12 @@ fn test_lexer_for_advanced() -> ParseResult<()> {
(Newline, newline), (Newline, newline),
(Symbol, "fib"), (Symbol, "fib"),
(NatLit, "0"), (NatLit, "0"),
(Equal, "="), (Assign, "="),
(NatLit, "0"), (NatLit, "0"),
(Newline, newline), (Newline, newline),
(Symbol, "fib"), (Symbol, "fib"),
(NatLit, "1"), (NatLit, "1"),
(Equal, "="), (Assign, "="),
(NatLit, "1"), (NatLit, "1"),
(Newline, newline), (Newline, newline),
(Symbol, "fib"), (Symbol, "fib"),
@ -156,7 +156,7 @@ fn test_lexer_for_advanced() -> ParseResult<()> {
(RParen, ")"), (RParen, ")"),
(Colon, ":"), (Colon, ":"),
(Symbol, "Nat"), (Symbol, "Nat"),
(Equal, "="), (Assign, "="),
(Symbol, "fib"), (Symbol, "fib"),
(LParen, "("), (LParen, "("),
(Symbol, "n"), (Symbol, "n"),
@ -174,7 +174,7 @@ fn test_lexer_for_advanced() -> ParseResult<()> {
(Newline, newline), (Newline, newline),
(Newline, newline), (Newline, newline),
(Symbol, "t"), (Symbol, "t"),
(Equal, "="), (Assign, "="),
(Symbol, "if"), (Symbol, "if"),
(BoolLit, "True"), (BoolLit, "True"),
(Colon, ":"), (Colon, ":"),
@ -197,7 +197,7 @@ fn test_lexer_for_advanced() -> ParseResult<()> {
(Newline, newline), (Newline, newline),
(Newline, newline), (Newline, newline),
(Symbol, "math"), (Symbol, "math"),
(Equal, "="), (Assign, "="),
(Symbol, "import"), (Symbol, "import"),
(StrLit, "\"math\""), (StrLit, "\"math\""),
(Newline, newline), (Newline, newline),
@ -206,7 +206,7 @@ fn test_lexer_for_advanced() -> ParseResult<()> {
(Symbol, "pi"), (Symbol, "pi"),
(Semi, ";"), (Semi, ";"),
(RBrace, "}"), (RBrace, "}"),
(Equal, "="), (Assign, "="),
(Symbol, "import"), (Symbol, "import"),
(StrLit, "\"math\""), (StrLit, "\"math\""),
(Newline, newline), (Newline, newline),
@ -315,7 +315,7 @@ fn test_lexer_for_multi_line_str_literal() -> ParseResult<()> {
(Newline, newline), (Newline, newline),
(Newline, newline), (Newline, newline),
(Symbol, "single_a"), (Symbol, "single_a"),
(Equal, "="), (Assign, "="),
(StrLit, "\"line break\naaa\nbbb\nccc\nline break\""), (StrLit, "\"line break\naaa\nbbb\nccc\nline break\""),
(Newline, newline), (Newline, newline),
(Symbol, "print!"), (Symbol, "print!"),
@ -323,7 +323,7 @@ fn test_lexer_for_multi_line_str_literal() -> ParseResult<()> {
(Newline, newline), (Newline, newline),
(Newline, newline), (Newline, newline),
(Symbol, "multi_line_a"), (Symbol, "multi_line_a"),
(Equal, "="), (Assign, "="),
( (
StrLit, StrLit,
"\"\"\"line break "\"\"\"line break
@ -338,7 +338,7 @@ line break\"\"\"",
(Newline, newline), (Newline, newline),
(Newline, newline), (Newline, newline),
(Symbol, "single_b"), (Symbol, "single_b"),
(Equal, "="), (Assign, "="),
( (
StrLit, StrLit,
"\"ignore line break Hello,\n Worldignored line break\"", "\"ignore line break Hello,\n Worldignored line break\"",
@ -349,7 +349,7 @@ line break\"\"\"",
(Newline, newline), (Newline, newline),
(Newline, newline), (Newline, newline),
(Symbol, "multi_line_b"), (Symbol, "multi_line_b"),
(Equal, "="), (Assign, "="),
( (
StrLit, StrLit,
"\"\"\"ignore line break Hello, "\"\"\"ignore line break Hello,
@ -361,7 +361,7 @@ line break\"\"\"",
(Newline, newline), (Newline, newline),
(Newline, newline), (Newline, newline),
(Symbol, "complex_string"), (Symbol, "complex_string"),
(Equal, "="), (Assign, "="),
(StrLit, "\"\"\"\\ \0\r\n\\\"\"\""), (StrLit, "\"\"\"\\ \0\r\n\\\"\"\""),
(Newline, newline), (Newline, newline),
(Symbol, "print!"), (Symbol, "print!"),
@ -369,7 +369,7 @@ line break\"\"\"",
(Newline, newline), (Newline, newline),
(Newline, newline), (Newline, newline),
(Symbol, "quotation_mark"), (Symbol, "quotation_mark"),
(Equal, "="), (Assign, "="),
(StrLit, "\"\"\"\"\"\"\"\"\""), (StrLit, "\"\"\"\"\"\"\"\"\""),
(Newline, newline), (Newline, newline),
(Symbol, "print!"), (Symbol, "print!"),
@ -377,7 +377,7 @@ line break\"\"\"",
(Newline, newline), (Newline, newline),
(Newline, newline), (Newline, newline),
(Symbol, "quotation_marks"), (Symbol, "quotation_marks"),
(Equal, "="), (Assign, "="),
( (
StrLit, StrLit,
"\"\"\"\" "\"\"\"\"

View file

@ -119,7 +119,7 @@ pub enum TokenKind {
/// `ref!` (special unary) /// `ref!` (special unary)
RefMutOp, RefMutOp,
/// = /// =
Equal, Assign,
/// <- /// <-
Inclusion, Inclusion,
/// := /// :=
@ -241,7 +241,7 @@ impl TokenKind {
Try => TokenCategory::PostfixOp, Try => TokenCategory::PostfixOp,
Comma | Colon | DblColon | SupertypeOf | SubtypeOf | Dot | Pipe | Walrus Comma | Colon | DblColon | SupertypeOf | SubtypeOf | Dot | Pipe | Walrus
| Inclusion => TokenCategory::SpecialBinOp, | Inclusion => TokenCategory::SpecialBinOp,
Equal => TokenCategory::DefOp, Assign => TokenCategory::DefOp,
FuncArrow | ProcArrow => TokenCategory::LambdaOp, FuncArrow | ProcArrow => TokenCategory::LambdaOp,
Semi | Newline => TokenCategory::Separator, Semi | Newline => TokenCategory::Separator,
LParen | LBrace | LSqBr | Indent => TokenCategory::LEnclosure, LParen | LBrace | LSqBr | Indent => TokenCategory::LEnclosure,
@ -275,7 +275,7 @@ impl TokenKind {
FuncArrow | ProcArrow | Inclusion => 60, // -> => <- FuncArrow | ProcArrow | Inclusion => 60, // -> => <-
Colon | SupertypeOf | SubtypeOf => 50, // : :> <: Colon | SupertypeOf | SubtypeOf => 50, // : :> <:
Comma => 40, // , Comma => 40, // ,
Equal | Walrus => 20, // = := Assign | Walrus => 20, // = :=
Newline | Semi => 10, // \n ; Newline | Semi => 10, // \n ;
LParen | LBrace | LSqBr | Indent => 0, // ( { [ Indent LParen | LBrace | LSqBr | Indent => 0, // ( { [ Indent
_ => return None, _ => return None,
@ -286,7 +286,7 @@ impl TokenKind {
pub const fn is_right_associative(&self) -> bool { pub const fn is_right_associative(&self) -> bool {
matches!( matches!(
self, self,
FuncArrow | ProcArrow | Equal /* | PreDollar | PreAt */ FuncArrow | ProcArrow | Assign /* | PreDollar | PreAt */
) )
} }
@ -335,7 +335,7 @@ pub struct Token {
pub const COLON: Token = Token::dummy(TokenKind::Colon, ":"); pub const COLON: Token = Token::dummy(TokenKind::Colon, ":");
pub const DOT: Token = Token::dummy(TokenKind::Dot, "."); pub const DOT: Token = Token::dummy(TokenKind::Dot, ".");
pub const EQUAL: Token = Token::dummy(TokenKind::Equal, "="); pub const EQUAL: Token = Token::dummy(TokenKind::Assign, "=");
impl fmt::Debug for Token { impl fmt::Debug for Token {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {