mirror of
https://github.com/yhirose/cpp-peglib.git
synced 2024-12-22 20:05:31 +00:00
Fix #136
This commit is contained in:
parent
1c00fa77fa
commit
9dfbbc5671
32
peglib.h
32
peglib.h
@ -22,6 +22,7 @@
|
|||||||
#include <memory>
|
#include <memory>
|
||||||
#include <mutex>
|
#include <mutex>
|
||||||
#include <set>
|
#include <set>
|
||||||
|
#include <sstream>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <unordered_map>
|
#include <unordered_map>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
@ -472,10 +473,17 @@ struct SemanticValues : protected std::vector<std::any> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
template <typename T> T token_to_number() const {
|
template <typename T> T token_to_number() const {
|
||||||
auto sv = token();
|
|
||||||
T n = 0;
|
T n = 0;
|
||||||
std::from_chars(sv.data(), sv.data() + sv.size(), n);
|
if constexpr (std::is_floating_point<T>::value) {
|
||||||
return n;
|
// TODO: The following code should be removed eventually.
|
||||||
|
std::istringstream ss(token_to_string());
|
||||||
|
ss >> n;
|
||||||
|
return n;
|
||||||
|
} else {
|
||||||
|
auto sv = token();
|
||||||
|
std::from_chars(sv.data(), sv.data() + sv.size(), n);
|
||||||
|
return n;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Transform the semantic value vector to another vector
|
// Transform the semantic value vector to another vector
|
||||||
@ -2684,8 +2692,9 @@ inline size_t PrecedenceClimbing::parse_expression(const char *s, size_t n,
|
|||||||
return i;
|
return i;
|
||||||
}
|
}
|
||||||
|
|
||||||
inline size_t Recovery::parse_core(const char *s, size_t n, SemanticValues &/*vs*/,
|
inline size_t Recovery::parse_core(const char *s, size_t n,
|
||||||
Context &c, std::any &/*dt*/) const {
|
SemanticValues & /*vs*/, Context &c,
|
||||||
|
std::any & /*dt*/) const {
|
||||||
auto save_log = c.log;
|
auto save_log = c.log;
|
||||||
c.log = nullptr;
|
c.log = nullptr;
|
||||||
|
|
||||||
@ -3683,10 +3692,17 @@ template <typename Annotation> struct AstBase : public Annotation {
|
|||||||
}
|
}
|
||||||
|
|
||||||
template <typename T> T token_to_number() const {
|
template <typename T> T token_to_number() const {
|
||||||
assert(is_token);
|
|
||||||
T n = 0;
|
T n = 0;
|
||||||
std::from_chars(token.data(), token.data() + token.size(), n);
|
if constexpr (std::is_floating_point<T>::value) {
|
||||||
return n;
|
// TODO: The following code should be removed eventually.
|
||||||
|
std::istringstream ss(token_to_string());
|
||||||
|
ss >> n;
|
||||||
|
return n;
|
||||||
|
} else {
|
||||||
|
assert(is_token);
|
||||||
|
std::from_chars(token.data(), token.data() + token.size(), n);
|
||||||
|
return n;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user