Ruby 4.1.0dev (2026-10-21 revision 536dc6f98b72e6999a84bb6373562c43cb1ddf8a)
Data Structures | Typedefs | Functions
parser.hpp File Reference

(536dc6f98b72e6999a84bb6373562c43cb1ddf8a)

Ownership of parsers from C++, and lookups through a parser into the source, the constant pool, comments, and diagnostics. More...

#include "prism/compiler/cplusplus.hpp"
#include "prism/compiler/lifetimebound.hpp"
#include "prism/arena.h"
#include "prism/constant_pool.h"
#include "prism/line_offset_list.h"
#include "prism/parser.h"
#include <cassert>
#include <cstddef>
#include <cstdint>
#include <iterator>
#include <memory>
#include <string_view>
Include dependency graph for parser.hpp:

Go to the source code of this file.

Data Structures

struct  prism::parser_deleter
 Frees a parser with pm_parser_free. More...
 
class  prism::detail::next_range< T, Next >
 The diagnostics, comments, or magic comments found while parsing, usable in a range-based for loop and with the standard algorithms. More...
 
class  prism::detail::next_range< T, Next >::iterator
 Steps through the items one after another. More...
 

Typedefs

using prism::unique_parser = std::unique_ptr< pm_parser_t, parser_deleter >
 An owned parser.
 
using prism::diagnostic_range = detail::next_range< pm_diagnostic_t, pm_diagnostic_next >
 The errors or warnings found while parsing.
 
using prism::comment_range = detail::next_range< pm_comment_t, pm_comment_next >
 The comments found while parsing.
 
using prism::magic_comment_range = detail::next_range< pm_magic_comment_t, pm_magic_comment_next >
 The magic comments found while parsing.
 

Functions

unique_parser prism::make_parser (pm_arena_t *arena PRISM_LIFETIMEBOUND, std::string_view source PRISM_LIFETIMEBOUND, const pm_options_t *options PRISM_LIFETIMEBOUND=nullptr) noexcept
 Allocate a new parser over the given source.
 
std::string_view prism::constant (const pm_parser_t *parser PRISM_LIFETIMEBOUND, pm_constant_id_t constant_id) noexcept
 The name of the constant with the given id, which must not be zero.
 
std::string_view prism::slice (const pm_parser_t *parser PRISM_LIFETIMEBOUND, pm_location_t location) noexcept
 The bytes of source that the given location covers.
 
pm_line_column_t prism::line_column (const pm_parser_t *parser, std::uint32_t offset) noexcept
 The line and column of the given byte offset into the source.
 
diagnostic_range prism::errors (const pm_parser_t *parser PRISM_LIFETIMEBOUND) noexcept
 The errors found while parsing.
 
diagnostic_range prism::warnings (const pm_parser_t *parser PRISM_LIFETIMEBOUND) noexcept
 The warnings found while parsing.
 
comment_range prism::comments (const pm_parser_t *parser PRISM_LIFETIMEBOUND) noexcept
 The comments found while parsing, in source order.
 
magic_comment_range prism::magic_comments (const pm_parser_t *parser PRISM_LIFETIMEBOUND) noexcept
 The magic comments found while parsing.
 

Detailed Description

Ownership of parsers from C++, and lookups through a parser into the source, the constant pool, comments, and diagnostics.

Definition in file parser.hpp.

Typedef Documentation

◆ comment_range

using prism::comment_range = typedef detail::next_range<pm_comment_t, pm_comment_next>

The comments found while parsing.

Definition at line 223 of file parser.hpp.

◆ diagnostic_range

using prism::diagnostic_range = typedef detail::next_range<pm_diagnostic_t, pm_diagnostic_next>

The errors or warnings found while parsing.

Definition at line 220 of file parser.hpp.

◆ magic_comment_range

The magic comments found while parsing.

Definition at line 226 of file parser.hpp.

◆ unique_parser

using prism::unique_parser = typedef std::unique_ptr<pm_parser_t, parser_deleter>

An owned parser.

Definition at line 38 of file parser.hpp.

Function Documentation

◆ comments()

comment_range prism::comments ( const pm_parser_t *parser  PRISM_LIFETIMEBOUND)
inlinenoexcept

The comments found while parsing, in source order.

Parameters
parserThe parser containing the source.
Returns
The range of comments found while parsing.

Definition at line 257 of file parser.hpp.

Referenced by prism::comments().

◆ constant()

std::string_view prism::constant ( const pm_parser_t *parser  PRISM_LIFETIMEBOUND,
pm_constant_id_t  constant_id 
)
inlinenoexcept

The name of the constant with the given id, which must not be zero.

Fields holding an optional constant use zero for none, so check those first.

Parameters
parserThe parser containing the constant.
constant_idThe id of the constant.
Returns
The value of the constant.

Definition at line 64 of file parser.hpp.

Referenced by prism::constant().

◆ errors()

diagnostic_range prism::errors ( const pm_parser_t *parser  PRISM_LIFETIMEBOUND)
inlinenoexcept

The errors found while parsing.

Parameters
parserThe parser containing the source.
Returns
The range of errors found while parsing.

Definition at line 235 of file parser.hpp.

Referenced by prism::errors().

◆ line_column()

pm_line_column_t prism::line_column ( const pm_parser_t *  parser,
std::uint32_t  offset 
)
inlinenoexcept

The line and column of the given byte offset into the source.

Lines start at the parser's start line, and columns are byte offsets from the line start.

Parameters
parserThe parser containing the source.
offsetThe byte offset into the source.
Returns
The line and column of the byte offset.

Definition at line 91 of file parser.hpp.

Referenced by prism::line_column().

◆ magic_comments()

magic_comment_range prism::magic_comments ( const pm_parser_t *parser  PRISM_LIFETIMEBOUND)
inlinenoexcept

The magic comments found while parsing.

Parameters
parserThe parser containing the source.
Returns
The range of magic comments found while parsing.

Definition at line 268 of file parser.hpp.

Referenced by prism::magic_comments().

◆ make_parser()

unique_parser prism::make_parser ( pm_arena_t *arena  PRISM_LIFETIMEBOUND,
std::string_view source  PRISM_LIFETIMEBOUND,
const pm_options_t *options  PRISM_LIFETIMEBOUND = nullptr 
)
inlinenoexcept

Allocate a new parser over the given source.

The source, the arena, and the options (which may be null) are not copied, so all three must outlive the parser. Allocation failure aborts, so this never throws.

Parameters
arenaThe arena to use for allocations.
sourceThe source code to parse.
optionsThe parse options, or null for defaults.
Returns
A unique_parser owning the newly allocated parser.

Definition at line 51 of file parser.hpp.

Referenced by prism::make_parser().

◆ slice()

std::string_view prism::slice ( const pm_parser_t *parser  PRISM_LIFETIMEBOUND,
pm_location_t  location 
)
inlinenoexcept

The bytes of source that the given location covers.

Parameters
parserThe parser containing the source.
locationThe location in the source.
Returns
The bytes of source covered by the location.

Definition at line 78 of file parser.hpp.

Referenced by prism::slice().

◆ warnings()

diagnostic_range prism::warnings ( const pm_parser_t *parser  PRISM_LIFETIMEBOUND)
inlinenoexcept

The warnings found while parsing.

Parameters
parserThe parser containing the source.
Returns
The range of warnings found while parsing.

Definition at line 246 of file parser.hpp.

Referenced by prism::warnings().