class
Crystal::Parser
Defined in:
compiler/crystal/syntax/parser.crConstant Summary
-
AtomicWithMethodCheck =
[:IDENT, :CONST, :OP_PLUS, :OP_MINUS, :OP_STAR, :OP_SLASH, :OP_SLASH_SLASH, :OP_PERCENT, :OP_BAR, :OP_AMP, :OP_CARET, :OP_TILDE, :OP_BANG, :OP_STAR_STAR, :OP_LT_LT, :OP_LT, :OP_LT_EQ, :OP_EQ_EQ, :OP_BANG_EQ, :OP_EQ_TILDE, :OP_BANG_TILDE, :OP_GT_GT, :OP_GT, :OP_GT_EQ, :OP_LT_EQ_GT, :OP_EQ_EQ_EQ, :OP_LSQUARE_RSQUARE, :OP_LSQUARE_RSQUARE_EQ, :OP_LSQUARE_RSQUARE_QUESTION, :OP_LSQUARE, :OP_AMP_PLUS, :OP_AMP_MINUS, :OP_AMP_STAR, :OP_AMP_STAR_STAR] of Token::Kind -
IDENT CONST + - * / // % | & ^ ~ ! ** << < <= == != =~ !~ >> > >= <=> === [] []= []? [ &+ &- &* &**
-
ConstOrDoubleColon =
[:CONST, :OP_COLON_COLON] of Token::Kind -
DefOrMacroCheck1 =
[:IDENT, :CONST, :OP_GRAVE, :OP_LT_LT, :OP_LT, :OP_LT_EQ, :OP_EQ_EQ, :OP_EQ_EQ_EQ, :OP_BANG_EQ, :OP_EQ_TILDE, :OP_BANG_TILDE, :OP_GT_GT, :OP_GT, :OP_GT_EQ, :OP_PLUS, :OP_MINUS, :OP_STAR, :OP_SLASH, :OP_SLASH_SLASH, :OP_BANG, :OP_TILDE, :OP_PERCENT, :OP_AMP, :OP_BAR, :OP_CARET, :OP_STAR_STAR, :OP_LSQUARE_RSQUARE, :OP_LSQUARE_RSQUARE_EQ, :OP_LSQUARE_RSQUARE_QUESTION, :OP_LT_EQ_GT, :OP_AMP_PLUS, :OP_AMP_MINUS, :OP_AMP_STAR, :OP_AMP_STAR_STAR] of Token::Kind -
IDENT CONST ` << < <= == === != =~ !~ >> > >= + - * / // ! ~ % & | ^ ** [] []? []= <=> &+ &- &* &**
-
DefOrMacroCheck2 =
[:OP_LT_LT, :OP_LT, :OP_LT_EQ, :OP_EQ_EQ, :OP_EQ_EQ_EQ, :OP_BANG_EQ, :OP_EQ_TILDE, :OP_BANG_TILDE, :OP_GT_GT, :OP_GT, :OP_GT_EQ, :OP_PLUS, :OP_MINUS, :OP_STAR, :OP_SLASH, :OP_SLASH_SLASH, :OP_BANG, :OP_TILDE, :OP_PERCENT, :OP_AMP, :OP_BAR, :OP_CARET, :OP_STAR_STAR, :OP_LSQUARE_RSQUARE, :OP_LSQUARE_RSQUARE_EQ, :OP_LSQUARE_RSQUARE_QUESTION, :OP_LT_EQ_GT, :OP_AMP_PLUS, :OP_AMP_MINUS, :OP_AMP_STAR, :OP_AMP_STAR_STAR] of Token::Kind -
<< < <= == === != =~ !~ >> > >= + - * / // ! ~ % & | ^ ** [] []? []= <=> &+ &- &* &**
-
IdentOrConst =
[:IDENT, :CONST] of Token::Kind -
SemicolonOrNewLine =
[:OP_SEMICOLON, :NEWLINE] of Token::Kind -
StatementEnd =
[:OP_SEMICOLON, :NEWLINE, :SPACE] of Token::Kind
Constructors
Class Method Summary
Macro Summary
Instance Method Summary
-
#add_when_exp(when_exps, exp)
Adds an expression to all when expressions and error on duplicates
- #call_block_arg_follows?
- #can_be_assigned?(node)
- #check(token_types : Array(Token::Kind))
- #check(token_type : Token::Kind)
- #check_const
- #check_ident(value : Keyword)
- #check_ident
- #check_macro_expression_end
- #check_macro_skip_whitespace
- #check_not_inside_def(message, &)
- #check_not_pipe_before_proc_literal_body
- #check_type_declaration(&)
- #check_valid_def_name
- #check_valid_def_op_name
- #check_valid_exhaustive_expression(exp)
- #check_valid_param_name(token : Token = @token)
- #check_void_expression_keyword
- #check_void_value(exp, location)
- #compute_block_arg_yields(block_arg)
- #consume_def_equals_sign
- #consume_def_equals_sign_skip_space
- #consume_def_or_macro_name
- #consume_delimiter(pieces, delimiter_state)
- #consume_heredoc(delimiter_state, node)
- #consume_heredocs
- #consume_interpolation(delimiter_state)
- #consume_regex_options
- #def_nest : Int32
- #def_nest=(def_nest : Int32)
- #delimiter_or_type_suffix?
- #end_token?
- #fun_nest : Int32
- #fun_nest=(fun_nest : Int32)
- #inside_def?
- #inside_fun?
- #invalid_internal_name?(keyword)
- #make_named_tuple_type(named_args)
- #make_nilable_expression(type)
- #make_nilable_type(type)
- #make_pointer_type(type)
- #make_static_array_type(type, size)
- #make_tuple_type(types)
- #multi_assign_left_hand(exp)
- #multi_assign_middle?(exp)
- #multi_assign_target?(exp)
- #named_tuple_start?
- #needs_heredoc_indent_removed?(delimiter_state)
- #new_hash_literal(entries, line, column, end_location, allow_of = true)
- #new_node_check_type_declaration(klass)
- #new_range(exp, location, exclusive)
- #next_comes_colon_space?
- #next_comes_plus_or_minus?
- #next_token
- #node_and_next_token(node)
- #open(symbol, location = @token.location, &)
- #parse(mode : ParseMode)
- #parse
- #parse_add_or_sub
- #parse_alias
- #parse_alignof
- #parse_and
- #parse_annotation
- #parse_annotation_def
- #parse_array_literal
- #parse_as(atomic, klass = Cast)
- #parse_as?(atomic)
- #parse_asm
- #parse_asm_clobbers
- #parse_asm_operand
- #parse_asm_operands
- #parse_asm_options
- #parse_atomic
- #parse_atomic_method_suffix(atomic, location)
- #parse_atomic_method_suffix_special(call, location)
- #parse_atomic_type
- #parse_atomic_type_with_suffix
- #parse_atomic_with_method
- #parse_atomic_without_location
-
#parse_bare_proc_type
Parse a bare proc type like
A, B, C -> D. - #parse_begin
- #parse_block(block, stop_on_do = false)
- #parse_block2(&)
- #parse_block_param(found_splat, all_names : Array(String))
- #parse_block_params(location)
- #parse_break
- #parse_c_struct_or_union(union : Bool)
- #parse_c_struct_or_union_body
- #parse_c_struct_or_union_fields(exps)
- #parse_call_arg(found_double_splat = false)
- #parse_call_args(stop_on_do_after_space = false, allow_curly = false, control = false)
- #parse_call_args_named_args(location, args, first_name, allow_newline)
- #parse_call_args_space_consumed(check_plus_and_minus = true, allow_curly = false, control = false, end_token : Token::Kind = :OP_RPAREN, allow_beginless_range = false)
- #parse_call_block_arg(args, check_paren, named_args = nil)
- #parse_call_block_arg_after_dot(obj)
- #parse_case
- #parse_class_def(is_abstract = false, is_struct = false, doc = nil)
- #parse_cmp
- #parse_control_expression(klass)
- #parse_curly_block(block)
- #parse_custom_literal(type)
- #parse_def(is_abstract = false, is_macro_def = false, doc = nil)
- #parse_def_block_param(extra_assigns, annotations : Array(Annotation) | Nil)
- #parse_def_free_vars
- #parse_def_helper(is_abstract = false)
- #parse_delimiter(want_skip_space = true)
- #parse_empty_array_literal
- #parse_enum_body
- #parse_enum_def
- #parse_equality
- #parse_exception_handler(exp, implicit = false, begin_location = nil)
- #parse_expression
- #parse_expression_inside_macro
- #parse_expression_suffix(atomic, location)
- #parse_expression_suffix(location, &)
- #parse_expressions
- #parse_expressions_internal
- #parse_extend
- #parse_fun_def(top_level, require_body = false)
- #parse_fun_literal
- #parse_fun_literal_param
- #parse_fun_pointer
- #parse_generic(global, location, expression)
-
#parse_generic(expression = false)
Parse generic type path like
A::B(C, D)?. - #parse_generic_or_custom_literal
- #parse_generic_or_global_call
- #parse_hash_literal(first_key, location, allow_of)
- #parse_hash_or_tuple_literal(allow_of = true)
- #parse_if(check_end = true)
- #parse_if_after_condition(cond, location, check_end)
- #parse_include
- #parse_include_or_extend(klass)
- #parse_instance_alignof
- #parse_instance_sizeof
- #parse_is_a(atomic)
- #parse_lib
- #parse_lib_body
- #parse_lib_body_exp
- #parse_lib_body_exp_without_location
- #parse_logical_and
- #parse_logical_or
- #parse_macro
- #parse_macro_body(start_location, macro_state = Token::MacroState.default)
- #parse_macro_control(start_location, macro_state = Token::MacroState.default)
- #parse_macro_expression
- #parse_macro_if(start_location, macro_state, check_end = true, is_unless = false)
- #parse_macro_var_exps
- #parse_module_def
- #parse_mul_or_div
- #parse_multi_assign
- #parse_named_args(location, first_name = nil, allow_newline = false)
- #parse_named_tuple(location, first_key)
- #parse_named_tuple(location)
- #parse_named_type_args(end_token : Token::Kind)
- #parse_negation_suffix(atomic)
- #parse_next
- #parse_nil?(atomic)
- #parse_offsetof
- #parse_op_assign(allow_ops = true, allow_suffix = true)
- #parse_op_assign_no_control(allow_ops = true, allow_suffix = true)
- #parse_or
- #parse_out
- #parse_param(params, extra_assigns, parentheses, found_default_value, found_splat, found_double_splat, allow_restrictions)
- #parse_param_name(location, extra_assigns, allow_external_name)
- #parse_parenthesized_expression
- #parse_path(global, location)
-
#parse_path
Parse type path.
- #parse_percent_array_element(&)
- #parse_percent_macro_control
- #parse_percent_macro_expression
- #parse_pointerof
- #parse_pow
- #parse_prefix
- #parse_proc_type_output(input_types, location)
- #parse_question_colon
- #parse_range
- #parse_read_instance_var(atomic)
- #parse_require
- #parse_rescue
- #parse_rescue_types
- #parse_responds_to(atomic)
- #parse_responds_to_name
- #parse_return
- #parse_select
- #parse_shift
- #parse_single_arg
- #parse_sizeof(klass)
- #parse_sizeof
- #parse_string_array
- #parse_string_literal_without_interpolation(context, want_skip_space = true)
- #parse_string_or_symbol_array_strings(&)
- #parse_string_without_interpolation(context, want_skip_space = true)
- #parse_symbol_array
- #parse_to_def(a_def)
- #parse_tuple(first_exp, location)
- #parse_type_arg
- #parse_type_args(name)
- #parse_type_declaration(var)
- #parse_type_def
- #parse_type_splat(&)
- #parse_type_suffix(type)
- #parse_type_vars
- #parse_typeof
- #parse_union_type
- #parse_union_types(end_token : Token::Kind, *, allow_splats = false)
- #parse_unless
- #parse_unless_after_condition(cond, location)
- #parse_until
- #parse_var_or_call(global = false, force_call = false, location = @token.location)
- #parse_visibility_modifier(modifier)
- #parse_when_expression(cond, single, exhaustive)
- #parse_while
- #parse_while_or_until(klass)
- #parse_yield(scope = nil, location = @token.location)
- #parse_yield_with_scope
- #prepare_parse_def
- #preserve_stop_on_do(new_value : Bool = false, &)
- #push_block_vars(node)
- #push_var(var : Var | Arg)
- #push_var(var : TypeDeclaration)
- #push_var(node)
- #push_var_name(name)
- #push_vars(vars)
- #push_visibility(&)
- #remove_heredoc_from_line(line, indent, line_number)
- #remove_heredoc_indent(pieces : Array, indent)
- #set_visibility(node)
- #string_literal_start?
- #temp_arg_name
- #type_nest : Int32
- #type_nest=(type_nest : Int32)
- #type_path_start?
- #type_start?
-
#type_start?(*, consume_newlines)
Looks ahead next tokens to check whether they indicate type.
- #unexpected_token(msg : String | Nil = nil, token : Token = @token)
- #unexpected_token_in_atomic
- #valid_select_when?(node)
- #var?(name)
- #var_in_scope?(name)
- #visibility : Visibility | Nil
- #visibility=(visibility : Visibility | Nil)
- #wants_doc=(wants_doc : Bool)
- #wants_doc? : Bool
-
#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.
- #when_expression_end
-
#with_isolated_var_scope(create_scope = true, &)
If create_scope is true, creates an isolated variable scope and returns the yield result, resetting the scope afterwards.
-
#with_lexical_var_scope(&)
Creates a new variable scope with the same variables as the current scope, and then returns the yield result, resetting the scope afterwards.
Instance methods inherited from class Crystal::Lexer
check_heredoc_end(delimiter_state)
check_heredoc_end,
check_heredoc_start
check_heredoc_start,
check_ident_or_keyword(keyword : Keyword, start)
check_ident_or_keyword,
closing_char(char = current_char)
closing_char,
column_number : Int32
column_number,
column_number=(column_number : Int32)
column_number=,
comments_enabled=(comments_enabled : Bool)
comments_enabled=,
comments_enabled? : Bool
comments_enabled?,
consume_braced_unicode_escape(allow_spaces = false)
consume_braced_unicode_escape,
consume_char_unicode_escape
consume_char_unicode_escape,
consume_comment(start_pos)
consume_comment,
consume_doc
consume_doc,
consume_loc_pragma
consume_loc_pragma,
consume_newlines
consume_newlines,
consume_non_braced_unicode_escape
consume_non_braced_unicode_escape,
consume_octal_escape(char)
consume_octal_escape,
consume_string_hex_escape
consume_string_hex_escape,
consume_string_unicode_brace_escape
consume_string_unicode_brace_escape,
consume_string_unicode_escape
consume_string_unicode_escape,
consume_whitespace
consume_whitespace,
count_whitespace=(count_whitespace : Bool)
count_whitespace=,
count_whitespace? : Bool
count_whitespace?,
current_char
current_char,
current_pos
current_pos,
current_pos=(pos)
current_pos=,
delimited_pair(kind : Token::DelimiterKind, string_nest, string_end, start, allow_escapes = true)
delimited_pair,
delimiter_state_for_percent_literal
delimiter_state_for_percent_literal,
doc_enabled=(doc_enabled : Bool)
doc_enabled=,
doc_enabled? : Bool
doc_enabled?,
expected_hexadecimal_character_in_unicode_escape
expected_hexadecimal_character_in_unicode_escape,
filename=(filename : Crystal::VirtualFile | String | Nil)
filename=,
handle_slash_r_slash_n_or_slash_n
handle_slash_r_slash_n_or_slash_n,
heredocs : Array({Crystal::Token::DelimiterState, Crystal::Lexer::HeredocItem})
heredocs,
ident_part_or_end?(char)
ident_part_or_end?,
incr_column_number(d = 1)
incr_column_number,
incr_line_number(column_number = 1)
incr_line_number,
line_number : Int32
line_number,
line_number=(line_number : Int32)
line_number=,
lookahead(preserve_token_on_fail = false, &)
lookahead,
macro_expansion_pragmas : Hash(Int32, Array(LocPragma)) | Nil
macro_expansion_pragmas,
macro_expansion_pragmas=(macro_expansion_pragmas : Hash(Int32, Array(LocPragma)) | Nil)
macro_expansion_pragmas=,
macro_starts_with_keyword?(beginning_of_line) : MacroKeywordState | Nil
macro_starts_with_keyword?,
next_char(token_type : Token::Kind)next_char next_char, next_char_and_symbol(value) next_char_and_symbol, next_char_check_line next_char_check_line, next_char_no_column_increment next_char_no_column_increment, next_macro_token(macro_state, skip_whitespace) next_macro_token, next_string_array_token_noescape(delimiter_state) next_string_array_token_noescape, next_string_token(delimiter_state) next_string_token, next_string_token_noescape(delimiter_state) next_string_token_noescape, next_token next_token, next_token_never_a_symbol next_token_never_a_symbol, next_token_skip_space next_token_skip_space, next_token_skip_space_or_newline next_token_skip_space_or_newline, next_token_skip_statement_end next_token_skip_statement_end, peek_ahead(&) peek_ahead, peek_next_char peek_next_char, peek_not_ident_part_or_end_next_char peek_not_ident_part_or_end_next_char, pop_location pop_location, push_location push_location, raise(message, token : Token, size = nil)
raise(message, location : Location)
raise(message, line_number = @line_number, column_number = @column_number, filename = @filename) raise, raise_unterminated_quoted(delimiter_state) raise_unterminated_quoted, raise_value_doesnt_fit_in(type, start, pos_before_suffix, alternative)
raise_value_doesnt_fit_in(type, start, pos_before_suffix) raise_value_doesnt_fit_in, reader : Char::Reader reader, reset_token reset_token, scan_ident(start) scan_ident, set_location(filename : Crystal::VirtualFile | String | Nil, line_number : Int32, column_number : Int32) set_location, set_token_raw_from_start(start) set_token_raw_from_start, skip_comment skip_comment, skip_macro_whitespace skip_macro_whitespace, skip_space skip_space, skip_space_or_newline skip_space_or_newline, skip_statement_end skip_statement_end, slash_is_not_regex! slash_is_not_regex!, slash_is_regex! slash_is_regex!, slash_is_regex=(slash_is_regex : Bool) slash_is_regex=, slash_is_regex? : Bool slash_is_regex?, slice_range(start_pos, end_pos)
slice_range(start_pos) slice_range, string string, string_range(start_pos, end_pos)
string_range(start_pos) string_range, string_range_from_pool(start_pos, end_pos)
string_range_from_pool(start_pos) string_range_from_pool, string_token_escape_value(value) string_token_escape_value, symbol(value) symbol, token : Token token, token_end_location token_end_location, unknown_token unknown_token, wants_def_or_macro_name(&) wants_def_or_macro_name, wants_def_or_macro_name=(wants_def_or_macro_name : Bool) wants_def_or_macro_name=, wants_def_or_macro_name? : Bool wants_def_or_macro_name?, wants_raw=(wants_raw : Bool) wants_raw=, wants_raw? : Bool wants_raw?, wants_symbol : Bool wants_symbol, wants_symbol=(wants_symbol : Bool) wants_symbol=, warn_large_uint64_literal(start, pos_before_suffix) warn_large_uint64_literal, warnings : WarningCollection warnings, warnings=(warnings : WarningCollection) warnings=
Constructor methods inherited from class Crystal::Lexer
new(string, string_pool : StringPool | Nil = nil, warnings : WarningCollection | Nil = nil)
new
Class methods inherited from class Crystal::Lexer
escape_forbidden_characters(string)
escape_forbidden_characters,
ident?(name)
ident?,
ident_part?(char)
ident_part?,
ident_start?(char)
ident_start?,
setter?(name)
setter?
Macros inherited from class Crystal::Lexer
gen_check_int_fits_in_size(type, method, size, number_size, raw_number_string, start, pos_before_suffix, negative)
gen_check_int_fits_in_size
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
Macro Detail
Instance Method Detail
Adds an expression to all when expressions and error on duplicates
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)
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.
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.
If create_scope is true, creates an isolated variable scope and returns the yield result, resetting the scope afterwards. Otherwise simply returns the yield result without touching the scopes.
Creates a new variable scope with the same variables as the current scope, and then returns the yield result, resetting the scope afterwards.