Skip to content

Commit

Permalink
Merge pull request fables-tales#306 from phiggins/handle_backtick_symbol
Browse files Browse the repository at this point in the history
Handle backtick symbol.
  • Loading branch information
phiggins authored Jun 3, 2021
2 parents a1e7774 + 8a21b65 commit 2983e25
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 9 deletions.
1 change: 1 addition & 0 deletions fixtures/small/backtick_symbol_actual.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
:`
1 change: 1 addition & 0 deletions fixtures/small/backtick_symbol_expected.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
:`
29 changes: 22 additions & 7 deletions librubyfmt/src/format.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
}

Expand Down
12 changes: 10 additions & 2 deletions librubyfmt/src/ripper_tree_types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1160,19 +1160,23 @@ impl IdentOrConst {
}

#[derive(RipperDeserialize, Debug, Clone)]
pub enum IdentOrConstOrKwOrOpOrIvarOrGvarOrCvar {
pub enum IdentOrConstOrKwOrOpOrIvarOrGvarOrCvarOrBacktick {
Ident(Ident),
Const(Const),
Keyword(Kw),
Op(Op),
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 {
Expand Down Expand Up @@ -1832,3 +1836,7 @@ pub struct IfOp(
pub Box<Expression>,
pub Box<Expression>,
);

def_tag!(backtick_tag, "@backtick");
#[derive(Deserialize, Debug, Clone)]
pub struct Backtick(backtick_tag, pub String, pub LineCol);

0 comments on commit 2983e25

Please sign in to comment.