Skip to content

class Crystal::Parser
inherits Crystal::Lexer

Constants

AtomicWithMethodCheck = [:IDENT, :CONST, :+, :-, :*, :/, ://, :%, :|, :&, :^, :~, :!, :**, :<<, :<, :<=, :==, :!=, :=~, :!~, :>>, :>, :>=, :<=>, :===, :[], :[]=, :[]?, :"[", :&+, :&-, :&*, :&**]

ConstOrDoubleColon = [:CONST, :"::"]

DefOrMacroCheck1 = [:IDENT, :CONST, :"`", :<<, :<, :<=, :==, :===, :!=, :=~, :!~, :>>, :>, :>=, :+, :-, :*, :/, ://, :!, :~, :%, :&, :|, :^, :**, :[], :[]?, :[]=, :<=>, :&+, :&-, :&*, :&**]

DefOrMacroCheck2 = [:<<, :<, :<=, :==, :===, :!=, :=~, :!~, :>>, :>, :>=, :+, :-, :*, :/, ://, :!, :~, :%, :&, :|, :^, :**, :[], :[]?, :[]=, :<=>, :&+, :&-, :&*, :&**]

IdentOrConst = [:IDENT, :CONST]

SemicolonOrNewLine = [:";", :NEWLINE]

Class methods

.parse(str, string_pool : StringPool? = nil, def_vars = [Set(String).new]) : ASTNode

View source

.new(str, string_pool : StringPool? = nil, def_vars = [Set(String).new])

View source

Methods

#add_when_exp(when_exps, exp)

Adds an expression to all when expressions and error on duplicates

View source

#call_block_arg_follows?

View source

#can_be_assigned?(node)

View source

#check(token_types : Array)

View source

#check(token_type)

View source

#check_const

View source

#check_ident

View source

#check_ident(value)

View source

#check_macro_expression_end

View source

#check_macro_skip_whitespace

View source

#check_not_inside_def

View source

#check_not_pipe_before_proc_literal_body

View source

#check_token(value)

View source

#check_type_declaration

View source

#check_valid_def_name

View source

#check_valid_def_op_name

View source

#check_valid_exhaustive_expression(exp)

View source

#check_void_expression_keyword

View source

#check_void_value(exp, location)

View source

#compute_block_arg_yields(block_arg)

View source

#consume_def_or_macro_name

View source

#consume_delimiter(pieces, delimiter_state, has_interpolation)

View source

#consume_heredoc(delimiter_state, node)

View source

#consume_heredocs

View source

#consume_regex_options

View source

#def_nest : Int32

View source

#def_nest=(def_nest : Int32)

View source

#delimiter_or_type_suffix?

View source

#end_token?

View source

#fun_nest : Int32

View source

#fun_nest=(fun_nest : Int32)

View source

#inside_def?

View source

#inside_fun?

View source

#invalid_internal_name?(keyword)

View source

#make_named_tuple_type(named_args)

View source

#make_nilable_expression(type)

View source

#make_nilable_type(type)

View source

#make_pointer_type(type)

View source

#make_static_array_type(type, size)

View source

#make_tuple_type(types)

View source

#multi_assign_middle?(exp)

View source

#multi_assign_target?(exp)

View source

#multiassign_left_hand(exp)

View source

#named_tuple_start?

View source

#needs_heredoc_indent_removed?(delimiter_state)

View source

#new_hash_literal(entries, line, column, end_location, allow_of = true)

View source

#new_node_check_type_declaration

View source

#new_node_check_type_declaration(klass)

View source

#new_range(exp, location, exclusive)

View source

#next_comes_colon_space?

View source

#next_comes_plus_or_minus?

View source

#next_token

View source

#node_and_next_token(node)

View source

#open

View source

#parse

View source

#parse(mode : ParseMode)

View source

#parse_add_or_sub

View source

#parse_alias

View source

#parse_and

View source

#parse_annotation

View source

#parse_annotation_def

View source

#parse_arg(args, extra_assigns, parentheses, found_default_value, found_splat, found_double_splat, allow_restrictions)

View source

#parse_arg_name(location, extra_assigns, allow_external_name)

View source

#parse_array_literal

View source

#parse_as(atomic, klass = Cast)

View source

#parse_as?(atomic)

View source

#parse_asm

View source

#parse_asm_clobbers

View source

#parse_asm_operand

View source

#parse_asm_operands

View source

#parse_asm_options

View source

#parse_atomic

View source

#parse_atomic_method_suffix(atomic, location)

View source

#parse_atomic_method_suffix_special(call, location)

View source

#parse_atomic_type

View source

#parse_atomic_type_with_suffix

View source

#parse_atomic_with_method

View source

#parse_atomic_without_location

View source

#parse_bare_proc_type

Parse a bare proc type like A, B, C -> D. Generally it is entry point of type parsing and it is used on the context expected type (e.g. type restrictions, rhs of alias and more)

View source

#parse_begin

View source

#parse_block(block, stop_on_do = false)

View source

#parse_block2

View source

#parse_block_arg(extra_assigns)

View source

#parse_break

View source

#parse_c_struct_or_union(union : Bool)

View source

#parse_c_struct_or_union_body

View source

#parse_c_struct_or_union_fields(exps)

View source

#parse_call_arg(found_double_splat = false)

View source

#parse_call_args(stop_on_do_after_space = false, allow_curly = false, control = false)

View source

#parse_call_args_named_args(location, args, first_name, allow_newline)

View source

#parse_call_args_space_consumed(check_plus_and_minus = true, allow_curly = false, control = false, end_token = :")", allow_beginless_range = false)

View source

#parse_call_block_arg(args, check_paren, named_args = nil)

View source

#parse_call_block_arg_after_dot(obj)

View source

#parse_case

View source

#parse_class_def(is_abstract = false, is_struct = false, doc = nil)

View source

#parse_cmp

View source

#parse_control_expression(klass)

View source

#parse_curly_block(block)

View source

#parse_custom_literal(type)

View source

#parse_def(is_abstract = false, is_macro_def = false, doc = nil)

View source

#parse_def_free_vars

View source

#parse_def_helper(is_abstract = false)

View source

#parse_delimiter(want_skip_space = true)

View source

#parse_empty_array_literal

View source

#parse_enum_body

View source

#parse_enum_def

View source

#parse_equality

View source

#parse_exception_handler(exp, implicit = false)

View source

#parse_expression

View source

#parse_expression_inside_macro

View source

#parse_expression_suffix

View source

#parse_expression_suffix(atomic, location)

View source

#parse_expressions

View source

#parse_expressions_internal

View source

#parse_extend

View source

#parse_fun_def(top_level, require_body = false)

View source

#parse_fun_literal

View source

#parse_fun_literal_arg

View source

#parse_fun_pointer

View source

#parse_generic(expression = false)

Parse generic type path like A::B(C, D)?. This method is used to parse not only a type, but also an expression represents type. And it also consumes prefix :: to specify global path.

View source

#parse_generic(global, location, expression)

View source

#parse_generic_or_custom_literal

View source

#parse_generic_or_global_call

View source

#parse_hash_literal(first_key, location, allow_of)

View source

#parse_hash_or_tuple_literal(allow_of = true)

View source

#parse_if(check_end = true)

View source

#parse_if_after_condition(cond, location, check_end)

View source

#parse_include

View source

#parse_include_or_extend(klass)

View source

#parse_instance_sizeof

View source

#parse_is_a(atomic)

View source

#parse_lib

View source

#parse_lib_body

View source

#parse_lib_body_exp

View source

#parse_lib_body_exp_without_location

View source

#parse_logical_and

View source

#parse_logical_or

View source

#parse_macro

View source

#parse_macro_body(start_location, macro_state = Token::MacroState.default)

View source

#parse_macro_control(start_location, macro_state = Token::MacroState.default)

View source

#parse_macro_expression

View source

#parse_macro_if(start_location, macro_state, check_end = true, is_unless = false)

View source

#parse_macro_var_exps

View source

#parse_module_def

View source

#parse_mul_or_div

View source

#parse_multi_assign

View source

#parse_named_args(location, first_name = nil, allow_newline = false)

View source

#parse_named_tuple(location, first_key)

View source

#parse_named_tuple(location)

View source

#parse_named_type_args(end_token)

View source

#parse_negation_suffix(atomic)

View source

#parse_next

View source

#parse_nil?(atomic)

View source

#parse_offsetof

View source

#parse_op_assign(allow_ops = true, allow_suffix = true)

View source

#parse_op_assign_no_control(allow_ops = true, allow_suffix = true)

View source

#parse_or

View source

#parse_out

View source

#parse_parenthesized_expression

View source

#parse_path

Parse type path. It also consumes prefix :: to specify global path.

View source

#parse_path(global, location)

View source

#parse_percent_macro_control

View source

#parse_percent_macro_expression

View source

#parse_pointerof

View source

#parse_pow

View source

#parse_prefix

View source

#parse_proc_type_output(input_types, location)

View source

#parse_question_colon

View source

#parse_range

View source

#parse_require

View source

#parse_rescue

View source

#parse_rescue_types

View source

#parse_responds_to(atomic)

View source

#parse_responds_to_name

View source

#parse_return

View source

#parse_select

View source

#parse_shift

View source

#parse_single_arg

View source

#parse_sizeof(klass)

View source

#parse_sizeof

View source

#parse_string_array

View source

#parse_string_or_symbol_array(klass, elements_type)

View source

#parse_string_without_interpolation(context, want_skip_space = true)

View source

#parse_symbol_array

View source

#parse_to_def(a_def)

View source

#parse_tuple(first_exp, location)

View source

#parse_type_arg

View source

#parse_type_args(name)

View source

#parse_type_declaration(var)

View source

#parse_type_def

View source

#parse_type_splat

View source

#parse_type_suffix(type)

View source

#parse_type_vars

View source

#parse_typeof

View source

#parse_union_type

View source

#parse_union_types(end_token, *, allow_splats = false)

View source

#parse_unless

View source

#parse_unless_after_condition(cond, location)

View source

#parse_until

View source

#parse_var_or_call(global = false, force_call = false)

View source

#parse_visibility_modifier(modifier)

View source

#parse_when_expression(cond, single, exhaustive)

View source

#parse_while

View source

#parse_while_or_until(klass)

View source

#parse_yield(scope = nil, location = @token.location)

View source

#parse_yield_with_scope

View source

#pop_def

View source

#prepare_parse_def

View source

#preserve_stop_on_do(new_value = false

View source

#push_def(set)

View source

#push_def

View source

#push_def

View source

#push_var(var : Var | Arg)

View source

#push_var(var : TypeDeclaration)

View source

#push_var(node)

View source

#push_var_name(name)

View source

#push_vars(vars)

View source

#push_visibility

View source

#remove_heredoc_from_line(line, indent, line_number)

View source

#remove_heredoc_indent(pieces : Array, indent)

View source

#set_visibility(node)

View source

#string_literal_start?

View source

#temp_arg_name

View source

#type_nest : Int32

View source

#type_nest=(type_nest : Int32)

View source

#type_path_start?

View source

#type_start?(*, consume_newlines)

Looks ahead next tokens to check whether they indicate type.

View source

#type_start?

View source

#unexpected_token(token = @token.to_s, msg = nil)

View source

#unexpected_token_in_atomic

View source

#valid_select_when?(node)

View source

#var?(name)

View source

#visibility : Visibility?

View source

#visibility=(visibility : Visibility?)

View source

#wants_doc=(wants_doc)

View source

#wants_doc? : Bool

View source

#when_exp_constant?(exp)

Only error on constant values, because calls might have side-effects: a first call might return one value and not match the case value, but the second same call returns something different and matches it.

View source

#when_expression_end

View source

Macros

parse_operator(name, next_operator, node, operators, right_associative = false)

View source