| Copyright | Will Thompson and Iñaki García Etxebarria |
|---|---|
| License | LGPL-2.1 |
| Maintainer | Iñaki García Etxebarria |
| Safe Haskell | None |
| Language | Haskell2010 |
GI.GLib.Structs.MarkupParseContext
Description
A parse context is used to parse a stream of bytes that you expect to contain marked-up text.
See markupParseContextNew, MarkupParser, and so
on for more details.
Synopsis
- newtype MarkupParseContext = MarkupParseContext (ManagedPtr MarkupParseContext)
- type family ResolveMarkupParseContextMethod (t :: Symbol) o where ...
- data MarkupParseContextEndParseMethodInfo
- markupParseContextEndParse :: (HasCallStack, MonadIO m) => MarkupParseContext -> m ()
- data MarkupParseContextFreeMethodInfo
- markupParseContextFree :: (HasCallStack, MonadIO m) => MarkupParseContext -> m ()
- data MarkupParseContextGetAttributePositionMethodInfo
- markupParseContextGetAttributePosition :: (HasCallStack, MonadIO m) => MarkupParseContext -> Word32 -> m (CSize, CSize, CSize, CSize, CSize, CSize)
- data MarkupParseContextGetElementMethodInfo
- markupParseContextGetElement :: (HasCallStack, MonadIO m) => MarkupParseContext -> m Text
- data MarkupParseContextGetElementStackMethodInfo
- markupParseContextGetElementStack :: (HasCallStack, MonadIO m) => MarkupParseContext -> m [Text]
- data MarkupParseContextGetOffsetMethodInfo
- markupParseContextGetOffset :: (HasCallStack, MonadIO m) => MarkupParseContext -> m CSize
- data MarkupParseContextGetPositionMethodInfo
- markupParseContextGetPosition :: (HasCallStack, MonadIO m) => MarkupParseContext -> m (Int32, Int32)
- data MarkupParseContextGetTagStartMethodInfo
- markupParseContextGetTagStart :: (HasCallStack, MonadIO m) => MarkupParseContext -> m (CSize, CSize, CSize)
- data MarkupParseContextGetUserDataMethodInfo
- markupParseContextGetUserData :: (HasCallStack, MonadIO m) => MarkupParseContext -> m (Ptr ())
- markupParseContextNew :: (HasCallStack, MonadIO m) => MarkupParser -> [MarkupParseFlags] -> Ptr () -> DestroyNotify -> m MarkupParseContext
- data MarkupParseContextParseMethodInfo
- markupParseContextParse :: (HasCallStack, MonadIO m) => MarkupParseContext -> Text -> Int64 -> m ()
- data MarkupParseContextPopMethodInfo
- markupParseContextPop :: (HasCallStack, MonadIO m) => MarkupParseContext -> m (Ptr ())
- data MarkupParseContextPushMethodInfo
- markupParseContextPush :: (HasCallStack, MonadIO m) => MarkupParseContext -> MarkupParser -> Ptr () -> m ()
- data MarkupParseContextRefMethodInfo
- markupParseContextRef :: (HasCallStack, MonadIO m) => MarkupParseContext -> m MarkupParseContext
- data MarkupParseContextUnrefMethodInfo
- markupParseContextUnref :: (HasCallStack, MonadIO m) => MarkupParseContext -> m ()
Exported types
newtype MarkupParseContext Source #
Memory-managed wrapper type.
Constructors
| MarkupParseContext (ManagedPtr MarkupParseContext) |
Instances
Methods
Click to display all available methods, including inherited ones
Methods
endParse, free, parse, pop, push, ref, unref.
Getters
getAttributePosition, getElement, getElementStack, getOffset, getPosition, getTagStart, getUserData.
Setters
None.
type family ResolveMarkupParseContextMethod (t :: Symbol) o where ... Source #
Equations
endParse
data MarkupParseContextEndParseMethodInfo Source #
Instances
| (signature ~ m (), MonadIO m) => OverloadedMethod MarkupParseContextEndParseMethodInfo MarkupParseContext signature Source # | |
Defined in GI.GLib.Structs.MarkupParseContext Methods overloadedMethod :: MarkupParseContext -> signature # | |
| OverloadedMethodInfo MarkupParseContextEndParseMethodInfo MarkupParseContext Source # | |
Defined in GI.GLib.Structs.MarkupParseContext Methods | |
markupParseContextEndParse Source #
Arguments
| :: (HasCallStack, MonadIO m) | |
| => MarkupParseContext |
|
| -> m () | (Can throw |
Signals to the MarkupParseContext that all data has been
fed into the parse context with markupParseContextParse.
This function reports an error if the document isn't complete, for example if elements are still open.
free
data MarkupParseContextFreeMethodInfo Source #
Instances
| (signature ~ m (), MonadIO m) => OverloadedMethod MarkupParseContextFreeMethodInfo MarkupParseContext signature Source # | |
Defined in GI.GLib.Structs.MarkupParseContext Methods overloadedMethod :: MarkupParseContext -> signature # | |
| OverloadedMethodInfo MarkupParseContextFreeMethodInfo MarkupParseContext Source # | |
Defined in GI.GLib.Structs.MarkupParseContext Methods | |
markupParseContextFree Source #
Arguments
| :: (HasCallStack, MonadIO m) | |
| => MarkupParseContext |
|
| -> m () |
Frees a MarkupParseContext.
This function can't be called from inside one of the
MarkupParser functions or while a subparser is pushed.
getAttributePosition
data MarkupParseContextGetAttributePositionMethodInfo Source #
Instances
| (signature ~ (Word32 -> m (CSize, CSize, CSize, CSize, CSize, CSize)), MonadIO m) => OverloadedMethod MarkupParseContextGetAttributePositionMethodInfo MarkupParseContext signature Source # | |
Defined in GI.GLib.Structs.MarkupParseContext Methods overloadedMethod :: MarkupParseContext -> signature # | |
| OverloadedMethodInfo MarkupParseContextGetAttributePositionMethodInfo MarkupParseContext Source # | |
Defined in GI.GLib.Structs.MarkupParseContext Methods | |
markupParseContextGetAttributePosition Source #
Arguments
| :: (HasCallStack, MonadIO m) | |
| => MarkupParseContext |
|
| -> Word32 |
|
| -> m (CSize, CSize, CSize, CSize, CSize, CSize) |
Retrieves the start and end positions of an attribute assignment in a start tag.
This function can be used in the start_element callback to
obtain location information for error reporting.
Calling it outside of the start_element callback
has undefined results.
Note that lineNumber and charNumber are intended for human
readable error messages and are therefore 1-based and in Unicode
characters. offset on the other hand is meant for programmatic
use, and thus is 0-based and in bytes.
The information is meant to accompany the values returned by
markupParseContextGetPosition, and comes with the
same accuracy guarantees.
Since: 2.90
getElement
data MarkupParseContextGetElementMethodInfo Source #
Instances
| (signature ~ m Text, MonadIO m) => OverloadedMethod MarkupParseContextGetElementMethodInfo MarkupParseContext signature Source # | |
Defined in GI.GLib.Structs.MarkupParseContext Methods overloadedMethod :: MarkupParseContext -> signature # | |
| OverloadedMethodInfo MarkupParseContextGetElementMethodInfo MarkupParseContext Source # | |
Defined in GI.GLib.Structs.MarkupParseContext Methods | |
markupParseContextGetElement Source #
Arguments
| :: (HasCallStack, MonadIO m) | |
| => MarkupParseContext |
|
| -> m Text | Returns: the name of the currently open element, or |
Retrieves the name of the currently open element.
If called from the start_element or end_element handlers this will
give the element_name as passed to those functions. For the parent
elements, see markupParseContextGetElementStack.
Since: 2.2
getElementStack
data MarkupParseContextGetElementStackMethodInfo Source #
Instances
| (signature ~ m [Text], MonadIO m) => OverloadedMethod MarkupParseContextGetElementStackMethodInfo MarkupParseContext signature Source # | |
Defined in GI.GLib.Structs.MarkupParseContext Methods overloadedMethod :: MarkupParseContext -> signature # | |
| OverloadedMethodInfo MarkupParseContextGetElementStackMethodInfo MarkupParseContext Source # | |
Defined in GI.GLib.Structs.MarkupParseContext Methods | |
markupParseContextGetElementStack Source #
Arguments
| :: (HasCallStack, MonadIO m) | |
| => MarkupParseContext |
|
| -> m [Text] | Returns: the element stack, which must not be modified |
Retrieves the element stack from the internal state of the parser.
The returned SList is a list of strings where the first item is
the currently open tag (as would be returned by
markupParseContextGetElement) and the next item is its
immediate parent.
This function is intended to be used in the start_element and
end_element handlers where markupParseContextGetElement
would merely return the name of the element that is being
processed.
Since: 2.16
getOffset
data MarkupParseContextGetOffsetMethodInfo Source #
Instances
| (signature ~ m CSize, MonadIO m) => OverloadedMethod MarkupParseContextGetOffsetMethodInfo MarkupParseContext signature Source # | |
Defined in GI.GLib.Structs.MarkupParseContext Methods overloadedMethod :: MarkupParseContext -> signature # | |
| OverloadedMethodInfo MarkupParseContextGetOffsetMethodInfo MarkupParseContext Source # | |
Defined in GI.GLib.Structs.MarkupParseContext Methods | |
markupParseContextGetOffset Source #
Arguments
| :: (HasCallStack, MonadIO m) | |
| => MarkupParseContext |
|
| -> m CSize | Returns: the offset |
Retrieves the current offset from the beginning of the document, in bytes.
The information is meant to accompany the values returned by
markupParseContextGetPosition, and comes with the
same accuracy guarantees.
Since: 2.88
getPosition
data MarkupParseContextGetPositionMethodInfo Source #
Instances
| (signature ~ m (Int32, Int32), MonadIO m) => OverloadedMethod MarkupParseContextGetPositionMethodInfo MarkupParseContext signature Source # | |
Defined in GI.GLib.Structs.MarkupParseContext Methods overloadedMethod :: MarkupParseContext -> signature # | |
| OverloadedMethodInfo MarkupParseContextGetPositionMethodInfo MarkupParseContext Source # | |
Defined in GI.GLib.Structs.MarkupParseContext Methods | |
markupParseContextGetPosition Source #
Arguments
| :: (HasCallStack, MonadIO m) | |
| => MarkupParseContext |
|
| -> m (Int32, Int32) |
Retrieves the current line number and the number of the character on that line. Intended for use in error messages; there are no strict semantics for what constitutes the "current" line number other than "the best number we could come up with for error messages."
getTagStart
data MarkupParseContextGetTagStartMethodInfo Source #
Instances
| (signature ~ m (CSize, CSize, CSize), MonadIO m) => OverloadedMethod MarkupParseContextGetTagStartMethodInfo MarkupParseContext signature Source # | |
Defined in GI.GLib.Structs.MarkupParseContext Methods overloadedMethod :: MarkupParseContext -> signature # | |
| OverloadedMethodInfo MarkupParseContextGetTagStartMethodInfo MarkupParseContext Source # | |
Defined in GI.GLib.Structs.MarkupParseContext Methods | |
markupParseContextGetTagStart Source #
Arguments
| :: (HasCallStack, MonadIO m) | |
| => MarkupParseContext |
|
| -> m (CSize, CSize, CSize) |
Retrieves the start position of the current start or end tag.
This function can be used in the start_element or end_element
callbacks to obtain location information for error reporting.
Calling it outside of these callbacks has undefined results.
Note that lineNumber and charNumber are intended for human
readable error messages and are therefore 1-based and in Unicode
characters. offset on the other hand is meant for programmatic
use, and thus is 0-based and in bytes.
The information is meant to accompany the values returned by
markupParseContextGetPosition, and comes with the
same accuracy guarantees.
Since: 2.88
getUserData
data MarkupParseContextGetUserDataMethodInfo Source #
Instances
| (signature ~ m (Ptr ()), MonadIO m) => OverloadedMethod MarkupParseContextGetUserDataMethodInfo MarkupParseContext signature Source # | |
Defined in GI.GLib.Structs.MarkupParseContext Methods overloadedMethod :: MarkupParseContext -> signature # | |
| OverloadedMethodInfo MarkupParseContextGetUserDataMethodInfo MarkupParseContext Source # | |
Defined in GI.GLib.Structs.MarkupParseContext Methods | |
markupParseContextGetUserData Source #
Arguments
| :: (HasCallStack, MonadIO m) | |
| => MarkupParseContext |
|
| -> m (Ptr ()) | Returns: the provided user_data. The returned data belongs to
the markup context and will be freed when
|
Returns the user_data associated with context.
This will either be the user_data that was provided to
markupParseContextNew or to the most recent call
of markupParseContextPush.
Since: 2.18
new
markupParseContextNew Source #
Arguments
| :: (HasCallStack, MonadIO m) | |
| => MarkupParser |
|
| -> [MarkupParseFlags] |
|
| -> Ptr () |
|
| -> DestroyNotify |
|
| -> m MarkupParseContext | Returns: a new |
Creates a new parse context. A parse context is used to parse marked-up documents. You can feed any number of documents into a context, as long as no errors occur; once an error occurs, the parse context can't continue to parse text (you have to free it and create a new parse context).
parse
data MarkupParseContextParseMethodInfo Source #
Instances
| (signature ~ (Text -> Int64 -> m ()), MonadIO m) => OverloadedMethod MarkupParseContextParseMethodInfo MarkupParseContext signature Source # | |
Defined in GI.GLib.Structs.MarkupParseContext Methods overloadedMethod :: MarkupParseContext -> signature # | |
| OverloadedMethodInfo MarkupParseContextParseMethodInfo MarkupParseContext Source # | |
Defined in GI.GLib.Structs.MarkupParseContext Methods | |
markupParseContextParse Source #
Arguments
| :: (HasCallStack, MonadIO m) | |
| => MarkupParseContext |
|
| -> Text |
|
| -> Int64 |
|
| -> m () | (Can throw |
Feed some data to the MarkupParseContext.
The data need not be valid UTF-8; an error will be signaled if
it's invalid. The data need not be an entire document; you can
feed a document into the parser incrementally, via multiple calls
to this function. Typically, as you receive data from a network
connection or file, you feed each received chunk of data into this
function, aborting the process if an error occurs. Once an error
is reported, no further data may be fed to the MarkupParseContext;
all errors are fatal.
pop
data MarkupParseContextPopMethodInfo Source #
Instances
| (signature ~ m (Ptr ()), MonadIO m) => OverloadedMethod MarkupParseContextPopMethodInfo MarkupParseContext signature Source # | |
Defined in GI.GLib.Structs.MarkupParseContext Methods overloadedMethod :: MarkupParseContext -> signature # | |
| OverloadedMethodInfo MarkupParseContextPopMethodInfo MarkupParseContext Source # | |
Defined in GI.GLib.Structs.MarkupParseContext Methods | |
markupParseContextPop Source #
Arguments
| :: (HasCallStack, MonadIO m) | |
| => MarkupParseContext |
|
| -> m (Ptr ()) | Returns: the user data passed to |
Completes the process of a temporary sub-parser redirection.
This function exists to collect the user_data allocated by a
matching call to markupParseContextPush. It must be called
in the end_element handler corresponding to the start_element
handler during which markupParseContextPush was called.
You must not call this function from the error callback -- the
userData is provided directly to the callback in that case.
This function is not intended to be directly called by users interested in invoking subparsers. Instead, it is intended to be used by the subparsers themselves to implement a higher-level interface.
Since: 2.18
push
data MarkupParseContextPushMethodInfo Source #
Instances
| (signature ~ (MarkupParser -> Ptr () -> m ()), MonadIO m) => OverloadedMethod MarkupParseContextPushMethodInfo MarkupParseContext signature Source # | |
Defined in GI.GLib.Structs.MarkupParseContext Methods overloadedMethod :: MarkupParseContext -> signature # | |
| OverloadedMethodInfo MarkupParseContextPushMethodInfo MarkupParseContext Source # | |
Defined in GI.GLib.Structs.MarkupParseContext Methods | |
markupParseContextPush Source #
Arguments
| :: (HasCallStack, MonadIO m) | |
| => MarkupParseContext |
|
| -> MarkupParser |
|
| -> Ptr () |
|
| -> m () |
Temporarily redirects markup data to a sub-parser.
This function may only be called from the start_element handler of
a MarkupParser. It must be matched with a corresponding call to
markupParseContextPop in the matching end_element handler
(except in the case that the parser aborts due to an error).
All tags, text and other data between the matching tags is
redirected to the subparser given by parser. userData is used
as the user_data for that parser. userData is also passed to the
error callback in the event that an error occurs. This includes
errors that occur in subparsers of the subparser.
The end tag matching the start tag for which this call was made is
handled by the previous parser (which is given its own user_data)
which is why markupParseContextPop is provided to allow "one
last access" to the userData provided to this function. In the
case of error, the userData provided here is passed directly to
the error callback of the subparser and markupParseContextPop
should not be called. In either case, if userData was allocated
then it ought to be freed from both of these locations.
This function is not intended to be directly called by users interested in invoking subparsers. Instead, it is intended to be used by the subparsers themselves to implement a higher-level interface.
As an example, see the following implementation of a simple parser that counts the number of tags encountered.
C code
typedef struct
{
gint tag_count;
} CounterData;
static void
counter_start_element (GMarkupParseContext *context,
const gchar *element_name,
const gchar **attribute_names,
const gchar **attribute_values,
gpointer user_data,
GError **error)
{
CounterData *data = user_data;
data->tag_count++;
}
static void
counter_error (GMarkupParseContext *context,
GError *error,
gpointer user_data)
{
CounterData *data = user_data;
g_slice_free (CounterData, data);
}
static GMarkupParser counter_subparser =
{
counter_start_element,
NULL,
NULL,
NULL,
counter_error
};In order to allow this parser to be easily used as a subparser, the following interface is provided:
C code
void
start_counting (GMarkupParseContext *context)
{
CounterData *data = g_slice_new (CounterData);
data->tag_count = 0;
g_markup_parse_context_push (context, &counter_subparser, data);
}
gint
end_counting (GMarkupParseContext *context)
{
CounterData *data = g_markup_parse_context_pop (context);
int result;
result = data->tag_count;
g_slice_free (CounterData, data);
return result;
}The subparser would then be used as follows:
C code
static void start_element (context, element_name, ...)
{
if (strcmp (element_name, "count-these") == 0)
start_counting (context);
// else, handle other tags...
}
static void end_element (context, element_name, ...)
{
if (strcmp (element_name, "count-these") == 0)
g_print ("Counted %d tags\n", end_counting (context));
// else, handle other tags...
}Since: 2.18
ref
data MarkupParseContextRefMethodInfo Source #
Instances
| (signature ~ m MarkupParseContext, MonadIO m) => OverloadedMethod MarkupParseContextRefMethodInfo MarkupParseContext signature Source # | |
Defined in GI.GLib.Structs.MarkupParseContext Methods overloadedMethod :: MarkupParseContext -> signature # | |
| OverloadedMethodInfo MarkupParseContextRefMethodInfo MarkupParseContext Source # | |
Defined in GI.GLib.Structs.MarkupParseContext Methods | |
markupParseContextRef Source #
Arguments
| :: (HasCallStack, MonadIO m) | |
| => MarkupParseContext |
|
| -> m MarkupParseContext | Returns: the same |
Increases the reference count of context.
Since: 2.36
unref
data MarkupParseContextUnrefMethodInfo Source #
Instances
| (signature ~ m (), MonadIO m) => OverloadedMethod MarkupParseContextUnrefMethodInfo MarkupParseContext signature Source # | |
Defined in GI.GLib.Structs.MarkupParseContext Methods overloadedMethod :: MarkupParseContext -> signature # | |
| OverloadedMethodInfo MarkupParseContextUnrefMethodInfo MarkupParseContext Source # | |
Defined in GI.GLib.Structs.MarkupParseContext Methods | |
markupParseContextUnref Source #
Arguments
| :: (HasCallStack, MonadIO m) | |
| => MarkupParseContext |
|
| -> m () |
Decreases the reference count of context. When its reference count
drops to 0, it is freed.
Since: 2.36