package Breccia.parser.plain; import Breccia.parser.FileFractum; import Breccia.parser.Granum; import java.util.List; final class FileFractum_ extends Fractum_ implements FileFractum { FileFractum_( BrecciaCursor cursor ) { super( cursor ); componentsWhenPresent = new GranalArrayList( cursor.spooler ); } List components; static final List componentsWhenAbsent = List.of(); /* Setting this will be marginally faster than would be the alternative of `components.clear`, at least for a `GranalArrayList`. */ final CoalescentGranalList componentsWhenPresent; FileFractum_ endSet() { end = new End_(); return this; } /** Control flag for late composition, subsequent to `commit`, for sake of efficient parsing. */ boolean isComposed; // ━━━ F r a c t u m _ ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ @Override void commit() { super.commit(); assert lineNumber() == 1; // As per contract. if( cursor.segmentEnd == 0 ) { components = FileFractum_.componentsWhenAbsent; isComposed = true; } else isComposed = false; // Pending demand. cursor.fileFractum( this ); } // ━━━ G r a n u m ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ public final @Override List components() { if( !isComposed ) { cursor.composeFileFractum(); isComposed = true; } assert components == componentsWhenPresent ? componentsWhenPresent.isFlush() : true; return components; } // ▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀ final class End_ extends Fractum_.End_ implements FileFractum.End { @Override void commit() { super.commit(); cursor.fileFractumEnd( this ); }}} // Copyright © 2021 Michael Allan. Licence MIT.