MCPcopy
hub / github.com/formatjs/formatjs / parseMessage

Method parseMessage

packages/icu-messageformat-parser/parser.ts:221–281  ·  view source on GitHub ↗
(
    nestingLevel: number,
    parentArgType: ArgType,
    expectingCloseTag: boolean
  )

Source from the content-addressed store, hash-verified

219 }
220
221 private parseMessage(
222 nestingLevel: number,
223 parentArgType: ArgType,
224 expectingCloseTag: boolean
225 ): Result<MessageFormatElement[], ParserError> {
226 let elements: MessageFormatElement[] = []
227
228 while (!this.isEOF()) {
229 const char = this.char()
230 if (char === 123 /* `{` */) {
231 const result = this.parseArgument(nestingLevel, expectingCloseTag)
232 if (result.err) {
233 return result
234 }
235 elements.push(result.val)
236 } else if (char === 125 /* `}` */ && nestingLevel > 0) {
237 break
238 } else if (
239 char === 35 /* `#` */ &&
240 (parentArgType === 'plural' || parentArgType === 'selectordinal')
241 ) {
242 const position = this.clonePosition()
243 this.bump()
244 elements.push({
245 type: TYPE.pound,
246 location: createLocation(position, this.clonePosition()),
247 })
248 } else if (
249 char === 60 /* `<` */ &&
250 !this.ignoreTag &&
251 this.peek() === 47 // char code for '/'
252 ) {
253 if (expectingCloseTag) {
254 break
255 } else {
256 return this.error(
257 ErrorKind.UNMATCHED_CLOSING_TAG,
258 createLocation(this.clonePosition(), this.clonePosition())
259 )
260 }
261 } else if (
262 char === 60 /* `<` */ &&
263 !this.ignoreTag &&
264 _isAlpha(this.peek() || 0)
265 ) {
266 const result = this.parseTag(nestingLevel, parentArgType)
267 if (result.err) {
268 return result
269 }
270 elements.push(result.val)
271 } else {
272 const result = this.parseLiteral(nestingLevel, parentArgType)
273 if (result.err) {
274 return result
275 }
276 elements.push(result.val)
277 }
278 }

Callers 3

parseMethod · 0.95
parseTagMethod · 0.95

Calls 11

isEOFMethod · 0.95
charMethod · 0.95
parseArgumentMethod · 0.95
clonePositionMethod · 0.95
bumpMethod · 0.95
peekMethod · 0.95
errorMethod · 0.95
parseTagMethod · 0.95
parseLiteralMethod · 0.95
createLocationFunction · 0.85
_isAlphaFunction · 0.85

Tested by

no test coverage detected