}//Run private void flush() { if ( (!isString) && (!isCommentBlock) && (!isCommentLine) && (buffer.Length == 0) ) { return; } string text = buffer.ToString(); object value = null; buffer.Length = 0; var type = JSONTokenType.tUnknown; if (isString) { type = JSONTokenType.tStringLiteral; if (!isVerbatim) { try //expand escapes { text = JSONStrings.UnescapeString(text); } catch (StringEscapeErrorException err) { lexer.EmitMessage(MessageType.Error, (int)JSONMsgCode.eInvalidStringEscape, tagStartPos, null, err.ErroredEscape); return; } } } else if (isCommentLine && isDirective)//directives treated similar to line comments { type = JSONTokenType.tDirective; } else if (isCommentBlock || isCommentLine) { type = JSONTokenType.tComment; } else { try { value = JSONNumbers.Convert(text, out type); } catch (ArgumentException err) { lexer.EmitMessage(MessageType.Error, (int)JSONMsgCode.eValueTooBig, tagStartPos, null, err.Message); return; } if (value == null) //not number { type = JSONKeywords.Resolve(text); if (type == JSONTokenType.tIdentifier) { if (text.StartsWith("$")) { text = text.Remove(0, 1); //take care of verbatim names like: $class, $method, $var etc.. tagStartPos = new SourcePosition(tagStartPos.LineNumber, tagStartPos.ColNumber + 1, tagStartPos.CharNumber + 1); } if (!JSONIdentifiers.Validate(text)) { lexer.EmitMessage(MessageType.Error, (int)JSONMsgCode.eInvalidIdentifier, tagStartPos, null, text); return; } } } //not number } //not comment if (type == JSONTokenType.tStringLiteral) { value = text; } tokens.Add(new JSONToken(lexer, type, tagStartPos, tagEndPos, text, value)); }