def expand_grid(tokens, name):
    """Expand the ``grid`` property."""
    line, column = tokens[0].source_line, tokens[0].source_column
    auto = IdentToken(line, column, 'auto')
    none = IdentToken(line, column, 'none')
    row = IdentToken(line, column, 'row')
    column = IdentToken(line, column, 'column')
    try:
        template = tuple(_expand_grid_template(tokens, 'grid-template'))
    except InvalidValues:
        pass
    else:
        for key, value in template:
            yield f'-template-{key.split("-")[-1]}', value
        yield '-auto-columns', [auto]
        yield '-auto-rows', [auto]
        yield '-auto-flow', [row]
        return
    split_tokens = [[]]
    for token in tokens:
        if token.type == 'literal' and token.value == '/':
            split_tokens.append([])
            continue
        split_tokens[-1].append(token)
    if len(split_tokens) != 2:
        raise InvalidValues
    auto_track = None
    dense = None
    templates = {'row': [], 'column': []}
    iterable = zip(split_tokens, templates.items())
    for tokens, (track, track_templates) in iterable:
        auto_flow_token = False
        for token in tokens:
            if get_keyword(token) == 'dense':
                if dense or (auto_track and auto_track != track):
                    raise InvalidValues
                dense = token
                auto_track = track
            elif get_keyword(token) == 'auto-flow':
                if auto_flow_token or (auto_track and auto_track != track):
                    raise InvalidValues
                auto_flow_token = True
                auto_track = track
            elif token == tokens[-1]:
                track_templates.append(token)
            else:
                raise InvalidValues
    if not auto_track:
        raise InvalidValues
    non_auto_track = 'row' if auto_track == 'column' else 'column'
    auto_track_token = column if auto_track == 'column' else row
    yield '-auto-flow', (
        (auto_track_token, dense) if dense else (auto_track_token,))
    yield f'-auto-{auto_track}s', tuple(templates[auto_track])
    yield f'-auto-{non_auto_track}s', [auto]
    yield f'-template-{auto_track}s', [none]
    yield f'-template-{non_auto_track}s', tuple(templates[non_auto_track])
    yield '-template-areas', [none]
Expand the ``grid`` property.
weasyprint/css/validation/expanders.py