/// <summary> /// Registers a end of a json object ('}') /// </summary> public void RegisterEndObject() { if (this.currentContext != JsonObjectContext.Object) { if (this.readMode) { throw new JsonUnexpectedEndObjectException(); } else { throw new JsonObjectNotStartedException(); } } // check if we have a property name but not a value if (this.CurrentTokenType == JsonTokenType.FieldName) { if (this.readMode) { throw new JsonUnexpectedEndObjectException(); } else { throw new JsonNotCompleteException(); } } this.nestingStackIndex--; this.CurrentTokenType = JsonTokenType.EndObject; this.currentContext = this.RetrieveCurrentContext; }
/// <summary> /// Initializes a new instance of the JsonObjectState class. /// </summary> /// <param name="readMode">Flag for determining whether to throw exceptions that correspond to a JsonReader or JsonWriter.</param> public JsonObjectState(bool readMode) { Debug.Assert(JsonMaxNestingDepth % 8 == 0, "JsonMaxNestingDepth must be multiple of 8"); Debug.Assert(JsonMaxNestingDepth < (1 << 15), "JsonMaxNestingDepth must be less than 2^15"); this.readMode = readMode; this.nestingStackBitmap = new byte[JsonMaxNestingDepth / 8]; this.nestingStackIndex = -1; this.CurrentTokenType = JsonTokenType.NotStarted; this.currentContext = JsonObjectContext.None; }
public JsonObjectContext jsonObject() { JsonObjectContext _localctx = new JsonObjectContext(Context, State); EnterRule(_localctx, 4, RULE_jsonObject); int _la; try { EnterOuterAlt(_localctx, 1); { State = 30; Match(T__4); State = 39; ErrorHandler.Sync(this); _la = TokenStream.LA(1); if (_la == STRING || _la == IDENT) { { State = 31; _localctx._jsonProp = jsonProp(); _localctx._props.Add(_localctx._jsonProp); State = 36; ErrorHandler.Sync(this); _la = TokenStream.LA(1); while (_la == T__2) { { { State = 32; Match(T__2); State = 33; _localctx._jsonProp = jsonProp(); _localctx._props.Add(_localctx._jsonProp); } } State = 38; ErrorHandler.Sync(this); _la = TokenStream.LA(1); } } } State = 41; Match(T__5); } } catch (RecognitionException re) { _localctx.exception = re; ErrorHandler.ReportError(this, re); ErrorHandler.Recover(this, re); } finally { ExitRule(); } return(_localctx); }
/// <summary> /// Registers the end of a json array (']') /// </summary> public void RegisterEndArray() { if (this.currentContext != JsonObjectContext.Array) { if (this.readMode) { throw new JsonUnexpectedEndArrayException(); } else { throw new JsonArrayNotStartedException(); } } this.nestingStackIndex--; this.CurrentTokenType = JsonTokenType.EndArray; this.currentContext = this.RetrieveCurrentContext; }
/// <summary> /// Pushes a JsonObjectContext onto the nesting stack. /// </summary> /// <param name="isArray">Whether the JsonObjectContext is an array.</param> private void Push(bool isArray) { if (this.nestingStackIndex + 1 >= JsonMaxNestingDepth) { throw new InvalidOperationException(RMResources.JsonMaxNestingExceeded); } this.nestingStackIndex++; if (isArray) { this.nestingStackBitmap[this.nestingStackIndex / 8] &= (byte)~this.Mask; this.currentContext = JsonObjectContext.Array; } else { this.nestingStackBitmap[this.nestingStackIndex / 8] |= this.Mask; this.currentContext = JsonObjectContext.Object; } }
public static Dictionary <string, AttributeValue> VisitJsonObject(JsonObjectContext context) { return(context.jsonValuePair() .Select(VisitJsonValuePair) .ToDictionary(kv => kv.Key, kv => kv.Value)); }
public static QsiRowValueExpressionNode GetRowValueFromJObject(JObject jObject, JsonObjectContext context, string[] columns) { var node = new QsiRowValueExpressionNode(); foreach (string column in columns) { if (jObject.TryGetValue(column, out var value)) { switch (value) { case JValue jValue: { node.ColumnValues.Add(jValue.Value switch { int i => TreeHelper.CreateLiteral(i), uint ui => TreeHelper.CreateLiteral(ui), long l => TreeHelper.CreateLiteral(l), bool b => TreeHelper.CreateLiteral(b), double d => TreeHelper.CreateLiteral(d), string s => TreeHelper.CreateLiteral(s), _ => TreeHelper.CreateNullLiteral() }); break; }