Skip to content

Commit

Permalink
Update docs, deprecate visit_scan_arg
Browse files Browse the repository at this point in the history
  • Loading branch information
eliaskosunen committed Oct 23, 2024
1 parent 6c7f974 commit 5d4153f
Show file tree
Hide file tree
Showing 13 changed files with 422 additions and 239 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ jobs:
- name: Generate docs
run: |
cd docs
poxy --verbose --git-tags --min-version v2.0.0
poxy --verbose --git-tags --min-version v2.0.0 --no-squash-patches
- name: Deploy
uses: peaceiris/actions-gh-pages@v3
Expand Down
12 changes: 12 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,17 @@
# Changelog

## 4.0.0

_Released 2024-xx-xx_

TODO

## 3.0.2

_Released 2024-xx-xx_

TODO

## 3.0.1

_Released 2024-06-15_
Expand Down
2 changes: 1 addition & 1 deletion cmake/dependencies.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ else ()
FetchContent_Declare(
fast_float
GIT_REPOSITORY https://github.com/fastfloat/fast_float.git
GIT_TAG v6.1.1
GIT_TAG v6.1.6
GIT_SHALLOW TRUE
)

Expand Down
1 change: 1 addition & 0 deletions docs/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ add_custom_command(
DEPENDS
"${CMAKE_CURRENT_LIST_DIR}/pages/guide.md"
"${CMAKE_CURRENT_LIST_DIR}/pages/mainpage.md"
"${CMAKE_CURRENT_LIST_DIR}/../CHANGELOG.md"
"${SCN_ABSOLUTE_PUBLIC_HEADERS}"
COMMENT "Generating docs"
VERBATIM)
Expand Down
13 changes: 8 additions & 5 deletions docs/pages/guide.md
Original file line number Diff line number Diff line change
Expand Up @@ -138,10 +138,10 @@ auto [other_result, i] = scn::scan<int>(result->range(), "{}");

The return type of `->range()` is a view into the range `scn::scan` was given.
Its type may not be the same as the source range, but its iterator and sentinel types are the same.
If the range given to `scn::scan` does not model `ranges::borrowed_range`
(essentially, the returned range would dangle), the returned range is of type `ranges::dangling`.
If the range given to `scn::scan` does not model `scn::ranges::borrowed_range`
(essentially, the returned range would dangle), the returned range is of type `scn::ranges::dangling`.

Because the range type returned by `scn::scan` is always a `subrange` over its input,
Because the range type returned by `scn::scan` is always a `scn::ranges::subrange` over its input,
it's easy to use `scn::scan` in loops, as long as the input type is a `subrange` to begin with.
If it's not, consider making it one with `scn::ranges::subrange{your-input-range}`.

