def parse_container(ctx: CTX, mark: str, location: Location, content: Content, indentation_before_mark: int) -> int: if mark != container_area_begin_mark: return PASS content.read_spaces() function = try_parse_entry(content) content.expect_end_of_line() with ctx.using_stop_mark(container_area_end_mark): component = capture_component(ctx, indentation_before_mark) content.pull(container_area_end_mark) content.expect_end_of_line() if function is not None: component = FunctionCall( location, inline=False, key=function.name, options=function.value, argument=component, ) ctx.composer.add(component) return CONSUMED
def parse_attribute(ctx: CTX, mark: str, content: Content) -> int: if mark != attribute_special_mark: return PASS entry = parse_entry(content) content.expect_end_of_line() ctx.composer.push_attribute(entry.name, entry.value) return CONSUMED
def parse_literal(ctx: CTX, mark: str, location: Location, content: Content, indentation_before_mark: int) -> int: if mark != literal_area_mark: return PASS content.read_spaces() function_location = content.get_location() function = try_parse_entry(content) content.expect_end_of_line() out = StringIO() while True: line = content.read_line(indentation_before_mark) if line is None: raise StxError(f'Expected: {mark}', content.get_location()) elif line.startswith(escape_char): line = line[1:] # remove escape char if not line.startswith(mark) and not line.startswith(escape_char): raise StxError(f'Invalid escaped sequence, expected:' f' {see(mark)} or {see(escape_char)}.') elif line.rstrip() == mark: break out.write(line) text = out.getvalue() if function is not None: component = FunctionCall( function_location, inline=False, key=function.name, options=function.value, argument=Literal(location, text), ) else: component = Literal(location, text) ctx.composer.add(component) return CONSUMED