rewrite of SearchExpression
This commit is contained in:
@@ -12,17 +12,16 @@ public class SaveParserEU4
|
||||
{
|
||||
protected Stream _saveFile;
|
||||
private BufferedEnumerator<Token> _tokens;
|
||||
private SearchExpression _query;
|
||||
private int _currentDepth;
|
||||
private ISearchExpression? _searchExprCurrent;
|
||||
|
||||
/// <param name="savefile">Uncompressed stream of <c>gamestate</c> file which can be extracted from save archive</param>
|
||||
/// <param name="query">Parsing whole save takes 10 seconds on mid pc and takes 1GB of RAM,
|
||||
/// so you should specify what exactly you want to get from save file</param>
|
||||
public SaveParserEU4(Stream savefile, SearchExpression query)
|
||||
public SaveParserEU4(Stream savefile, ISearchExpression? query)
|
||||
{
|
||||
_tokens = new BufferedEnumerator<Token>(LexTextSave(), 5);
|
||||
_saveFile = savefile;
|
||||
_query = query;
|
||||
_searchExprCurrent = query;
|
||||
}
|
||||
|
||||
protected enum TokenType : byte
|
||||
@@ -199,9 +198,7 @@ public class SaveParserEU4
|
||||
return l;
|
||||
return tok.value;
|
||||
case TokenType.BracketOpen:
|
||||
_currentDepth++;
|
||||
var obj = ParseListOrDict();
|
||||
_currentDepth--;
|
||||
return obj;
|
||||
case TokenType.BracketClose:
|
||||
return null;
|
||||
@@ -307,16 +304,21 @@ public class SaveParserEU4
|
||||
// Example: `map_area_data {` instead of `map_area_data = {`
|
||||
else if (tok.type != TokenType.BracketOpen)
|
||||
throw new UnexpectedTokenException(tok);
|
||||
|
||||
if (!_query.DoesMatch(new SearchArgs(key, _currentDepth, localIndex)))
|
||||
|
||||
ISearchExpression? searchExprNext = null;
|
||||
if (_searchExprCurrent != null
|
||||
&& !_searchExprCurrent.DoesMatch(new SearchArgs(key, localIndex), out searchExprNext))
|
||||
{
|
||||
SkipValue();
|
||||
continue;
|
||||
}
|
||||
|
||||
|
||||
var searExpressionPrevious = _searchExprCurrent;
|
||||
_searchExprCurrent = searchExprNext;
|
||||
object? value = ParseValue();
|
||||
if (value is null)
|
||||
throw new UnexpectedTokenException(_tokens.Current.Value);
|
||||
_searchExprCurrent = searExpressionPrevious;
|
||||
|
||||
if(!dict.TryGetValue(key, out List<object>? list))
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user