moonrockz/xaml/nodes does not have a README file

    XamlReader

    pub(open) trait XamlReader {
    fn read(Self) -> Bool
    fn node(Self) -> XamlNode?
    fn diagnostics(Self) -> ReadOnlyArray[Diagnostic]
    fn source_span(Self) -> SourceSpan? = _
    }

    A pull source of a XAML node stream, in the style of System.Xaml XamlReader (design D4).

    read advances to the next node and returns false at the end of the stream. Once it returns false it keeps returning false and the diagnostics no longer change. node is the current node and source_span its range in the source text, as System.Xaml IXamlLineInfo gives it: both are None before the first read and after the end, and a reader without line information keeps the default source_span, which is None. Spans are not part of node values.

    XamlWriter

    pub(open) trait XamlWriter {
    fn write_node(Self, XamlNode) -> Unit raise XamlWriteError
    fn close(Self) -> Unit raise XamlWriteError
    fn set_source_span(Self, SourceSpan?) -> Unit = _
    }

    A sink for a XAML node stream, in the style of System.Xaml XamlWriter.

    set_source_span sets the range of the nodes that follow, as System.Xaml IXamlLineInfoConsumer does; None clears it, and errors carry the range active at the failing node. The default ignores spans. A writer reports an unbalanced stream from write_node as soon as a node cannot follow the nodes before it. close ends the stream: it completes the members and objects still open, innermost first, as System.Xaml XamlObjectWriter does when disposed (design D8). A writer that reports an error produces no result, even when later nodes would balance the stream.

    TypeNameError

    pub(all) suberror TypeNameError {
    MalformedTypeName(text~ : String, offset~ : Int, message~ : String)
    UnknownTypeNamePrefix(text~ : String, prefix~ : String)
    ArrayTypeName(text~ : String)
    NoPrefixForNamespace(namespace_uri~ : String)
    } derive(Eq,
    Debug
    )

    Why a type name cannot be parsed from text or formatted as text.

    TypeNameError::message

    fn TypeNameError::message(self : TypeNameError) -> String

    A description of the error for people.

    XamlWriteError

    pub(all) suberror XamlWriteError {
    UnbalancedStream(reason~ : UnbalancedReason, node~ : XamlNode?, index~ : Int, span~ : SourceSpan?)
    InvalidNode(node~ : XamlNode, index~ : Int, message~ : String, span~ : SourceSpan?)
    ReaderFailed(diagnostics~ : ReadOnlyArray[Diagnostic])
    } derive(Eq,
    Debug
    )

    An error that a XAML writer reports.

    XamlWriteError::message

    fn XamlWriteError::message(self : XamlWriteError) -> String

    A description of the error for people.

    Diagnostic

    pub(all) struct Diagnostic {
    severity : Severity
    code : String
    message : String
    span : SourceSpan?
    } derive(Eq,
    Debug
    )

    A problem that a reader found. code is a stable identifier, such as xml-malformed or unknown-type; message is for people.

    Diagnostic::error

    fn Diagnostic::error(code : String, message : String, span? : SourceSpan) -> Diagnostic

    Diagnostic::is_error

    fn Diagnostic::is_error(self : Diagnostic) -> Bool

    Diagnostic::warning

    fn Diagnostic::warning(code : String, message : String, span? : SourceSpan) -> Diagnostic

    MemberRule

    pub(all) struct MemberRule {
    identity : XamlMemberName
    values : ValueCardinality
    } derive(Eq,
    Debug
    )

    What a writer knows about the member that a start member names (design D8, 2F17).

    Two start members of one object with the same identity assign one member twice. A schema-backed writer gives the resolved member's name as the identity, so Member(Button,Content) and Member(ContentControl, Content) are one member when Button inherits Content, and gives the name itself for a name that resolves to nothing.

    NodeListReader

    pub struct NodeListReader {
    // private fields
    }

    A reader over a fixed list of nodes, with optional source spans. It reports no diagnostics.

    NodeListReader::diagnostics

    fn NodeListReader::diagnostics(_self : NodeListReader) -> ReadOnlyArray[Diagnostic]

    NodeListReader::new

    A reader over nodes, which gives no spans.

    NodeListReader::node

    NodeListReader::read

    fn NodeListReader::read(self : NodeListReader) -> Bool

    NodeListReader::source_span

    fn NodeListReader::source_span(self : NodeListReader) -> SourceSpan?

    NodeListReader::with_spans

    A reader over nodes each with its source span, such as a text reader gives.

    NodeListWriter

    pub struct NodeListWriter {
    // private fields
    }

    A writer that checks that a stream is balanced and keeps its nodes.

    NodeListWriter::close

    fn NodeListWriter::close(self : NodeListWriter) -> Unit raise XamlWriteError

    Complete the open members and objects, innermost first, and end the stream.

    NodeListWriter::new

    NodeListWriter::nodes

    fn NodeListWriter::nodes(self : NodeListWriter) -> ReadOnlyArray[XamlNode]?

    The nodes of the stream once close has succeeded and no error was reported, else None.

    NodeListWriter::set_source_span

    fn NodeListWriter::set_source_span(_self : NodeListWriter, _span : SourceSpan?) -> Unit

    NodeListWriter::write_node

    fn NodeListWriter::write_node(self : NodeListWriter, node : XamlNode) -> Unit raise XamlWriteError

    NodeStreamValidator

    pub struct NodeStreamValidator {
    // private fields
    }

    The balance rules of a node stream, for writers to apply before they act on a node.

    It holds the open objects and members of the stream seen so far.

    NodeStreamValidator::check

    fn NodeStreamValidator::check(self : NodeStreamValidator, node : XamlNode) -> Unit raise XamlWriteError

    Accept node, or raise UnbalancedStream and leave the state unchanged.

    NodeStreamValidator::closing_nodes

    The end member and end object nodes that close the open frames, innermost first, as close writes them.

    NodeStreamValidator::count

    fn NodeStreamValidator::count(self : NodeStreamValidator) -> Int

    The number of nodes accepted so far.

    NodeStreamValidator::depth

    fn NodeStreamValidator::depth(self : NodeStreamValidator) -> Int

    The number of open objects and members.

    NodeStreamValidator::finish

    fn NodeStreamValidator::finish(self : NodeStreamValidator) -> Unit raise XamlWriteError

    Accept the end of the stream, or raise UnbalancedStream when nodes are open or there was no root object.

    NodeStreamValidator::new

    A validator. member_rule gives the identity and value cardinality of each member; without it, members are told apart by name and may hold several values, which is all that a writer without a schema can check (NodeListWriter).

    NodeStreamValidator::set_source_span

    fn NodeStreamValidator::set_source_span(self : NodeStreamValidator, span : SourceSpan?) -> Unit

    Set the source range of the nodes that follow, which errors carry; None clears it.

    ObjectKey

    pub struct ObjectKey[T] {
    // private fields
    }

    A key that wraps values of type T in XamlObject handles and reads them back.

    Registration code creates one key for each MoonBit type that it exposes to XAML.

    ObjectKey::id

    fn[T] ObjectKey::id(self : ObjectKey[T]) -> Int

    The identity of the key, which XamlObject::key_id gives for its handles.

    ObjectKey::new

    fn[T] ObjectKey::new(equal? : (T, T) -> Bool, hash? : (T) -> Int) -> ObjectKey[T]

    A new key. equal decides when two wrapped objects are equal, and makes the handles values; without it, handles are equal only when they wrap the same object. hash must give equal hashes for objects that the key treats as equal: the same object, or objects that equal accepts.

    ObjectKey::unwrap

    fn[T] ObjectKey::unwrap(self : ObjectKey[T], handle : XamlObject) -> T?

    The object in handle when this key wrapped it, else None.

    ObjectKey::wrap

    fn[T] ObjectKey::wrap(self : ObjectKey[T], type_name : XamlTypeName, value : T) -> XamlObject

    Wrap value as an object of the XAML type type_name.

    Severity

    pub(all) enum Severity {
    Error
    Warning
    } derive(Compare, Eq,
    Debug
    )

    SourcePosition

    pub(all) struct SourcePosition {
    line : Int
    column : Int
    offset : Int
    } derive(Compare, Eq,
    Debug
    )

    A position in source text. line and column start at 1. offset counts UTF-16 code units from the start of the text, as MoonBit String indexes do.

    SourceSpan

    pub(all) struct SourceSpan {
    start : SourcePosition
    end : SourcePosition
    } derive(Eq,
    Debug
    )

    A range of source text from start (inclusive) to end (exclusive).

    UnbalancedReason

    pub(all) enum UnbalancedReason {
    EndObjectWithoutObject
    EndMemberWithoutMember
    ValueOutsideMember
    MemberOutsideObject
    ObjectOutsideMember
    GetObjectAtRoot
    NodeAfterRoot
    NamespaceDeclarationInObject
    DanglingNamespaceDeclaration
    DuplicateMember
    SecondValueInMember(XamlMemberName)
    UnclosedNodes
    MissingRoot
    } derive(Eq,
    Debug
    )

    Why a node stream is not balanced.

    ValueCardinality

    pub(all) enum ValueCardinality {
    AtMostOne
    Several
    } derive(Eq,
    Debug
    )

    How many values, start objects and get objects a member holds.

    XamlMemberName

    pub(all) enum XamlMemberName {
    Member(owner~ : XamlTypeName, name~ : String)
    Attached(owner~ : XamlTypeName, name~ : String)
    Directive(namespace_uri~ : String, name~ : String)
    UnknownDirective(namespace_uri~ : String, name~ : String)
    } derive(Compare, Eq, Hash,
    Debug
    )

    The name of a XAML member in a start member node.

    • Member is a member of the object; owner is the type that declares it, such as Control for Content on a Button.
    • Attached is an attached member that owner defines, such as Grid.Row, set on another object.
    • Directive is a member of a XAML namespace that no type declares, such as x:Name.
    • UnknownDirective names a directive with no schema entry, as System.Xaml's newXamlDirective(ns, name): a reader gives it for a directive written where its directive does not allow it, and it never resolves to the registered directive of that name (design D8, 3F5).

    XamlMemberName::name

    fn XamlMemberName::name(self : XamlMemberName) -> String

    The local name of a member, without its owner or namespace.

    XamlNode

    pub(all) enum XamlNode {
    NamespaceDeclaration(prefix~ : String, namespace_uri~ : String)
    StartObject(XamlTypeName)
    GetObject
    EndObject
    StartMember(XamlMemberName)
    EndMember
    Value(XamlValue)
    } derive(Eq,
    Debug
    )

    One node of a XAML node stream. Node values are immutable.

    A well-formed stream has one root object. Namespace declarations come immediately before the start object that they apply to, at the start of the stream or inside a member, never before a get object or directly inside an object. An object holds start member and end member pairs; a member holds values, objects and get objects.

    The payloads (design D8, 2F19): NamespaceDeclaration carries the prefix, "" for the default namespace, and the namespace URI; StartObject a XamlTypeName; StartMember a XamlMemberName; Value a XamlValue. Nodes carry names, not schema entries, and no source positions, so streams compare equal across a round trip.

    XamlNode::describe

    fn XamlNode::describe(self : XamlNode) -> String

    The node for people, such as start member {urn:ui}Button.Content. Type names and values are written with explicit work stacks, so a deeply nested node cannot overflow a target's stack.

    XamlNode::kind

    fn XamlNode::kind(self : XamlNode) -> XamlNodeKind

    XamlNodeKind

    pub(all) enum XamlNodeKind {
    NamespaceDeclaration
    StartObject
    GetObject
    EndObject
    StartMember
    EndMember
    Value
    } derive(Eq, Hash,
    Debug
    )

    The node kinds, for code that dispatches on the kind alone.

    XamlObject

    pub struct XamlObject {
    type_name : XamlTypeName
    // private fields
    }

    A handle to an object that registered code created: the runtime XAML type of the object, the key that wrapped it and an opaque payload.

    MoonBit has no Any type and no downcasts. The payload is a closure that stores the object in the slot of the ObjectKey[T] that wrapped it, so only code that holds that key can read the object back as a T. Each handle records the key that made it, so another key never runs the payload. Two handles are equal when they have the same type and key and their objects are equal by the key's equality: by default the same object, or the equal function given to the key. A key with an equal function classifies its handles as values, which saving writes inline and never shares, as .NET value types are copied (F17).
    impl Eq for XamlObject
    impl Hash for XamlObject

    XamlObject::is_value

    fn XamlObject::is_value(self : XamlObject) -> Bool

    Whether the key that wrapped the object compares by value, so the handle stands for a value rather than a shared object (F17).

    XamlObject::key_id

    fn XamlObject::key_id(self : XamlObject) -> Int

    The identity of the key that wrapped the object. Handles of different keys are never the same object.

    XamlObject::object_hash

    fn XamlObject::object_hash(self : XamlObject) -> Int?

    The key's hash of the object, consistent with the key's equality, or None when the key has no hash (F5). Identity tables index by key and hash and search linearly without one.

    XamlObject::type_name

    fn XamlObject::type_name(self : XamlObject) -> XamlTypeName

    The runtime type that a handle names.

    XamlTypeName

    pub(all) struct XamlTypeName {
    namespace_uri : String
    name : String
    type_arguments : ReadOnlyArray[XamlTypeName]
    }

    The name of a XAML type: a XAML namespace URI, a local name and the type arguments of a closed generic type, each itself a type name (design D11). A non-generic name has no type arguments.

    Equality, comparison, hashing, text and debug output walk the type arguments with explicit work stacks, so deeply nested names cannot overflow a target's stack (design D8, 2F18).
    impl Eq for XamlTypeName

    XamlTypeName::arity

    fn XamlTypeName::arity(self : XamlTypeName) -> Int

    The number of type arguments: the generic arity that the name looks a type up by.

    XamlTypeName::new

    fn XamlTypeName::new(namespace_uri : String, name : String, type_arguments? : ArrayView[XamlTypeName]) -> XamlTypeName

    XamlTypeName::parse

    fn XamlTypeName::parse(text : String, namespace_of : (String) -> String?) -> XamlTypeName raise TypeNameError

    Parse one type name in the text form prefix:Name(Arg1, Arg2). namespace_of resolves a prefix, "" for an unprefixed name, to its namespace URI. White space around names, parentheses and commas is allowed.

    XamlTypeName::parse_list

    fn XamlTypeName::parse_list(text : String, namespace_of : (String) -> String?) -> Array[XamlTypeName] raise TypeNameError

    Parse a comma-separated list of one or more type names, as x:TypeArguments holds.

    XamlTypeName::to_string

    fn XamlTypeName::to_string(self : XamlTypeName) -> String

    Default implementation for Show::to_string, uses a StringBuilder

    XamlTypeName::to_text

    fn XamlTypeName::to_text(self : XamlTypeName, prefix_of : (String) -> String?) -> String raise TypeNameError

    The text form prefix:Name(Arg1, Arg2), as System.Xaml XamlTypeName.ToString gives it with a prefix lookup. prefix_of gives the prefix of a namespace URI; the prefix "" writes no prefix:. It raises NoPrefixForNamespace for a namespace that has no prefix.

    XamlValue

    pub(all) enum XamlValue {
    Null
    Bool(Bool)
    Byte(Byte)
    Int16(Int16)
    Int(Int)
    Int64(Int64)
    Single(Float)
    Double(Double)
    Char(UInt16)
    String(String)
    List(ReadOnlyArray[XamlValue])
    Object(XamlObject)
    }

    A dynamic value in a XAML node stream and in the members of loaded objects (design D2).

    The numeric cases are distinct, as .NET's boxed primitives are: Int(1) is not Int64(1). Char holds one UTF-16 code unit, as System.Char does (F24). List holds a read-only array, so a value can be shared without copying. Object holds a handle to an object that registered code created; x:Decimal, x:TimeSpan and x:Uri values are handles of those types (D12).

    Equality treats NaN as equal to NaN, as .NET Double.Equals and Single.Equals do, and 0.0 as equal to -0.0 (F52). Equality, hashing and debug output walk lists with explicit work stacks, so deeply nested lists cannot overflow a target's stack (2F18).
    impl Eq for XamlValue
    impl Hash for XamlValue
    impl Debug for XamlValue

    XamlValue::list

    fn XamlValue::list(items : ArrayView[XamlValue]) -> XamlValue

    A list value with a copy of items.

    is_handler_name

    fn is_handler_name(text : String) -> Bool

    Whether text can be the name of an event handler, by the pattern of [MS-XAML-2017] 7.4.14: as for the name of an object, and a modifier letter can also be the first one.

    is_ncname

    fn is_ncname(text : String) -> Bool

    Whether text is an NCName: an XML name without :, such as a namespace prefix.

    is_object_name

    fn is_object_name(text : String) -> Bool

    Whether text can be the name of an object, by the rules of System.Xaml NameValidationHelper: a letter or _, and then letters, _, digits and marks. Each UTF-16 unit counts alone, so a character above U+FFFF is in no name. Empty text is no name.

    read_all

    fn[R : XamlReader] read_all(reader : R) -> Array[XamlNode] raise XamlWriteError

    Read every node of reader. As soon as the reader reports an error diagnostic it raises ReaderFailed with the reader's errors, as transfer does; warnings stay in the reader's diagnostics.

    transfer

    fn[R : XamlReader, W : XamlWriter] transfer(reader : R, writer : W) -> Unit raise XamlWriteError

    Write every node of reader to writer in order, each after its source_span through set_source_span, so an absent span clears the previous location; then close writer once and raise any error of close (design D4, D8, F21, F22).

    It stops at the first writer error and raises it. As soon as the reader reports an error diagnostic, it raises ReaderFailed with the reader's errors, writes no further node and does not close the writer, so the writer produces no result. A reader that ends with objects or members open is an unbalanced stream (UnclosedNodes), raised without closing the writer, so truncated input is not completed by close.

    xaml_language_namespace

    let xaml_language_namespace : String

    The XAML language namespace of [MS-XAML-2017], conventionally bound to the prefix x.