Class: SyntaxTree::HashKeyFormatter::Labels

Inherits:
Object
  • Object
show all
Defined in:
lib/syntax_tree/node.rb

Overview

Formats the keys of a hash literal using labels.

Constant Summary collapse

LABEL =
/\A[A-Za-z_](\w*[\w!?])?\z/

Instance Method Summary collapse

Instance Method Details

#format_key(q, key) ⇒ Object



1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
# File 'lib/syntax_tree/node.rb', line 1415

def format_key(q, key)
  case key
  in Label
    q.format(key)
  in SymbolLiteral
    q.format(key.value)
    q.text(":")
  in DynaSymbol[parts: [TStringContent[value: LABEL] => part]]
    q.format(part)
    q.text(":")
  in DynaSymbol
    q.format(key)
    q.text(":")
  end
end