Files
mbs/examples/main.cpp
Allan K. Koech 9a30408129 fix: correct scientific notation lexing, &&/|| return type, and Expr::kind init
- B1: malformed scientific notation (1e+, 1e-) no longer silently eats
  the following operator
- B2: && and || now consistently return booleans on every path (C-style
  semantics), instead of leaking the raw operand on the non-short-circuit
  path
- B3: example main.cpp passes the populated context instead of an empty
  object
- B4: give Expr::kind a default initializer to avoid reading an
  uninitialized enum
2026-08-20 14:00:19 +03:00

23 lines
661 B
C++

#include <iostream>
#include <mbs/script.hpp>
#include <nlohmann/json.hpp>
using mbs::EvalErr;
using mbs::EvalOk;
using mbs::eval_true;
using mbs::eval_val;
using mbs::test;
using nlohmann::json;
int main() {
const std::string src = "1+1+@pi";
json ctx = json::object();
ctx["pi"] = 3.14;
const auto r = eval_val(src, ctx);
std::cout << "Res: " << std::holds_alternative<EvalOk>(r) << std::endl;
std::cout << "Res: " << std::get<EvalOk>(r).value << std::endl;
std::cout << "@pi = " << std::get<EvalOk>(eval_val("@pi", ctx)).value << std::endl;
std::cout << "@pi = " << eval_true("@pi", ctx).value << std::endl;
return 0;
}