Skip to content

Commit

Permalink
even crazier readAndProcessCC
Browse files Browse the repository at this point in the history
  • Loading branch information
NQNStudios committed Dec 11, 2024
1 parent e09993e commit df8edf7
Showing 1 changed file with 12 additions and 10 deletions.
22 changes: 12 additions & 10 deletions src/kiss/Reader.hx
Original file line number Diff line number Diff line change
Expand Up @@ -411,7 +411,7 @@ class Reader {
Read all the expressions in the given stream, processing them one by one while reading.
They can't be read all at once because some expressions change the Readtable state
**/
public static function readAndProcessCC(stream:Stream, k:HasReadTables, process:(ReaderExp, cc:Void->Void) -> Void, nested = false) {
public static function readAndProcessCC(stream:Stream, k:HasReadTables, process:(ReaderExp, cc:Void->Void) -> Void, nested = false):Void->Void {
if (nested) {
nestedReadExpArrayStartPositions.push(readExpArrayStartPositions);
readExpArrayStartPositions = [];
Expand Down Expand Up @@ -458,22 +458,24 @@ class Reader {
}
}

var startOfFileMacro = chooseReadFunction(stream, k.startOfFileReadTable);
if (startOfFileMacro != null) {
var pos = stream.position();
var v = startOfFileMacro(stream, k);
if (v != null)
process(v.withPos(pos), afterStartOfFile);
} else {
afterStartOfFile();
return () -> {
var startOfFileMacro = chooseReadFunction(stream, k.startOfFileReadTable);
if (startOfFileMacro != null) {
var pos = stream.position();
var v = startOfFileMacro(stream, k);
if (v != null)
process(v.withPos(pos), afterStartOfFile);
} else {
afterStartOfFile();
}
}
}

public static function readAndProcess(stream:Stream, k:HasReadTables, process:(ReaderExp) -> Void, nested = false) {
readAndProcessCC(stream, k, (exp, cc) -> {
process(exp);
cc();
});
})();
}

public static function withPos(def:ReaderExpDef, pos:Position) {
Expand Down

0 comments on commit df8edf7

Please sign in to comment.