From: Frank Brehm Date: Fri, 28 Jan 2011 12:31:54 +0000 (+0000) Subject: Split unquotet tokens by ';' or '{' or '}' X-Git-Url: https://git.uhu-banane.org/?a=commitdiff_plain;h=434a3d1ca47396a57aa30cdea7a5d66daa46fec6;p=my-stuff%2Fisc-config-parser.git Split unquotet tokens by ';' or '{' or '}' git-svn-id: http://svn.brehm-online.com/svn/my-stuff/python/IscConfigParser/trunk@192 ec8d2aa5-1599-4edb-8739-2b3a1bc399aa --- diff --git a/IscConfigParser.py b/IscConfigParser.py index 31f7bb6..e7d16d4 100755 --- a/IscConfigParser.py +++ b/IscConfigParser.py @@ -180,8 +180,8 @@ class IscConfigParser(LoggingObject): The number of the beginning of line is after in self._files[ self._current_filename ]['current_rownum'] (except in case of EOF). - @return: the content of this line or None if EOF - @rtype: str or None + @return: the content of this line as a list of tokens or None if EOF + @rtype: list or None """ filename = self._current_filename @@ -249,17 +249,26 @@ class IscConfigParser(LoggingObject): # Tokens without quotings match = re.search( r'^([^"\s]+)', line ) if match is not None: + token = match.group(1) - if token == ';': - res_array.append( ';' ) + + # Split token by ';' or '{' or '}' + if token == ';' or token == '{' or token == '}': + res_array.append( token ) else: - semicolon_match = re.search( r';$', token ) - if semicolon_match is not None: - token = re.sub( r';$', '', token ) - res_array.append( token ) - res_array.append( ';' ) - else: - res_array.append( token ) + while token != '': + specialchar_match = re.search( r'^([^;{}]*)([;{}])', token ) + if specialchar_match is not None: + first = specialchar_match.group(1) + specialchar = specialchar_match.group(2) + if first is not None and first != '': + res_array.append( first ) + res_array.append( specialchar ) + token = re.sub( r'^[^;{}]*[;{}]', '', token ) + else: + res_array.append( token ) + token = '' + line = re.sub( r'^[^"\s]+\s*', '', line ) continue