11 #include <unordered_map>
18 namespace expression {
28 using ParseResult = std::optional<std::unique_ptr<Expression>>;
34 Scope(
const std::map<
std::string, std::shared_ptr<Expression>>& bindings_, std::shared_ptr<Scope> parent_ =
nullptr) :
39 const std::map<std::string, std::shared_ptr<Expression>>&
bindings;
49 return std::optional<std::shared_ptr<Expression>>();
90 const std::vector<ParsingError>&
getErrors()
const {
return *errors; }
97 const std::optional<TypeAnnotationOption>& = std::nullopt);
111 std::optional<type::Type> = std::nullopt,
112 const std::optional<TypeAnnotationOption>& = std::nullopt);
119 std::optional<type::Type>,
120 const std::map<
std::string, std::shared_ptr<Expression>>&);
128 if (!scope)
return std::optional<std::shared_ptr<Expression>>();
129 return scope->get(name);
135 errors->push_back({std::move(message), key +
"[" +
util::toString(child) +
"]"});
144 errors->reserve(errors->size() + ctx.errors->size());
145 std::move(ctx.errors->begin(), ctx.errors->end(), std::inserter(*errors, errors->end()));
155 std::shared_ptr<std::vector<ParsingError>> errors_,
156 std::optional<type::Type> expected_,
157 std::shared_ptr<detail::Scope> scope_)
158 : key(
std::move(key_)),
160 scope(
std::move(scope_)),
161 errors(
std::move(errors_))
175 std::shared_ptr<detail::Scope> scope;
176 std::shared_ptr<std::vector<ParsingError>> errors;
ParsingContext(std::string key_)
ParsingContext(type::Type expected_)
std::string getKey() const
ParseResult parseExpression(const mbgl::style::conversion::Convertible &value, const std::optional< TypeAnnotationOption > &=std::nullopt)
const std::vector< ParsingError > & getErrors() const
std::optional< std::string > checkType(const type::Type &t)
std::optional< std::shared_ptr< Expression > > getBinding(const std::string &name)
void appendErrors(ParsingContext &&ctx)
ParsingContext(const ParsingContext &)=delete
ParseResult parse(const mbgl::style::conversion::Convertible &, std::size_t index, std::optional< type::Type >, const std::map< std::string, std::shared_ptr< Expression >> &)
ParsingContext(ParsingContext &&)=default
ParseResult parse(const mbgl::style::conversion::Convertible &, std::size_t, std::optional< type::Type >=std::nullopt, const std::optional< TypeAnnotationOption > &=std::nullopt)
void error(std::string message, std::size_t child)
std::string getCombinedErrors() const
ParseResult parseLayerPropertyExpression(const mbgl::style::conversion::Convertible &value)
void error(std::string message)
std::optional< type::Type > getExpected() const
void error(std::string message, std::size_t child, std::size_t grandchild)
ParsingContext & operator=(const ParsingContext &)=delete
std::optional< std::shared_ptr< Expression > > get(const std::string &name)
std::shared_ptr< Scope > parent
const std::map< std::string, std::shared_ptr< Expression > > & bindings
Scope(const std::map< std::string, std::shared_ptr< Expression >> &bindings_, std::shared_ptr< Scope > parent_=nullptr)
std::unique_ptr< Expression > string(std::unique_ptr< Expression >, std::unique_ptr< Expression > def=nullptr)
variant< NullType, NumberType, BooleanType, StringType, ColorType, ObjectType, ValueType, mapbox::util::recursive_wrapper< Array >, CollatorType, FormattedType, ErrorType, ImageType > Type
bool isExpression(const conversion::Convertible &value)
std::optional< std::unique_ptr< Expression > > ParseResult
std::string toString(const CanonicalTileID &)
nonstd::expected< T, E > expected
bool operator==(const ParsingError &rhs) const