static CKey CreateNewArrayKey(CKey inParent, CTokenLine line, CBuildCommands inCommands) { var res_arr_key = CKey.CreateArrayKey(inParent, line.Position); if (inCommands.IsNextArrayKeyNamePresent) { res_arr_key.SetName(inCommands.PopNextArrayKeyName(inParent)); } return(res_arr_key); }
//inStartLine - next of parent line static void CollectByDivs(CKey inParent, int inParentRank, int inStartLine, int inEndLine, List <CTokenLine> inLines, ITreeBuildSupport inSupport, CKey inRoot, EKeyAddingMode inKeyAddingMode) { int curr_rank = inParentRank + 1; List <Tuple <int, int> > recs_by_divs = new List <Tuple <int, int> >(); CollectDividers(inStartLine, inEndLine, curr_rank, inLines, inSupport, recs_by_divs); if (recs_by_divs.Count > 1) { if (inKeyAddingMode == EKeyAddingMode.Override) { inParent.ClearAllArrayKeys(); } for (int i = 0; i < recs_by_divs.Count; i++) { int first_line = recs_by_divs[i].Item1; int exlude_last_line = recs_by_divs[i].Item2; if (first_line < exlude_last_line) { CKey arr_key = CKey.CreateArrayKey(inParent, inLines[first_line].Position); if (IsLinePresent(curr_rank, first_line, exlude_last_line, inLines)) { Collect(arr_key, curr_rank, first_line, exlude_last_line, inLines, inSupport, inRoot, EKeyAddingMode.AddUnique); } else { CollectByDivs(arr_key, curr_rank, first_line, exlude_last_line, inLines, inSupport, inRoot, EKeyAddingMode.AddUnique); } if (arr_key.IsEmpty) { arr_key.SetParent(null); } } } } else { Collect(inParent, inParentRank, recs_by_divs[0].Item1, recs_by_divs[0].Item2, inLines, inSupport, inRoot, inKeyAddingMode); } }
public static IKey CreateArrayKey(IKey inParent) { return(CKey.CreateArrayKey(inParent as CKey)); }
static Tuple <CKey, int> CreateKey(int inStartLine, int inEndLine, List <CTokenLine> inLines, ITreeBuildSupport inSupport, CKey inRoot, CKey inParent, EKeyAddingMode inKeyAddingMode) { CTokenLine line = inLines[inStartLine]; int key_rank = line.Rank; if (line.IsHeadEmpty) { CKey arr_key = CKey.CreateArrayKey(inParent, line.Position); arr_key.AddTokenTail(line, inSupport.GetLogger()); return(new Tuple <CKey, int>(arr_key, inStartLine + 1)); } else { CKey key = null; if (inKeyAddingMode != EKeyAddingMode.AddUnique) { key = inParent.FindChildKey(line.Head.Text); if (key == null) { inSupport.GetLogger().LogError(EErrorCode.CantFindKey, line, $"Key name: {line.Head.Text}"); } else { if (inKeyAddingMode == EKeyAddingMode.Override) { key.ClearComments(); key.ClearValues(); } if (inKeyAddingMode == EKeyAddingMode.Override || inKeyAddingMode == EKeyAddingMode.Add) { key.AddTokenTail(line, inSupport.GetLogger()); } } } else if (inParent.IsKeyWithNamePresent(line.Head.Text)) { inSupport.GetLogger().LogError(EErrorCode.ElementWithNameAlreadyPresent, line); } if (key == null) { key = CKey.Create(inParent, line, inSupport.GetLogger()); } int last_line = FindNextSameRankLine(inStartLine, inEndLine, key_rank, inLines); if (last_line > inStartLine + 1) { EKeyAddingMode next_add_mode = inKeyAddingMode; if (next_add_mode == EKeyAddingMode.Add) { next_add_mode = EKeyAddingMode.AddUnique; } CollectByDivs(key, key_rank, inStartLine + 1, last_line, inLines, inSupport, inRoot, next_add_mode); } if (key.KeyCount == 0 && key.ValuesCount == 0) { inSupport.GetLogger().LogError(EErrorCode.HeadWithoutValues, line); } return(new Tuple <CKey, int>(key, last_line)); } }