Skip to content

Commit

Permalink
Change token names to represent the character instead of the operation.
Browse files Browse the repository at this point in the history
  • Loading branch information
gilbens-starkware committed Dec 17, 2023
1 parent f4cac86 commit 0944200
Show file tree
Hide file tree
Showing 23 changed files with 769 additions and 756 deletions.
22 changes: 12 additions & 10 deletions crates/cairo-lang-formatter/src/node_properties.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ impl SyntaxNodeFormat for SyntaxNode {
| SyntaxKind::TokenRBrack
| SyntaxKind::TokenLBrack
| SyntaxKind::TokenSingleLineComment => true,
SyntaxKind::TokenNot
SyntaxKind::TokenBang
if matches!(
grandparent_kind(db, self),
Some(SyntaxKind::ExprInlineMacro | SyntaxKind::ItemInlineMacro)
Expand Down Expand Up @@ -75,8 +75,8 @@ impl SyntaxNodeFormat for SyntaxNode {
fn force_no_space_after(&self, db: &dyn SyntaxGroup) -> bool {
match self.kind(db) {
SyntaxKind::TokenDot
| SyntaxKind::TokenNot
| SyntaxKind::TokenBitNot
| SyntaxKind::TokenBang
| SyntaxKind::TokenTilde
| SyntaxKind::TokenAt
| SyntaxKind::TokenColonColon
| SyntaxKind::TokenLParen
Expand Down Expand Up @@ -111,7 +111,7 @@ impl SyntaxNodeFormat for SyntaxNode {
{
true
}
SyntaxKind::TokenMinus | SyntaxKind::TokenMul => {
SyntaxKind::TokenMinus | SyntaxKind::TokenStar => {
matches!(grandparent_kind(db, self), Some(SyntaxKind::ExprUnary))
}
SyntaxKind::TokenPlus
Expand Down Expand Up @@ -473,15 +473,17 @@ impl SyntaxNodeFormat for SyntaxNode {
true,
))
}
SyntaxKind::TerminalMul if parent_kind(db, self) != Some(SyntaxKind::ExprUnary) => {
SyntaxKind::TerminalStar
if parent_kind(db, self) != Some(SyntaxKind::ExprUnary) =>
{
BreakLinePointsPositions::Leading(BreakLinePointProperties::new(
9,
BreakLinePointIndentation::Indented,
true,
true,
))
}
SyntaxKind::TerminalDiv => {
SyntaxKind::TerminalSlash => {
BreakLinePointsPositions::Leading(BreakLinePointProperties::new(
9,
BreakLinePointIndentation::Indented,
Expand Down Expand Up @@ -523,7 +525,7 @@ impl SyntaxNodeFormat for SyntaxNode {
true,
))
}
SyntaxKind::TerminalXor => {
SyntaxKind::TerminalCaret => {
BreakLinePointsPositions::Leading(BreakLinePointProperties::new(
14,
BreakLinePointIndentation::Indented,
Expand All @@ -542,9 +544,9 @@ impl SyntaxNodeFormat for SyntaxNode {
SyntaxKind::TokenEq
| SyntaxKind::TokenPlusEq
| SyntaxKind::TokenMinusEq
| SyntaxKind::TokenMulEq
| SyntaxKind::TokenDivEq
| SyntaxKind::TokenModEq => {
| SyntaxKind::TokenStarEq
| SyntaxKind::TokenSlashEq
| SyntaxKind::TokenPercentEq => {
BreakLinePointsPositions::Trailing(BreakLinePointProperties::new(
16,
BreakLinePointIndentation::Indented,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ impl SemanticTokenKind {
SyntaxKind::TokenIdentifier => {}
_ if kind.is_keyword_token() => return Some(SemanticTokenKind::Keyword),
SyntaxKind::TokenLiteralNumber => return Some(SemanticTokenKind::Number),
SyntaxKind::TokenNot
SyntaxKind::TokenBang
if matches!(
grandparent_kind(syntax_db, &node),
Some(SyntaxKind::ExprInlineMacro | SyntaxKind::ItemInlineMacro)
Expand All @@ -76,12 +76,12 @@ impl SemanticTokenKind {
| SyntaxKind::TokenGT
| SyntaxKind::TokenLE
| SyntaxKind::TokenLT
| SyntaxKind::TokenNot
| SyntaxKind::TokenBang
| SyntaxKind::TokenPlus
| SyntaxKind::TokenMinus
| SyntaxKind::TokenMul
| SyntaxKind::TokenDiv
| SyntaxKind::TokenMod => return Some(SemanticTokenKind::Operator),
| SyntaxKind::TokenStar
| SyntaxKind::TokenSlash
| SyntaxKind::TokenPercent => return Some(SemanticTokenKind::Operator),
SyntaxKind::TokenSingleLineComment => return Some(SemanticTokenKind::Comment),
SyntaxKind::TokenShortString | SyntaxKind::TokenString => {
return Some(SemanticTokenKind::String);
Expand Down
1 change: 0 additions & 1 deletion crates/cairo-lang-lowering/src/test_data/match
Original file line number Diff line number Diff line change
Expand Up @@ -775,4 +775,3 @@ error: Enum variant `Four` not covered.

//! > lowering_flat
Parameters: v0: test::A

12 changes: 6 additions & 6 deletions crates/cairo-lang-parser/src/colored_printer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,9 @@ fn set_color(text: SmolStr, kind: SyntaxKind) -> ColoredString {
SyntaxKind::TokenIdentifier => text.truecolor(255, 255, 100), // Yellow
SyntaxKind::TokenPlus
| SyntaxKind::TokenMinus
| SyntaxKind::TokenMul
| SyntaxKind::TokenDiv
| SyntaxKind::TokenMod
| SyntaxKind::TokenStar
| SyntaxKind::TokenSlash
| SyntaxKind::TokenPercent
| SyntaxKind::TokenDot => text.bright_magenta(),
SyntaxKind::TokenLiteralNumber
| SyntaxKind::TokenFalse
Expand All @@ -90,7 +90,7 @@ fn set_color(text: SmolStr, kind: SyntaxKind) -> ColoredString {
| SyntaxKind::TokenMut
| SyntaxKind::TokenNoPanic => text.bright_blue(),
SyntaxKind::TokenArrow
| SyntaxKind::TokenMatchArrow
| SyntaxKind::TokenFatArrow
| SyntaxKind::TokenColon
| SyntaxKind::TokenColonColon
| SyntaxKind::TokenDotDot
Expand All @@ -99,8 +99,8 @@ fn set_color(text: SmolStr, kind: SyntaxKind) -> ColoredString {
| SyntaxKind::TokenAndAnd
| SyntaxKind::TokenOr
| SyntaxKind::TokenOrOr
| SyntaxKind::TokenXor
| SyntaxKind::TokenNot
| SyntaxKind::TokenCaret
| SyntaxKind::TokenBang
| SyntaxKind::TokenQuestionMark
| SyntaxKind::TokenUnderscore
| SyntaxKind::TokenHash => text.truecolor(255, 180, 255), // Pink
Expand Down
20 changes: 10 additions & 10 deletions crates/cairo-lang-parser/src/lexer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -459,25 +459,25 @@ fn token_kind_to_terminal_syntax_kind(kind: TokenKind) -> SyntaxKind {
TokenKind::At => SyntaxKind::TerminalAt,
TokenKind::Or => SyntaxKind::TerminalOr,
TokenKind::OrOr => SyntaxKind::TerminalOrOr,
TokenKind::Xor => SyntaxKind::TerminalXor,
TokenKind::Xor => SyntaxKind::TerminalCaret,
TokenKind::EqEq => SyntaxKind::TerminalEqEq,
TokenKind::Neq => SyntaxKind::TerminalNeq,
TokenKind::GE => SyntaxKind::TerminalGE,
TokenKind::GT => SyntaxKind::TerminalGT,
TokenKind::LE => SyntaxKind::TerminalLE,
TokenKind::LT => SyntaxKind::TerminalLT,
TokenKind::Not => SyntaxKind::TerminalNot,
TokenKind::BitNot => SyntaxKind::TerminalBitNot,
TokenKind::Not => SyntaxKind::TerminalBang,
TokenKind::BitNot => SyntaxKind::TerminalTilde,
TokenKind::Plus => SyntaxKind::TerminalPlus,
TokenKind::PlusEq => SyntaxKind::TerminalPlusEq,
TokenKind::Minus => SyntaxKind::TerminalMinus,
TokenKind::MinusEq => SyntaxKind::TerminalMinusEq,
TokenKind::Mul => SyntaxKind::TerminalMul,
TokenKind::MulEq => SyntaxKind::TerminalMulEq,
TokenKind::Div => SyntaxKind::TerminalDiv,
TokenKind::DivEq => SyntaxKind::TerminalDivEq,
TokenKind::Mod => SyntaxKind::TerminalMod,
TokenKind::ModEq => SyntaxKind::TerminalModEq,
TokenKind::Mul => SyntaxKind::TerminalStar,
TokenKind::MulEq => SyntaxKind::TerminalStarEq,
TokenKind::Div => SyntaxKind::TerminalSlash,
TokenKind::DivEq => SyntaxKind::TerminalSlashEq,
TokenKind::Mod => SyntaxKind::TerminalPercent,
TokenKind::ModEq => SyntaxKind::TerminalPercentEq,
TokenKind::Colon => SyntaxKind::TerminalColon,
TokenKind::ColonColon => SyntaxKind::TerminalColonColon,
TokenKind::Comma => SyntaxKind::TerminalComma,
Expand All @@ -497,7 +497,7 @@ fn token_kind_to_terminal_syntax_kind(kind: TokenKind) -> SyntaxKind {
TokenKind::Ref => SyntaxKind::TerminalRef,
TokenKind::Mut => SyntaxKind::TerminalMut,
TokenKind::Arrow => SyntaxKind::TerminalArrow,
TokenKind::MatchArrow => SyntaxKind::TerminalMatchArrow,
TokenKind::MatchArrow => SyntaxKind::TerminalFatArrow,
TokenKind::BadCharacters => SyntaxKind::TerminalBadCharacters,
TokenKind::EndOfFile => SyntaxKind::TerminalEndOfFile,
}
Expand Down
38 changes: 19 additions & 19 deletions crates/cairo-lang-parser/src/lexer_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,10 +67,10 @@ fn terminal_kind_to_text(kind: SyntaxKind) -> Vec<&'static str> {
SyntaxKind::TerminalColon => vec![":"],
SyntaxKind::TerminalColonColon => vec!["::"],
SyntaxKind::TerminalComma => vec![","],
SyntaxKind::TerminalDiv => vec!["/"],
SyntaxKind::TerminalDivEq => vec!["/="],
SyntaxKind::TerminalMod => vec!["%"],
SyntaxKind::TerminalModEq => vec!["%="],
SyntaxKind::TerminalSlash => vec!["/"],
SyntaxKind::TerminalSlashEq => vec!["/="],
SyntaxKind::TerminalPercent => vec!["%"],
SyntaxKind::TerminalPercentEq => vec!["%="],
SyntaxKind::TerminalDot => vec!["."],
SyntaxKind::TerminalDotDot => vec![".."],
SyntaxKind::TerminalEq => vec!["="],
Expand All @@ -81,14 +81,14 @@ fn terminal_kind_to_text(kind: SyntaxKind) -> Vec<&'static str> {
SyntaxKind::TerminalLT => vec!["<"],
SyntaxKind::TerminalMinus => vec!["-"],
SyntaxKind::TerminalMinusEq => vec!["-="],
SyntaxKind::TerminalMul => vec!["*"],
SyntaxKind::TerminalMulEq => vec!["*="],
SyntaxKind::TerminalStar => vec!["*"],
SyntaxKind::TerminalStarEq => vec!["*="],
SyntaxKind::TerminalNeq => vec!["!="],
SyntaxKind::TerminalNot => vec!["!"],
SyntaxKind::TerminalBitNot => vec!["~"],
SyntaxKind::TerminalBang => vec!["!"],
SyntaxKind::TerminalTilde => vec!["~"],
SyntaxKind::TerminalOr => vec!["|"],
SyntaxKind::TerminalOrOr => vec!["||"],
SyntaxKind::TerminalXor => vec!["^"],
SyntaxKind::TerminalCaret => vec!["^"],
SyntaxKind::TerminalPlus => vec!["+"],
SyntaxKind::TerminalPlusEq => vec!["+="],
SyntaxKind::TerminalSemicolon => vec![";"],
Expand All @@ -101,7 +101,7 @@ fn terminal_kind_to_text(kind: SyntaxKind) -> Vec<&'static str> {
SyntaxKind::TerminalLParen => vec!["("],
SyntaxKind::TerminalRParen => vec![")"],
SyntaxKind::TerminalArrow => vec!["->"],
SyntaxKind::TerminalMatchArrow => vec!["=>"],
SyntaxKind::TerminalFatArrow => vec!["=>"],
SyntaxKind::TerminalEndOfFile => vec![],
_ => {
assert!(!kind.is_terminal());
Expand Down Expand Up @@ -141,24 +141,24 @@ fn terminal_kinds() -> Vec<SyntaxKind> {
SyntaxKind::TerminalAt,
SyntaxKind::TerminalOr,
SyntaxKind::TerminalOrOr,
SyntaxKind::TerminalXor,
SyntaxKind::TerminalCaret,
SyntaxKind::TerminalEqEq,
SyntaxKind::TerminalNeq,
SyntaxKind::TerminalGE,
SyntaxKind::TerminalGT,
SyntaxKind::TerminalLE,
SyntaxKind::TerminalLT,
SyntaxKind::TerminalNot,
SyntaxKind::TerminalBang,
SyntaxKind::TerminalPlus,
SyntaxKind::TerminalPlusEq,
SyntaxKind::TerminalMinus,
SyntaxKind::TerminalMinusEq,
SyntaxKind::TerminalMul,
SyntaxKind::TerminalMulEq,
SyntaxKind::TerminalDiv,
SyntaxKind::TerminalDivEq,
SyntaxKind::TerminalMod,
SyntaxKind::TerminalModEq,
SyntaxKind::TerminalStar,
SyntaxKind::TerminalStarEq,
SyntaxKind::TerminalSlash,
SyntaxKind::TerminalSlashEq,
SyntaxKind::TerminalPercent,
SyntaxKind::TerminalPercentEq,
SyntaxKind::TerminalColon,
SyntaxKind::TerminalColonColon,
SyntaxKind::TerminalComma,
Expand All @@ -175,7 +175,7 @@ fn terminal_kinds() -> Vec<SyntaxKind> {
SyntaxKind::TerminalLParen,
SyntaxKind::TerminalRParen,
SyntaxKind::TerminalArrow,
SyntaxKind::TerminalMatchArrow,
SyntaxKind::TerminalFatArrow,
SyntaxKind::TerminalEndOfFile,
SyntaxKind::TerminalShortString,
SyntaxKind::TerminalString,
Expand Down
16 changes: 8 additions & 8 deletions crates/cairo-lang-parser/src/operators.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ use cairo_lang_syntax::node::kind::SyntaxKind;
pub fn get_unary_operator_precedence(kind: SyntaxKind) -> Option<usize> {
match kind {
SyntaxKind::TerminalAt
| SyntaxKind::TerminalNot
| SyntaxKind::TerminalBitNot
| SyntaxKind::TerminalMul
| SyntaxKind::TerminalBang
| SyntaxKind::TerminalTilde
| SyntaxKind::TerminalStar
| SyntaxKind::TerminalMinus => Some(2),
_ => None,
}
Expand All @@ -16,10 +16,10 @@ pub fn get_post_operator_precedence(kind: SyntaxKind) -> Option<usize> {
SyntaxKind::TerminalQuestionMark
// [] Operator.
| SyntaxKind::TerminalLBrack => Some(1),
SyntaxKind::TerminalMul | SyntaxKind::TerminalDiv | SyntaxKind::TerminalMod => Some(2),
SyntaxKind::TerminalStar | SyntaxKind::TerminalSlash | SyntaxKind::TerminalPercent => Some(2),
SyntaxKind::TerminalPlus | SyntaxKind::TerminalMinus => Some(3),
SyntaxKind::TerminalAnd => Some(4),
SyntaxKind::TerminalXor => Some(5),
SyntaxKind::TerminalCaret => Some(5),
SyntaxKind::TerminalOr => Some(6),
SyntaxKind::TerminalEqEq
| SyntaxKind::TerminalNeq
Expand All @@ -32,9 +32,9 @@ pub fn get_post_operator_precedence(kind: SyntaxKind) -> Option<usize> {
SyntaxKind::TerminalEq
| SyntaxKind::TerminalPlusEq
| SyntaxKind::TerminalMinusEq
| SyntaxKind::TerminalMulEq
| SyntaxKind::TerminalDivEq
| SyntaxKind::TerminalModEq => Some(10),
| SyntaxKind::TerminalStarEq
| SyntaxKind::TerminalSlashEq
| SyntaxKind::TerminalPercentEq => Some(10),
_ => None,
}
}
Loading

0 comments on commit 0944200

Please sign in to comment.