class
Crystal::Formatter
Defined in:
compiler/crystal/tools/formatter.crConstructors
Class Method Summary
- .format(source, filename = nil, report_warnings : IO | Nil = nil, flags : Array(String) | Nil = nil)
Instance Method Summary
- #abstract_def?(node)
- #accept(node : HashLiteral::Entry)
- #accept(node : NamedTupleLiteral::Entry)
- #accept_assign_value(value, check_align = false)
- #accept_assign_value_after_equals(value, check_align = false)
- #align_comment(line, i, comment_column, max_column)
-
#align_comments(lines)
Align series of successive comments
- #align_info(lines, info, max_size)
-
#align_infos(lines, align_infos)
Align series of successive inline when/else (in a case), or hash literals (the left side of the =>)
- #assign?(exp)
- #assign_length(exp)
-
#at_skip?
The parser transforms
def foo(@x); endtodef foo(x); @x = x; endso if we find an instance var we later need to skip the first expressions in the body - #check(*token_types : Token::Kind)
- #check_assign_align(before_column, exp)
- #check_assign_length(exp)
- #check_end
- #check_hash_info(hash, key, start_line, start_column, middle_column)
- #check_keyword(*keywords : Keyword)
- #check_macro_whitespace
- #clear_object(node)
- #consume_newlines(next_comes_end = false)
- #decrement_line
- #end_visit_any(node)
- #find_assign_chunk(expressions, last, i)
- #find_last_info(align_infos, base, i)
- #find_max_column(lines, base, max)
- #finish
- #finish_args(has_parentheses, has_newlines, ends_with_newline, found_comment, column)
- #finish_list(suffix : Token::Kind, has_newlines, found_comment, found_first_newline, write_space_at_end)
- #fix_heredocs(lines)
- #flag?(flag)
- #format_alias_or_typedef(node, keyword : Keyword, value)
- #format_args(args : Array, has_parentheses, named_args = nil, block_arg = nil, needed_indent = @indent + 2, do_consume_newlines = false)
- #format_args_simple(args, needed_indent, do_consume_newlines)
- #format_binary(node, token : Token::Kind)
- #format_block(node, needs_space)
- #format_block_arg(block_arg, needed_indent)
- #format_block_arg
- #format_block_args(args, node)
- #format_call_args(node : ASTNode, has_parentheses, base_indent)
- #format_control_expression(node, keyword : Keyword)
- #format_def_arg(wrote_newline, has_more, write_trailing_comma = false, &)
- #format_def_args(args : Array, block_arg, splat_index, variadic, double_splat, yields)
- #format_def_args(node : Def | Macro)
- #format_doc_comments(lines)
- #format_elsif(node_else, keyword : Keyword)
- #format_end(column)
- #format_hash_entry(hash, entry)
- #format_if_at_cond(node, keyword : Keyword, check_end = true)
- #format_literal_elements(elements, prefix : Token::Kind, suffix : Token::Kind)
- #format_macro_body(node)
- #format_macro_contents(node, macro_node_line)
- #format_macro_end
- #format_macro_if_epilogue(node, macro_state : Crystal::Token::MacroState, check_end = true)
- #format_multi_assign_values(values)
- #format_named_args(args, named_args, needed_indent)
- #format_named_argument_name(name)
- #format_named_tuple_entry(hash, entry)
- #format_nested(node, indent = @indent, write_end_line = true, write_indent = true)
- #format_nested_with_end(node, column = @indent, write_end_line = true)
- #format_parenthesized_args(args, named_args = nil)
- #format_regex_modifiers
- #format_type_vars(type_vars, splat_index)
- #format_when(case_node, node, is_last, align_number)
- #format_while_or_until(node, keyword : Keyword)
- #increment_line
- #indent(indent : Int, node : ASTNode | HashLiteral::Entry | NamedTupleLiteral::Entry)
- #indent(node : ASTNode)
- #indent : Int32
- #indent(indent : Int, &)
- #indent(&)
- #indent=(indent : Int32)
- #inside_call_or_assign(&)
- #inside_cond(&)
- #inside_enum : Int32
- #inside_enum=(inside_enum : Int32)
- #inside_lib : Int32
- #inside_lib=(inside_lib : Int32)
- #inside_macro(&)
- #inside_macro?
- #inside_struct_or_union : Int32
- #inside_struct_or_union=(inside_struct_or_union : Int32)
- #jump_semicolon
- #last?(index, collection)
- #leading_space_count(line, max_count)
- #leading_tuple_depth(exp)
- #needs_two_lines?(node, next_node)
- #needs_two_lines?(node)
- #next_macro_token
- #next_string_token
- #next_token
- #next_token_skip_space
- #next_token_skip_space_or_newline
- #no_indent(node : ASTNode)
- #no_indent(&)
- #no_rstrip_lines : Set(Int32)
- #opening_curly_brace_count
- #outside_macro(&)
- #remove_to_skip(node, to_skip)
- #reset_macro_state
- #skip_semicolon
- #skip_semicolon_or_space
- #skip_semicolon_or_space_or_newline
- #skip_space(write_comma : Bool = false, consume_newline : Bool = true)
- #skip_space(indent : Int32, write_comma = false)
- #skip_space_in_percent_array_literal
- #skip_space_or_newline(last : Bool = false, at_least_one : Bool = false, next_comes_end : Bool = false)
- #skip_space_or_newline(indent : Int32, last : Bool = false, at_least_one : Bool = false, next_comes_end : Bool = false)
- #skip_space_write_line
- #slash_is_not_regex!
- #slash_is_regex!
- #space_slash_newline?
- #subformat(source)
- #subformat_nesting : Int32
- #subformat_nesting=(subformat_nesting : Int32)
-
#to_s(io : IO) : Nil
Appends a short String representation of this object which includes its class name and its object address.
- #vars : Array(Set(String))
- #vars=(vars : Array(Set(String)))
- #visit(node : FileNode)
- #visit(node : Expressions)
- #visit(node : Nop)
- #visit(node : NilLiteral)
- #visit(node : BoolLiteral)
- #visit(node : CharLiteral)
- #visit(node : SymbolLiteral)
- #visit(node : NumberLiteral)
- #visit(node : StringLiteral)
- #visit(node : StringInterpolation)
- #visit(node : RegexLiteral)
- #visit(node : ArrayLiteral)
- #visit(node : TupleLiteral)
- #visit(node : HashLiteral)
- #visit(node : NamedTupleLiteral)
- #visit(node : RangeLiteral)
- #visit(node : Path)
- #visit(node : Generic)
- #visit(node : Union)
- #visit(node : If)
- #visit(node : Unless)
- #visit(node : While)
- #visit(node : Until)
- #visit(node : Def)
- #visit(node : FunDef)
- #visit(node : Macro)
- #visit(node : MacroLiteral)
- #visit(node : MacroVerbatim)
- #visit(node : MacroExpression)
- #visit(node : MacroIf)
- #visit(node : MacroFor)
- #visit(node : MacroVar)
- #visit(node : Arg)
- #visit(node : Splat)
- #visit(node : DoubleSplat)
- #visit(node : ProcNotation)
- #visit(node : Self)
- #visit(node : Var)
- #visit(node : InstanceVar)
- #visit(node : ClassVar)
- #visit(node : Global)
- #visit(node : ReadInstanceVar)
- #visit(node : Call)
- #visit(node : NamedArgument)
- #visit(node : IsA)
- #visit(node : RespondsTo)
- #visit(node : Or)
- #visit(node : And)
- #visit(node : Not)
- #visit(node : Assign)
- #visit(node : OpAssign)
- #visit(node : Require)
- #visit(node : VisibilityModifier)
- #visit(node : MagicConstant)
- #visit(node : ModuleDef)
- #visit(node : AnnotationDef)
- #visit(node : ClassDef)
- #visit(node : CStructOrUnionDef)
- #visit(node : Include)
- #visit(node : Extend)
- #visit(node : LibDef)
- #visit(node : EnumDef)
- #visit(node : TypeDeclaration)
- #visit(node : UninitializedVar)
- #visit(node : Return)
- #visit(node : Break)
- #visit(node : Next)
- #visit(node : Yield)
- #visit(node : Case)
- #visit(node : ImplicitObj)
- #visit(node : Select)
- #visit(node : Annotation)
- #visit(node : Cast)
- #visit(node : NilableCast)
- #visit(node : TypeOf)
- #visit(node : SizeOf)
- #visit(node : InstanceSizeOf)
- #visit(node : AlignOf)
- #visit(node : InstanceAlignOf)
- #visit(node : OffsetOf)
- #visit(node : PointerOf)
- #visit(node : Underscore)
- #visit(node : MultiAssign)
- #visit(node : ExceptionHandler)
- #visit(node : Alias)
- #visit(node : TypeDef)
- #visit(node : ProcPointer)
- #visit(node : ProcLiteral)
- #visit(node : ExternalVar)
- #visit(node : Out)
- #visit(node : Metaclass)
- #visit(node : Block)
- #visit(node : When)
- #visit(node : Rescue)
- #visit(node : MacroId)
- #visit(node : MetaVar)
- #visit(node : Asm)
- #visit(node : AsmOperand)
- #visit(node : ASTNode)
- #visit_asm_parts(parts, colon_column, &) : Nil
- #visit_if_or_unless(node, keyword : Keyword)
- #visit_splat(node, token : Token::Kind)
- #visit_string_body(node, is_regex = false)
- #visit_string_interpolation(node, token : Crystal::Token, line, column, old_indent, old_string_continuation : Int32, wrote_token = false)
- #visit_string_interpolation_body(node, delimiter_state, column, *, is_regex = false, is_heredoc = false)
- #write(string : String, no_rstrip : Bool = false)
- #write(obj)
- #write_comment(needs_indent = true, consume_newline = true, next_comes_end = false)
- #write_indent(indent, node)
- #write_indent(indent)
- #write_indent
- #write_indent(indent = @indent, &)
- #write_keyword(before : String, keyword : Keyword, after : String)
- #write_keyword(before : String, keyword : Keyword)
- #write_keyword(keyword : Keyword, after : String, skip_space_or_newline = true)
- #write_keyword(keyword : Keyword)
- #write_line
- #write_token(before : String, type : Token::Kind, after : String)
- #write_token(before : String, type : Token::Kind)
- #write_token(type : Token::Kind, after : String)
- #write_token(type : Token::Kind)
Instance methods inherited from class Crystal::Visitor
accept(node)
accept,
end_visit(node)
end_visit,
end_visit_any(node)
end_visit_any,
visit_any(node)
visit_any
Instance methods inherited from class Reference
==(other : self)==(other : JSON::Any)
==(other : YAML::Any)
==(other) ==, dup dup, hash(hasher) hash, initialize initialize, inspect(io : IO) : Nil inspect, object_id : UInt64 object_id, pretty_print(pp) : Nil pretty_print, same?(other : Reference) : Bool
same?(other : Nil) same?, to_s(io : IO) : Nil to_s
Constructor methods inherited from class Reference
new
new,
unsafe_construct(address : Pointer, *args, **opts) : self
unsafe_construct
Class methods inherited from class Reference
pre_initialize(address : Pointer)
pre_initialize
Instance methods inherited from class Object
! : Bool
!,
!=(other)
!=,
!~(other)
!~,
==(other)
==,
===(other : JSON::Any)===(other : YAML::Any)
===(other) ===, =~(other) =~, as(type : Class) as, as?(type : Class) as?, class class, dup dup, hash(hasher)
hash hash, in?(collection : Object) : Bool
in?(*values : Object) : Bool in?, inspect(io : IO) : Nil
inspect : String inspect, is_a?(type : Class) : Bool is_a?, itself itself, nil? : Bool nil?, not_nil!(message)
not_nil! not_nil!, pretty_inspect(width = 79, newline = "\n", indent = 0) : String pretty_inspect, pretty_print(pp : PrettyPrint) : Nil pretty_print, responds_to?(name : Symbol) : Bool responds_to?, tap(&) tap, to_json(io : IO) : Nil
to_json : String to_json, to_pretty_json(indent : String = " ") : String
to_pretty_json(io : IO, indent : String = " ") : Nil to_pretty_json, to_s(io : IO) : Nil
to_s : String to_s, to_yaml(io : IO) : Nil
to_yaml : String to_yaml, try(&) try, unsafe_as(type : T.class) forall T unsafe_as
Class methods inherited from class Object
from_json(string_or_io : String | IO, root : String)from_json(string_or_io : String | IO) from_json, from_yaml(string_or_io : String | IO) from_yaml
Macros inherited from class Object
class_getter(*names, &block)
class_getter,
class_getter!(*names)
class_getter!,
class_getter?(*names, &block)
class_getter?,
class_property(*names, &block)
class_property,
class_property!(*names)
class_property!,
class_property?(*names, &block)
class_property?,
class_setter(*names)
class_setter,
def_clone
def_clone,
def_equals(*fields)
def_equals,
def_equals_and_hash(*fields)
def_equals_and_hash,
def_hash(*fields)
def_hash,
delegate(*methods, to object)
delegate,
forward_missing_to(delegate)
forward_missing_to,
getter(*names, &block)
getter,
getter!(*names)
getter!,
getter?(*names, &block)
getter?,
property(*names, &block)
property,
property!(*names)
property!,
property?(*names, &block)
property?,
setter(*names)
setter
Constructor Detail
Class Method Detail
def self.format(source, filename = nil, report_warnings : IO | Nil = nil, flags : Array(String) | Nil = nil)
#
Instance Method Detail
def align_infos(lines, align_infos)
#
Align series of successive inline when/else (in a case), or hash literals (the left side of the =>)
def at_skip?
#
The parser transforms def foo(@x); end to def foo(x); @x = x; end so if we
find an instance var we later need to skip the first expressions in the body
def finish_args(has_parentheses, has_newlines, ends_with_newline, found_comment, column)
#
def finish_list(suffix : Token::Kind, has_newlines, found_comment, found_first_newline, write_space_at_end)
#
def format_args(args : Array, has_parentheses, named_args = nil, block_arg = nil, needed_indent = @indent + 2, do_consume_newlines = false)
#
def skip_space_or_newline(last : Bool = false, at_least_one : Bool = false, next_comes_end : Bool = false)
#
def skip_space_or_newline(indent : Int32, last : Bool = false, at_least_one : Bool = false, next_comes_end : Bool = false)
#
Description copied from class Reference
Appends a short String representation of this object which includes its class name and its object address.
class Person
def initialize(@name : String, @age : Int32)
end
end
Person.new("John", 32).to_s # => #<Person:0x10a199f20>
def visit_string_interpolation(node, token : Crystal::Token, line, column, old_indent, old_string_continuation : Int32, wrote_token = false)
#
def visit_string_interpolation_body(node, delimiter_state, column, *, is_regex = false, is_heredoc = false)
#