コード例 #1
0
ファイル: glsl_parse.py プロジェクト: wno-git/dnload
def glsl_parse_tokenized(source):
    """Parse tokenized source."""
    # End of input.
    if not source:
        return []
    # Try default parses for global scope.
    (block, remaining) = glsl_parse_inout(source)
    if block:
        return [block] + glsl_parse_tokenized(remaining)
    (block, remaining) = glsl_parse_struct(source)
    if block:
        return [block] + glsl_parse_tokenized(remaining)
    (block, remaining) = glsl_parse_pervertex(source)
    if block:
        return [block] + glsl_parse_tokenized(remaining)
    (block, remaining) = glsl_parse_uniform(source)
    if block:
        return [block] + glsl_parse_tokenized(remaining)
    (block, remaining) = glsl_parse_function(source)
    if block:
        return [block] + glsl_parse_tokenized(remaining)
    # Try parses normally for local scope.
    (block, remaining) = glsl_parse_declaration(source)
    if block:
        return [block] + glsl_parse_tokenized(remaining)
    (block, remaining) = glsl_parse_assignment(source)
    if block:
        return [block] + glsl_parse_tokenized(remaining)
    # Fallback, should never happen.
    return glsl_parse_default(source)
コード例 #2
0
def glsl_parse_parameter(source):
    """Parse parameter block."""
    (inout, typeid, content) = extract_tokens(source, ("?o", "?t"))
    if not inout:
        (typeid, content) = extract_tokens(source, ("?t"))
        if not typeid:
            return (None, source)
    (assignment, remaining) = glsl_parse_assignment(content, False)
    if not assignment:
        raise RuntimeError("could not parse assignment from '%s'" % (str(map(str, content))))
    if inout and (not inout.format(False) in ("in", "inout", "out")):
        raise RuntimeError("invalid inout directive for parameter: '%s'" % (inout.format(False)))
    return (GlslBlockParameter(inout, typeid, assignment), remaining)
コード例 #3
0
ファイル: glsl_block_scope.py プロジェクト: faemiyah/dnload
def glsl_parse_scope(source, explicit=True):
    """Parse scope block."""
    (content, remaining) = extract_tokens(source, ("?{",))
    if not (content is None):
        return (GlslBlockScope(glsl_parse_content(content), explicit), remaining)
    # If explicit scope is not expected, try legal one-statement scopes.
    elif not explicit:
        (block, remaining) = glsl_parse_flow(source)
        if block:
            return (GlslBlockScope([block], explicit), remaining)
        (block, remaining) = glsl_parse_unary(source)
        if block:
            return (GlslBlockScope([block], explicit), remaining)
        (block, remaining) = glsl_parse_assignment(source)
        if block:
            return (GlslBlockScope([block], explicit), remaining)
    # No scope found.
    return (None, source)
コード例 #4
0
def glsl_parse_declaration(source):
    """Parse declaration block."""
    (typeid, content) = extract_tokens(source, ("?t", ))
    if not typeid:
        return (None, source)
    # Loop until nothing found.
    lst = []
    while True:
        (assignment, remaining) = glsl_parse_assignment(content)
        if assignment:
            lst += [assignment]
            # Might have been last assignement.
            if assignment.getTerminator() == ";":
                return (GlslBlockDeclaration(typeid, lst), remaining)
            # Otherwise keep going.
            content = remaining
            continue
        # Unknown element, not a valid declaration.
        return (None, source)
コード例 #5
0
def glsl_parse_scope(source, explicit=True):
    """Parse scope block."""
    (content, remaining) = extract_tokens(source, ("?{", ))
    if not (content is None):
        return (GlslBlockScope(glsl_parse_content(content),
                               explicit), remaining)
    # If explicit scope is not expected, try legal one-statement scopes.
    elif not explicit:
        (block, remaining) = glsl_parse_flow(source)
        if block:
            return (GlslBlockScope([block], explicit), remaining)
        (block, remaining) = glsl_parse_unary(source)
        if block:
            return (GlslBlockScope([block], explicit), remaining)
        (block, remaining) = glsl_parse_assignment(source)
        if block:
            return (GlslBlockScope([block], explicit), remaining)
    # No scope found.
    return (None, source)
コード例 #6
0
def glsl_parse_declaration(source):
    """Parse declaration block."""
    (typeid, content) = extract_tokens(source, ("?t",))
    if not typeid:
        return (None, source)
    # Loop until nothing found.
    lst = []
    while True:
        (assignment, remaining) = glsl_parse_assignment(content)
        if assignment:
            lst += [assignment]
            # Might have been last assignement.
            if assignment.getTerminator() == ";":
                return (GlslBlockDeclaration(typeid, lst), remaining)
            # Otherwise keep going.
            content = remaining
            continue
        # Unknown element, not a valid declaration.
        return (None, source)