@@ -2225,13 +2225,16 @@ object Parsers {
22252225 def finalizeDef (md : MemberDef , mods : Modifiers , start : Int ): md.ThisTree [Untyped ] =
22262226 md.withMods(mods).setComment(in.getDocComment(start))
22272227
2228+ type ImportConstr = (Boolean , Tree , List [Tree ]) => Tree
2229+
22282230 /** Import ::= import [implied] [ImportExpr {`,' ImportExpr}
2231+ * Export ::= export [implied] [ImportExpr {`,' ImportExpr}
22292232 */
2230- def importClause (): List [Tree ] = {
2231- val offset = accept(IMPORT )
2233+ def importClause (leading : Token , mkTree : ImportConstr ): List [Tree ] = {
2234+ val offset = accept(leading )
22322235 val importImplied = in.token == IMPLIED
22332236 if (importImplied) in.nextToken()
2234- commaSeparated(importExpr(importImplied)) match {
2237+ commaSeparated(importExpr(importImplied, mkTree )) match {
22352238 case t :: rest =>
22362239 // The first import should start at the start offset of the keyword.
22372240 val firstPos =
@@ -2244,23 +2247,28 @@ object Parsers {
22442247
22452248 /** ImportExpr ::= StableId `.' (id | `_' | ImportSelectors)
22462249 */
2247- def importExpr (importImplied : Boolean ): () => Import = {
2250+ def importExpr (importImplied : Boolean , mkTree : ImportConstr ): () => Tree = {
22482251
22492252 val handleImport : Tree => Tree = { tree : Tree =>
2250- if (in.token == USCORE ) Import (importImplied, tree, importSelector() :: Nil )
2251- else if (in.token == LBRACE ) Import (importImplied, tree, inBraces(importSelectors()))
2253+ if (in.token == USCORE ) mkTree (importImplied, tree, importSelector() :: Nil )
2254+ else if (in.token == LBRACE ) mkTree (importImplied, tree, inBraces(importSelectors()))
22522255 else tree
22532256 }
22542257
2255- () => path(thisOK = false , handleImport) match {
2256- case imp : Import =>
2257- imp
2258- case sel @ Select (qual, name) =>
2259- val selector = atSpan(pointOffset(sel)) { Ident (name) }
2260- cpy.Import (sel)(importImplied, qual, selector :: Nil )
2261- case t =>
2262- accept(DOT )
2263- Import (importImplied, t, Ident (nme.WILDCARD ) :: Nil )
2258+ def derived (impExp : Tree , qual : Tree , selectors : List [Tree ]) =
2259+ mkTree(impliedOnly, qual, selectors).withSpan(impExp.span)
2260+
2261+ () => {
2262+ val p = path(thisOK = false , handleImport)
2263+ p match {
2264+ case _ : Import | _ : Export => p
2265+ case sel @ Select (qual, name) =>
2266+ val selector = atSpan(pointOffset(sel)) { Ident (name) }
2267+ mkTree(importImplied, qual, selector :: Nil ).withSpan(sel.span)
2268+ case t =>
2269+ accept(DOT )
2270+ mkTree(importImplied, t, Ident (nme.WILDCARD ) :: Nil )
2271+ }
22642272 }
22652273 }
22662274
@@ -2769,7 +2777,7 @@ object Parsers {
27692777 else stats += packaging(start)
27702778 }
27712779 else if (in.token == IMPORT )
2772- stats ++= importClause()
2780+ stats ++= importClause(IMPORT , Import )
27732781 else if (in.token == AT || isDefIntro(modifierTokens))
27742782 stats +++= defOrDcl(in.offset, defAnnotsMods(modifierTokens))
27752783 else if (! isStatSep) {
@@ -2816,7 +2824,9 @@ object Parsers {
28162824 while (! isStatSeqEnd && ! exitOnError) {
28172825 setLastStatOffset()
28182826 if (in.token == IMPORT )
2819- stats ++= importClause()
2827+ stats ++= importClause(IMPORT , Import )
2828+ else if (in.token == EXPORT )
2829+ stats ++= importClause(EXPORT , Export .apply)
28202830 else if (isExprIntro)
28212831 stats += expr1()
28222832 else if (isDefIntro(modifierTokensOrCase))
@@ -2888,7 +2898,7 @@ object Parsers {
28882898 while (! isStatSeqEnd && in.token != CASE && ! exitOnError) {
28892899 setLastStatOffset()
28902900 if (in.token == IMPORT )
2891- stats ++= importClause()
2901+ stats ++= importClause(IMPORT , Import )
28922902 else if (in.token == GIVEN )
28932903 stats += implicitClosure(in.offset, Location .InBlock , modifiers(closureMods))
28942904 else if (isExprIntro)
0 commit comments