def parseSourceString(sourceString): global lastLoc, currentPackage successful = True cntlr.showStatus("Compiling sphinx file {0}".format( os.path.basename(sphinxFile))) try: lastLoc = 0 currentPackage = None prog = sphinxGrammar.parseString(sourceString, parseAll=True) xmlns.clear() # dereference xmlns definitions prog.insert(0, astSourceFile(sphinxFile)) # keep the source file name sphinxProgs.append(prog) except (ParseException, ParseSyntaxException) as err: from arelle.XPathParser import exceptionErrorIndication file = os.path.basename(sphinxFile) logMessage("ERROR", "sphinxCompiler:syntaxError", _("Parse error: \n%(error)s"), sphinxFile=sphinxFile, sourceFileLines=((file, lineno(err.loc, err.pstr)), ), error=exceptionErrorIndication(err)) successful = False except (ValueError) as err: file = os.path.basename(sphinxFile) logMessage("ERROR", "sphinxCompiler:valueError", _("Parsing terminated due to error: \n%(error)s"), sphinxFile=sphinxFile, sourceFileLines=((file, lineno(lastLoc, sourceString)), ), error=err) successful = False except Exception as err: file = os.path.basename(sphinxFile) logMessage("ERROR", "sphinxCompiler:parserException", _("Parsing of terminated due to error: \n%(error)s"), sphinxFile=sphinxFile, sourceFileLines=((file, lineno(lastLoc, sourceString)), ), error=err, exc_info=True) successful = False cntlr.showStatus("Compiled sphinx files {0}".format({ True: "successful", False: "with errors" }[successful]), clearAfter=5000) xmlns.clear() return successful
def parse(modelFormula): if sys.version[0] >= '3': # python 3 requires modified parser to allow release of global objects when closing DTS from arelle.pyparsing.pyparsing_py3 import ParseException, ParseSyntaxException else: from pyparsing import ParseException, ParseSyntaxException modelXbrl = modelFormula.modelXbrl global formulaFile, lineno, xmlns, logMessage logMessage = modelXbrl.log formulaFile = modelFormula.modelDocument.uri baseName = modelFormula.modelDocument.basename lineno = modelFormula.sourceline sourceString = modelFormula.select xmlns = modelFormula.nsmap # cdr doesn't declare xsd namespace URI prefixes for ns, nsDocs in modelXbrl.namespaceDocs.items(): for nsDoc in nsDocs: nsDocPrefix = XmlUtil.xmlnsprefix(nsDoc.xmlRootElement, ns) if nsDocPrefix and nsDocPrefix not in xmlns: xmlns[nsDocPrefix] = ns xmlns[nsDocPrefix.upper()] = ns # cdr also has upper case prefixes intermixed break try: modelFormula.prog = cdrProg.parseString( sourceString, parseAll=True ) successful = True except (ParseException, ParseSyntaxException) as err: from arelle.XPathParser import exceptionErrorIndication logMessage("ERROR", "cdrFormula:syntaxError", _("Parse error: \n%(error)s"), formulaFile=formulaFile, sourceFileLines=((baseName, lineno),), error=exceptionErrorIndication(err)) successful = False except (ValueError) as err: logMessage("ERROR", "cdrFormula:valueError", _("Parsing terminated due to error: \n%(error)s"), formulaFile=formulaFile, sourceFileLines=((baseName, lineno),), error=err) successful = False except Exception as err: logMessage("ERROR", "cdrFormula:parserException", _("Parsing of terminated due to error: \n%(error)s"), formulaFile=formulaFile, sourceFileLines=((baseName, lineno),), error=err, exc_info=True) successful = False return successful
def parseSourceString(sourceString): global lastLoc, currentPackage successful = True cntlr.showStatus("Compiling sphinx file {0}".format(os.path.basename(sphinxFile))) try: lastLoc = 0 currentPackage = None prog = sphinxGrammar.parseString( sourceString, parseAll=True ) xmlns.clear() # dereference xmlns definitions prog.insert(0, astSourceFile(sphinxFile)) # keep the source file name sphinxProgs.append( prog ) except (ParseException, ParseSyntaxException) as err: from arelle.XPathParser import exceptionErrorIndication file = os.path.basename(sphinxFile) logMessage("ERROR", "sphinxCompiler:syntaxError", _("Parse error: \n%(error)s"), sphinxFile=sphinxFile, sourceFileLines=((file, lineno(err.loc,err.pstr)),), error=exceptionErrorIndication(err)) successful = False except (ValueError) as err: file = os.path.basename(sphinxFile) logMessage("ERROR", "sphinxCompiler:valueError", _("Parsing terminated due to error: \n%(error)s"), sphinxFile=sphinxFile, sourceFileLines=((file,lineno(lastLoc,sourceString)),), error=err) successful = False except Exception as err: file = os.path.basename(sphinxFile) logMessage("ERROR", "sphinxCompiler:parserException", _("Parsing of terminated due to error: \n%(error)s"), sphinxFile=sphinxFile, sourceFileLines=((file,lineno(lastLoc,sourceString)),), error=err, exc_info=True) successful = False cntlr.showStatus("Compiled sphinx files {0}".format({True:"successful", False:"with errors"}[successful]), clearAfter=5000) xmlns.clear() return successful
def sourceErrorIndication(self): return exceptionErrorIndication(self)