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