| 186 | } |
| 187 | |
| 188 | parse(): Result<MessageFormatElement[], ParserError> { |
| 189 | if (this.offset() !== 0) { |
| 190 | throw Error('parser can only be used once') |
| 191 | } |
| 192 | if (this.message.length > 0) { |
| 193 | const firstCode = this.message.charCodeAt(0) |
| 194 | if ( |
| 195 | firstCode !== 35 /* # */ && |
| 196 | firstCode !== 39 /* ' */ && |
| 197 | firstCode !== 60 /* < */ && |
| 198 | firstCode !== 123 /* { */ && |
| 199 | firstCode !== 125 /* } */ |
| 200 | ) { |
| 201 | const plainEndPosition = plainTopLevelEndPosition(this.message) |
| 202 | if (plainEndPosition) { |
| 203 | const start = this.clonePosition() |
| 204 | this.position = plainEndPosition |
| 205 | return { |
| 206 | val: [ |
| 207 | { |
| 208 | type: TYPE.literal, |
| 209 | value: this.message, |
| 210 | location: createLocation(start, this.clonePosition()), |
| 211 | }, |
| 212 | ], |
| 213 | err: null, |
| 214 | } |
| 215 | } |
| 216 | } |
| 217 | } |
| 218 | return this.parseMessage(0, '', false) |
| 219 | } |
| 220 | |
| 221 | private parseMessage( |
| 222 | nestingLevel: number, |