@@ -1644,37 +1644,40 @@ object Parsers {
16441644 }
16451645
16461646 /** CaptureRef ::= { SimpleRef `.` } SimpleRef [`*`] [CapFilter] [`.` `rd`] -- under captureChecking
1647- * CapFilter ::= `.` `as ` `[` QualId `]`
1647+ * CapFilter ::= `.` `only ` `[` QualId `]`
16481648 */
16491649 def captureRef (): Tree =
16501650
1651- def derived (ref : Tree ): Tree =
1652- atSpan(startOffset(ref)) :
1653- if in.isIdent(nme.raw. STAR ) then
1651+ def reachOpt (ref : Tree ): Tree =
1652+ if in.isIdent(nme.raw. STAR ) then
1653+ atSpan(startOffset(ref)) :
16541654 in.nextToken()
16551655 Annotated (ref, makeReachAnnot())
1656- else if in.isIdent(nme.rd) then
1656+ else ref
1657+
1658+ def restrictedOpt (ref : Tree ): Tree =
1659+ if in.token == DOT && in.lookahead.isIdent(nme.only) then
1660+ atSpan(startOffset(ref)):
16571661 in.nextToken()
1658- Annotated (ref, makeReadOnlyAnnot())
1659- else if in.isIdent(nme.only) then
16601662 in.nextToken()
16611663 Annotated (ref, makeOnlyAnnot(inBrackets(convertToTypeId(qualId()))))
1662- else assert( false )
1664+ else ref
16631665
1664- def recur (ref : Tree ): Tree =
1665- if in.token == DOT then
1666- in.nextToken()
1667- if in.isIdent(nme.rd) || in.isIdent(nme.only) then derived(ref)
1668- else recur(selector(ref))
1669- else if in.isIdent(nme.raw.STAR ) then
1670- val reachRef = derived(ref)
1671- val next = in.lookahead
1672- if in.token == DOT && (next.isIdent(nme.rd) || next.isIdent(nme.only)) then
1666+ def readOnlyOpt (ref : Tree ): Tree =
1667+ if in.token == DOT && in.lookahead.isIdent(nme.rd) then
1668+ atSpan(startOffset(ref)):
16731669 in.nextToken()
1674- derived(reachRef )
1675- else reachRef
1670+ in.nextToken( )
1671+ Annotated (ref, makeReadOnlyAnnot())
16761672 else ref
16771673
1674+ def recur (ref : Tree ): Tree =
1675+ val ref1 = readOnlyOpt(restrictedOpt(reachOpt(ref)))
1676+ if (ref1 eq ref) && in.token == DOT then
1677+ in.nextToken()
1678+ recur(selector(ref))
1679+ else ref1
1680+
16781681 recur(simpleRef())
16791682 end captureRef
16801683
0 commit comments