vxml
Core VXML tree types, parsers, validators, and serializers.
VXML is a generic XML-like tree with two node kinds: element nodes (V)
and text nodes (T). It can be serialized to a readable VXML text format,
XML, HTML, or JSX-like output. This module also includes XML/HTML parsing
helpers.
Types
An attribute on a VXML element node.
pub type Attr {
Attr(blame: blame.Blame, key: String, val: String)
}
Constructors
-
Attr(blame: blame.Blame, key: String, val: String)
A reason an attribute key cannot be represented in serialized VXML.
pub type BadKey {
EmptyKey
IllegalKeyCharacter(String, String)
}
Constructors
-
EmptyKey -
IllegalKeyCharacter(String, String)
A reason an element tag does not satisfy the VXML tag grammar.
pub type BadTag {
EmptyTag
MalformedTag(String, String)
}
Constructors
-
EmptyTag -
MalformedTag(String, String)
A reason a text node cannot be represented in serialized VXML.
pub type BadText {
EmptyText
IllegalTextCharacter(String, String)
}
Constructors
-
EmptyText -
IllegalTextCharacter(String, String)
A reason an attribute value cannot be represented in serialized VXML.
pub type BadValue {
IllegalValueCharacter(String, String)
}
Constructors
-
IllegalValueCharacter(String, String)
One line of text inside a VXML text node.
pub type Line {
Line(blame: blame.Blame, content: String)
}
Constructors
-
Line(blame: blame.Blame, content: String)
A generic XML-like tree.
V is an element node. T is a text node containing one or more lines.
pub type VXML {
V(
blame: blame.Blame,
tag: String,
attrs: List(Attr),
children: List(VXML),
)
T(blame: blame.Blame, lines: List(Line))
}
Constructors
-
V( blame: blame.Blame, tag: String, attrs: List(Attr), children: List(VXML), ) -
T(blame: blame.Blame, lines: List(Line))
An error encountered while parsing serialized VXML.
pub type VXMLParseError {
VXMLParseErrorAttributeAssignmentMissing(blame.Blame, String)
VXMLParseErrorBadTag(blame.Blame, BadTag)
VXMLParseErrorBadAttributeKey(blame.Blame, BadKey)
VXMLParseErrorIndentationTooLarge(blame.Blame, String)
VXMLParseErrorIndentationNotMultipleOfFour(blame.Blame, String)
VXMLParseErrorTextMissing(blame.Blame)
VXMLParseErrorTextNoClosingQuote(blame.Blame, String)
VXMLParseErrorTextNoOpeningQuote(blame.Blame, String)
VXMLParseErrorTextOutOfPlace(blame.Blame, String)
VXMLParseErrorCaretExpected(blame.Blame, String)
VXMLParseErrorNonUniqueRoot(Int)
}
Constructors
-
VXMLParseErrorAttributeAssignmentMissing(blame.Blame, String) -
VXMLParseErrorBadTag(blame.Blame, BadTag) -
VXMLParseErrorBadAttributeKey(blame.Blame, BadKey) -
VXMLParseErrorIndentationTooLarge(blame.Blame, String) -
VXMLParseErrorIndentationNotMultipleOfFour(blame.Blame, String) -
VXMLParseErrorTextMissing(blame.Blame) -
VXMLParseErrorTextNoClosingQuote(blame.Blame, String) -
VXMLParseErrorTextNoOpeningQuote(blame.Blame, String) -
VXMLParseErrorTextOutOfPlace(blame.Blame, String) -
VXMLParseErrorCaretExpected(blame.Blame, String) -
VXMLParseErrorNonUniqueRoot(Int)
An I/O or document error encountered while parsing a VXML file.
pub type VXMLParseFileError {
IOError(simplifile.FileError)
DocumentError(VXMLParseError)
}
Constructors
-
IOError(simplifile.FileError) -
DocumentError(VXMLParseError)
A serialized-VXML failure with the valid output produced before it.
pub type VXMLSerializationError {
VXMLSerializationError(
partial: List(io_lines.OutputLine),
blame: blame.Blame,
problem: VXMLSerializationProblem,
)
}
Constructors
-
VXMLSerializationError( partial: List(io_lines.OutputLine), blame: blame.Blame, problem: VXMLSerializationProblem, )
A VXML tree-validation failure and the provenance of the invalid value.
pub type VXMLValidationError {
VXMLValidationError(
blame: blame.Blame,
problem: VXMLSerializationProblem,
)
}
Constructors
-
VXMLValidationError( blame: blame.Blame, problem: VXMLSerializationProblem, )
Values
pub fn annotate_blames(vxml: VXML) -> VXML
Adds structural descriptions to blame comments throughout a VXML tree.
This is intended for diagnostic tables. Blame identities and tree contents are otherwise unchanged.
pub fn html_repair(content: String) -> String
Applies the package’s best-effort HTML repairs for XML-oriented parsing.
pub fn html_repair_close_void_tags(content: String) -> String
Converts common HTML void-element openings to self-closing XML syntax.
pub fn html_repair_escape_non_entity_ampersands(
content: String,
) -> String
Escapes ampersands that do not begin a syntactically plausible entity.
pub fn html_repair_expand_boolean_attrs(
content: String,
) -> String
Gives common bare HTML boolean attributes empty assigned values.
pub fn html_repair_remove_attrs_from_closing_tags(
content: String,
) -> String
Removes attributes from malformed closing tags.
pub fn parse_file(
path: String,
unique_root: Bool,
) -> Result(List(VXML), VXMLParseFileError)
Parse a file containing the VXML text format.
When unique_root is True, any root count other than one is an error.
pub fn parse_input_lines(
lines: List(io_lines.InputLine),
unique_root: Bool,
) -> Result(List(VXML), VXMLParseError)
Parses input lines containing the VXML text format.
When unique_root is True, any root count other than one is an error.
pub fn parse_string(
source: String,
filename: String,
unique_root: Bool,
) -> Result(List(VXML), VXMLParseError)
Parse a string containing the VXML text format.
filename is recorded in source blame. When unique_root is True, any
root count other than one is an error.
pub fn parse_xml(
content: String,
filename: String,
) -> Result(VXML, #(blame.Blame, String))
Parse an XML-like string into VXML.
filename is recorded in source blame. XML names are accepted as parsed
and may not satisfy validate_tag.
pub fn parse_xml_input_lines(
lines: List(io_lines.InputLine),
) -> Result(VXML, #(blame.Blame, String))
Parse XML-like input lines into VXML.
XML names are accepted as parsed and may not satisfy validate_tag.
pub const tag_pattern: String
The regular-expression pattern accepted by validate_tag.
pub fn validate(vxml: VXML) -> Result(Nil, VXMLValidationError)
Validates a complete VXML tree against the VXML text-format rules.
This checks element tags, attribute keys and values, text contents, and the requirement that every text node contain at least one line. Attribute boundary whitespace is valid and is not rejected.
pub fn validate_key(key: String) -> Result(String, BadKey)
Validate an attribute key for the VXML text format.
pub fn validate_tag(tag: String) -> Result(String, BadTag)
Validate an element tag for the VXML text format.
pub fn validate_value(value: String) -> Result(String, BadValue)
Validate an attribute value for the VXML text format.
pub const vxml_line_delimiter: String
The delimiter surrounding text-line contents in serialized VXML.
pub fn vxml_table(
vxml: VXML,
banner: String,
indent: Int,
) -> Result(String, VXMLSerializationError)
Renders one VXML tree as a blame-annotated diagnostic table.
pub fn vxml_to_html_output_lines(
node: VXML,
indent: Int,
spaces: Int,
) -> List(io_lines.OutputLine)
Serialize one VXML node to HTML output lines.
pub fn vxml_to_jsx(
vxml: VXML,
starting_indent: Int,
indentation: Int,
) -> String
Serializes one VXML node to a JSX-like string.
pub fn vxml_to_jsx_output_lines(
vxml: VXML,
starting_indent: Int,
indentation: Int,
) -> List(io_lines.OutputLine)
Serializes one VXML node to JSX-like output lines.
pub fn vxml_to_output_lines(
vxml: VXML,
) -> Result(List(io_lines.OutputLine), VXMLSerializationError)
Serialize one VXML node to VXML text-format output lines.
pub fn vxml_to_string(
vxml: VXML,
) -> Result(String, VXMLSerializationError)
Serialize one VXML node to the VXML text format.
pub fn vxml_to_xml(
vxml: VXML,
starting_indent: Int,
indentation: Int,
) -> String
Serialize one VXML node to XML.
pub fn vxml_to_xml_output_lines(
vxml: VXML,
starting_indent: Int,
indentation: Int,
) -> List(io_lines.OutputLine)
Serialize one VXML node to XML output lines.
Element-only content is indented. Mixed content remains compact so that formatting does not introduce text whitespace.
pub fn vxmls_to_html_output_lines(
vxmls: List(VXML),
indent: Int,
spaces: Int,
) -> List(io_lines.OutputLine)
Serializes VXML nodes to HTML output lines in the same order.
pub fn vxmls_to_jsx(
vxmls: List(VXML),
starting_indent: Int,
indentation: Int,
) -> String
Serializes VXML nodes to one JSX-like string in the same order.
pub fn vxmls_to_jsx_output_lines(
vxmls: List(VXML),
starting_indent: Int,
indentation: Int,
) -> List(io_lines.OutputLine)
Serializes VXML nodes to JSX-like output lines in the same order.
pub fn vxmls_to_output_lines(
vxmls: List(VXML),
) -> Result(List(io_lines.OutputLine), VXMLSerializationError)
Serializes VXML nodes to VXML text-format output lines in the same order.
pub fn vxmls_to_string(
vxmls: List(VXML),
) -> Result(String, VXMLSerializationError)
Serializes VXML nodes to the VXML text format in the same order.
pub fn vxmls_to_xml(
vxmls: List(VXML),
starting_indent: Int,
indentation: Int,
) -> String
Serialize VXML nodes to XML.
pub fn vxmls_to_xml_output_lines(
vxmls: List(VXML),
starting_indent: Int,
indentation: Int,
) -> List(io_lines.OutputLine)
Serialize VXML nodes to XML output lines.