All pastes #382064 Raw Edit

Cody Brocious

public python v1 · immutable
·published 2007-03-05 08:25 UTC
rendered paste body
import sysfrom pyparsing import *filename = sys.argv[1]code = file(filename).read()hlslComment = cppStyleComment hlslIdentifier = Regex(r'[a-zA-Z_][a-zA-Z0-9_]*')hlslNumber = Regex(r'[0-9]+(\.[0-9]*f)?')hlslFile = Forward()hlslFunctionArgs = Group(hlslIdentifier + hlslIdentifier + Suppress(':') +        hlslIdentifier)hlslFunctionDefinition = (hlslIdentifier + hlslIdentifier + Suppress('(') +        delimitedList(hlslFunctionArgs) + Suppress(')') + Suppress(':') +        hlslIdentifier)hlslStatement = Forward()hlslAssignment = hlslIdentifier + Keyword('=') + hlslStatementhlslFunctionCall = hlslIdentifier + Suppress('(') + delimitedList(hlslStatement) + Suppress(')')hlslReturnStatement = Keyword("return") + hlslStatementhlslStatement << (hlslReturnStatement | hlslAssignment | hlslFunctionCall | hlslIdentifier | hlslNumber)hlslLine = hlslStatement + Suppress(';')hlslFunctionBody = ZeroOrMore(hlslLine)hlslFunction = (hlslFunctionDefinition + Suppress('{') + hlslFunctionBody +        Suppress('}'))hlslFile << (ZeroOrMore(hlslFunction) + StringEnd())hlslFile.ignore(hlslComment)try:    print hlslFile.parseString(code)except ParseException, pe:    print "Parsing failed"    print pe