/*
 * Copyright (c) 2018, 2026, Oracle and/or its affiliates.
 * Licensed under The Universal Permissive License (UPL), Version 1.0
 * as shown at https://oss.oracle.com/licenses/upl/
 */
const AstJson=require("../lib/AstJson");const FILETYPE=require("./filetypes");class Json{constructor(parser,nd,rules,fileIndex,appCtx,msgCtx){this._parser=parser;this._rules=rules;this._Issue=appCtx.Issue;this._reporter=appCtx.reporter;this._fileIndex=fileIndex;this._utils=appCtx.utils;this._msgCtx=msgCtx;this._nd=nd;this._Ast=null;this._AstJson=new AstJson(msgCtx)}parse(data,file){var suppData,rc;suppData=this._checkSyntax(data,false);rc=this._parser.fireHookFileRules(suppData.ast,suppData,false);if(typeof rc==="undefined"||typeof rc==="boolean"&&rc){this._rules.fireRules({type:FILETYPE.JSON,obj:suppData,tagNode:null,node:suppData.ast,rawData:this._rawData,data:data,suppData:suppData},null,file,FILETYPE.JSON,suppData,false)}this._parser.fireHookFileRules(null,null)}parseOnly(data){return this._checkSyntax(data,false)}getAst(){return this._Ast}clear(){}_checkSyntax(data,hasComments){var suppData=this._isValidJson(data,hasComments);if(typeof suppData.msg==="string"){suppData.ast=null;this._parser.startIndex=this._parser.endIndex=suppData.position}else{suppData.ast=this._AstJson.parse(data);this._startIndex=this._endIndex=0}return suppData}_isValidJson(data,isComments){var obj=this._utils.parseJson(data,isComments);if(obj.msg){obj.msg=obj.msg+` at line ${obj.line}, col ${obj.col} (position ${obj.startIndex})`;obj.position=obj.startIndex}return obj}}module.exports=Json;