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::PreMinus => Some(OpKind::Neg),
TokenKind::PreBitNot => Some(OpKind::Invert),
TokenKind::Equal => Some(OpKind::Eq),
TokenKind::DblEq => Some(OpKind::Eq),
TokenKind::NotEq => Some(OpKind::Ne),
TokenKind::Less => Some(OpKind::Lt),
TokenKind::LessEq => Some(OpKind::Le),

View file

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

View file

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

View file

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

View file

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

View file

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