Ruby 3.3.7p123 (2025-01-15 revision be31f993d7fa0219d85f7b3c694d454da4ecc10b)
|
The parser used to parse Ruby source. More...
#include "prism/ast.h"
#include "prism/defines.h"
#include "prism/encoding.h"
#include "prism/util/pm_constant_pool.h"
#include "prism/util/pm_list.h"
#include "prism/util/pm_newline_list.h"
#include "prism/util/pm_state_stack.h"
#include "prism/util/pm_string.h"
#include <stdbool.h>
Go to the source code of this file.
Data Structures | |
struct | pm_lex_mode |
When lexing Ruby source, the lexer has a small amount of state to tell which kind of token it is currently lexing. More... | |
struct | pm_context_node |
This is a node in a linked list of contexts. More... | |
struct | pm_comment |
This is a node in the linked list of comments that we've found while parsing. More... | |
struct | pm_magic_comment_t |
This is a node in the linked list of magic comments that we've found while parsing. More... | |
struct | pm_lex_callback_t |
When you are lexing through a file, the lexer needs all of the information that the parser additionally provides (for example, the local table). More... | |
struct | pm_scope |
This struct represents a node in a linked list of scopes. More... | |
struct | pm_parser |
This struct represents the overall parser. More... | |
Macros | |
#define | PM_KEYWORD_HASH_NODE_FLAGS_SYMBOL_KEYS PM_KEYWORD_HASH_NODE_FLAGS_STATIC_KEYS |
Temporary alias for the PM_NODE_FLAG_STATIC_KEYS flag. | |
#define | PM_LEX_STACK_SIZE 4 |
We pre-allocate a certain number of lex states in order to avoid having to call malloc too many times while parsing. | |
Typedefs | |
typedef 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 currently lexing. | |
typedef struct pm_parser | pm_parser_t |
The parser used to parse Ruby source. | |
typedef struct pm_context_node | pm_context_node_t |
This is a node in a linked list of contexts. | |
typedef struct pm_comment | pm_comment_t |
This is a node in the linked list of comments that we've found while parsing. | |
typedef 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 here to call out to a user-defined function. | |
typedef struct pm_scope | pm_scope_t |
This struct represents a node in a linked list of scopes. | |
Enumerations | |
enum | pm_lex_state_bit_t { PM_LEX_STATE_BIT_BEG , PM_LEX_STATE_BIT_END , PM_LEX_STATE_BIT_ENDARG , PM_LEX_STATE_BIT_ENDFN , PM_LEX_STATE_BIT_ARG , PM_LEX_STATE_BIT_CMDARG , PM_LEX_STATE_BIT_MID , PM_LEX_STATE_BIT_FNAME , PM_LEX_STATE_BIT_DOT , PM_LEX_STATE_BIT_CLASS , PM_LEX_STATE_BIT_LABEL , PM_LEX_STATE_BIT_LABELED , PM_LEX_STATE_BIT_FITEM } |
This enum provides various bits that represent different kinds of states that the lexer can track. More... | |
enum | pm_lex_state_t { PM_LEX_STATE_NONE = 0 , PM_LEX_STATE_BEG = (1 << PM_LEX_STATE_BIT_BEG) , PM_LEX_STATE_END = (1 << PM_LEX_STATE_BIT_END) , PM_LEX_STATE_ENDARG = (1 << PM_LEX_STATE_BIT_ENDARG) , PM_LEX_STATE_ENDFN = (1 << PM_LEX_STATE_BIT_ENDFN) , PM_LEX_STATE_ARG = (1 << PM_LEX_STATE_BIT_ARG) , PM_LEX_STATE_CMDARG = (1 << PM_LEX_STATE_BIT_CMDARG) , PM_LEX_STATE_MID = (1 << PM_LEX_STATE_BIT_MID) , PM_LEX_STATE_FNAME = (1 << PM_LEX_STATE_BIT_FNAME) , PM_LEX_STATE_DOT = (1 << PM_LEX_STATE_BIT_DOT) , PM_LEX_STATE_CLASS = (1 << PM_LEX_STATE_BIT_CLASS) , PM_LEX_STATE_LABEL = (1 << PM_LEX_STATE_BIT_LABEL) , PM_LEX_STATE_LABELED = (1 << PM_LEX_STATE_BIT_LABELED) , PM_LEX_STATE_FITEM = (1 << PM_LEX_STATE_BIT_FITEM) , PM_LEX_STATE_BEG_ANY = PM_LEX_STATE_BEG | PM_LEX_STATE_MID | PM_LEX_STATE_CLASS , PM_LEX_STATE_ARG_ANY = PM_LEX_STATE_ARG | PM_LEX_STATE_CMDARG , PM_LEX_STATE_END_ANY = PM_LEX_STATE_END | PM_LEX_STATE_ENDARG | PM_LEX_STATE_ENDFN } |
This enum combines the various bits from the above enum into individual values that represent the various states of the lexer. More... | |
enum | pm_heredoc_quote_t { PM_HEREDOC_QUOTE_NONE , PM_HEREDOC_QUOTE_SINGLE = '\'' , PM_HEREDOC_QUOTE_DOUBLE = '"' , PM_HEREDOC_QUOTE_BACKTICK = '`' } |
The type of quote that a heredoc uses. More... | |
enum | pm_heredoc_indent_t { PM_HEREDOC_INDENT_NONE , PM_HEREDOC_INDENT_DASH , PM_HEREDOC_INDENT_TILDE } |
The type of indentation that a heredoc uses. More... | |
enum | pm_context_t { PM_CONTEXT_BEGIN , PM_CONTEXT_BLOCK_BRACES , PM_CONTEXT_BLOCK_KEYWORDS , PM_CONTEXT_CASE_WHEN , PM_CONTEXT_CASE_IN , PM_CONTEXT_CLASS , PM_CONTEXT_DEF , PM_CONTEXT_DEF_PARAMS , PM_CONTEXT_DEFAULT_PARAMS , PM_CONTEXT_ELSE , PM_CONTEXT_ELSIF , PM_CONTEXT_EMBEXPR , PM_CONTEXT_ENSURE , PM_CONTEXT_ENSURE_DEF , PM_CONTEXT_FOR , PM_CONTEXT_FOR_INDEX , PM_CONTEXT_IF , PM_CONTEXT_LAMBDA_BRACES , PM_CONTEXT_LAMBDA_DO_END , PM_CONTEXT_MAIN , PM_CONTEXT_MODULE , PM_CONTEXT_PARENS , PM_CONTEXT_POSTEXE , PM_CONTEXT_PREDICATE , PM_CONTEXT_PREEXE , PM_CONTEXT_RESCUE_ELSE , PM_CONTEXT_RESCUE_ELSE_DEF , PM_CONTEXT_RESCUE , PM_CONTEXT_RESCUE_DEF , PM_CONTEXT_SCLASS , PM_CONTEXT_UNLESS , PM_CONTEXT_UNTIL , PM_CONTEXT_WHILE } |
While parsing, we keep track of a stack of contexts. More... | |
enum | pm_comment_type_t { PM_COMMENT_INLINE , PM_COMMENT_EMBDOC } |
This is the type of a comment that we've found while parsing. More... | |
The parser used to parse Ruby source.
Definition in file parser.h.
#define PM_KEYWORD_HASH_NODE_FLAGS_SYMBOL_KEYS PM_KEYWORD_HASH_NODE_FLAGS_STATIC_KEYS |
#define PM_LEX_STACK_SIZE 4 |
We pre-allocate a certain number of lex states in order to avoid having to call malloc too many times while parsing.
You really shouldn't need more than this because you only really nest deeply when doing string interpolation.
Definition at line 254 of file parser.h.
Referenced by pm_parser_free().
typedef struct pm_comment pm_comment_t |
This is a node in the linked list of comments that we've found while parsing.
typedef struct pm_context_node pm_context_node_t |
This is a node in a linked list of contexts.
typedef void(* pm_encoding_changed_callback_t) (pm_parser_t *parser) |
typedef 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 currently lexing.
For example, when we find the start of a string, the first token that we return is a TOKEN_STRING_BEGIN token. After that the lexer is now in the PM_LEX_STRING mode, and will return tokens that are found as part of a string.
typedef struct pm_parser pm_parser_t |
typedef struct pm_scope pm_scope_t |
This struct represents a node in a linked list of scopes.
Some scopes can see into their parent scopes, while others cannot.
enum pm_comment_type_t |
enum pm_context_t |
While parsing, we keep track of a stack of contexts.
This is helpful for error recovery so that we can pop back to a previous context when we hit a token that is understood by a parent context but not by the current context.
enum pm_heredoc_indent_t |
enum pm_heredoc_quote_t |
enum pm_lex_state_bit_t |
enum pm_lex_state_t |