7#ifndef PRISM_PARSER_HPP
8#define PRISM_PARSER_HPP
63[[nodiscard]]
inline std::string_view
65 assert(constant_id != 0);
66 const pm_constant_t *entry = pm_parser_constant(parser, constant_id);
67 return std::string_view(
reinterpret_cast<const char *
>(pm_constant_start(entry)), pm_constant_length(entry));
77[[nodiscard]]
inline std::string_view
79 return std::string_view(
reinterpret_cast<const char *
>(pm_parser_start(parser) + location.start), location.length);
92 return pm_line_offset_list_line_column(pm_parser_line_offsets(parser), offset, pm_parser_start_line(parser));
105template <
typename T, const T *(*Next)(const T *)>
class next_range {
133 explicit
iterator(const T *current) noexcept : current_(current) {}
149 assert(current_ !=
nullptr);
150 current_ = Next(current_);
173 const T *current_ =
nullptr;
203 std::size_t
size() const noexcept {
return size_; }
210 [[nodiscard]]
bool empty() const noexcept {
return size_ == 0; }
236 return diagnostic_range(pm_parser_errors_first(parser), pm_parser_errors_size(parser));
245[[nodiscard]]
inline diagnostic_range
247 return diagnostic_range(pm_parser_warnings_first(parser), pm_parser_warnings_size(parser));
256[[nodiscard]]
inline comment_range
258 return comment_range(pm_parser_comments_first(parser), pm_parser_comments_size(parser));
267[[nodiscard]]
inline magic_comment_range
269 return magic_comment_range(pm_parser_magic_comments_first(parser), pm_parser_magic_comments_size(parser));
A bump allocator for the prism parser.
Steps through the items one after another.
std::forward_iterator_tag iterator_category
The iterator category, for the standard algorithms.
iterator & operator++() noexcept
Advance to the next item.
reference operator*() const noexcept
The item at this position, which must not be the end.
iterator operator++(int) noexcept
Advance to the next item, returning the iterator from before.
const T * value_type
The type of each element.
const value_type & reference
The type of a reference to an element.
friend bool operator==(iterator left, iterator right) noexcept
Whether the two iterators are at the same item.
const value_type * pointer
The type of a pointer to an element.
std::ptrdiff_t difference_type
The type of the distance between two iterators.
friend bool operator!=(iterator left, iterator right) noexcept
Whether the two iterators are at different items.
iterator() noexcept=default
Create the iterator that marks the end of the items.
The diagnostics, comments, or magic comments found while parsing, usable in a range-based for loop an...
bool empty() const noexcept
Whether there are no items.
next_range(const T *first, std::size_t size) noexcept
Create a range of the given number of items starting at first.
std::size_t size() const noexcept
The number of items.
iterator end() const noexcept
An iterator past the last item.
iterator begin() const noexcept
An iterator at the first item.
A data structure that stores a set of strings.
uint32_t pm_constant_id_t
A constant id is a unique identifier for a constant in the constant pool.
#define PRISM_LIFETIMEBOUND
Mark a parameter that the return value points into, so that the compiler warns if a temporary is pass...
A list of byte offsets of newlines in a string.
The parser used to parse Ruby source.
PRISM_NODISCARD PRISM_EXPORTED_FUNCTION pm_parser_t * pm_parser_new(pm_arena_t *arena, const uint8_t *source, size_t size, const pm_options_t *options) PRISM_NONNULL(1)
Allocate and initialize a parser with the given start and end pointers.
PRISM_EXPORTED_FUNCTION void pm_parser_free(pm_parser_t *parser) PRISM_NONNULL(1)
Free both the memory held by the given parser and the parser itself.
std::string_view slice(const pm_parser_t *parser PRISM_LIFETIMEBOUND, pm_location_t location) noexcept
The bytes of source that the given location covers.
comment_range comments(const pm_parser_t *parser PRISM_LIFETIMEBOUND) noexcept
The comments found while parsing, in source order.
std::unique_ptr< pm_parser_t, parser_deleter > unique_parser
An owned parser.
magic_comment_range magic_comments(const pm_parser_t *parser PRISM_LIFETIMEBOUND) noexcept
The magic comments found while parsing.
std::string_view 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.
diagnostic_range errors(const pm_parser_t *parser PRISM_LIFETIMEBOUND) noexcept
The errors found while parsing.
unique_parser 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.
pm_line_column_t 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 warnings(const pm_parser_t *parser PRISM_LIFETIMEBOUND) noexcept
The warnings found while parsing.
A line and column in a string.
This struct represents a slice in the source code, defined by an offset and a length.
Frees a parser with pm_parser_free.
void operator()(pm_parser_t *parser) const noexcept
Free the given parser.