Skip to content

Commit

Permalink
GH-556 Change synchronized-source instead of root source-stream in Su…
Browse files Browse the repository at this point in the history
…bparsersUtils#readType utility method
  • Loading branch information
dzikoysk committed Dec 2, 2020
1 parent 87ba211 commit 8a1d7fb
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 6 deletions.
2 changes: 1 addition & 1 deletion examples/tests/current_test.panda
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ main {
log 10 + Int.parseInt('5') + list.size()

// map array to iterable in foreach
foreach (String var : new Array<String>(10)) { }
// foreach (String var : new Array<String>(10)) { }

// make sure that we can use primitive arrays
// PrimitiveChar[] primitiveArray = (')#onlypanda').toCharArray()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
import org.panda_lang.language.architecture.type.signature.Signature;
import org.panda_lang.language.interpreter.parser.expression.ExpressionContext;
import org.panda_lang.language.interpreter.parser.expression.ExpressionResult;
import org.panda_lang.language.interpreter.token.SourceStream;
import org.panda_lang.panda.language.interpreter.parser.PandaSourceReader;
import org.panda_lang.panda.language.resource.syntax.type.SignatureParser;
import org.panda_lang.utilities.commons.function.Result;
Expand All @@ -32,14 +31,12 @@ final class SubparsersUtils {
private SubparsersUtils() { }

protected static Result<Signature, ExpressionResult> readType(@Nullable Signature parent, ExpressionContext<?> context) {
SourceStream stream = context.toStream();
PandaSourceReader sourceReader = new PandaSourceReader(context.toStream());
int index = stream.getUnreadLength();
PandaSourceReader sourceReader = new PandaSourceReader(context.getSynchronizedSource().getAvailableSource().toStream());

return sourceReader.readSignature()
.map(source -> Result.<Signature, ExpressionResult> ok(SIGNATURE_PARSER.parse(parent, context, source)))
.orElseGet(() -> Result.error(ExpressionResult.error("Unknown type", context.getSynchronizedSource().getSource())))
.peek(signature -> context.getSynchronizedSource().next(index - stream.getUnreadLength()));
.peek(signature -> context.getSynchronizedSource().next(sourceReader.getStream().getReadLength()));
}

}

0 comments on commit 8a1d7fb

Please sign in to comment.