Ruby: prism/parser.h Source File

Ruby 4.0.6p0 (2026-07-14 revision 03b6d3f8898a28604fe6cb00eae3226b821168f4)

parser.h
Go to the documentation of this file.
1
6#ifndef PRISM_PARSER_H
7#define PRISM_PARSER_H
8
9#include "prism/defines.h"
10#include "prism/ast.h"
11#include "prism/encoding.h"
12#include "prism/options.h"
13#include "prism/static_literals.h"
14#include "prism/util/pm_constant_pool.h"
15#include "prism/util/pm_list.h"
16#include "prism/util/pm_newline_list.h"
17#include "prism/util/pm_string.h"
18
19#include <stdbool.h>
20
26 typedef enum {
27 PM_LEX_STATE_BIT_BEG,
28 PM_LEX_STATE_BIT_END,
29 PM_LEX_STATE_BIT_ENDARG,
30 PM_LEX_STATE_BIT_ENDFN,
31 PM_LEX_STATE_BIT_ARG,
32 PM_LEX_STATE_BIT_CMDARG,
33 PM_LEX_STATE_BIT_MID,
34 PM_LEX_STATE_BIT_FNAME,
35 PM_LEX_STATE_BIT_DOT,
36 PM_LEX_STATE_BIT_CLASS,
37 PM_LEX_STATE_BIT_LABEL,
38 PM_LEX_STATE_BIT_LABELED,
39 PM_LEX_STATE_BIT_FITEM
40} pm_lex_state_bit_t;
41
46 typedef enum {
47 PM_LEX_STATE_NONE = 0,
48 PM_LEX_STATE_BEG = (1 << PM_LEX_STATE_BIT_BEG),
49 PM_LEX_STATE_END = (1 << PM_LEX_STATE_BIT_END),
50 PM_LEX_STATE_ENDARG = (1 << PM_LEX_STATE_BIT_ENDARG),
51 PM_LEX_STATE_ENDFN = (1 << PM_LEX_STATE_BIT_ENDFN),
52 PM_LEX_STATE_ARG = (1 << PM_LEX_STATE_BIT_ARG),
53 PM_LEX_STATE_CMDARG = (1 << PM_LEX_STATE_BIT_CMDARG),
54 PM_LEX_STATE_MID = (1 << PM_LEX_STATE_BIT_MID),
55 PM_LEX_STATE_FNAME = (1 << PM_LEX_STATE_BIT_FNAME),
56 PM_LEX_STATE_DOT = (1 << PM_LEX_STATE_BIT_DOT),
57 PM_LEX_STATE_CLASS = (1 << PM_LEX_STATE_BIT_CLASS),
58 PM_LEX_STATE_LABEL = (1 << PM_LEX_STATE_BIT_LABEL),
59 PM_LEX_STATE_LABELED = (1 << PM_LEX_STATE_BIT_LABELED),
60 PM_LEX_STATE_FITEM = (1 << PM_LEX_STATE_BIT_FITEM),
61 PM_LEX_STATE_BEG_ANY = PM_LEX_STATE_BEG | PM_LEX_STATE_MID | PM_LEX_STATE_CLASS,
62 PM_LEX_STATE_ARG_ANY = PM_LEX_STATE_ARG | PM_LEX_STATE_CMDARG,
63 PM_LEX_STATE_END_ANY = PM_LEX_STATE_END | PM_LEX_STATE_ENDARG | PM_LEX_STATE_ENDFN
64} pm_lex_state_t;
65
69 typedef enum {
70 PM_HEREDOC_QUOTE_NONE,
71 PM_HEREDOC_QUOTE_SINGLE = '\'',
72 PM_HEREDOC_QUOTE_DOUBLE = '"',
73 PM_HEREDOC_QUOTE_BACKTICK = '`',
74} pm_heredoc_quote_t;
75
79 typedef enum {
80 PM_HEREDOC_INDENT_NONE,
81 PM_HEREDOC_INDENT_DASH,
82 PM_HEREDOC_INDENT_TILDE,
83} pm_heredoc_indent_t;
84
88 typedef struct {
90 const uint8_t *ident_start;
91
93 size_t ident_length;
94
96 pm_heredoc_quote_t quote;
97
99 pm_heredoc_indent_t indent;
100} pm_heredoc_lex_mode_t;
101
109 typedef struct pm_lex_mode {
111 enum {
113 PM_LEX_DEFAULT,
114
119 PM_LEX_EMBEXPR,
120
125 PM_LEX_EMBVAR,
126
128 PM_LEX_HEREDOC,
129
134 PM_LEX_LIST,
135
140 PM_LEX_REGEXP,
141
146 PM_LEX_STRING
147 } mode;
148
150 union {
151 struct {
153 size_t nesting;
154
156 bool interpolation;
157
162 uint8_t incrementor;
163
165 uint8_t terminator;
166
171 uint8_t breakpoints[11];
172 } list;
173
174 struct {
178 size_t nesting;
179
184 uint8_t incrementor;
185
187 uint8_t terminator;
188
193 uint8_t breakpoints[7];
194 } regexp;
195
196 struct {
198 size_t nesting;
199
201 bool interpolation;
202
208 bool label_allowed;
209
214 uint8_t incrementor;
215
220 uint8_t terminator;
221
226 uint8_t breakpoints[7];
227 } string;
228
229 struct {
233 pm_heredoc_lex_mode_t base;
234
239 const uint8_t *next_start;
240
246 size_t *common_whitespace;
247
249 bool line_continuation;
250 } heredoc;
251 } as;
252
254 struct pm_lex_mode *prev;
255} pm_lex_mode_t;
256
262#define PM_LEX_STACK_SIZE 4
263
267 typedef struct pm_parser pm_parser_t;
268
274 typedef enum {
276 PM_CONTEXT_NONE = 0,
277
279 PM_CONTEXT_BEGIN,
280
282 PM_CONTEXT_BEGIN_ENSURE,
283
285 PM_CONTEXT_BEGIN_ELSE,
286
288 PM_CONTEXT_BEGIN_RESCUE,
289
291 PM_CONTEXT_BLOCK_BRACES,
292
294 PM_CONTEXT_BLOCK_KEYWORDS,
295
297 PM_CONTEXT_BLOCK_ENSURE,
298
300 PM_CONTEXT_BLOCK_ELSE,
301
303 PM_CONTEXT_BLOCK_PARAMETERS,
304
306 PM_CONTEXT_BLOCK_RESCUE,
307
309 PM_CONTEXT_CASE_WHEN,
310
312 PM_CONTEXT_CASE_IN,
313
315 PM_CONTEXT_CLASS,
316
318 PM_CONTEXT_CLASS_ENSURE,
319
321 PM_CONTEXT_CLASS_ELSE,
322
324 PM_CONTEXT_CLASS_RESCUE,
325
327 PM_CONTEXT_DEF,
328
330 PM_CONTEXT_DEF_ENSURE,
331
333 PM_CONTEXT_DEF_ELSE,
334
336 PM_CONTEXT_DEF_RESCUE,
337
339 PM_CONTEXT_DEF_PARAMS,
340
342 PM_CONTEXT_DEFINED,
343
345 PM_CONTEXT_DEFAULT_PARAMS,
346
348 PM_CONTEXT_ELSE,
349
351 PM_CONTEXT_ELSIF,
352
354 PM_CONTEXT_EMBEXPR,
355
357 PM_CONTEXT_FOR,
358
360 PM_CONTEXT_FOR_INDEX,
361
363 PM_CONTEXT_IF,
364
366 PM_CONTEXT_LAMBDA_BRACES,
367
369 PM_CONTEXT_LAMBDA_DO_END,
370
372 PM_CONTEXT_LAMBDA_ENSURE,
373
375 PM_CONTEXT_LAMBDA_ELSE,
376
378 PM_CONTEXT_LAMBDA_RESCUE,
379
381 PM_CONTEXT_LOOP_PREDICATE,
382
384 PM_CONTEXT_MAIN,
385
387 PM_CONTEXT_MODULE,
388
390 PM_CONTEXT_MODULE_ENSURE,
391
393 PM_CONTEXT_MODULE_ELSE,
394
396 PM_CONTEXT_MODULE_RESCUE,
397
399 PM_CONTEXT_MULTI_TARGET,
400
402 PM_CONTEXT_PARENS,
403
405 PM_CONTEXT_POSTEXE,
406
408 PM_CONTEXT_PREDICATE,
409
411 PM_CONTEXT_PREEXE,
412
414 PM_CONTEXT_RESCUE_MODIFIER,
415
417 PM_CONTEXT_SCLASS,
418
420 PM_CONTEXT_SCLASS_ENSURE,
421
423 PM_CONTEXT_SCLASS_ELSE,
424
426 PM_CONTEXT_SCLASS_RESCUE,
427
429 PM_CONTEXT_TERNARY,
430
432 PM_CONTEXT_UNLESS,
433
435 PM_CONTEXT_UNTIL,
436
438 PM_CONTEXT_WHILE,
439} pm_context_t;
440
442 typedef struct pm_context_node {
444 pm_context_t context;
445
447 struct pm_context_node *prev;
448} pm_context_node_t;
449
451 typedef enum {
452 PM_COMMENT_INLINE,
453 PM_COMMENT_EMBDOC
454} pm_comment_type_t;
455
461 typedef struct pm_comment {
463 pm_list_node_t node;
464
466 pm_location_t location;
467
469 pm_comment_type_t type;
470} pm_comment_t;
471
478 typedef struct {
480 pm_list_node_t node;
481
483 const uint8_t *key_start;
484
486 const uint8_t *value_start;
487
489 uint32_t key_length;
490
492 uint32_t value_length;
493} pm_magic_comment_t;
494
499 typedef void (*pm_encoding_changed_callback_t)(pm_parser_t *parser);
500
509 typedef struct {
515 void *data;
516
521 void (*callback)(void *data, pm_parser_t *parser, pm_token_t *token);
522} pm_lex_callback_t;
523
525 typedef uint8_t pm_shareable_constant_value_t;
526static const pm_shareable_constant_value_t PM_SCOPE_SHAREABLE_CONSTANT_NONE = 0x0;
527static const pm_shareable_constant_value_t PM_SCOPE_SHAREABLE_CONSTANT_LITERAL = PM_SHAREABLE_CONSTANT_NODE_FLAGS_LITERAL;
528static const pm_shareable_constant_value_t PM_SCOPE_SHAREABLE_CONSTANT_EXPERIMENTAL_EVERYTHING = PM_SHAREABLE_CONSTANT_NODE_FLAGS_EXPERIMENTAL_EVERYTHING;
529static const pm_shareable_constant_value_t PM_SCOPE_SHAREABLE_CONSTANT_EXPERIMENTAL_COPY = PM_SHAREABLE_CONSTANT_NODE_FLAGS_EXPERIMENTAL_COPY;
530
535 typedef struct {
537 pm_constant_id_t name;
538
540 pm_location_t location;
541
543 uint32_t index;
544
546 uint32_t reads;
547
549 uint32_t hash;
550} pm_local_t;
551
557 typedef struct pm_locals {
559 uint32_t size;
560
562 uint32_t capacity;
563
565 pm_local_t *locals;
566} pm_locals_t;
567
569 typedef uint8_t pm_scope_parameters_t;
570static const pm_scope_parameters_t PM_SCOPE_PARAMETERS_NONE = 0x0;
571static const pm_scope_parameters_t PM_SCOPE_PARAMETERS_FORWARDING_POSITIONALS = 0x1;
572static const pm_scope_parameters_t PM_SCOPE_PARAMETERS_FORWARDING_KEYWORDS = 0x2;
573static const pm_scope_parameters_t PM_SCOPE_PARAMETERS_FORWARDING_BLOCK = 0x4;
574static const pm_scope_parameters_t PM_SCOPE_PARAMETERS_FORWARDING_ALL = 0x8;
575static const pm_scope_parameters_t PM_SCOPE_PARAMETERS_IMPLICIT_DISALLOWED = 0x10;
576static const pm_scope_parameters_t PM_SCOPE_PARAMETERS_NUMBERED_INNER = 0x20;
577static const pm_scope_parameters_t PM_SCOPE_PARAMETERS_NUMBERED_FOUND = 0x40;
578
583 typedef struct pm_scope {
585 struct pm_scope *previous;
586
588 pm_locals_t locals;
589
596 pm_node_list_t implicit_parameters;
597
617 pm_scope_parameters_t parameters;
618
623 pm_shareable_constant_value_t shareable_constant;
624
629 bool closed;
630} pm_scope_t;
631
635 typedef uint32_t pm_state_stack_t;
636
643 struct pm_parser {
649 uint32_t node_id;
650
652 pm_lex_state_t lex_state;
653
655 int enclosure_nesting;
656
661 int lambda_enclosure_nesting;
662
667 int brace_nesting;
668
673 pm_state_stack_t do_loop_stack;
674
679 pm_state_stack_t accepts_block_stack;
680
682 struct {
684 pm_lex_mode_t *current;
685
687 pm_lex_mode_t stack[PM_LEX_STACK_SIZE];
688
690 size_t index;
691 } lex_modes;
692
694 const uint8_t *start;
695
697 const uint8_t *end;
698
700 pm_token_t previous;
701
703 pm_token_t current;
704
710 const uint8_t *next_start;
711
718 const uint8_t *heredoc_end;
719
721 pm_list_t comment_list;
722
724 pm_list_t magic_comment_list;
725
731 pm_location_t data_loc;
732
734 pm_list_t warning_list;
735
737 pm_list_t error_list;
738
740 pm_scope_t *current_scope;
741
743 pm_context_node_t *current_context;
744
752 pm_static_literals_t *current_hash_keys;
753
758 const pm_encoding_t *encoding;
759
765 pm_encoding_changed_callback_t encoding_changed_callback;
766
771 const uint8_t *encoding_comment_start;
772
777 pm_lex_callback_t *lex_callback;
778
783 pm_string_t filepath;
784
789 pm_constant_pool_t constant_pool;
790
792 pm_newline_list_t newline_list;
793
800 pm_node_flags_t integer_base;
801
806 pm_string_t current_string;
807
812 int32_t start_line;
813
843 const pm_encoding_t *explicit_encoding;
844
856 pm_node_list_t *current_block_exits;
857
859 pm_options_version_t version;
860
862 uint8_t command_line;
863
872 int8_t frozen_string_literal;
873
878 bool parsing_eval;
879
885 bool partial_script;
886
888 bool command_start;
889
891 bool recovering;
892
899 bool encoding_locked;
900
906 bool encoding_changed;
907
912 bool pattern_matching_newlines;
913
915 bool in_keyword_arg;
916
921 bool semantic_token_seen;
922
927 bool current_regular_expression_ascii_only;
928
933 bool warn_mismatched_indentation;
934};
935
936#endif
options.h
The options that can be passed to parsing.
pm_options_version_t
pm_options_version_t
The version of Ruby syntax that we should be parsing with.
Definition options.h:84
pm_locals_t
struct pm_locals pm_locals_t
This is a set of local variables in a certain lexical context (method, class, module,...
pm_heredoc_indent_t
pm_heredoc_indent_t
The type of indentation that a heredoc uses.
Definition parser.h:79
pm_context_node_t
struct pm_context_node pm_context_node_t
This is a node in a linked list of contexts.
pm_state_stack_t
uint32_t pm_state_stack_t
A struct that represents a stack of boolean values.
Definition parser.h:635
PM_LEX_STACK_SIZE
#define PM_LEX_STACK_SIZE
We pre-allocate a certain number of lex states in order to avoid having to call malloc too many times...
Definition parser.h:262
pm_parser_t
struct pm_parser pm_parser_t
The parser used to parse Ruby source.
Definition parser.h:267
pm_lex_mode_t
struct pm_lex_mode pm_lex_mode_t
When lexing Ruby source, the lexer has a small amount of state to tell which kind of token it is curr...
pm_comment_t
struct pm_comment pm_comment_t
This is a node in the linked list of comments that we've found while parsing.
pm_lex_state_bit_t
pm_lex_state_bit_t
This enum provides various bits that represent different kinds of states that the lexer can track.
Definition parser.h:26
pm_lex_state_t
pm_lex_state_t
This enum combines the various bits from the above enum into individual values that represent the var...
Definition parser.h:46
pm_scope_t
struct pm_scope pm_scope_t
This struct represents a node in a linked list of scopes.
pm_heredoc_quote_t
pm_heredoc_quote_t
The type of quote that a heredoc uses.
Definition parser.h:69
pm_encoding_changed_callback_t
void(* pm_encoding_changed_callback_t)(pm_parser_t *parser)
When the encoding that is being used to parse the source is changed by prism, we provide the ability ...
Definition parser.h:499
pm_context_t
pm_context_t
While parsing, we keep track of a stack of contexts.
Definition parser.h:274
PM_CONTEXT_CLASS_RESCUE
@ PM_CONTEXT_CLASS_RESCUE
a rescue statement within a class statement
Definition parser.h:324
PM_CONTEXT_ELSIF
@ PM_CONTEXT_ELSIF
an elsif clause
Definition parser.h:351
PM_CONTEXT_DEF_RESCUE
@ PM_CONTEXT_DEF_RESCUE
a rescue statement within a method definition
Definition parser.h:336
PM_CONTEXT_ELSE
@ PM_CONTEXT_ELSE
an else clause
Definition parser.h:348
PM_CONTEXT_FOR_INDEX
@ PM_CONTEXT_FOR_INDEX
a for loop's index
Definition parser.h:360
PM_CONTEXT_CASE_WHEN
@ PM_CONTEXT_CASE_WHEN
a case when statements
Definition parser.h:309
PM_CONTEXT_BLOCK_RESCUE
@ PM_CONTEXT_BLOCK_RESCUE
a rescue statement within a do..end block
Definition parser.h:306
PM_CONTEXT_MODULE
@ PM_CONTEXT_MODULE
a module declaration
Definition parser.h:387
PM_CONTEXT_DEF_PARAMS
@ PM_CONTEXT_DEF_PARAMS
a method definition's parameters
Definition parser.h:339
PM_CONTEXT_CASE_IN
@ PM_CONTEXT_CASE_IN
a case in statements
Definition parser.h:312
PM_CONTEXT_BLOCK_ELSE
@ PM_CONTEXT_BLOCK_ELSE
a rescue else statement within a do..end block
Definition parser.h:300
PM_CONTEXT_LOOP_PREDICATE
@ PM_CONTEXT_LOOP_PREDICATE
the predicate clause of a loop statement
Definition parser.h:381
PM_CONTEXT_SCLASS
@ PM_CONTEXT_SCLASS
a singleton class definition
Definition parser.h:417
PM_CONTEXT_UNLESS
@ PM_CONTEXT_UNLESS
an unless statement
Definition parser.h:432
PM_CONTEXT_POSTEXE
@ PM_CONTEXT_POSTEXE
an END block
Definition parser.h:405
PM_CONTEXT_IF
@ PM_CONTEXT_IF
an if statement
Definition parser.h:363
PM_CONTEXT_MULTI_TARGET
@ PM_CONTEXT_MULTI_TARGET
a multiple target expression
Definition parser.h:399
PM_CONTEXT_LAMBDA_RESCUE
@ PM_CONTEXT_LAMBDA_RESCUE
a rescue statement within a lambda expression
Definition parser.h:378
PM_CONTEXT_BEGIN_ELSE
@ PM_CONTEXT_BEGIN_ELSE
a rescue else statement with an explicit begin
Definition parser.h:285
PM_CONTEXT_NONE
@ PM_CONTEXT_NONE
a null context, used for returning a value from a function
Definition parser.h:276
PM_CONTEXT_CLASS_ELSE
@ PM_CONTEXT_CLASS_ELSE
a rescue else statement within a class statement
Definition parser.h:321
PM_CONTEXT_LAMBDA_ENSURE
@ PM_CONTEXT_LAMBDA_ENSURE
an ensure statement within a lambda expression
Definition parser.h:372
PM_CONTEXT_BLOCK_ENSURE
@ PM_CONTEXT_BLOCK_ENSURE
an ensure statement within a do..end block
Definition parser.h:297
PM_CONTEXT_CLASS_ENSURE
@ PM_CONTEXT_CLASS_ENSURE
an ensure statement within a class statement
Definition parser.h:318
PM_CONTEXT_LAMBDA_BRACES
@ PM_CONTEXT_LAMBDA_BRACES
a lambda expression with braces
Definition parser.h:366
PM_CONTEXT_MODULE_ELSE
@ PM_CONTEXT_MODULE_ELSE
a rescue else statement within a module statement
Definition parser.h:393
PM_CONTEXT_PARENS
@ PM_CONTEXT_PARENS
a parenthesized expression
Definition parser.h:402
PM_CONTEXT_BLOCK_BRACES
@ PM_CONTEXT_BLOCK_BRACES
expressions in block arguments using braces
Definition parser.h:291
PM_CONTEXT_BLOCK_PARAMETERS
@ PM_CONTEXT_BLOCK_PARAMETERS
expressions in block parameters foo do |...| end
Definition parser.h:303
PM_CONTEXT_DEF_ENSURE
@ PM_CONTEXT_DEF_ENSURE
an ensure statement within a method definition
Definition parser.h:330
PM_CONTEXT_SCLASS_RESCUE
@ PM_CONTEXT_SCLASS_RESCUE
a rescue statement with a singleton class
Definition parser.h:426
PM_CONTEXT_PREEXE
@ PM_CONTEXT_PREEXE
a BEGIN block
Definition parser.h:411
PM_CONTEXT_DEFINED
@ PM_CONTEXT_DEFINED
a defined?
Definition parser.h:342
PM_CONTEXT_MODULE_ENSURE
@ PM_CONTEXT_MODULE_ENSURE
an ensure statement within a module statement
Definition parser.h:390
PM_CONTEXT_BEGIN_RESCUE
@ PM_CONTEXT_BEGIN_RESCUE
a rescue statement with an explicit begin
Definition parser.h:288
PM_CONTEXT_UNTIL
@ PM_CONTEXT_UNTIL
an until statement
Definition parser.h:435
PM_CONTEXT_DEF_ELSE
@ PM_CONTEXT_DEF_ELSE
a rescue else statement within a method definition
Definition parser.h:333
PM_CONTEXT_FOR
@ PM_CONTEXT_FOR
a for loop
Definition parser.h:357
PM_CONTEXT_PREDICATE
@ PM_CONTEXT_PREDICATE
a predicate inside an if/elsif/unless statement
Definition parser.h:408
PM_CONTEXT_BEGIN_ENSURE
@ PM_CONTEXT_BEGIN_ENSURE
an ensure statement with an explicit begin
Definition parser.h:282
PM_CONTEXT_SCLASS_ENSURE
@ PM_CONTEXT_SCLASS_ENSURE
an ensure statement with a singleton class
Definition parser.h:420
PM_CONTEXT_DEFAULT_PARAMS
@ PM_CONTEXT_DEFAULT_PARAMS
a method definition's default parameter
Definition parser.h:345
PM_CONTEXT_LAMBDA_ELSE
@ PM_CONTEXT_LAMBDA_ELSE
a rescue else statement within a lambda expression
Definition parser.h:375
PM_CONTEXT_CLASS
@ PM_CONTEXT_CLASS
a class declaration
Definition parser.h:315
PM_CONTEXT_MAIN
@ PM_CONTEXT_MAIN
the top level context
Definition parser.h:384
PM_CONTEXT_LAMBDA_DO_END
@ PM_CONTEXT_LAMBDA_DO_END
a lambda expression with do..end
Definition parser.h:369
PM_CONTEXT_BEGIN
@ PM_CONTEXT_BEGIN
a begin statement
Definition parser.h:279
PM_CONTEXT_RESCUE_MODIFIER
@ PM_CONTEXT_RESCUE_MODIFIER
a modifier rescue clause
Definition parser.h:414
PM_CONTEXT_EMBEXPR
@ PM_CONTEXT_EMBEXPR
an interpolated expression
Definition parser.h:354
PM_CONTEXT_TERNARY
@ PM_CONTEXT_TERNARY
a ternary expression
Definition parser.h:429
PM_CONTEXT_DEF
@ PM_CONTEXT_DEF
a method definition
Definition parser.h:327
PM_CONTEXT_SCLASS_ELSE
@ PM_CONTEXT_SCLASS_ELSE
a rescue else statement with a singleton class
Definition parser.h:423
PM_CONTEXT_MODULE_RESCUE
@ PM_CONTEXT_MODULE_RESCUE
a rescue statement within a module statement
Definition parser.h:396
PM_CONTEXT_BLOCK_KEYWORDS
@ PM_CONTEXT_BLOCK_KEYWORDS
expressions in block arguments using do..end
Definition parser.h:294
PM_CONTEXT_WHILE
@ PM_CONTEXT_WHILE
a while statement
Definition parser.h:438
pm_scope_parameters_t
uint8_t pm_scope_parameters_t
The flags about scope parameters that can be set.
Definition parser.h:569
pm_shareable_constant_value_t
uint8_t pm_shareable_constant_value_t
The type of shareable constant value that can be set.
Definition parser.h:525
pm_comment_type_t
pm_comment_type_t
This is the type of a comment that we've found while parsing.
Definition parser.h:451
pm_constant_pool.h
A data structure that stores a set of strings.
pm_constant_id_t
uint32_t pm_constant_id_t
A constant id is a unique identifier for a constant in the constant pool.
Definition pm_constant_pool.h:31
pm_list.h
An abstract linked list.
pm_list_node_t
struct pm_list_node pm_list_node_t
This struct represents an abstract linked list that provides common functionality.
pm_newline_list.h
A list of byte offsets of newlines in a string.
pm_string.h
A generic string type that can have various ownership semantics.
defines.h
Macro definitions used throughout the prism library.
encoding.h
The encoding interface and implementations used by the parser.
static_literals.h
A set of static literal nodes that can be checked for duplicates.
stdbool.h
C99 shim for <stdbool.h>.
pm_comment
This is a node in the linked list of comments that we've found while parsing.
Definition parser.h:461
pm_comment::node
pm_list_node_t node
The embedded base node.
Definition parser.h:463
pm_comment::type
pm_comment_type_t type
The type of comment that we've found.
Definition parser.h:469
pm_comment::location
pm_location_t location
The location of the comment in the source.
Definition parser.h:466
pm_constant_pool_t
The overall constant pool, which stores constants found while parsing.
Definition pm_constant_pool.h:134
pm_context_node
This is a node in a linked list of contexts.
Definition parser.h:442
pm_context_node::context
pm_context_t context
The context that this node represents.
Definition parser.h:444
pm_context_node::prev
struct pm_context_node * prev
A pointer to the previous context in the linked list.
Definition parser.h:447
pm_encoding_t
This struct defines the functions necessary to implement the encoding interface so we can determine h...
Definition encoding.h:23
pm_heredoc_lex_mode_t
All of the information necessary to store to lexing a heredoc.
Definition parser.h:88
pm_heredoc_lex_mode_t::ident_length
size_t ident_length
The length of the heredoc identifier.
Definition parser.h:93
pm_heredoc_lex_mode_t::quote
pm_heredoc_quote_t quote
The type of quote that the heredoc uses.
Definition parser.h:96
pm_heredoc_lex_mode_t::indent
pm_heredoc_indent_t indent
The type of indentation that the heredoc uses.
Definition parser.h:99
pm_heredoc_lex_mode_t::ident_start
const uint8_t * ident_start
A pointer to the start of the heredoc identifier.
Definition parser.h:90
pm_lex_callback_t
When you are lexing through a file, the lexer needs all of the information that the parser additional...
Definition parser.h:509
pm_lex_callback_t::callback
void(* callback)(void *data, pm_parser_t *parser, pm_token_t *token)
This is the callback that is called when a token is lexed.
Definition parser.h:521
pm_lex_callback_t::data
void * data
This opaque pointer is used to provide whatever information the user deemed necessary to the callback...
Definition parser.h:515
pm_lex_mode
When lexing Ruby source, the lexer has a small amount of state to tell which kind of token it is curr...
Definition parser.h:109
pm_lex_mode::PM_LEX_LIST
@ PM_LEX_LIST
This state is used when we are lexing a list of tokens, as in a w word list literal or a i symbol lis...
Definition parser.h:134
pm_lex_mode::PM_LEX_EMBVAR
@ PM_LEX_EMBVAR
This state is used when we're lexing a variable that is embedded directly inside of a string with the...
Definition parser.h:125
pm_lex_mode::PM_LEX_REGEXP
@ PM_LEX_REGEXP
This state is used when a regular expression has been begun and we are looking for the terminator.
Definition parser.h:140
pm_lex_mode::PM_LEX_DEFAULT
@ PM_LEX_DEFAULT
This state is used when any given token is being lexed.
Definition parser.h:113
pm_lex_mode::PM_LEX_HEREDOC
@ PM_LEX_HEREDOC
This state is used when you are inside the content of a heredoc.
Definition parser.h:128
pm_lex_mode::PM_LEX_EMBEXPR
@ PM_LEX_EMBEXPR
This state is used when we're lexing as normal but inside an embedded expression of a string.
Definition parser.h:119
pm_lex_mode::PM_LEX_STRING
@ PM_LEX_STRING
This state is used when we are lexing a string or a string-like token, as in string content with eith...
Definition parser.h:146
pm_lex_mode::terminator
uint8_t terminator
This is the terminator of the list literal.
Definition parser.h:165
pm_lex_mode::nesting
size_t nesting
This keeps track of the nesting level of the list.
Definition parser.h:153
pm_lex_mode::interpolation
bool interpolation
Whether or not interpolation is allowed in this list.
Definition parser.h:156
pm_lex_mode::incrementor
uint8_t incrementor
When lexing a list, it takes into account balancing the terminator if the terminator is one of (),...
Definition parser.h:162
pm_lex_mode::breakpoints
uint8_t breakpoints[11]
This is the character set that should be used to delimit the tokens within the list.
Definition parser.h:171
pm_lex_mode::base
pm_heredoc_lex_mode_t base
All of the data necessary to lex a heredoc.
Definition parser.h:233
pm_lex_mode::line_continuation
bool line_continuation
True if the previous token ended with a line continuation.
Definition parser.h:249
pm_lex_mode::prev
struct pm_lex_mode * prev
The previous lex state so that it knows how to pop.
Definition parser.h:254
pm_lex_mode::as
union pm_lex_mode::@303336126360075302344075121136356113360170030306 as
The data associated with this type of lex mode.
pm_lex_mode::label_allowed
bool label_allowed
Whether or not at the end of the string we should allow a :, which would indicate this was a dynamic ...
Definition parser.h:208
pm_lex_mode::next_start
const uint8_t * next_start
This is the pointer to the character where lexing should resume once the heredoc has been completely ...
Definition parser.h:239
pm_lex_mode::common_whitespace
size_t * common_whitespace
This is used to track the amount of common whitespace on each line so that we know how much to dedent...
Definition parser.h:246
pm_lex_mode::mode
enum pm_lex_mode::@204051102252353332352362146052355003264223055126 mode
The type of this lex mode.
pm_list_t
This represents the overall linked list.
Definition pm_list.h:55
pm_local_t
This tracks an individual local variable in a certain lexical context, as well as the number of times...
Definition parser.h:535
pm_local_t::name
pm_constant_id_t name
The name of the local variable.
Definition parser.h:537
pm_local_t::location
pm_location_t location
The location of the local variable in the source.
Definition parser.h:540
pm_local_t::hash
uint32_t hash
The hash of the local variable.
Definition parser.h:549
pm_local_t::index
uint32_t index
The index of the local variable in the local table.
Definition parser.h:543
pm_local_t::reads
uint32_t reads
The number of times the local variable is read.
Definition parser.h:546
pm_locals
This is a set of local variables in a certain lexical context (method, class, module,...
Definition parser.h:557
pm_locals::locals
pm_local_t * locals
The nullable allocated memory for the local variables in the set.
Definition parser.h:565
pm_locals::capacity
uint32_t capacity
The capacity of the local variables set.
Definition parser.h:562
pm_locals::size
uint32_t size
The number of local variables in the set.
Definition parser.h:559
pm_location_t
This represents a range of bytes in the source string to which a node or token corresponds.
Definition ast.h:544
pm_magic_comment_t
This is a node in the linked list of magic comments that we've found while parsing.
Definition parser.h:478
pm_magic_comment_t::key_length
uint32_t key_length
The length of the key in the source.
Definition parser.h:489
pm_magic_comment_t::node
pm_list_node_t node
The embedded base node.
Definition parser.h:480
pm_magic_comment_t::key_start
const uint8_t * key_start
A pointer to the start of the key in the source.
Definition parser.h:483
pm_magic_comment_t::value_start
const uint8_t * value_start
A pointer to the start of the value in the source.
Definition parser.h:486
pm_magic_comment_t::value_length
uint32_t value_length
The length of the value in the source.
Definition parser.h:492
pm_newline_list_t
A list of offsets of newlines in a string.
Definition pm_newline_list.h:28
pm_parser
This struct represents the overall parser.
Definition parser.h:643
pm_parser::explicit_encoding
const pm_encoding_t * explicit_encoding
When a string-like expression is being lexed, any byte or escape sequence that resolves to a value wh...
Definition parser.h:843
pm_parser::lex_state
pm_lex_state_t lex_state
The current state of the lexer.
Definition parser.h:652
pm_parser::command_line
uint8_t command_line
The command line flags given from the options.
Definition parser.h:862
pm_parser::encoding
const pm_encoding_t * encoding
The encoding functions for the current file is attached to the parser as it's parsing so that it can ...
Definition parser.h:758
pm_parser::partial_script
bool partial_script
Whether or not we are parsing a "partial" script, which is a script that will be evaluated in the con...
Definition parser.h:885
pm_parser::pattern_matching_newlines
bool pattern_matching_newlines
This flag indicates that we are currently parsing a pattern matching expression and impacts that calc...
Definition parser.h:912
pm_parser::end
const uint8_t * end
The pointer to the end of the source.
Definition parser.h:697
pm_parser::recovering
bool recovering
Whether or not we're currently recovering from a syntax error.
Definition parser.h:891
pm_parser::integer_base
pm_node_flags_t integer_base
We want to add a flag to integer nodes that indicates their base.
Definition parser.h:800
pm_parser::warn_mismatched_indentation
bool warn_mismatched_indentation
By default, Ruby always warns about mismatched indentation.
Definition parser.h:933
pm_parser::constant_pool
pm_constant_pool_t constant_pool
This constant pool keeps all of the constants defined throughout the file so that we can reference th...
Definition parser.h:789
pm_parser::in_keyword_arg
bool in_keyword_arg
This flag indicates that we are currently parsing a keyword argument.
Definition parser.h:915
pm_parser::do_loop_stack
pm_state_stack_t do_loop_stack
The stack used to determine if a do keyword belongs to the predicate of a while, until,...
Definition parser.h:673
pm_parser::next_start
const uint8_t * next_start
This is a special field set on the parser when we need the parser to jump to a specific location when...
Definition parser.h:710
pm_parser::current_hash_keys
pm_static_literals_t * current_hash_keys
The hash keys for the hash that is currently being parsed.
Definition parser.h:752
pm_parser::magic_comment_list
pm_list_t magic_comment_list
The list of magic comments that have been found while parsing.
Definition parser.h:724
pm_parser::lambda_enclosure_nesting
int lambda_enclosure_nesting
Used to temporarily track the nesting of enclosures to determine if a { is the beginning of a lambda ...
Definition parser.h:661
pm_parser::lex_callback
pm_lex_callback_t * lex_callback
This is an optional callback that can be attached to the parser that will be called whenever a new to...
Definition parser.h:777
pm_parser::version
pm_options_version_t version
The version of prism that we should use to parse.
Definition parser.h:859
pm_parser::previous
pm_token_t previous
The previous token we were considering.
Definition parser.h:700
pm_parser::current_string
pm_string_t current_string
This string is used to pass information from the lexer to the parser.
Definition parser.h:806
pm_parser::parsing_eval
bool parsing_eval
Whether or not we are parsing an eval string.
Definition parser.h:878
pm_parser::current_regular_expression_ascii_only
bool current_regular_expression_ascii_only
True if the current regular expression being lexed contains only ASCII characters.
Definition parser.h:927
pm_parser::encoding_changed
bool encoding_changed
Whether or not the encoding has been changed by a magic comment.
Definition parser.h:906
pm_parser::data_loc
pm_location_t data_loc
An optional location that represents the location of the END marker and the rest of the content of th...
Definition parser.h:731
pm_parser::current_context
pm_context_node_t * current_context
The current parsing context.
Definition parser.h:743
pm_parser::start
const uint8_t * start
The pointer to the start of the source.
Definition parser.h:694
pm_parser::accepts_block_stack
pm_state_stack_t accepts_block_stack
The stack used to determine if a do keyword belongs to the beginning of a block.
Definition parser.h:679
pm_parser::enclosure_nesting
int enclosure_nesting
Tracks the current nesting of (), [], and {}.
Definition parser.h:655
pm_parser::error_list
pm_list_t error_list
The list of errors that have been found while parsing.
Definition parser.h:737
pm_parser::frozen_string_literal
int8_t frozen_string_literal
Whether or not we have found a frozen_string_literal magic comment with a true or false value.
Definition parser.h:872
pm_parser::current_block_exits
pm_node_list_t * current_block_exits
When parsing block exits (e.g., break, next, redo), we need to validate that they are in correct cont...
Definition parser.h:856
pm_parser::encoding_comment_start
const uint8_t * encoding_comment_start
This pointer indicates where a comment must start if it is to be considered an encoding comment.
Definition parser.h:771
pm_parser::stack
pm_lex_mode_t stack[PM_LEX_STACK_SIZE]
The stack of lexer modes.
Definition parser.h:687
pm_parser::warning_list
pm_list_t warning_list
The list of warnings that have been found while parsing.
Definition parser.h:734
pm_parser::heredoc_end
const uint8_t * heredoc_end
This field indicates the end of a heredoc whose identifier was found on the current line.
Definition parser.h:718
pm_parser::brace_nesting
int brace_nesting
Used to track the nesting of braces to ensure we get the correct value when we are interpolating bloc...
Definition parser.h:667
pm_parser::encoding_changed_callback
pm_encoding_changed_callback_t encoding_changed_callback
When the encoding that is being used to parse the source is changed by prism, we provide the ability ...
Definition parser.h:765
pm_parser::start_line
int32_t start_line
The line number at the start of the parse.
Definition parser.h:812
pm_parser::encoding_locked
bool encoding_locked
This is very specialized behavior for when you want to parse in a context that does not respect encod...
Definition parser.h:899
pm_parser::current
pm_lex_mode_t * current
The current mode of the lexer.
Definition parser.h:684
pm_parser::lex_modes
struct pm_parser::@236040131255244317313236162207277265316171136011 lex_modes
A stack of lex modes.
pm_parser::comment_list
pm_list_t comment_list
The list of comments that have been found while parsing.
Definition parser.h:721
pm_parser::index
size_t index
The current index into the lexer mode stack.
Definition parser.h:690
pm_parser::filepath
pm_string_t filepath
This is the path of the file being parsed.
Definition parser.h:783
pm_parser::current_scope
pm_scope_t * current_scope
The current local scope.
Definition parser.h:740
pm_parser::command_start
bool command_start
Whether or not we're at the beginning of a command.
Definition parser.h:888
pm_parser::newline_list
pm_newline_list_t newline_list
This is the list of newline offsets in the source file.
Definition parser.h:792
pm_parser::semantic_token_seen
bool semantic_token_seen
Whether or not the parser has seen a token that has semantic meaning (i.e., a token that is not a com...
Definition parser.h:921
pm_parser::node_id
uint32_t node_id
The next node identifier that will be assigned.
Definition parser.h:649
pm_scope
This struct represents a node in a linked list of scopes.
Definition parser.h:583
pm_scope::previous
struct pm_scope * previous
A pointer to the previous scope in the linked list.
Definition parser.h:585
pm_scope::implicit_parameters
pm_node_list_t implicit_parameters
This is a list of the implicit parameters contained within the block.
Definition parser.h:596
pm_scope::shareable_constant
pm_shareable_constant_value_t shareable_constant
The current state of constant shareability for this scope.
Definition parser.h:623
pm_scope::locals
pm_locals_t locals
The IDs of the locals in the given scope.
Definition parser.h:588
pm_scope::parameters
pm_scope_parameters_t parameters
This is a bitfield that indicates the parameters that are being used in this scope.
Definition parser.h:617
pm_scope::closed
bool closed
A boolean indicating whether or not this scope can see into its parent.
Definition parser.h:629
pm_static_literals_t
Certain sets of nodes (hash keys and when clauses) check for duplicate nodes to alert the user of pot...
Definition static_literals.h:38
pm_string_t
A generic string type that can have various ownership semantics.
Definition pm_string.h:33
pm_token_t
This struct represents a token in the Ruby source.
Definition ast.h:529