public void Parse <TPackage>(IBlockGenerator <TBlock, TPackage> inGenerator, BlockMetaCache inCache = null) where TPackage : ScriptableDataBlockPackage <TBlock> { if (m_Parsed) { return; } TPackage self = (TPackage)this; BlockParser.Parse(ref self, name, Source(), BlockParsingRules.Default, inGenerator, inCache); }
public void Dispose() { if (Builder != null) { BlockParser.ReturnStringBuilder(Builder); Builder = null; } if (ContentBuilder != null) { BlockParser.ReturnStringBuilder(ContentBuilder); ContentBuilder = null; } PrefixPriorities = null; Rules = null; Generator = null; TagDelimiters = null; Cache = null; Package = null; CurrentBlock = null; }
static internal IEnumerator ParseFile(string inFileName, StringSlice inFile, TPackage ioPackage, IBlockParsingRules inRules, IBlockGenerator <TBlock, TPackage> inGenerator, BlockMetaCache inCache) { var state = new ParseState(); state.PrefixPriorities = GeneratePrefixPriority(inRules); state.Rules = inRules; state.Generator = inGenerator; state.TagDelimiters = new BlockParser.BlockTagDelimiters(inRules); state.Package = ioPackage; state.Builder = BlockParser.RentStringBuilder(); state.ContentBuilder = BlockParser.RentStringBuilder(); state.Cache = inCache ?? BlockMetaCache.Default; using (var disposeRef = state) { uint lineNumber = 0; state.Position = new BlockFilePosition(inFileName, lineNumber); inGenerator.OnStart(state, state.Package); foreach (var rawLine in SplitIntoLines(inRules, inFile)) { lineNumber++; state.Position = new BlockFilePosition(inFileName, lineNumber); LineResult result = ParseLine(ref state, rawLine); if (result == LineResult.Exception) { inGenerator.OnEnd(state, state.Package, true); yield break; } yield return(null); } if (state.CurrentBlock != null) { state.Error |= !TryEndBlock(ref state, StringSlice.Empty); } inGenerator.OnEnd(state, state.Package, state.Error); } }
/// <summary> /// Parses the given file contents into blocks asynchronously. /// Each MoveNext() call on the returned IEnumerator will parse one line. /// </summary> static public TPackage ParseAsync <TBlock, TPackage>(string inFileName, StringSlice inFile, IBlockParsingRules inRules, IBlockGenerator <TBlock, TPackage> inGenerator, BlockMetaCache inCache, out IEnumerator outLoader) where TBlock : class, IDataBlock where TPackage : class, IDataBlockPackage <TBlock> { if (inFile.IsEmpty) { outLoader = null; return(null); } if (inRules == null) { throw new ArgumentNullException("inRules"); } if (inGenerator == null) { throw new ArgumentNullException("inGenerator"); } string fileName = string.IsNullOrEmpty(inFileName) ? NullFilename : inFileName; TPackage package = inGenerator.CreatePackage(fileName); outLoader = InternalBlockParser <TBlock, TPackage> .ParseFile(fileName, inFile, package, inRules, inGenerator, inCache); return(package); }
/// <summary> /// Parses the given file contents into blocks /// and merges into the given package. /// </summary> static public void Parse <TBlock, TPackage>(ref TPackage ioPackage, string inFileName, StringSlice inFile, IBlockParsingRules inRules, IBlockGenerator <TBlock, TPackage> inGenerator, BlockMetaCache inCache = null) where TBlock : class, IDataBlock where TPackage : class, IDataBlockPackage <TBlock> { IEnumerator parser = ParseAsync(ref ioPackage, inFileName, inFile, inRules, inGenerator, inCache); if (parser != null) { while (parser.MoveNext()) { ; } } }
/// <summary> /// Parses the given file contents into blocks. /// </summary> static public TPackage Parse <TBlock, TPackage>(string inFileName, StringSlice inFile, IBlockParsingRules inRules, IBlockGenerator <TBlock, TPackage> inGenerator, BlockMetaCache inCache = null) where TBlock : class, IDataBlock where TPackage : class, IDataBlockPackage <TBlock> { IEnumerator parser; TPackage package = ParseAsync(inFileName, inFile, inRules, inGenerator, inCache, out parser); if (parser != null) { while (parser.MoveNext()) { ; } } return(package); }
/// <summary> /// Parses the given file contents into blocks asynchronously /// and merges into the given package. /// Each MoveNext() call on the returned IEnumerator will parse one line. /// </summary> static public IEnumerator ParseAsync <TBlock, TPackage>(ref TPackage ioPackage, string inFileName, StringSlice inFile, IBlockParsingRules inRules, IBlockGenerator <TBlock, TPackage> inGenerator, BlockMetaCache inCache = null) where TBlock : class, IDataBlock where TPackage : class, IDataBlockPackage <TBlock> { if (inFile.IsEmpty) { return(null); } if (inRules == null) { throw new ArgumentNullException("inRules"); } if (inGenerator == null) { throw new ArgumentNullException("inGenerator"); } string fileName = string.IsNullOrEmpty(inFileName) ? NullFilename : inFileName; if (ioPackage == null) { ioPackage = inGenerator.CreatePackage(fileName); } return(InternalBlockParser <TBlock, TPackage> .ParseFile(fileName, inFile, ioPackage, inRules, inGenerator, inCache)); }
public IEnumerator ParseAsync <TPackage>(IBlockParsingRules inRules, IBlockGenerator <TBlock, TPackage> inGenerator, BlockMetaCache inCache = null) where TPackage : ScriptableDataBlockPackage <TBlock> { if (m_Parsed) { return(null); } TPackage self = (TPackage)this; return(BlockParser.ParseAsync(ref self, name, Source(), inRules, inGenerator, inCache)); }