/// <summary> /// Sets state of the current block and checks its integrity /// </summary> /// <param name="pair"></param> private void CheckBlockIntegrity(DOM.Pair pair) { if (_currentModule.TargetFormat == Module.TargetFormats.Xml) { return; } if (!_blockStateUnknown) { var blockState = _blockState.Peek(); if (blockState == JsonGenerator.BlockState.Array) { if (string.IsNullOrEmpty(pair.Name) || pair.Delimiter == DelimiterEnum.None) { return; } ReportErrorForEachNodeInAliasContext( n => CompilerErrorFactory.ArrayItemIsExpected((IMappedPair)n, _currentModule.FileName)); Context.AddError(CompilerErrorFactory.ArrayItemIsExpected((IMappedPair)pair, _currentModule.FileName)); } else { if (!string.IsNullOrEmpty(pair.Name) && pair.Delimiter != DelimiterEnum.None) { return; } if (_currentModule.TargetFormat == Module.TargetFormats.Xml && ((IMappedPair)pair).IsValueNode) { return; } ReportErrorForEachNodeInAliasContext( n => CompilerErrorFactory.PropertyIsExpected((IMappedPair)n, _currentModule.FileName)); Context.AddError(CompilerErrorFactory.PropertyIsExpected((IMappedPair)pair, _currentModule.FileName)); } return; } //This element is the first element of the block. It decides if the block is array or object _blockState.Push(string.IsNullOrEmpty(pair.Name) || pair.Delimiter == DelimiterEnum.None ? JsonGenerator.BlockState.Array : JsonGenerator.BlockState.Object); _blockStateUnknown = false; }
/// <summary> /// Sets state of the current block and checks its integrity /// </summary> /// <param name="pair"></param> private void CheckBlockIntegrity(DOM.Pair pair) { if (_currentModule.TargetFormat == Module.TargetFormats.Xml) { return; } if (!_blockStateUnknown) { var blockState = _blockState.Peek(); if (blockState == JsonGenerator.BlockStateEnum.Array) { //Starting new block if (string.IsNullOrEmpty(pair.Name) && pair.Assignment == AssignmentEnum.None) { _blockState.Push(((IMappedPair)pair).BlockType == BlockType.JsonArray ? JsonGenerator.BlockStateEnum.Array : JsonGenerator.BlockStateEnum.Object); } if (string.IsNullOrEmpty(pair.Name) || pair.Assignment == AssignmentEnum.None) { return; } ReportErrorForEachNodeInAliasContext( n => CompilerErrorFactory.ArrayItemIsExpected(((IMappedPair)n).NameInterval, _currentModule.FileName)); Context.AddError(CompilerErrorFactory.ArrayItemIsExpected(((IMappedPair)pair).NameInterval, _currentModule.FileName)); } else if (blockState == JsonGenerator.BlockStateEnum.Object) { if (string.IsNullOrEmpty(pair.Name) && pair.Assignment == AssignmentEnum.None) { if (((IMappedPair)pair).BlockType == BlockType.JsonArray) { _blockState.Push(JsonGenerator.BlockStateEnum.Array); ReportErrorForEachNodeInAliasContext( n => CompilerErrorFactory.PropertyIsExpected(((IMappedPair)n).NameInterval, _currentModule.FileName)); Context.AddError(CompilerErrorFactory.PropertyIsExpected(((IMappedPair)pair).AssignmentInterval, _currentModule.FileName)); } return; } if (!string.IsNullOrEmpty(pair.Name) && pair.Assignment != AssignmentEnum.None) { return; } //if(_currentModule.TargetFormat == Module.TargetFormats.Xml && ((IMappedPair)pair).IsValueNode ) return; ReportErrorForEachNodeInAliasContext( n => CompilerErrorFactory.PropertyIsExpected(((IMappedPair)n).NameInterval, _currentModule.FileName)); Context.AddError(CompilerErrorFactory.PropertyIsExpected(((IMappedPair)pair).NameInterval, _currentModule.FileName)); } return; } if (string.IsNullOrEmpty(pair.Name) && pair.Assignment == AssignmentEnum.None) { _blockState.Push(((IMappedPair)pair).BlockType == BlockType.JsonArray ? JsonGenerator.BlockStateEnum.Array : JsonGenerator.BlockStateEnum.Object); } else { //This element is the first element of the block. It decides if the block is array or object _blockState.Push(string.IsNullOrEmpty(pair.Name) || pair.Assignment == AssignmentEnum.None ? JsonGenerator.BlockStateEnum.Array : JsonGenerator.BlockStateEnum.Object); } _blockStateUnknown = false; }