bromlife - O Markup Language parser library in C
License
Copyright (C) 2026 gemmaro
This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License along with this program. If not, see <https://www.gnu.org/licenses/>.
Commentary
"Things" in this library, such as
macros, types, functions, and constants are prefixed by OML_ or
oml_, except for the BROMLIFE_H macro, which indicates this
header has been already included before. Note that this document
doen't explain all such things, only the public ones.
This library requires stddef.h and stdint.h. If it is
used by C++, stdbool.h is required. No other headers are
necessary.
OML_VERSION, OML_VERSION_MAJOR, OML_VERSION_MINOR,
OML_VERSION_PATCH are int macros. The versioning scheme is
based on the semantic versioning, that is, the backward
incompatible public API changes cause the minor (or major, some
day) version incremented.
OML_STATIC_BUILD and OML_LIBRARY_BUILD macros are
available for MSVC. Please note that the support is still
experimental.
This is for getting the bromlife version of
the shared object file. The returned value and OML_VERSION can
be different in some cases.
static inline int
oml_version (void)
{
return OML_VERSION;
}If OML_NESTING is defined in advance, the value is used. It
should be 32 or larger, according to the specification. This is 32
of type int by default.
This creates a parser. The bytes is a input string content,
and the len is the input length in bytes. The input content
should be encoded in UTF-8. Any ASCII based encoding might be
used, but not supported.
OML_PUBLIC struct oml_parser oml_parser (const OML_CHAR *bytes, size_t len);This gets a next event, which is roughly a token in the parser context.
OML_PUBLIC struct oml_event oml_next (struct oml_parser *);These functions are for checking its type. Especially "empty" means that there are no more events.
static inline OML_BOOL
oml_event_is_null (struct oml_event e)
{
return e.type == OML_EVENT_NULL;
}
static inline OML_BOOL
oml_event_is_left (struct oml_event e)
{
return e.type == OML_EVENT_LEFT;
}
static inline OML_BOOL
oml_event_is_right (struct oml_event e)
{
return e.type == OML_EVENT_RIGHT;
}
static inline OML_BOOL
oml_event_is_body (struct oml_event e)
{
return e.type == OML_EVENT_BODY;
}
static inline OML_BOOL
oml_event_is_empty (struct oml_event e)
{
return e.type == OML_EVENT_EMPTY;
}These functions are for checking its role. "null" can be either of "normal" or "ignored". "body" can be either of "normal", "ignored", or "label". "left" and "right" can be either of "normal", "ignored", "vocab", "word", or "label".
static inline OML_BOOL
oml_event_is_normal (struct oml_event e)
{
return e.role == OML_ROLE_NORMAL;
}
static inline OML_BOOL
oml_event_is_ignored (struct oml_event e)
{
return e.role == OML_ROLE_IGNORED;
}
static inline OML_BOOL
oml_event_is_vocab (struct oml_event e)
{
return e.role == OML_ROLE_VOCAB;
}
static inline OML_BOOL
oml_event_is_word (struct oml_event e)
{
return e.role == OML_ROLE_WORD;
}
static inline OML_BOOL
oml_event_is_label (struct oml_event e)
{
return e.role == OML_ROLE_LABEL;
}Every events have its length and its offset, except for the "empty" events. These can be used with the input bytes to extract the span of the event.
static inline size_t
oml_event_len (struct oml_event e)
{
return e.len;
}
static inline size_t
oml_event_offset (struct oml_event e)
{
return e.offset;
}These functions are available for the "normal left" or "normal right" events.
static inline size_t
oml_event_label_len (struct oml_event e)
{
return e.label.len;
}
static inline size_t
oml_event_label_offset (struct oml_event e)
{
return e.label.offset;
}