Prism Ruby parser
Loading...
Searching...
No Matches
Data Structures | Typedefs | Functions
parser.hpp File Reference

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, std::string_view source, const pm_options_t *options=nullptr) noexcept
 Allocate a new parser over the given source.
 
std::string_view prism::constant (const pm_parser_t *parser, 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, 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) noexcept
 The errors found while parsing.
 
diagnostic_range prism::warnings (const pm_parser_t *parser) noexcept
 The warnings found while parsing.
 
comment_range prism::comments (const pm_parser_t *parser) noexcept
 The comments found while parsing, in source order.
 
magic_comment_range prism::magic_comments (const pm_parser_t *parser) 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.

Function Documentation

◆ make_parser()

unique_parser prism::make_parser ( pm_arena_t *  arena,
std::string_view  source,
const pm_options_t *  options = 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.

◆ constant()

std::string_view prism::constant ( const pm_parser_t *  parser,
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.

◆ slice()

std::string_view prism::slice ( const pm_parser_t *  parser,
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.

◆ 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.

◆ errors()

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

The errors found while parsing.

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

◆ warnings()

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

The warnings found while parsing.

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

◆ comments()

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

The comments found while parsing, in source order.

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

◆ magic_comments()

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

The magic comments found while parsing.

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