/*
 * 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 FILETYPE=require("./filetypes");const Json=require("./Json.js");const Ts=require("./Ts.js");const Md=require("./Md.js");function Parser(core,nodeDeps,rules,fileIndex,DomUtils,appCtx,msgCtx,constants){this.cssUtils=null;this.curFile=null;this.curFileType=null;this._fireHookFileRules=appCtx.fireHookFileRules;this.startCssPosition=0;this.startJsPosition=0;this.startIndex=0;this.endIndex=0;this.parseErrors=0;this._setConstants(constants);this._appCtx=appCtx;this._msgCtx=msgCtx;this._Json=new Json(this,nodeDeps,rules,fileIndex,appCtx,msgCtx);this._Ts=new Ts(this,nodeDeps,rules,fileIndex,appCtx,msgCtx);this._Md=new Md(this,nodeDeps,rules,fileIndex,appCtx,msgCtx)};Parser.prototype.clear=function(){this.startIndex=0;this.endIndex=0;this.startCssPosition={row:1,col:1,index:0};this._Json.clear();this._Ts.clear();this._Md.clear()};Parser.prototype.getAst=function(){var o;switch(this.curFileType){case FILETYPE.TS:o=this._Ts;break;case FILETYPE.JS:o=this._Js;break;case FILETYPE.JSON:o=this._Json;break;case FILETYPE.MD:o=this._Md;break}return o?o.getAst():null};Parser.prototype.getAstUtils=function(){return FILETYPE.isFileTypeTsOrTsx(this.curFileType)?this._Ts.getAstUtils():this.curFileType==="js"?this.Js.getAstUtils():null};Parser.prototype.fireHookFileRules=function(node,obj,inScriptJs){return this._fireHookFileRules(node,obj,inScriptJs)};Parser.prototype.getParseErrors=function(){return this.parseErrors};Parser.prototype.parse=function(text,curFile,curFileType,arg1){var ret;switch(curFileType){case FILETYPE.TS:case FILETYPE.TSX:ret=this._parseTs(text,curFile,curFileType,arg1);break;case FILETYPE.JSON:ret=this._parseJson(text,curFile,curFileType);break;case FILETYPE.MD:ret=this._parseMd(text,curFile,curFileType);break}return ret};Parser.prototype.parseOnly=function(text,curFile,curFileType){var ret;switch(curFileType){case FILETYPE.JSON:ret=this._parseJsonOnly(text,curFile,curFileType);break;default:this._msgCtx.assert("Unhandled Parser.parseOnly unexpected invocation")}return ret};Parser.prototype._parseHtml=function(text,curFile,curFileType,rawData,suppData){};Parser.prototype.getHtmlTopNode=function(){return this._Html.getTopNode()};Parser.prototype.getCurTagNode=function(){return this._Html.getCurTagNode()};Parser.prototype._parseCss=function(text){return this._Css.parse(text)};Parser.prototype._parseJs=function(text,curFile,curFileType,inner){if(curFile){this.curFile=curFile}if(curFileType){this.curFileType=curFileType}return this._Js.parse(text,inner)};Parser.prototype.getJsAst=function(){return this._Js.getJsAst()};Parser.prototype.getInScriptJs=function(){return this._Html.getInScriptJs()};Parser.prototype._parseTs=function(text,curFile,curFileType){if(curFile){this.curFile=curFile}if(curFileType){this.curFileType=curFileType}if(this._Ts.hasParser()){return this._Ts.parse(text,curFile,curFileType)}if(!this._oneTimeMsg){this._Ts.reportNoParser();this._oneTimeMsg=true}return false};Parser.prototype._parseJson=function(text,curFile,curFileType){if(curFile){this.curFile=curFile}if(curFileType){this.curFileType=curFileType}return this._Json.parse(text,curFile,curFileType)};Parser.prototype._parseJsonOnly=function(text,curFile,curFileType){return this._Json.parseOnly(text,curFile,curFileType)};Parser.prototype._parseMd=function(text,curFile,curFileType){if(curFile){this.curFile=curFile}if(curFileType){this.curFileType=curFileType}return this._Md.parse(text,curFile,curFileType)};Parser.prototype.setCssUtils=function(utils){this.cssUtils=utils};Parser.prototype._setConstants=function(constants){for(let con in constants){this[con]=constants[con]}};module.exports=Parser;