mu-sexp: add some small conveniences
This commit is contained in:
@ -61,14 +61,25 @@ struct Sexp {
|
|||||||
* Make a node for a string/integer/symbol/list value
|
* Make a node for a string/integer/symbol/list value
|
||||||
*
|
*
|
||||||
* @param val some value
|
* @param val some value
|
||||||
|
* @param empty_is_nil turn empty string into a 'nil' symbol
|
||||||
*
|
*
|
||||||
* @return a node
|
* @return a node
|
||||||
*/
|
*/
|
||||||
static Sexp make_string(std::string&& val) { return Sexp{Type::String, std::move(val)}; }
|
static Sexp make_string(std::string&& val, bool empty_is_nil=false)
|
||||||
static Sexp make_string(const std::string& val)
|
|
||||||
{
|
{
|
||||||
|
if (empty_is_nil && val.empty())
|
||||||
|
return make_symbol("nil");
|
||||||
|
else
|
||||||
|
return Sexp{Type::String, std::move(val)};
|
||||||
|
}
|
||||||
|
static Sexp make_string(const std::string& val, bool empty_is_nil=false)
|
||||||
|
{
|
||||||
|
if (empty_is_nil && val.empty())
|
||||||
|
return make_symbol("nil");
|
||||||
|
else
|
||||||
return Sexp{Type::String, std::string(val)};
|
return Sexp{Type::String, std::string(val)};
|
||||||
}
|
}
|
||||||
|
|
||||||
static Sexp make_number(int val) { return Sexp{Type::Number, format("%d", val)}; }
|
static Sexp make_number(int val) { return Sexp{Type::Number, format("%d", val)}; }
|
||||||
static Sexp make_symbol(std::string&& val)
|
static Sexp make_symbol(std::string&& val)
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user