@@ -108,15 +108,15 @@ object ParseResult {
108108
109109 @ sharable private [this ] val CommandExtract = """ (:[\S]+)\s*(.*)""" .r
110110
111- private def parseStats (sourceCode : String )( implicit ctx : Context ): List [untpd.Tree ] = {
111+ private def parseStats (implicit ctx : Context ): List [untpd.Tree ] = {
112112 val parser = new Parser (ctx.source)
113113 val stats = parser.blockStatSeq()
114114 parser.accept(Tokens .EOF )
115115 stats
116116 }
117117
118- /** Extract a `ParseResult` from the string `sourceCode` */
119- def apply ( sourceCode : String )( implicit state : State ) : ParseResult =
118+ def apply ( source : SourceFile )( implicit state : State ) : ParseResult = {
119+ val sourceCode = source.content().mkString
120120 sourceCode match {
121121 case " " => Newline
122122 case CommandExtract (cmd, arg) => cmd match {
@@ -132,10 +132,8 @@ object ParseResult {
132132 case _ =>
133133 implicit val ctx : Context = state.context
134134
135- val source = SourceFile .virtual(str.REPL_SESSION_LINE + (state.objectIndex + 1 ), sourceCode)
136-
137135 val reporter = newStoreReporter
138- val stats = parseStats(sourceCode)( state.context.fresh.setReporter(reporter).withSource(source))
136+ val stats = parseStats(state.context.fresh.setReporter(reporter).withSource(source))
139137
140138 if (reporter.hasErrors)
141139 SyntaxErrors (
@@ -145,6 +143,10 @@ object ParseResult {
145143 else
146144 Parsed (source, stats)
147145 }
146+ }
147+
148+ def apply (sourceCode : String )(implicit state : State ): ParseResult =
149+ apply(SourceFile .virtual(str.REPL_SESSION_LINE + (state.objectIndex + 1 ), sourceCode))
148150
149151 /** Check if the input is incomplete
150152 *
@@ -160,7 +162,7 @@ object ParseResult {
160162 val localCtx = ctx.fresh.setSource(source).setReporter(reporter)
161163 var needsMore = false
162164 reporter.withIncompleteHandler((_, _) => needsMore = true ) {
163- parseStats(sourceCode)( localCtx)
165+ parseStats(localCtx)
164166 }
165167 ! reporter.hasErrors && needsMore
166168 }
0 commit comments