diff --git a/fixtures/small/backtick_symbol_actual.rb b/fixtures/small/backtick_symbol_actual.rb new file mode 100644 index 00000000..118d64f7 --- /dev/null +++ b/fixtures/small/backtick_symbol_actual.rb @@ -0,0 +1 @@ +:` diff --git a/fixtures/small/backtick_symbol_expected.rb b/fixtures/small/backtick_symbol_expected.rb new file mode 100644 index 00000000..118d64f7 --- /dev/null +++ b/fixtures/small/backtick_symbol_expected.rb @@ -0,0 +1 @@ +:` diff --git a/librubyfmt/src/format.rs b/librubyfmt/src/format.rs index e780eadd..febe1266 100644 --- a/librubyfmt/src/format.rs +++ b/librubyfmt/src/format.rs @@ -889,22 +889,37 @@ pub fn format_kw(ps: &mut dyn ConcreteParserState, kw: Kw) { } } +pub fn format_backtick(ps: &mut dyn ConcreteParserState, backtick: Backtick) { + if ps.at_start_of_line() { + ps.emit_indent(); + } + + handle_string_and_linecol(ps, backtick.1, backtick.2); + + if ps.at_start_of_line() { + ps.emit_newline(); + } +} + pub fn format_symbol(ps: &mut dyn ConcreteParserState, symbol: Symbol) { ps.emit_ident(":".to_string()); match symbol.1 { - IdentOrConstOrKwOrOpOrIvarOrGvarOrCvar::Ident(i) => format_ident(ps, i), - IdentOrConstOrKwOrOpOrIvarOrGvarOrCvar::Const(c) => format_const(ps, c), - IdentOrConstOrKwOrOpOrIvarOrGvarOrCvar::Keyword(kw) => format_kw(ps, kw), - IdentOrConstOrKwOrOpOrIvarOrGvarOrCvar::Op(op) => format_op(ps, op), - IdentOrConstOrKwOrOpOrIvarOrGvarOrCvar::IVar(ivar) => { + IdentOrConstOrKwOrOpOrIvarOrGvarOrCvarOrBacktick::Ident(i) => format_ident(ps, i), + IdentOrConstOrKwOrOpOrIvarOrGvarOrCvarOrBacktick::Const(c) => format_const(ps, c), + IdentOrConstOrKwOrOpOrIvarOrGvarOrCvarOrBacktick::Keyword(kw) => format_kw(ps, kw), + IdentOrConstOrKwOrOpOrIvarOrGvarOrCvarOrBacktick::Op(op) => format_op(ps, op), + IdentOrConstOrKwOrOpOrIvarOrGvarOrCvarOrBacktick::IVar(ivar) => { format_var_ref_type(ps, VarRefType::IVar(ivar)) } - IdentOrConstOrKwOrOpOrIvarOrGvarOrCvar::GVar(gvar) => { + IdentOrConstOrKwOrOpOrIvarOrGvarOrCvarOrBacktick::GVar(gvar) => { format_var_ref_type(ps, VarRefType::GVar(gvar)) } - IdentOrConstOrKwOrOpOrIvarOrGvarOrCvar::CVar(cvar) => { + IdentOrConstOrKwOrOpOrIvarOrGvarOrCvarOrBacktick::CVar(cvar) => { format_var_ref_type(ps, VarRefType::CVar(cvar)) } + IdentOrConstOrKwOrOpOrIvarOrGvarOrCvarOrBacktick::Backtick(backtick) => { + format_backtick(ps, backtick) + } } } diff --git a/librubyfmt/src/ripper_tree_types.rs b/librubyfmt/src/ripper_tree_types.rs index a9b6ae33..8d75325c 100644 --- a/librubyfmt/src/ripper_tree_types.rs +++ b/librubyfmt/src/ripper_tree_types.rs @@ -1160,7 +1160,7 @@ impl IdentOrConst { } #[derive(RipperDeserialize, Debug, Clone)] -pub enum IdentOrConstOrKwOrOpOrIvarOrGvarOrCvar { +pub enum IdentOrConstOrKwOrOpOrIvarOrGvarOrCvarOrBacktick { Ident(Ident), Const(Const), Keyword(Kw), @@ -1168,11 +1168,15 @@ pub enum IdentOrConstOrKwOrOpOrIvarOrGvarOrCvar { IVar(IVar), GVar(GVar), CVar(CVar), + Backtick(Backtick), } def_tag!(symbol_tag, "symbol"); #[derive(Deserialize, Debug, Clone)] -pub struct Symbol(pub symbol_tag, pub IdentOrConstOrKwOrOpOrIvarOrGvarOrCvar); +pub struct Symbol( + pub symbol_tag, + pub IdentOrConstOrKwOrOpOrIvarOrGvarOrCvarOrBacktick, +); #[derive(RipperDeserialize, Debug, Clone)] pub enum CallLeft { @@ -1832,3 +1836,7 @@ pub struct IfOp( pub Box, pub Box, ); + +def_tag!(backtick_tag, "@backtick"); +#[derive(Deserialize, Debug, Clone)] +pub struct Backtick(backtick_tag, pub String, pub LineCol);