The dom.base module¶
Some general element types and some base classes for the quickly.dom elements.
Base classes¶
The following are base element classes for different languages.
-
class
Document(*children, **attrs)[source]¶ Bases:
quickly.dom.element.ElementBase class for a full source document.
-
space_between= '\n\n'¶
-
concat_space(n, m)[source]¶ Return the minimum whitespace to apply between these child nodes.
This method is called in the
points()method, when calculating whitespace between two adjacent child nodes. By default, the value of thespace_betweenattribute is returned. Reimplement this method to differentiate whitespacing based on the (type or contents of the) nodes.
-
-
class
String(head, *children, **attrs)[source]¶ Bases:
quickly.dom.element.TextElementBase class for a string element.
-
class
Comment(head, *children, **attrs)[source]¶ Bases:
quickly.dom.element.TextElementBase class for a comment element.
-
class
SinglelineComment(head, *children, **attrs)[source]¶ Bases:
quickly.dom.base.CommentBase class for a multiline comment element.
-
class
MultilineComment(head, *children, **attrs)[source]¶ Bases:
quickly.dom.base.CommentBase class for a multiline comment element.
-
class
BackslashCommand(head, *children, **attrs)[source]¶ Bases:
quickly.dom.element.TextElementA command that starts with a backslash, like in LaTeX and LilyPond.
The backslash (
\) is not in the head value.
Generic elements¶
These are generic elements, which are never created from transforming a sourcce, but may be used to alter the output of a DOM tree/document.
-
class
Newline(*children, **attrs)[source]¶ Bases:
quickly.dom.element.ElementA Newline.
Not created from existing documents, but you can insert this node anywhere you want a newline in manually crafted documents.
-
head= ''¶
-
space_after= '\n'¶
-
-
class
BlankLine(*children, **attrs)[source]¶ Bases:
quickly.dom.element.ElementA blank line.
Not created from existing documents, but you can insert this node anywhere you want a blank line in manually crafted documents.
-
head= ''¶
-
space_after= '\n\n'¶
-
-
class
Line(*children, **attrs)[source]¶ Bases:
quickly.dom.element.ElementContainer that prints the child nodes on one line with a space in between.
Not created from existing documents, but you can insert this node in a Document when you want some nodes to be on the same line, for example when you want to write a comment at the end of the preceding line instead of on a line of its own.
-
space_before= '\n'¶
-
space_after= '\n'¶
-
space_between= ' '¶
-
-
class
Column(*children, **attrs)[source]¶ Bases:
quickly.dom.element.ElementContainer that prints every child node on a new line.
Not created from existing documents, but you can insert this node in a Document when you want some nodes to be stacked vertically.
-
space_before= '\n'¶
-
space_after= '\n'¶
-
space_between= '\n'¶
-
-
class
Text(head, *children, **attrs)[source]¶ Bases:
quickly.dom.element.TextElementGeneric text that is printed unmodified.
Special element¶
There is one “special” element.
-
class
Unknown(*children, **attrs)[source]¶ Bases:
quickly.dom.element.HeadElementRepresents a document region that is not transformed.
This element can only occur in documents transformed from source. It is used to denote reqions that are not transformed, such as CSS style tags or attributes, or script tags, in Html documents containing LilyPond music.
Parce has fancy highlighting for those text fragments, but it makes no sense to try to transform those also to useful DOM nodes. So instead, we simply record the positions in the source document of these fragments using the first and the last token of such contexts that are not transformed.
Calling
write_head()on this element results in an exception, because it does not know how it looks. But it knows the position in the document, because the first and the last untransformed tokens are in the origin.Before you can write out a document containing
Unknownelements fully out (e.g. usingwrite()orwrite_indented()), you should replace those elements with e.g.Textelements that have the text such as it appears in the source document. This can be done usingutil.replace_unknown().You can
edit()documents with this element however, it will simply leave the unknown parts of the document as they are.
Language and Transform base/helper classes¶
-
class
XmlLike[source]¶ Bases:
objectMixin class for a language definition that bases on parce.lang.Xml.
Adds the comsume attribute to some lexicons, like comment and string, which makes transforming easier.
-
comment= XmlLike.comment¶
-
sqstring= XmlLike.sqstring¶
-
dqstring= XmlLike.dqstring¶
-
cdata= XmlLike.cdata¶
-
processing_instruction= XmlLike.processing_instruction¶
-
-
class
Transform[source]¶ Bases:
parce.transform.TransformTransform base class that keeps the origin tokens.
Provides the
factory()method that creates the DOM node.-
factory(element_class, head_origin, tail_origin=(), *children)[source]¶ Create an Element, keeping its origin.
The
head_originand optionallytail_originis an iterable of Token instances. All elements should be created using this method, so that it can be overridden for the case you don’t want to remember the origin.
-
-
class
AdHocTransform[source]¶ Bases:
objectTransform mixin class that does not keep the origin tokens.
This is used to create pieces (nodes) of a LilyPond document from text, and then use that pieces to compose a larger Document or to edit an existing document. It is undesirable that origin tokens then would mistakenly be used as if they originated from the document that’s being edited.
-
factory(element_class, head_origin, tail_origin=(), *children)[source]¶ Create an Item without keeping its origin.
The
head_originand optionallytail_originis an iterable of Token instances. All items should be created using this method, so that it can be overridden for the case you don’t want to remember the origin.
-