def format(text): engine = SyntaxEngine(text) engine.add('beginning_of_file', lambda text, pos, context: pos == 0, formatBeginningOfFile) engine.add('head_of_line', lambda text, pos, context: context['isHeadOfLine'] == True, formatHeadOfLine) engine.add('copy_to_eof', lambda text, pos, context: True, copyToEOF) engine.add('literal_string', lambda text, pos, context: text[pos] == r'"', formatLiteralString) engine.add('line_comment', lambda text, pos, context: text[pos:pos + 2] == r'//', formatLineComment) engine.add('block_comment', lambda text, pos, context: text[pos:pos + 2] == r'/*', formatBlockComment) engine.add('char01', matchChar01, formatChar01) engine.add('charP1', matchCharP1, formatCharP1) engine.add('charN0', matchCharN0, formatCharN0) engine.add('left_curly_brace', matchLeftCurlyBrace, formatLeftCurlyBrace) engine.add('right_curly_brace', matchRightCurlyBrace, formatRightCurlyBrace) engine.add('space_char', matchSpaceChar, lambda text, pos, context: BasicFormater.skipSpaces(text, pos)) engine.add('return_char', matchReturnChar, formatReturnChar) engine.add('any_punctuation', matchPunctuation, formatPunctuation) engine.add('any_symbol', matchAnySymbol, formatAnySymbol) engine.add('properties', matchProperties, BasicFormater.formatEmptyString) engine.match('beginning_of_file') mainFormat(engine) return engine.context['formattedText']
def format(text): engine = SyntaxEngine(text) engine.add('beginning_of_file', lambda text, pos, context: pos == 0, formatBeginningOfFile) engine.add('head_of_line', lambda text, pos, context: context['isHeadOfLine'] == True, formatHeadOfLine) engine.add('copy_to_eof', lambda text, pos, context: True, copyToEOF) engine.add('literal_string', lambda text, pos, context: text[pos] == r'"', formatLiteralString) engine.add('line_comment', lambda text, pos, context: text[pos:pos + 2] == r'//', formatLineComment) engine.add('block_comment', lambda text, pos, context: text[pos:pos + 2] == r'/*', formatBlockComment) engine.add('char01', matchChar01, formatChar01) engine.add('charP1', matchCharP1, formatCharP1) engine.add('charN0', matchCharN0, formatCharN0) engine.add('left_curly_brace', matchLeftCurlyBrace, formatLeftCurlyBrace) engine.add('right_curly_brace', matchRightCurlyBrace, formatRightCurlyBrace) engine.add('return_char', matchReturnChar, formatReturnChar) engine.add('any_char', lambda text, pos, context: True, formatAnyChar) engine.match('beginning_of_file') mainFormat(engine) return engine.context['formattedText']