Changeset 144:f644601710b1
- Timestamp:
- 29/04/10 22:49:35 (22 months ago)
- Author:
- Menno Smits <menno@…>
- Branch:
- default
- Message:
-
#43: numeric folder names break list_folders
Further hacks to the lexer to allow the response parser to
distinguish between a string with digits in it and an actual
integer. This prevents folder names comprising of just
digits from being returned as integers instead of strings.
- Files:
-
Legend:
- Unmodified
- Added
- Removed
-
|
r142
|
r144
|
|
| 141 | 141 | |
| 142 | 142 | def read(self, n): |
| 143 | | # We also hack into the lexer so we get special treatment for '\\' |
| 144 | | # chars - they are only special inside a quoted string. |
| | 143 | # Two additional hacks: |
| | 144 | # 1. Hack into the lexer so we get special treatment for backslash |
| | 145 | # chars - they are only special inside a quoted string. |
| | 146 | # 2. For quoted strings return the quotes around the string so |
| | 147 | # that atom() can distinguish numbers from strings. Eg. "123" vs 123. |
| | 148 | # These are stripped off before returning them to the user. |
| 145 | 149 | assert n==1 |
| 146 | 150 | if self.pushed is not None: |
| … |
… |
|
| 149 | 153 | else: |
| 150 | 154 | ret = self.src.read(n) |
| 151 | | if ret=="\\" and self.lexer.state not in '"\\': |
| | 155 | if ret == "\\" and self.lexer.state not in '"\\': |
| 152 | 156 | self.pushed = "\\" |
| | 157 | elif ret == '"' and self.lexer.state != '\\': |
| | 158 | self.lexer.token += '"' |
| 153 | 159 | return ret |
| 154 | 160 | |
| … |
… |
|
| 208 | 214 | literal_len, len(literal_text))) |
| 209 | 215 | return literal_text |
| | 216 | elif len(token) >= 2 and (token[0] == token[-1] == '"'): |
| | 217 | return token[1:-1] |
| 210 | 218 | elif token.isdigit(): |
| 211 | 219 | return int(token) |
-
|
r143
|
r144
|
|
| 147 | 147 | 'foo "bar"', |
| 148 | 148 | 'stuff & things', |
| 149 | | u'test & \u2622'] |
| | 149 | u'test & \u2622', |
| | 150 | '123'] |
| 150 | 151 | |
| 151 | 152 | for folder in test_folders: |