def __parse_function_argument_list(fh, ReferenceName): argument_list = [] position = fh.tell() try: # Read argument list if check(fh, "(") == False: return [] text = "" while 1 + 1 == 2: tmp = fh.read(1) if tmp == ")": break elif tmp in ["(", "[", "{"]: closing_bracket = {"(": ")", "[": "]", "{": "}"}[tmp] text += tmp + read_until_closing_bracket( fh, tmp, closing_bracket) + closing_bracket elif tmp == "\"": text += tmp + read_until_closing_bracket( fh, "", "\"", IgnoreRegions=[]) + "\"" elif tmp == "'": text += tmp + read_until_closing_bracket( fh, "", "'", IgnoreRegions=[]) + "'" elif tmp == ",": argument_list.append(text) text = "" elif tmp == "": fh.seek(position) error_msg( "End of file reached while parsing argument list for %s." % ReferenceName, fh) else: text += tmp if text != "": argument_list.append(text) argument_list = map(lambda arg: arg.strip(), argument_list) argument_list = filter(lambda arg: arg != "", argument_list) return argument_list except EndOfStreamException: fh.seek(position) error_msg("End of file reached while parsing token shortcut.", fh)
def __parse_function_argument_list(fh, ReferenceName): argument_list = [] position = fh.tell() try: # Read argument list if check(fh, "(") == False: return [] text = "" while 1 + 1 == 2: tmp = fh.read(1) if tmp == ")": break elif tmp in ["(", "[", "{"]: closing_bracket = {"(": ")", "[": "]", "{": "}"}[tmp] text += tmp + read_until_closing_bracket(fh, tmp, closing_bracket) + closing_bracket elif tmp == "\"": text += tmp + read_until_closing_bracket(fh, "", "\"", IgnoreRegions = []) + "\"" elif tmp == "'": text += tmp + read_until_closing_bracket(fh, "", "'", IgnoreRegions = []) + "'" elif tmp == ",": argument_list.append(text) text = "" elif tmp == "": fh.seek(position) error.error_eof("argument list for %s" % ReferenceName, fh) else: text += tmp if text != "": argument_list.append(text) argument_list = map(lambda arg: arg.strip(), argument_list) argument_list = filter(lambda arg: arg != "", argument_list) return argument_list except EndOfStreamException: fh.seek(position) error.error_eof("token", fh)
def test(Text, Opener, Closer, IgnoreRegions=[]): sh = StringIO(Text) try: accumulated_text = read_until_closing_bracket(sh, Opener, Closer, IgnoreRegions) except: print "ERROR" return print "##-----------------------------------------------------------------------" print Text print "##" print accumulated_text + "[[END]]" print "##"
def __parse_normal(fh, code_fragment_name): code = read_until_closing_bracket(fh, "{", "}") return CodeUser(code, SourceRef.from_FileHandle(fh))
def __parse_normal(fh, code_fragment_name): position = fh.tell() code = read_until_closing_bracket(fh, "{", "}") return CodeUser(code, SourceRef.from_FileHandle(fh, BeginPos=position))
def __parse_normal(fh, code_fragment_name): LanguageDB = Setup.language_db line_n = get_current_line_info_number(fh) + 1 code = read_until_closing_bracket(fh, "{", "}") return UserCodeFragment(code, fh.name, line_n, LanguageDB)