All pastes #382054 Raw Edit

Something

public text v1 · immutable
·published 2007-03-05 07:55 UTC
rendered paste body
import sys

from pyparsing import *

filename = sys.argv[1]

code = file(filename).read()

hlslComment = cppStyleComment 

hlslIdentifier = Regex(r'[a-zA-Z_][a-zA-Z0-9_]*')

hlslFile = Forward()

hlslFunctionArgs = Group(hlslIdentifier + hlslIdentifier + Suppress(':') +
        hlslIdentifier)

hlslFunctionDefintion = (hlslIdentifier + hlslIdentifier + Suppress('(') +
        delimitedList(hlslFunctionArgs) + Suppress(')') + Suppress(':') +
        hlslIdentifier)

hlslReturnStatement = Keyword("return") + hlslIdentifier

hlslStatement = hlslReturnStatement

hlslFunctionBody = delimitedList(hlslStatement, delim=';')

hlslFunction = (hlslFunctionDefintion + Suppress('{') + hlslFunctionBody +
        Suppress('}'))

hlslFile << ZeroOrMore(hlslFunction)

hlslFile.ignore(hlslComment)


try:
    print hlslFile.parseString(code)
except ParseException, pe:
    print "Parsing failed"
    print pe