Show More
@@ -1073,7 +1073,7 b' def formatspec(expr, *args):' | |||||
1073 | >>> formatspec('%d:: and not %d::', 10, 20) |
|
1073 | >>> formatspec('%d:: and not %d::', 10, 20) | |
1074 | '10:: and not 20::' |
|
1074 | '10:: and not 20::' | |
1075 | >>> formatspec('%ld or %ld', [], [1]) |
|
1075 | >>> formatspec('%ld or %ld', [], [1]) | |
1076 |
'(0-0) or |
|
1076 | '(0-0) or 1' | |
1077 | >>> formatspec('keyword(%s)', 'foo\\xe9') |
|
1077 | >>> formatspec('keyword(%s)', 'foo\\xe9') | |
1078 | "keyword('foo\\\\xe9')" |
|
1078 | "keyword('foo\\\\xe9')" | |
1079 | >>> b = lambda: 'default' |
|
1079 | >>> b = lambda: 'default' | |
@@ -1081,7 +1081,7 b' def formatspec(expr, *args):' | |||||
1081 | >>> formatspec('branch(%b)', b) |
|
1081 | >>> formatspec('branch(%b)', b) | |
1082 | "branch('default')" |
|
1082 | "branch('default')" | |
1083 | >>> formatspec('root(%ls)', ['a', 'b', 'c', 'd']) |
|
1083 | >>> formatspec('root(%ls)', ['a', 'b', 'c', 'd']) | |
1084 | "root(('a' or 'b' or 'c' or 'd'))" |
|
1084 | "root((('a' or 'b') or ('c' or 'd')))" | |
1085 | ''' |
|
1085 | ''' | |
1086 |
|
1086 | |||
1087 | def quote(s): |
|
1087 | def quote(s): | |
@@ -1100,6 +1100,16 b' def formatspec(expr, *args):' | |||||
1100 | elif c == 'b': |
|
1100 | elif c == 'b': | |
1101 | return quote(arg.branch()) |
|
1101 | return quote(arg.branch()) | |
1102 |
|
1102 | |||
|
1103 | def listexp(s, t): | |||
|
1104 | "balance a list s of type t to limit parse tree depth" | |||
|
1105 | l = len(s) | |||
|
1106 | if l == 0: | |||
|
1107 | return '(0-0)' # a minimal way to represent an empty set | |||
|
1108 | if l == 1: | |||
|
1109 | return argtype(t, s[0]) | |||
|
1110 | m = l / 2 | |||
|
1111 | return '(%s or %s)' % (listexp(s[:m], t), listexp(s[m:], t)) | |||
|
1112 | ||||
1103 | ret = '' |
|
1113 | ret = '' | |
1104 | pos = 0 |
|
1114 | pos = 0 | |
1105 | arg = 0 |
|
1115 | arg = 0 | |
@@ -1117,11 +1127,7 b' def formatspec(expr, *args):' | |||||
1117 | # a list of some type |
|
1127 | # a list of some type | |
1118 | pos += 1 |
|
1128 | pos += 1 | |
1119 | d = expr[pos] |
|
1129 | d = expr[pos] | |
1120 |
|
|
1130 | ret += listexp(args[arg], d) | |
1121 | lv = ' or '.join(argtype(d, e) for e in args[arg]) |
|
|||
1122 | else: |
|
|||
1123 | lv = '0-0' # a minimal way to represent an empty set |
|
|||
1124 | ret += '(%s)' % lv |
|
|||
1125 | arg += 1 |
|
1131 | arg += 1 | |
1126 | else: |
|
1132 | else: | |
1127 | raise util.Abort('unexpected revspec format character %s' % d) |
|
1133 | raise util.Abort('unexpected revspec format character %s' % d) |
General Comments 0
You need to be logged in to leave comments.
Login now