Esempio n. 1
0
def _render_set(value: sets.Set, builder: BoxBuilder) -> None:
    builder.append_chunk("{", math="\\left\\{")
    for member, lookahead in iter_lookahead(value.members):
        builder.append_term(member)
        if lookahead:
            builder.append_chunk(", ", math=",\\ ")
    builder.append_chunk("}", math="\\right\\}")
Esempio n. 2
0
def render_function_operator(
    operator: terms.FunctionOperator,
    arguments: terms.Arguments,
    builder: BoxBuilder,
) -> None:
    try:
        render = _render_function_operator[operator]
    except KeyError:
        if operator.name is not None:
            builder.append_chunk(
                operator.name,
                math=f"\\applyFunction{{\\texttt{{{operator.name}}}}}",
            )
            builder.append_chunk("(", math="{{")
            for argument, lookahead in iter_lookahead(arguments):
                builder.append_term(argument)
                if lookahead:
                    builder.append_chunk(", ", math=",\\ ")
            builder.append_chunk(")", math="}}")
        else:
            error_operator = operator.name or operator.implementation
            raise NotImplementedError(
                f"rendering function for {error_operator!r} not implemented")
    else:
        render(arguments, builder)
Esempio n. 3
0
def _render_tuple(value: tuples.Tuple, builder: BoxBuilder) -> None:
    builder.append_chunk("⟨", math="\\left[\\,")
    for component, lookahead in iter_lookahead(value.components):
        builder.append_term(component)
        if lookahead:
            builder.append_chunk(", ", math=",")
    builder.append_chunk("⟩", math="\\,\\right]")
Esempio n. 4
0
def _stringify_choice(pattern: patterns.Choice, ctx: _Context) -> None:
    ctx.chunks.append("(?:")
    for alternative, lookahead in iter_lookahead(pattern.alternatives):
        _stringify_pattern(alternative, ctx)
        if lookahead is not None:
            ctx.chunks.append("|")
    ctx.chunks.append(")")
Esempio n. 5
0
 def _render_sequence(self, term: terms.Sequence, builder: BoxBuilder) -> None:
     builder.append_chunk("(", math="\\left(")
     for child, lookahead in iter_lookahead(term.elements):
         builder.append_term(child)
         if lookahead:
             builder.append_chunk(" ", math="\\ ")
     builder.append_chunk(")", math="\\right)")
Esempio n. 6
0
def _render_mapping(value: mappings.Mapping, builder: BoxBuilder) -> None:
    builder.append_chunk("{", math="\\left\\{")
    for (key, term), lookahead in iter_lookahead(value.entries.items()):
        builder.append_term(key)
        builder.append_chunk(" ↦ ", math="\\mapsto")
        builder.append_term(term)
        if lookahead:
            builder.append_chunk(", ", math=",")
    builder.append_chunk("}", math="\\right\\}")
Esempio n. 7
0
def _render_record(value: records.Record, builder: BoxBuilder) -> None:
    builder.append_chunk("⟨", math="\\left\\langle")
    for (field_name, field_value), lookahead in iter_lookahead(value.fields.items()):
        builder.append_chunk(field_name)
        builder.append_chunk(": ", math=":")
        builder.append_term(field_value)
        if lookahead:
            builder.append_chunk(", ", math=",")
    builder.append_chunk("⟩", math="\\right\\rangle")
Esempio n. 8
0
def _render_records_construct(arguments: terms.Arguments,
                              builder: BoxBuilder) -> None:
    builder.append_chunk("⟨", math="\\left\\langle")
    for (field_name, field_value), lookahead in iter_lookahead(
            zip(arguments[::2], arguments[1::2])):
        builder.append_term(field_name)
        builder.append_chunk(": ", math=":")
        builder.append_term(field_value)
        if lookahead:
            builder.append_chunk(", ", math=",")
    builder.append_chunk("⟩", math="\\right\\rangle")