1.1 --- a/imiptools/text.py Tue May 16 00:41:37 2017 +0200
1.2 +++ b/imiptools/text.py Tue May 23 16:31:27 2017 +0200
1.3 @@ -3,7 +3,7 @@
1.4 """
1.5 Parsing of textual content.
1.6
1.7 -Copyright (C) 2014, 2015, 2016 Paul Boddie <paul@boddie.org.uk>
1.8 +Copyright (C) 2014, 2015, 2016, 2017 Paul Boddie <paul@boddie.org.uk>
1.9
1.10 This program is free software; you can redistribute it and/or modify it under
1.11 the terms of the GNU General Public License as published by the Free Software
1.12 @@ -24,14 +24,17 @@
1.13
1.14 # Parsing of lines to obtain functions and arguments.
1.15
1.16 -line_pattern_str = r"(?:" \
1.17 - r"(?:'(.*?)')" \
1.18 - r"|" \
1.19 - r'(?:"(.*?)")' \
1.20 - r"|" \
1.21 - r"([^\s]+)" \
1.22 - r")+" \
1.23 - r"(?:\s+|$)"
1.24 +line_pattern_str = (
1.25 + r"(?:"
1.26 + r"(?:'(.*?)')" # single-quoted text
1.27 + r"|"
1.28 + r'(?:"(.*?)")' # double-quoted text
1.29 + r"|"
1.30 + r"([^\s]+)" # non-whitespace characters
1.31 + r")+"
1.32 + r"(?:\s+|$)" # optional trailing whitespace before line end
1.33 + )
1.34 +
1.35 line_pattern = re.compile(line_pattern_str)
1.36
1.37 def parse_line(text):
1.38 @@ -40,6 +43,10 @@
1.39 Parse the given 'text', returning a list of words separated by whitespace in
1.40 the input, where whitespace may occur inside words if quoted using single or
1.41 double quotes.
1.42 +
1.43 + Hello world -> ['Hello', 'world']
1.44 + Hello ' world' -> ['Hello', ' world']
1.45 + Hello' 'world -> ["'Hello'", "'world']
1.46 """
1.47
1.48 parts = []