Files
mercury/extras/xml/xml.doc.m
Mark Brown d465fa53cb Update the COPYING.LIB file and references to it.
Discussion of these changes can be found on the Mercury developers
mailing list archives from June 2018.

COPYING.LIB:
    Add a special linking exception to the LGPL.

*:
    Update references to COPYING.LIB.

    Clean up some minor errors that have accumulated in copyright
    messages.
2018-06-09 17:43:12 +10:00

70 lines
1.5 KiB
Mathematica

%---------------------------------------------------------------------------%
% Copyright (C) 2000, 2011 The University of Melbourne.
% Copyright (C) 2018 The Mercury team.
% This file is distributed under the terms specified in COPYING.LIB.
%---------------------------------------------------------------------------%
%
% Main author: conway@cs.mu.oz.au.
%
%---------------------------------------------------------------------------%
:- module xml.doc.
:- interface.
:- import_module array, list, map.
:- type document
---> doc(
prestuff :: list(ref(content)),
root :: ref(content),
poststuff :: list(ref(content)),
content :: array(content)
).
:- type content
---> element(element)
; pi(string, string)
; comment(string)
; data(string)
.
:- type contentStore
---> content(
eNext :: ref(content),
eMap :: map(ref(content), content)
).
:- type element
---> element(
eName :: string,
eAttrs :: list(attribute),
eContent :: list(ref(content))
).
:- type attribute
---> attribute(
aName :: string,
aValue :: string
).
:- type ref(T) == int.
:- func ref(contentStore, ref(content)) = content.
:- pred add(content, ref(content), contentStore, contentStore).
:- mode add(in, out, in, out) is det.
:- implementation.
:- import_module int.
ref(Elems, Ref) = Elem :-
lookup(Elems^eMap, Ref, Elem).
add(Elem, Ref, Elems0, Elems) :-
Ref = Elems0^eNext,
Elems1 = Elems0^eNext := Ref + 1,
map.set(Ref, Elem, Elems1^eMap, Map),
Elems = Elems1^eMap := Map.