The dom.scm module

Elements needed for Scheme expressions.

Besides the elements a few functions are provided to make it easier to manually construct scheme expressions. For example:

>>> from quickly.dom.scm import q, qq, uq, i, p, s
>>> s(True)
<scm.Bool #t>
>>> s(100)
<scm.Number 100>
>>> s(100.123)
<scm.Number 100.123>
>>> s(('text', -2)).dump()
<scm.List (3 children)>
 ├╴<scm.String 'text'>
 ├╴<scm.Dot>
 ╰╴<scm.Number -2>
>>> s(('text', -2)).write()
'("text" . -2)'
>>> q(s((i('text'), -2))).write()
"'(text . -2)"
>>> n = s([i('if'), [i('<'), i('a'), 100], "smaller", "larger"])
>>> n.dump()
<scm.List (4 children)>
 ├╴<scm.Identifier 'if'>
 ├╴<scm.List (3 children)>
 │  ├╴<scm.Identifier '<'>
 │  ├╴<scm.Identifier 'a'>
 │  ╰╴<scm.Number 100>
 ├╴<scm.String 'smaller'>
 ╰╴<scm.String 'larger'>
>>> n.write()
'(if (< a 100) "smaller" "larger")'
class LilyPond(*children, **attrs)[source]

Bases: BlockElement

A LilyPond block inside Scheme, between #{ and #}.

head = '#{'
tail = '#}'
class Document(*children, **attrs)[source]

Bases: Document

A full Scheme document.

class SinglelineComment(head, *children, **attrs)[source]

Bases: SinglelineComment

A singleline comment in Scheme after ;.

space_after = '\n'

whitespace after this element

classmethod read_head(origin)[source]

Return the value as computed from the specified origin Tokens.

The default implementation concatenates the text from all tokens.

write_head()[source]

Return the textual output that represents our head value.

The default implementation just returns the head attribute, assuming it is text.

class MultilineComment(head, *children, **attrs)[source]

Bases: MultilineComment

A multiline comment in Scheme after #!.

classmethod read_head(origin)[source]

Return the value as computed from the specified origin Tokens.

The default implementation concatenates the text from all tokens.

write_head()[source]

Return the textual output that represents our head value.

The default implementation just returns the head attribute, assuming it is text.

class Char(head, *children, **attrs)[source]

Bases: TextElement

A Scheme character.

classmethod read_head(origin)[source]

Return the value as computed from the specified origin Tokens.

The default implementation concatenates the text from all tokens.

write_head()[source]

Return the textual output that represents our head value.

The default implementation just returns the head attribute, assuming it is text.

class String(head, *children, **attrs)[source]

Bases: String

A quoted string.

class Identifier(head, *children, **attrs)[source]

Bases: TextElement

A Scheme identifier (keyword, variable, symbol).

class List(*children, **attrs)[source]

Bases: BlockElement

A Scheme pair or list ( … ).

space_between = ' '

whitespace between children

head = '('
tail = ')'
indent_align_indices()[source]

How to align child nodes if on a new line.

class Vector(*children, **attrs)[source]

Bases: BlockElement

A Scheme vector #( … ).

space_between = ' '

whitespace between children

head = '#('
tail = ')'
class Quote(head, *children, **attrs)[source]

Bases: TextElement

A Scheme quote ', \`, , or ,@.

classmethod check_head(head)[source]

Returns whether the proposed head value is valid.

class Number(head, *children, **attrs)[source]

Bases: TextElement

A decimal numerical value, and the base class for Hex, Bin, Oct.

All features of Scheme numerical values are supported: exact/inexactness, polar coordinates, complex numbers, fractions, infinity, nan and unknown digits (#).

radix = 10
classmethod read_head(origin)[source]

Return the value as computed from the specified origin Tokens.

The default implementation concatenates the text from all tokens.

write_head()[source]

Return the textual output that represents our head value.

The default implementation just returns the head attribute, assuming it is text.

repr_head()[source]

Dump Scheme numbers in Scheme syntax.

class Bin(head, *children, **attrs)[source]

Bases: Number

A Scheme binary integer value.

radix = 2
class Oct(head, *children, **attrs)[source]

Bases: Number

A Scheme octal integer value.

radix = 8
class Hex(head, *children, **attrs)[source]

Bases: Number

A Scheme hexadecimal integer value.

radix = 16
class Bool(head, *children, **attrs)[source]

Bases: Number

A Scheme boolean value.

classmethod read_head(origin)[source]

Return the value as computed from the specified origin Tokens.

The default implementation concatenates the text from all tokens.

write_head()[source]

Return the textual output that represents our head value.

The default implementation just returns the head attribute, assuming it is text.

class NaN(head, *children, **attrs)[source]

Bases: Number

Not a Number, created when a number context has invalid tokens.

classmethod read_head(origin)[source]

Return the value as computed from the specified origin Tokens.

The default implementation concatenates the text from all tokens.

class Dot(*children, **attrs)[source]

Bases: HeadElement

A dot, e.g. in a Scheme pair.

head = '.'
create_element_from_value(value)[source]

Convert a regular Python value to a scheme Element node.

Python bool, int, float or str values are converted into Bool, Number, or String objects respectively. A list is converted into a List element, and a tuple (of length > 1) in a pair, with a dot inserted before the last node. Element objects are returned unchanged.

A KeyError is raised when there is no conversion for the value’s type.

q(arg)[source]

Quote arg. Automatically converts arguments if needed.

qq(arg)[source]

Quasi-quote arg. Automatically converts arguments if needed.

uq(arg)[source]

Un-quote arg. Automatically converts arguments if needed.

i(arg)[source]

Make an identifier of str arg.

p(arg1, arg2, *args)[source]

Return a pair (two-or-more element List with dot before last element).

s(arg)[source]

Same as create_element_from_value().