mirror of
https://github.com/ChaiScript/ChaiScript.git
synced 2026-02-07 10:19:57 +08:00
Fix parsing of operators
* Only parse valid operators * Don't swallow a symbol if it would produce an invalid operator Closes #198
This commit is contained in:
parent
9d17b18f26
commit
0c4951d742
@ -1222,6 +1222,16 @@ namespace chaiscript
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool is_operator(const std::string &t_s) const {
|
||||||
|
return std::any_of(m_operator_matches.begin(), m_operator_matches.end(),
|
||||||
|
[t_s](const std::vector<std::string> &opers) {
|
||||||
|
return std::any_of(opers.begin(), opers.end(),
|
||||||
|
[t_s](const std::string &s) {
|
||||||
|
return s == t_s;
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
/// Reads (and potentially captures) a symbol group from input if it matches the parameter
|
/// Reads (and potentially captures) a symbol group from input if it matches the parameter
|
||||||
bool Symbol(const char *t_s, const bool t_capture = false, const bool t_disallow_prevention=false) {
|
bool Symbol(const char *t_s, const bool t_capture = false, const bool t_disallow_prevention=false) {
|
||||||
SkipWS();
|
SkipWS();
|
||||||
@ -1230,8 +1240,12 @@ namespace chaiscript
|
|||||||
|
|
||||||
// ignore substring matches
|
// ignore substring matches
|
||||||
if (retval && m_position.has_more() && (t_disallow_prevention == false) && char_in_alphabet(*m_position,detail::symbol_alphabet)) {
|
if (retval && m_position.has_more() && (t_disallow_prevention == false) && char_in_alphabet(*m_position,detail::symbol_alphabet)) {
|
||||||
m_position = start;
|
if (*m_position != '=' && is_operator(Position::str(start, m_position)) && !is_operator(Position::str(start, m_position+1))) {
|
||||||
retval = false;
|
// don't throw this away, it's a good match and the next is not
|
||||||
|
} else {
|
||||||
|
m_position = start;
|
||||||
|
retval = false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( t_capture && retval ) {
|
if ( t_capture && retval ) {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user