Skip to content

Commit d0e0f91

Browse files
committed
Add IOS smart quotes to parser.py
1 parent e60c94f commit d0e0f91

1 file changed

Lines changed: 7 additions & 2 deletions

File tree

karma/parser.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,11 @@ def make_op_regex(o):
5353
class KarmaParser(TextParsers):
5454
anything = reg(r".") > constant(None)
5555

56+
quotes = reg(r'["“”]')
57+
5658
word_topic = reg(r'[^"\s]+?(?=[+-]{2})')
57-
string_topic = reg(r'".*?(?<!\\)(\\\\)*?"(?=[+-]{2})')
59+
string_topic = quotes & reg(r".*?(?<!\\)(\\\\)*?") & quotes & reg(r"(?=[+-]{2})")
60+
5861
topic = (word_topic > (lambda t: [t, False])) | (
5962
string_topic > (lambda t: [t[1:-1], True])
6063
)
@@ -67,7 +70,9 @@ class KarmaParser(TextParsers):
6770
operator = op_positive | op_neutral | op_negative
6871

6972
bracket_reason = reg(r"\(.+?\)") > (lambda s: s[1:-1])
70-
quote_reason = reg(r'".*?(?<!\\)(\\\\)*?"(?![+-]{2})') > (lambda s: s[1:-1])
73+
quote_reason = reg(r"\".*?(?<!\\)(\\\\)*?\"(?![+-]{2})") > (
74+
lambda s: s[1:-1]
75+
)
7176
reason_words = reg(r"(?i)because") | reg(r"(?i)for")
7277
text_reason = reason_words >> (reg(r'[^",]+') | quote_reason)
7378
reason = bracket_reason | quote_reason | text_reason

0 commit comments

Comments
 (0)