INNER CODE UNIT · Python

parse

kejilion/sh · site_access_nginx.py:100

def parse(text: str) -> Block:
    root = Block([], 0, 0, len(text))
    stack, words = [root], []
    for token in tokenize(text):
        if not token.delimiter:
            words.append(token)
        elif token.value == ";":
            if not words:
                raise ConfigError("empty directive")
            stack[-1].directives.append(Directive([w.value for w in words], words[0].start, token.end))
            words = []
        elif token.value == "{":
            if not words:
                raise ConfigError("block has no name")
            block = Block([w.value for w in words], words[0].start, token.end)
            stack[-1].children.append(block)
            stack.append(block)
            words = []

View source record →

📰 Research Paper
Loading…
⏳ Fetching content…