compiler_explorer.hpp
Go to the documentation of this file.
1 // Copyright (C) 2020-2024 Jonathan Müller and lexy contributors
2 // SPDX-License-Identifier: BSL-1.0
3 
4 #ifndef LEXY_EXT_COMPILER_EXPLORER_HPP_INCLUDED
5 #define LEXY_EXT_COMPILER_EXPLORER_HPP_INCLUDED
6 
7 #include <cstdio>
10 #include <lexy/input/buffer.hpp>
11 
12 namespace lexy_ext
13 {
17 {
18  // We can't use ftell() to get file size
19  // So instead use a conservative loop.
21  while (true)
22  {
23  const auto buffer_size = builder.write_size();
24  LEXY_ASSERT(buffer_size > 0, "buffer empty?!");
25 
26  // Read into the entire write area of the buffer from stdin,
27  // commiting what we've just read.
28  const auto read = std::fread(builder.write_data(), sizeof(char), buffer_size, stdin);
29  builder.commit(read);
30 
31  // Check whether we have exhausted the file.
32  if (read < buffer_size)
33  {
34  // We should have reached the end.
35  LEXY_ASSERT(!std::ferror(stdin), "read error");
36  LEXY_ASSERT(std::feof(stdin), "why did fread() not read enough?");
37  break;
38  }
39 
40  // We've filled the entire buffer and need more space.
41  // This grow might be unnecessary if we're just so happen to reach EOF with the next
42  // input, but checking this requires reading more input.
43  builder.grow();
44  }
45 
46  return lexy::buffer<lexy::utf8_encoding>(builder.read_data(), builder.read_size());
47 }
48 
49 //=== convenience typedefs ===//
51 
52 template <typename Tag>
54 
55 template <typename Production>
57 } // namespace lexy_ext
58 
59 #endif // LEXY_EXT_COMPILER_EXPLORER_HPP_INCLUDED
60 
config.hpp
lexy::_detail::buffer_builder::read_data
const T * read_data() const noexcept
Definition: buffer_builder.hpp:51
lexy_ext
Definition: compiler_explorer.hpp:12
lexy::_detail::buffer_builder
Definition: buffer_builder.hpp:19
lexy::_detail::buffer_builder::write_data
T * write_data() noexcept
Definition: buffer_builder.hpp:61
lexy::error_context
Contains information about the context of an error, production is type-erased.
Definition: error.hpp:233
lexy::error
Generic failure.
Definition: error.hpp:14
buffer_builder.hpp
lexy_ext::compiler_explorer_input
lexy::buffer< lexy::utf8_encoding > compiler_explorer_input()
Definition: compiler_explorer.hpp:16
lexy::_detail::buffer_builder::grow
void grow()
Definition: buffer_builder.hpp:86
lexy::_detail::buffer_builder::read_size
std::size_t read_size() const noexcept
Definition: buffer_builder.hpp:55
lexy::buffer
Definition: buffer.hpp:95
lexy::lexeme
Definition: lexeme.hpp:16
lexy::_detail::buffer_builder::commit
void commit(std::size_t n) noexcept
Definition: buffer_builder.hpp:78
buffer.hpp
lexy::_detail::buffer_builder::write_size
std::size_t write_size() const noexcept
Definition: buffer_builder.hpp:65
LEXY_ASSERT
#define LEXY_ASSERT(Expr, Msg)
Definition: assert.hpp:37


behaviortree_cpp_v4
Author(s): Davide Faconti
autogenerated on Fri Dec 13 2024 03:19:16