ThirdParty/Pygments/pygments/regexopt.py

changeset 5713
6762afd9f963
parent 4697
c2e9bf425554
equal deleted inserted replaced
5712:f0d08bdeacf4 5713:6762afd9f963
4 ~~~~~~~~~~~~~~~~~ 4 ~~~~~~~~~~~~~~~~~
5 5
6 An algorithm that generates optimized regexes for matching long lists of 6 An algorithm that generates optimized regexes for matching long lists of
7 literal strings. 7 literal strings.
8 8
9 :copyright: Copyright 2006-2015 by the Pygments team, see AUTHORS. 9 :copyright: Copyright 2006-2017 by the Pygments team, see AUTHORS.
10 :license: BSD, see LICENSE for details. 10 :license: BSD, see LICENSE for details.
11 """ 11 """
12 12
13 import re 13 import re
14 from re import escape 14 from re import escape
52 if rest: 52 if rest:
53 # print '-> 1-character + rest' 53 # print '-> 1-character + rest'
54 return open_paren + regex_opt_inner(rest, '') + '|' \ 54 return open_paren + regex_opt_inner(rest, '') + '|' \
55 + make_charset(oneletter) + close_paren 55 + make_charset(oneletter) + close_paren
56 # print '-> only 1-character' 56 # print '-> only 1-character'
57 return make_charset(oneletter) 57 return open_paren + make_charset(oneletter) + close_paren
58 prefix = commonprefix(strings) 58 prefix = commonprefix(strings)
59 if prefix: 59 if prefix:
60 plen = len(prefix) 60 plen = len(prefix)
61 # we have a prefix for all strings 61 # we have a prefix for all strings
62 # print '-> prefix:', prefix 62 # print '-> prefix:', prefix

eric ide

mercurial