@@ -314,6 +314,26 @@ object MarkupParsers {
314314 done
315315 }
316316
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+
317337 /** Use a lookahead parser to run speculative body, and return the first char afterward. */
318338 private def charComingAfter (body : => Unit ): Char = {
319339 try {
@@ -327,8 +347,8 @@ object MarkupParsers {
327347 /** xLiteral = element { element }
328348 * @return Scala representation of this xml literal
329349 */
330- def xLiteral : Tree = {
331- try return {
350+ def xLiteral : Tree = xLiteralCommon(
351+ () => {
332352 input = parser.in
333353 handle.isPattern = false
334354
@@ -351,43 +371,25 @@ object MarkupParsers {
351371 assert(ts.length == 1 )
352372 ts(0 )
353373 }
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+ )
366377
367378 /** @see xmlPattern. resynchronizes after successful parse
368379 * @return this xml pattern
369380 */
370- def xLiteralPattern : Tree = {
371- try return {
381+ def xLiteralPattern : Tree = xLiteralCommon(
382+ () => {
372383 input = parser.in
373384 saving[Boolean , Tree ](handle.isPattern, handle.isPattern = _) {
374385 handle.isPattern = true
375386 val tree = xPattern
376387 xSpaceOpt()
377388 tree
378389 }
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+ )
391393
392394 def escapeToScala [A ](op : => A , kind : String ) = {
393395 xEmbeddedBlock = false
0 commit comments