Expand Down Expand Up @@ -284,7 +284,7 @@ template <>
struct scn::scanner<mytype, char> {
template <typename ParseContext>
constexpr auto parse(ParseContext& pctx)
-> scan_expected<typename ParseContext::iterator>;
-> typename ParseContext::iterator;

template <typename Context>
auto scan(mytype& val, Context& ctx)
Expand All @@ -302,11 +302,14 @@ struct scn::scanner<mytype, char> : scn::scanner<std::string_view, char> {};

// Accept only empty
template <typename ParseContext>
constexpr auto parse(ParseContext& pctx) -> scan_expected<typename ParseContext::iterator> {
constexpr auto parse(ParseContext& pctx) -> typename ParseContext::iterator {
return pctx.begin();
}
\endcode

`parse` can report errors by throwing an exception of type `scn::scan_format_string_error`,
or by calling the `on_error` member function on the `ParseContext`.

`scan` parses the actual value, using the supplied `Context`.
The context has a member function, `current`, to get an iterator pointing to the next character in the source range,
and `range`, to get the entire source range that's still left to scan.
Expand Down
28 changes: 20 additions & 8 deletions docs/pages/mainpage.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ The code lives over at GitHub, at https://github.com/eliaskosunen/scnlib.

\code{.cpp}
#include <scn/scan.h>
#include <print> // for std::print, C++23
#include <print> // for std::println, C++23

int main() {
auto result = scn::scan<int, double>("42, 3.14", "{}, {}");
Expand All @@ -23,8 +23,9 @@ int main() {

\section main-about About this documentation

This documentation is for the version 3.0 of the library.
For version 2.0.3, see https://scnlib.dev/v2.0.3/.
This documentation is for the version 4.0 of the library.
For other versions, see the dropdown in the upper right corner of the website.
See <b><a href="./md_poxy_changelog.html">Changelog</a></b> for more.

An introductory guide to the library can be found at \ref guide "Guide".

Expand Down Expand Up @@ -71,7 +72,7 @@ Another option would be usage through CMake's `FetchContent` module.
FetchContent_Declare(
scn
GIT_REPOSITORY https://github.com/eliaskosunen/scnlib
GIT_TAG v3.0.1
GIT_TAG v4.0.0
GIT_SHALLOW TRUE
)
FetchContent_MakeAvailable(scn)
Expand All @@ -83,7 +84,7 @@ target_link_libraries(my_program scn::scn)

\subsection main-deps Dependencies

scnlib internally depends on
scnlib internally optionally depends on
<a href="https://github.com/fastfloat/fast_float">fast_float</a>.

By default, the CMake machinery automatically fetches, builds, and links it with `FetchContent`.
Expand Down Expand Up @@ -117,8 +118,8 @@ Library dependencies
<tr>
<td>fast_float</td>
<td>`>= 5.0.0`</td>
<td></td>
<td>Header only. Downloaded by default with `FetchContent`, controlled with `SCN_USE_EXTERNAL_FAST_FLOAT`.</td>
<td>⚠️</td>
<td>Required if `SCN_DISABLE_FAST_FLOAT` is `OFF`.<br>Header only. Downloaded by default with `FetchContent`, controlled with `SCN_USE_EXTERNAL_FAST_FLOAT`.</td>
</tr>

<tr>
Expand Down Expand Up @@ -214,6 +215,14 @@ scnlib configuration options
<th>Description</th>
</tr>

<tr>
<td>`SCN_DISABLE_FAST_FLOAT`</td>
<td>✅</td>
<td>✅</td>
<td>`OFF`</td>
<td>Disable external dependency on FastFloat.<br>Using `ON` requires standard library support for floating-point `std::from_chars`.<sup>1</sup></td>
</tr>

<tr>
<td>`SCN_DISABLE_REGEX`</td>
<td>✅</td>
Expand All @@ -227,7 +236,7 @@ scnlib configuration options
<td>✅</td>
<td>⚠️</td>
<td>`"std"`</td>
<td>Regular expression backend to use<br>(use integer values on the command line)<br>Values: `"std"=0`, `"Boost"`=1`, `"re2"=2`</td>
<td>Regular expression backend to use<br> (use integer values on the command line)<br>Values: `"std"=0`, `"Boost"=1`, `"re2"=2`</td>
</tr>

<tr>
Expand Down Expand Up @@ -279,6 +288,9 @@ scnlib configuration options
</tr>
</table>

<sup>1</sup>: As on October 2024, `std::from_chars` with floating-point values is supported on libstdc++ v11 and newer,
and MSVC 19.24 (VS 2019 16.4) or newer. libc++ doesn't provide any support yet.

Below, `ENABLE_FULL` is true, if `SCN_CI` is set in CMake, or scnlib
is built as the primary project.

Expand Down
2 changes: 1 addition & 1 deletion include/scn/fwd.h
Original file line number Diff line number Diff line change
Expand Up @@ -937,7 +937,7 @@ SCN_GCC_POP
#define SCN_FWD(x) static_cast<decltype(x)&&>(x)
#define SCN_DECLVAL(T) static_cast<T (*)()>(nullptr)()

#define SCN_BEGIN_NAMESPACE inline namespace v3 {
#define SCN_BEGIN_NAMESPACE inline namespace v4 {
#define SCN_END_NAMESPACE }

/////////////////////////////////////////////////////////////////
Expand Down
22 changes: 11 additions & 11 deletions include/scn/istream.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,16 +29,14 @@ SCN_BEGIN_NAMESPACE

namespace detail {
template <typename T, typename CharT, typename Enable = void>
struct is_streamable_impl : std::false_type {
};
struct is_streamable_impl : std::false_type {};

template <typename T, typename CharT>
struct is_streamable_impl<
T,
CharT,
std::enable_if_t<sizeof(SCN_DECLVAL(std::basic_istream<CharT>&)
<< std::declval<T>()) != 0>> : std::true_type {
};
<< std::declval<T>()) != 0>> : std::true_type {};

template <typename CharT>
struct dummy_context_for_is_streamamble {
Expand All @@ -54,8 +52,7 @@ struct is_streamable
map(SCN_DECLVAL(T&)))>,
unscannable&>,
is_streamable_impl<T, CharT>,
std::false_type> {
};
std::false_type> {};

/**
* Wraps `SourceRange`, and makes it a `std::basic_streambuf`.
Expand Down Expand Up @@ -189,16 +186,19 @@ struct basic_istream_scanner {

if (!(stream >> val)) {
if (stream.eof()) {
return unexpected_scan_error(scan_error::end_of_input, "EOF");
return detail::unexpected_scan_error(scan_error::end_of_input,
"EOF");
}
if (SCN_UNLIKELY(stream.bad())) {
return unexpected_scan_error(scan_error::invalid_source_state,
"Bad std::istream after reading");
return detail::unexpected_scan_error(
scan_error::invalid_source_state,
"Bad std::istream after reading");
}

SCN_UNLIKELY_ATTR
return unexpected_scan_error(scan_error::invalid_scanned_value,
"Failed to read with std::istream");
return detail::unexpected_scan_error(
scan_error::invalid_scanned_value,
"Failed to read with std::istream");
}

if (traits::eq_int_type(streambuf.last_char(), traits::eof())) {
Expand Down
Loading

0 comments on commit 5d4153f

Please sign in to comment.