if ( self.verbose > 2 ):
self.logger.debug( "new line: {0!r}".format( line ) )
- line = line.lstrip()
-
+ # Tokens without quotings
match = re.search( r'^([^"\s]+)', line )
if match is not None:
- res_array.append( match.group(1) )
+ token = match.group(1)
+ if token == ';':
+ res_array.append( ';' )
+ 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 )
line = re.sub( r'^[^"\s]+\s*', '', line )
continue
+ # quoted tokens
match = re.search( r'^\s*"((?:[^"]|(?<=\\"))*)"', line )
if match is not None:
res_array.append( match.group(1) )
line = re.sub( r'^\s*"(?:[^"]|(?<=\\"))*\s*"', '', line )
+ continue
+
+ # tokens with line breaks
+ match = re.search( r'^\s*"', line )
+ if match is not None:
+
+ token = re.sub( r'^\s*"', '', line )
-# # remove whitespaces from the beginning and end of the line
-# if not self._in_quoting:
-# result = result.strip( " \t\n\r" )
+ do_quote_loop = True
+ while do_quote_loop:
-# # Remove Perl-like comments
-# if re.search( r'^(:?[^"]*(:?"[^"]*")?)*?#', result ):
-# result = re.sub( r'^((:?[^"]*(:?"[^"]*")?)*?)#.*', r'\1', result )
+ new_line = fd.readline()
+
+ if new_line == '' or new_line is None:
+ raise IscConfigParserError( "Unbalanced Quotings in {0!r}, starting at line {1}.".format( filename, current_rownum ) )
+
+ if ( self.verbose > 2 ):
+ self.logger.debug( "read line {0}: {1!r}".format( next_rownum, new_line ) )
+ next_rownum += 1
+
+ quote_end_match = re.search( r'((?:[^"]|(?<=\\"))*)"', new_line )
+ if quote_end_match is not None:
+ token += quote_end_match.group(1)
+ res_array.append( token )
+ do_quote_loop = False
+ line = re.sub( r'(?:[^"]|(?<=\\"))*"', '', new_line )
+ else:
+ token += new_line
+
+ continue
+
+ line = line.lstrip()
+ if line == '':
+ break
-# # Remoce C++-like comments
-# if re.search( r'^(?:[^"]*(:?"[^"]*")?)*?//', result ):
-# result = re.sub( r'^((:?[^"]*(:?"[^"]*")?)*?)//.*', r'\1', result )
+ raise IscConfigParserError( "This should not happen! file: {0!r}, line {1}, rest of line: {2!r}".format(
+ filename, current_rownum, line
+ ) )
self._files[filename]['current_rownum'] = current_rownum
self._files[filename]['next_rownum'] = next_rownum
print "Configfiles to read: %s" % ( pp.pformat( files ) )
for conffile in files:
- conf = parse_isc_config( conffile, verbose = verbose )
- print "Read configuration: \n%s" % ( pp.pformat( conf ) )
+ try:
+ conf = parse_isc_config( conffile, verbose = verbose )
+ print "Read configuration: \n%s" % ( pp.pformat( conf ) )
+ except IscConfigParserError as e:
+ print "Error in reading configuration file {0!r}: {1}".format( conffile, e )
#========================================================================