58 lines
1.5 KiB
C
58 lines
1.5 KiB
C
#include <mie/attribute/attribute-definition.h>
|
|
#include <mie/attribute/attribute.h>
|
|
#include <mie/ctx.h>
|
|
#include <mie/dialect/builtin.h>
|
|
#include <mie/macros.h>
|
|
#include <mie/parse/parser.h>
|
|
#include <mie/print/printer.h>
|
|
|
|
static enum mie_status print(
|
|
const struct mie_attribute *value, struct mie_printer *out)
|
|
{
|
|
const struct mie_string *str = (const struct mie_string *)value;
|
|
if (out->p_flags & MIE_PRINT_F_ABBREVIATED) {
|
|
b_stream_write_fmt(out->p_stream, NULL, "\"%s\"", str->str_val);
|
|
} else {
|
|
b_stream_write_fmt(
|
|
out->p_stream, NULL, "#builtin.string<\"%s\">",
|
|
str->str_val);
|
|
}
|
|
return MIE_SUCCESS;
|
|
}
|
|
|
|
static enum mie_status parse(
|
|
struct mie_parser *ctx, const struct mie_attribute **out)
|
|
{
|
|
b_string *str = mie_parser_get_tempstr(ctx);
|
|
struct mie_file_span span;
|
|
if (!mie_parser_parse_string(ctx, str, &span)) {
|
|
return MIE_ERR_BAD_SYNTAX;
|
|
}
|
|
|
|
struct mie_attribute *v = mie_ctx_get_string(
|
|
mie_parser_get_mie_ctx(ctx), b_string_ptr(str));
|
|
|
|
if (!v) {
|
|
return MIE_ERR_NO_MEMORY;
|
|
}
|
|
|
|
*out = v;
|
|
return MIE_SUCCESS;
|
|
}
|
|
|
|
const char *mie_string_get_cstr(const struct mie_attribute *attrib)
|
|
{
|
|
if (!mie_attribute_check_name(attrib, "builtin", "string")) {
|
|
return NULL;
|
|
}
|
|
|
|
const struct mie_string *str = (const struct mie_string *)attrib;
|
|
return str->str_val;
|
|
}
|
|
|
|
MIE_ATTRIBUTE_DEFINITION_BEGIN(mie_builtin_string, "string")
|
|
MIE_ATTRIBUTE_DEFINITION_STRUCT(struct mie_string);
|
|
MIE_ATTRIBUTE_DEFINITION_PRINT(print);
|
|
MIE_ATTRIBUTE_DEFINITION_PARSE(parse);
|
|
MIE_ATTRIBUTE_DEFINITION_END();
|