|
48 | 48 |
|
49 | 49 | import operator
|
50 | 50 | import os
|
51 |
| -import re |
52 | 51 | import sys
|
53 | 52 |
|
54 | 53 |
|
|
70 | 69 | # https://www.gnu.org/software/gettext/manual/gettext.html#Plural-forms
|
71 | 70 | # http://git.savannah.gnu.org/cgit/gettext.git/tree/gettext-runtime/intl/plural.y
|
72 | 71 |
|
73 |
| -_token_pattern = re.compile(r""" |
74 |
| - (?P<WHITESPACES>[ \t]+) | # spaces and horizontal tabs |
75 |
| - (?P<NUMBER>[0-9]+\b) | # decimal integer |
76 |
| - (?P<NAME>n\b) | # only n is allowed |
77 |
| - (?P<PARENTHESIS>[()]) | |
78 |
| - (?P<OPERATOR>[-*/%+?:]|[><!]=?|==|&&|\|\|) | # !, *, /, %, +, -, <, >, |
79 |
| - # <=, >=, ==, !=, &&, ||, |
80 |
| - # ? : |
81 |
| - # unary and bitwise ops |
82 |
| - # not allowed |
83 |
| - (?P<INVALID>\w+|.) # invalid token |
84 |
| - """, re.VERBOSE|re.DOTALL) |
85 |
| - |
| 72 | +_token_pattern = None |
86 | 73 |
|
87 | 74 | def _tokenize(plural):
|
88 |
| - for mo in re.finditer(_token_pattern, plural): |
| 75 | + global _token_pattern |
| 76 | + if _token_pattern is None: |
| 77 | + import re |
| 78 | + _token_pattern = re.compile(r""" |
| 79 | + (?P<WHITESPACES>[ \t]+) | # spaces and horizontal tabs |
| 80 | + (?P<NUMBER>[0-9]+\b) | # decimal integer |
| 81 | + (?P<NAME>n\b) | # only n is allowed |
| 82 | + (?P<PARENTHESIS>[()]) | |
| 83 | + (?P<OPERATOR>[-*/%+?:]|[><!]=?|==|&&|\|\|) | # !, *, /, %, +, -, <, >, |
| 84 | + # <=, >=, ==, !=, &&, ||, |
| 85 | + # ? : |
| 86 | + # unary and bitwise ops |
| 87 | + # not allowed |
| 88 | + (?P<INVALID>\w+|.) # invalid token |
| 89 | + """, re.VERBOSE|re.DOTALL) |
| 90 | + |
| 91 | + for mo in _token_pattern.finditer(plural): |
89 | 92 | kind = mo.lastgroup
|
90 | 93 | if kind == 'WHITESPACES':
|
91 | 94 | continue
|
|
0 commit comments