";" input does not raise an error anymore. Missing '=' precedanse
This commit is contained in:
parent
cb13dc9591
commit
98a88c3acc
4
examples/common-array-operations.mq
Normal file
4
examples/common-array-operations.mq
Normal file
@ -0,0 +1,4 @@
|
||||
var map = [fn array | var result = []; for array [v | result = result & [fn v] ]; result];
|
||||
var drop = [n arr | arr.(range n (len arr))];
|
||||
var take = [n arr | arr.(up n)];
|
||||
var filter = [predicate arr | arr.(map predicate arr)];
|
@ -206,13 +206,9 @@ static Result<Value> multiplication_operator(Interpreter &i, std::vector<Value>
|
||||
|
||||
using Operator_Entry = std::tuple<char const*, Intrinsic>;
|
||||
|
||||
struct pow_operator
|
||||
{
|
||||
inline Result<Number> operator()(Number lhs, Number rhs)
|
||||
{
|
||||
using power = decltype([](Number lhs, Number rhs) -> Result<Number> {
|
||||
return lhs.pow(rhs);
|
||||
}
|
||||
};
|
||||
});
|
||||
|
||||
/// Operators definition table
|
||||
static constexpr auto Operators = std::array {
|
||||
@ -221,7 +217,7 @@ static constexpr auto Operators = std::array {
|
||||
Operator_Entry { "*", multiplication_operator },
|
||||
Operator_Entry { "/", binary_operator<std::divides<>, '/'> },
|
||||
Operator_Entry { "%", binary_operator<std::modulus<>, '%'> },
|
||||
Operator_Entry { "**", binary_operator<pow_operator, '*', '*'> },
|
||||
Operator_Entry { "**", binary_operator<power, '*', '*'> },
|
||||
|
||||
Operator_Entry { "!=", comparison_operator<std::not_equal_to<>> },
|
||||
Operator_Entry { "<", comparison_operator<std::less<>> },
|
||||
|
@ -379,8 +379,15 @@ static Result<std::vector<Ast>> parse_many(
|
||||
std::vector<Ast> trees;
|
||||
Result<Ast> expr;
|
||||
|
||||
if (at_least == At_Least::Zero && p.token_id >= p.tokens.size())
|
||||
// Consume random separators laying before sequence. This was added to prevent
|
||||
// an error when input is only expression separator ";"
|
||||
while (separator && at_least == At_Least::Zero && p.expect(*separator)) {
|
||||
p.consume();
|
||||
}
|
||||
|
||||
if (at_least == At_Least::Zero && p.token_id >= p.tokens.size()) {
|
||||
return {};
|
||||
}
|
||||
|
||||
while ((expr = (p.*parser)()).has_value()) {
|
||||
trees.push_back(std::move(expr).value());
|
||||
@ -524,6 +531,7 @@ static usize precedense(std::string_view op)
|
||||
// Exclusion of them is marked by subtracting total number of excluded operators.
|
||||
static_assert(Operators_Count - 1 == 15, "Ensure that all operators have defined precedense below");
|
||||
|
||||
if (one_of(op, "=")) return 0;
|
||||
if (one_of(op, "or")) return 100;
|
||||
if (one_of(op, "and")) return 150;
|
||||
if (one_of(op, "<", ">", "<=", ">=", "==", "!=")) return 200;
|
||||
|
Loading…
Reference in New Issue
Block a user