@@ -314,6 +314,26 @@ object MarkupParsers {
314
314
done
315
315
}
316
316
317
+ /** Some try/catch/finally logic used by xLiteral and xLiteralPattern. */
318
+ @ inline private def xLiteralCommon (f : () => Tree , ifTruncated : String => Unit ): Tree = {
319
+ var output : Tree = null .asInstanceOf [Tree ]
320
+ try output = f()
321
+ catch {
322
+ case c @ TruncatedXMLControl =>
323
+ ifTruncated(c.getMessage)
324
+ case c @ (MissingEndTagControl | ConfusedAboutBracesControl ) =>
325
+ parser.syntaxError(c.getMessage + debugLastElem + " >" , debugLastPos)
326
+ case _ : ArrayIndexOutOfBoundsException =>
327
+ parser.syntaxError(" missing end tag in XML literal for <%s>" format debugLastElem, debugLastPos)
328
+ }
329
+ finally parser.in resume Tokens .XMLSTART
330
+
331
+ if (output == null )
332
+ parser.errorTermTree
333
+ else
334
+ output
335
+ }
336
+
317
337
/** Use a lookahead parser to run speculative body, and return the first char afterward. */
318
338
private def charComingAfter (body : => Unit ): Char = {
319
339
try {
@@ -327,8 +347,8 @@ object MarkupParsers {
327
347
/** xLiteral = element { element }
328
348
* @return Scala representation of this xml literal
329
349
*/
330
- def xLiteral : Tree = {
331
- try return {
350
+ def xLiteral : Tree = xLiteralCommon(
351
+ () => {
332
352
input = parser.in
333
353
handle.isPattern = false
334
354
@@ -351,43 +371,25 @@ object MarkupParsers {
351
371
assert(ts.length == 1 )
352
372
ts(0 )
353
373
}
354
- } catch {
355
- case c @ TruncatedXMLControl =>
356
- parser.incompleteInputError(c.getMessage)
357
- case c @ (MissingEndTagControl | ConfusedAboutBracesControl ) =>
358
- parser.syntaxError(c.getMessage + debugLastElem + " >" , debugLastPos)
359
- case _ : ArrayIndexOutOfBoundsException =>
360
- parser.syntaxError(" missing end tag in XML literal for <%s>" format debugLastElem, debugLastPos)
361
- }
362
- finally parser.in resume Tokens .XMLSTART
363
-
364
- parser.errorTermTree
365
- }
374
+ },
375
+ msg => parser.incompleteInputError(msg)
376
+ )
366
377
367
378
/** @see xmlPattern. resynchronizes after successful parse
368
379
* @return this xml pattern
369
380
*/
370
- def xLiteralPattern : Tree = {
371
- try return {
381
+ def xLiteralPattern : Tree = xLiteralCommon(
382
+ () => {
372
383
input = parser.in
373
384
saving[Boolean , Tree ](handle.isPattern, handle.isPattern = _) {
374
385
handle.isPattern = true
375
386
val tree = xPattern
376
387
xSpaceOpt()
377
388
tree
378
389
}
379
- } catch {
380
- case c @ TruncatedXMLControl =>
381
- parser.syntaxError(c.getMessage, curOffset)
382
- case c @ (MissingEndTagControl | ConfusedAboutBracesControl ) =>
383
- parser.syntaxError(c.getMessage + debugLastElem + " >" , debugLastPos)
384
- case _ : ArrayIndexOutOfBoundsException =>
385
- parser.syntaxError(" missing end tag in XML literal for <%s>" format debugLastElem, debugLastPos)
386
- }
387
- finally parser.in resume Tokens .XMLSTART
388
-
389
- parser.errorTermTree
390
- }
390
+ },
391
+ msg => parser.syntaxError(msg, curOffset)
392
+ )
391
393
392
394
def escapeToScala [A ](op : => A , kind : String ) = {
393
395
xEmbeddedBlock = false
0 commit comments