@@ -108,15 +108,15 @@ object ParseResult {
108
108
109
109
@ sharable private [this ] val CommandExtract = """ (:[\S]+)\s*(.*)""" .r
110
110
111
- private def parseStats (sourceCode : String )( implicit ctx : Context ): List [untpd.Tree ] = {
111
+ private def parseStats (implicit ctx : Context ): List [untpd.Tree ] = {
112
112
val parser = new Parser (ctx.source)
113
113
val stats = parser.blockStatSeq()
114
114
parser.accept(Tokens .EOF )
115
115
stats
116
116
}
117
117
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
120
120
sourceCode match {
121
121
case " " => Newline
122
122
case CommandExtract (cmd, arg) => cmd match {
@@ -132,10 +132,8 @@ object ParseResult {
132
132
case _ =>
133
133
implicit val ctx : Context = state.context
134
134
135
- val source = SourceFile .virtual(str.REPL_SESSION_LINE + (state.objectIndex + 1 ), sourceCode)
136
-
137
135
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))
139
137
140
138
if (reporter.hasErrors)
141
139
SyntaxErrors (
@@ -145,6 +143,10 @@ object ParseResult {
145
143
else
146
144
Parsed (source, stats)
147
145
}
146
+ }
147
+
148
+ def apply (sourceCode : String )(implicit state : State ): ParseResult =
149
+ apply(SourceFile .virtual(str.REPL_SESSION_LINE + (state.objectIndex + 1 ), sourceCode))
148
150
149
151
/** Check if the input is incomplete
150
152
*
@@ -160,7 +162,7 @@ object ParseResult {
160
162
val localCtx = ctx.fresh.setSource(source).setReporter(reporter)
161
163
var needsMore = false
162
164
reporter.withIncompleteHandler((_, _) => needsMore = true ) {
163
- parseStats(sourceCode)( localCtx)
165
+ parseStats(localCtx)
164
166
}
165
167
! reporter.hasErrors && needsMore
166
168
}
0 commit comments