MCPcopy
hub / github.com/microsoft/vscode / visit

Function visit

src/vs/base/common/json.ts:1069–1309  ·  view source on GitHub ↗
(text: string, visitor: JSONVisitor, options: ParseOptions = ParseOptions.DEFAULT)

Source from the content-addressed store, hash-verified

1067 * Parses the given text and invokes the visitor functions for each object, array and literal reached.
1068 */
1069export function visit(text: string, visitor: JSONVisitor, options: ParseOptions = ParseOptions.DEFAULT): any {
1070
1071 const _scanner = createScanner(text, false);
1072
1073 function toNoArgVisit(visitFunction?: (offset: number, length: number) => void): () => void {
1074 return visitFunction ? () => visitFunction(_scanner.getTokenOffset(), _scanner.getTokenLength()) : () => true;
1075 }
1076 function toOneArgVisit<T>(visitFunction?: (arg: T, offset: number, length: number) => void): (arg: T) => void {
1077 return visitFunction ? (arg: T) => visitFunction(arg, _scanner.getTokenOffset(), _scanner.getTokenLength()) : () => true;
1078 }
1079
1080 const onObjectBegin = toNoArgVisit(visitor.onObjectBegin),
1081 onObjectProperty = toOneArgVisit(visitor.onObjectProperty),
1082 onObjectEnd = toNoArgVisit(visitor.onObjectEnd),
1083 onArrayBegin = toNoArgVisit(visitor.onArrayBegin),
1084 onArrayEnd = toNoArgVisit(visitor.onArrayEnd),
1085 onLiteralValue = toOneArgVisit(visitor.onLiteralValue),
1086 onSeparator = toOneArgVisit(visitor.onSeparator),
1087 onComment = toNoArgVisit(visitor.onComment),
1088 onError = toOneArgVisit(visitor.onError);
1089
1090 const disallowComments = options && options.disallowComments;
1091 const allowTrailingComma = options && options.allowTrailingComma;
1092 function scanNext(): SyntaxKind {
1093 while (true) {
1094 const token = _scanner.scan();
1095 switch (_scanner.getTokenError()) {
1096 case ScanError.InvalidUnicode:
1097 handleError(ParseErrorCode.InvalidUnicode);
1098 break;
1099 case ScanError.InvalidEscapeCharacter:
1100 handleError(ParseErrorCode.InvalidEscapeCharacter);
1101 break;
1102 case ScanError.UnexpectedEndOfNumber:
1103 handleError(ParseErrorCode.UnexpectedEndOfNumber);
1104 break;
1105 case ScanError.UnexpectedEndOfComment:
1106 if (!disallowComments) {
1107 handleError(ParseErrorCode.UnexpectedEndOfComment);
1108 }
1109 break;
1110 case ScanError.UnexpectedEndOfString:
1111 handleError(ParseErrorCode.UnexpectedEndOfString);
1112 break;
1113 case ScanError.InvalidCharacter:
1114 handleError(ParseErrorCode.InvalidCharacter);
1115 break;
1116 }
1117 switch (token) {
1118 case SyntaxKind.LineCommentTrivia:
1119 case SyntaxKind.BlockCommentTrivia:
1120 if (disallowComments) {
1121 handleError(ParseErrorCode.InvalidCommentToken);
1122 } else {
1123 onComment();
1124 }
1125 break;
1126 case SyntaxKind.Unknown:

Callers 10

parseFunction · 0.90
parseSettingsFunction · 0.90
traverseNodesFunction · 0.70
getLocationFunction · 0.70
parseFunction · 0.70
parseTreeFunction · 0.70
renderMethod · 0.50

Calls 7

toNoArgVisitFunction · 0.85
toOneArgVisitFunction · 0.85
parseValueFunction · 0.85
createScannerFunction · 0.70
scanNextFunction · 0.70
handleErrorFunction · 0.70
getTokenMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…