arelle-release 2.37.47__py3-none-any.whl → 2.37.49__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of arelle-release might be problematic. Click here for more details.
- arelle/CntlrCmdLine.py +5 -1
- arelle/ModelObjectFactory.py +18 -2
- arelle/_version.py +2 -2
- arelle/plugin/validate/EDINET/Constants.py +6 -0
- arelle/plugin/validate/EDINET/PluginValidationDataExtension.py +134 -7
- arelle/plugin/validate/EDINET/Statement.py +139 -0
- arelle/plugin/validate/EDINET/rules/contexts.py +5 -10
- arelle/plugin/validate/EDINET/rules/edinet.py +89 -51
- arelle/plugin/validate/EDINET/rules/gfm.py +41 -0
- {arelle_release-2.37.47.dist-info → arelle_release-2.37.49.dist-info}/METADATA +3 -1
- {arelle_release-2.37.47.dist-info → arelle_release-2.37.49.dist-info}/RECORD +15 -99
- arelle/archive/CustomLogger.py +0 -43
- arelle/archive/LoadEFMvalidate.py +0 -32
- arelle/archive/LoadSavePreLbCsv.py +0 -26
- arelle/archive/LoadValidate.cs +0 -31
- arelle/archive/LoadValidate.py +0 -36
- arelle/archive/LoadValidateCmdLine.java +0 -69
- arelle/archive/LoadValidatePostedZip.java +0 -57
- arelle/archive/LoadValidateWebService.java +0 -34
- arelle/archive/SaveTableToExelle.py +0 -140
- arelle/archive/TR3toTR4.py +0 -88
- arelle/archive/plugin/ESEF_2022/__init__.py +0 -47
- arelle/archive/plugin/bigInstance.py +0 -394
- arelle/archive/plugin/cmdWebServerExtension.py +0 -43
- arelle/archive/plugin/crashTest.py +0 -38
- arelle/archive/plugin/functionsXmlCreation.py +0 -106
- arelle/archive/plugin/hello_i18n.pot +0 -26
- arelle/archive/plugin/hello_i18n.py +0 -32
- arelle/archive/plugin/importTestChild1.py +0 -21
- arelle/archive/plugin/importTestChild2.py +0 -22
- arelle/archive/plugin/importTestGrandchild1.py +0 -21
- arelle/archive/plugin/importTestGrandchild2.py +0 -21
- arelle/archive/plugin/importTestImported1.py +0 -23
- arelle/archive/plugin/importTestImported11.py +0 -22
- arelle/archive/plugin/importTestParent.py +0 -48
- arelle/archive/plugin/instanceInfo.py +0 -306
- arelle/archive/plugin/loadFromOIM-2018.py +0 -1282
- arelle/archive/plugin/locale/fr/LC_MESSAGES/hello_i18n.po +0 -25
- arelle/archive/plugin/objectmaker.py +0 -285
- arelle/archive/plugin/packagedImportTest/__init__.py +0 -47
- arelle/archive/plugin/packagedImportTest/importTestChild1.py +0 -21
- arelle/archive/plugin/packagedImportTest/importTestChild2.py +0 -22
- arelle/archive/plugin/packagedImportTest/importTestGrandchild1.py +0 -21
- arelle/archive/plugin/packagedImportTest/importTestGrandchild2.py +0 -21
- arelle/archive/plugin/packagedImportTest/importTestImported1.py +0 -24
- arelle/archive/plugin/packagedImportTest/importTestImported11.py +0 -21
- arelle/archive/plugin/packagedImportTest/subdir/importTestImported111.py +0 -21
- arelle/archive/plugin/packagedImportTest/subdir/subsubdir/importTestImported1111.py +0 -21
- arelle/archive/plugin/sakaCalendar.py +0 -215
- arelle/archive/plugin/saveInstanceInfoset.py +0 -121
- arelle/archive/plugin/sphinx/FormulaGenerator.py +0 -823
- arelle/archive/plugin/sphinx/SphinxContext.py +0 -404
- arelle/archive/plugin/sphinx/SphinxEvaluator.py +0 -783
- arelle/archive/plugin/sphinx/SphinxMethods.py +0 -1287
- arelle/archive/plugin/sphinx/SphinxParser.py +0 -1093
- arelle/archive/plugin/sphinx/SphinxValidator.py +0 -163
- arelle/archive/plugin/sphinx/US-GAAP Ratios Example.xsr +0 -52
- arelle/archive/plugin/sphinx/__init__.py +0 -285
- arelle/archive/plugin/streamingExtensions.py +0 -335
- arelle/archive/plugin/updateTableLB.py +0 -242
- arelle/archive/plugin/validate/SBRnl/CustomLoader.py +0 -19
- arelle/archive/plugin/validate/SBRnl/DTS.py +0 -305
- arelle/archive/plugin/validate/SBRnl/Dimensions.py +0 -357
- arelle/archive/plugin/validate/SBRnl/Document.py +0 -799
- arelle/archive/plugin/validate/SBRnl/Filing.py +0 -467
- arelle/archive/plugin/validate/SBRnl/__init__.py +0 -75
- arelle/archive/plugin/validate/SBRnl/config.xml +0 -26
- arelle/archive/plugin/validate/SBRnl/sbr-nl-taxonomies.xml +0 -754
- arelle/archive/plugin/validate/USBestPractices.py +0 -570
- arelle/archive/plugin/validate/USCorpAction.py +0 -557
- arelle/archive/plugin/validate/USSecTagging.py +0 -337
- arelle/archive/plugin/validate/XDC/__init__.py +0 -77
- arelle/archive/plugin/validate/XDC/config.xml +0 -20
- arelle/archive/plugin/validate/XFsyntax/__init__.py +0 -64
- arelle/archive/plugin/validate/XFsyntax/xf.py +0 -2227
- arelle/archive/plugin/validate/calc2.py +0 -536
- arelle/archive/plugin/validateSchemaLxml.py +0 -156
- arelle/archive/plugin/validateTableInfoset.py +0 -52
- arelle/archive/us-gaap-dei-docType-extraction-frm.xml +0 -90
- arelle/archive/us-gaap-dei-ratio-cash-frm.xml +0 -150
- arelle/examples/plugin/formulaSuiteConverter.py +0 -212
- arelle/examples/plugin/functionsCustom.py +0 -59
- arelle/examples/plugin/hello_dolly.py +0 -64
- arelle/examples/plugin/multi.py +0 -58
- arelle/examples/plugin/rssSaveOim.py +0 -96
- arelle/examples/plugin/validate/XYZ/DisclosureSystems.py +0 -2
- arelle/examples/plugin/validate/XYZ/PluginValidationDataExtension.py +0 -10
- arelle/examples/plugin/validate/XYZ/ValidationPluginExtension.py +0 -50
- arelle/examples/plugin/validate/XYZ/__init__.py +0 -75
- arelle/examples/plugin/validate/XYZ/resources/config.xml +0 -16
- arelle/examples/plugin/validate/XYZ/rules/__init__.py +0 -0
- arelle/examples/plugin/validate/XYZ/rules/rules01.py +0 -110
- arelle/examples/plugin/validate/XYZ/rules/rules02.py +0 -59
- arelle/scripts-macOS/startWebServer.command +0 -3
- arelle/scripts-unix/startWebServer.sh +0 -1
- arelle/scripts-windows/startWebServer.bat +0 -5
- {arelle_release-2.37.47.dist-info → arelle_release-2.37.49.dist-info}/WHEEL +0 -0
- {arelle_release-2.37.47.dist-info → arelle_release-2.37.49.dist-info}/entry_points.txt +0 -0
- {arelle_release-2.37.47.dist-info → arelle_release-2.37.49.dist-info}/licenses/LICENSE.md +0 -0
- {arelle_release-2.37.47.dist-info → arelle_release-2.37.49.dist-info}/top_level.txt +0 -0
|
@@ -1,1093 +0,0 @@
|
|
|
1
|
-
'''
|
|
2
|
-
SphinxParser is an example of a package plug-in parser for the CoreFiling Sphinx language.
|
|
3
|
-
|
|
4
|
-
See COPYRIGHT.md for copyright information.
|
|
5
|
-
|
|
6
|
-
Sphinx is a Rules Language for XBRL described by a Sphinx 2 Primer
|
|
7
|
-
(c) Copyright 2012 CoreFiling, Oxford UK.
|
|
8
|
-
Sphinx copyright applies to the Sphinx language, not to this software.
|
|
9
|
-
Workiva, Inc. conveys neither rights nor license for the Sphinx language.
|
|
10
|
-
'''
|
|
11
|
-
|
|
12
|
-
import time, sys, os, os.path, zipfile
|
|
13
|
-
import regex as re
|
|
14
|
-
from arelle.ModelValue import qname
|
|
15
|
-
from arelle.ModelFormulaObject import Aspect, aspectStr
|
|
16
|
-
from arelle.ModelXbrl import DEFAULT, NONDEFAULT, DEFAULTorNONDEFAULT
|
|
17
|
-
|
|
18
|
-
# Debugging flag can be set to either "debug_flag=True" or "debug_flag=False"
|
|
19
|
-
debug_flag=True
|
|
20
|
-
|
|
21
|
-
logMessage = None
|
|
22
|
-
sphinxFile = None
|
|
23
|
-
lastLoc = 0
|
|
24
|
-
lineno = None
|
|
25
|
-
xmlns = {}
|
|
26
|
-
|
|
27
|
-
reservedWords = {"tuple", "primary", "entity", "period", "unit", "segment", "scenario",
|
|
28
|
-
"NaN", "unbound", "none"}
|
|
29
|
-
|
|
30
|
-
isGrammarCompiled = False
|
|
31
|
-
|
|
32
|
-
class PrefixError(Exception):
|
|
33
|
-
def __init__(self, qnameToken):
|
|
34
|
-
self.qname = qnameToken
|
|
35
|
-
self.message = "QName prefix undeclared"
|
|
36
|
-
self.args = ( self.__repr__(), )
|
|
37
|
-
def __repr__(self):
|
|
38
|
-
return _("QName prefix undeclared: {0}").format(self.qname)
|
|
39
|
-
|
|
40
|
-
# parse operations ("compile methods") are listed alphabetically
|
|
41
|
-
|
|
42
|
-
def compileAnnotation( sourceStr, loc, toks ):
|
|
43
|
-
return None
|
|
44
|
-
|
|
45
|
-
def compileAnnotationDeclaration( sourceStr, loc, toks ):
|
|
46
|
-
global lastLoc # for exception handling
|
|
47
|
-
lastLoc = loc
|
|
48
|
-
return astAnnotationDeclaration(sourceStr, loc, toks[0], toks[1] if len(toks) > 1 else None)
|
|
49
|
-
|
|
50
|
-
def compileBinaryOperation( sourceStr, loc, toks ):
|
|
51
|
-
if len(toks) == 1:
|
|
52
|
-
return toks
|
|
53
|
-
global lastLoc; lastLoc = loc
|
|
54
|
-
return astBinaryOperation(sourceStr, loc, toks[0], toks[1], toks[2])
|
|
55
|
-
|
|
56
|
-
def compileBrackets( sourceStr, loc, toks ):
|
|
57
|
-
if len(toks) == 1: # parentheses around an expression
|
|
58
|
-
return astUnaryOperation(sourceStr, loc, "brackets", toks[0])
|
|
59
|
-
return astFunctionReference(sourceStr, loc, "list", [tok for tok in toks if tok != ','])
|
|
60
|
-
|
|
61
|
-
def compileComment( sourceStr, loc, toks ):
|
|
62
|
-
global lastLoc; lastLoc = loc
|
|
63
|
-
return astComment(sourceStr, loc, toks[0])
|
|
64
|
-
|
|
65
|
-
def compileConstant( sourceStr, loc, toks ):
|
|
66
|
-
return astConstant(sourceStr, loc, toks)
|
|
67
|
-
|
|
68
|
-
def compileFloatLiteral( sourceStr, loc, toks ):
|
|
69
|
-
global lastLoc; lastLoc = loc
|
|
70
|
-
return astNumericLiteral(sourceStr, loc, float(toks[0]))
|
|
71
|
-
|
|
72
|
-
def compileFor( sourceStr, loc, toks ):
|
|
73
|
-
global lastLoc; lastLoc = loc
|
|
74
|
-
return astFor(sourceStr, loc, toks[1], toks[2], toks[3])
|
|
75
|
-
|
|
76
|
-
def compileFormulaRule( sourceStr, loc, toks ):
|
|
77
|
-
return astFormulaRule(sourceStr, loc, toks)
|
|
78
|
-
|
|
79
|
-
def compileFunctionDeclaration( sourceStr, loc, toks ):
|
|
80
|
-
global lastLoc; lastLoc = loc
|
|
81
|
-
return astFunctionDeclaration(sourceStr, loc, toks[0], toks[1], toks[3:-2], toks[-1])
|
|
82
|
-
|
|
83
|
-
def compileFunctionReference( sourceStr, loc, toks ):
|
|
84
|
-
global lastLoc; lastLoc = loc
|
|
85
|
-
name = toks[0]
|
|
86
|
-
if isinstance(name, astFunctionReference) and not name.args:
|
|
87
|
-
name = name.name
|
|
88
|
-
if name == "unit":
|
|
89
|
-
try:
|
|
90
|
-
return astFunctionReference(sourceStr, loc, name, toks[astQnameLiteral(sourceStr, loc, toks[1])])
|
|
91
|
-
except PrefixError as err:
|
|
92
|
-
logMessage("ERROR", "sphinxCompiler:missingXmlnsDeclarations",
|
|
93
|
-
_("Missing xmlns for prefix in unit %(qname)s"),
|
|
94
|
-
sourceFileLines=((sphinxFile, lineno(loc, sourceStr)),),
|
|
95
|
-
qname=err.qname)
|
|
96
|
-
return None
|
|
97
|
-
# compile any args
|
|
98
|
-
return astFunctionReference(sourceStr, loc, name, toks[1:])
|
|
99
|
-
|
|
100
|
-
def compileHyperspaceAxis( sourceStr, loc, toks ):
|
|
101
|
-
try:
|
|
102
|
-
return astHyperspaceAxis( sourceStr, loc, toks )
|
|
103
|
-
except PrefixError as err:
|
|
104
|
-
logMessage("ERROR", "sphinxCompiler:missingXmlnsDeclarations",
|
|
105
|
-
_("Missing xmlns for prefix in %(qname)s"),
|
|
106
|
-
sourceFileLines=((sphinxFile, lineno(loc, sourceStr)),),
|
|
107
|
-
qname=err.qname)
|
|
108
|
-
return None
|
|
109
|
-
|
|
110
|
-
def compileHyperspaceExpression( sourceStr, loc, toks ):
|
|
111
|
-
try:
|
|
112
|
-
return astHyperspaceExpression(sourceStr, loc, toks)
|
|
113
|
-
except PrefixError as err:
|
|
114
|
-
logMessage("ERROR", "sphinxCompiler:missingXmlnsDeclarations",
|
|
115
|
-
_("Missing xmlns for prefix in %(qname)s"),
|
|
116
|
-
sourceFileLines=((sphinxFile, lineno(loc, sourceStr)),),
|
|
117
|
-
qname=err.qname)
|
|
118
|
-
return None
|
|
119
|
-
|
|
120
|
-
def compileIf( sourceStr, loc, toks ):
|
|
121
|
-
global lastLoc; lastLoc = loc
|
|
122
|
-
return astIf(sourceStr, loc, toks[1], toks[2], toks[3])
|
|
123
|
-
|
|
124
|
-
def compileIntegerLiteral( sourceStr, loc, toks ):
|
|
125
|
-
global lastLoc; lastLoc = loc
|
|
126
|
-
return astNumericLiteral(sourceStr, loc, int(toks[0]))
|
|
127
|
-
|
|
128
|
-
def compileMessage( sourceStr, loc, toks ):
|
|
129
|
-
# construct a message object and return it
|
|
130
|
-
global lastLoc; lastLoc = loc
|
|
131
|
-
return astMessage(sourceStr, loc, toks[0])
|
|
132
|
-
|
|
133
|
-
def compileMethodReference( sourceStr, loc, toks ):
|
|
134
|
-
if len(toks) == 1:
|
|
135
|
-
return toks
|
|
136
|
-
global lastLoc; lastLoc = loc
|
|
137
|
-
if len(toks) > 1 and toks[0] == "::": # method with no object, e.g., ::taxonomy
|
|
138
|
-
result = None
|
|
139
|
-
methNameTokNdx = 1
|
|
140
|
-
elif len(toks) > 2 and toks[1] == "::":
|
|
141
|
-
result = toks[0]
|
|
142
|
-
methNameTokNdx = 2
|
|
143
|
-
else:
|
|
144
|
-
return toks
|
|
145
|
-
while methNameTokNdx < len(toks):
|
|
146
|
-
taggedExpr = toks[methNameTokNdx]
|
|
147
|
-
if isinstance(taggedExpr, astTagAssignment):
|
|
148
|
-
methArg = taggedExpr.expr
|
|
149
|
-
else:
|
|
150
|
-
methArg = taggedExpr
|
|
151
|
-
if isinstance(methArg, str):
|
|
152
|
-
methName = methArg
|
|
153
|
-
methArgs = []
|
|
154
|
-
elif isinstance(methArg, astQnameLiteral) and methArg.value.namespaceURI is None:
|
|
155
|
-
methName = methArg.value.localName
|
|
156
|
-
methArgs = []
|
|
157
|
-
elif isinstance(methArg, astFunctionReference):
|
|
158
|
-
methName = methArg.name
|
|
159
|
-
methArgs = methArg.args
|
|
160
|
-
else:
|
|
161
|
-
logMessage("ERROR", "sphinxCompiler:methodNameNotRecognized",
|
|
162
|
-
_("Method name not recognized: %(name)s"),
|
|
163
|
-
sourceFileLines=((sphinxFile, lineno(loc, sourceStr)),),
|
|
164
|
-
name=methArg)
|
|
165
|
-
return "none" # probably syntax error?? need message???
|
|
166
|
-
result = astMethodReference(sourceStr, loc, methName, [result] + methArgs)
|
|
167
|
-
if isinstance(taggedExpr, astTagAssignment):
|
|
168
|
-
taggedExpr.expr = result
|
|
169
|
-
result = taggedExpr
|
|
170
|
-
if methNameTokNdx + 2 < len(toks) and toks[methNameTokNdx + 1] == "::":
|
|
171
|
-
methNameTokNdx += 2
|
|
172
|
-
else:
|
|
173
|
-
# probably suntax if extra toks
|
|
174
|
-
break
|
|
175
|
-
return result
|
|
176
|
-
|
|
177
|
-
def compileNamespaceDeclaration( sourceStr, loc, toks ):
|
|
178
|
-
global lastLoc; lastLoc = loc
|
|
179
|
-
prefix = None if len(toks) == 2 else toks[1]
|
|
180
|
-
namespaceNode = toks[-1]
|
|
181
|
-
if prefix in xmlns:
|
|
182
|
-
logMessage("ERROR", "sphinxCompiler:multipleXmlnsDeclarations",
|
|
183
|
-
_("Duplicate xmlns for prefix %(prefix)s"),
|
|
184
|
-
sourceFileLines=((sphinxFile, lineno(loc, sourceStr)),),
|
|
185
|
-
prefix=prefix)
|
|
186
|
-
elif not isinstance(namespaceNode, astStringLiteral):
|
|
187
|
-
logMessage("ERROR", "sphinxCompiler:xmlnsNotStringConstant",
|
|
188
|
-
_("Xmlns for prefix %(prefix)s does not assign a string constant."),
|
|
189
|
-
sourceFileLines=((sphinxFile, lineno(loc, sourceStr)),),
|
|
190
|
-
prefix=prefix)
|
|
191
|
-
else:
|
|
192
|
-
namespace = namespaceNode.text
|
|
193
|
-
xmlns[prefix] = namespace
|
|
194
|
-
return astNamespaceDeclaration(sourceStr, loc, prefix, namespace)
|
|
195
|
-
return astNoOp(sourceStr, loc)
|
|
196
|
-
|
|
197
|
-
def compileOp( sourceStr, loc, toks ):
|
|
198
|
-
global lastLoc; lastLoc = loc
|
|
199
|
-
return toks
|
|
200
|
-
|
|
201
|
-
def compilePackageDeclaration( sourceStr, loc, toks ):
|
|
202
|
-
global lastLoc; lastLoc = loc
|
|
203
|
-
global currentPackage
|
|
204
|
-
currentPackage = toks[0]
|
|
205
|
-
return None
|
|
206
|
-
|
|
207
|
-
def compilePrecondition( sourceStr, loc, toks ):
|
|
208
|
-
# construct a precondition object and return it
|
|
209
|
-
return astPreconditionReference(sourceStr, loc, toks)
|
|
210
|
-
|
|
211
|
-
def compilePreconditionDeclaration( sourceStr, loc, toks ):
|
|
212
|
-
global lastLoc; lastLoc = loc
|
|
213
|
-
if len(toks) >= 2 and toks[-2] == "otherwise": # has otherwise
|
|
214
|
-
return astPreconditionReference(sourceStr, loc, toks[0:-2], toks[-1])
|
|
215
|
-
return astPreconditionDeclaration(sourceStr, loc, toks[0], toks[1], None)
|
|
216
|
-
|
|
217
|
-
def compileQname( sourceStr, loc, toks ):
|
|
218
|
-
global lastLoc; lastLoc = loc
|
|
219
|
-
qnameTok = toks[0]
|
|
220
|
-
if qnameTok in {"error", "warning", "info", "pass"}:
|
|
221
|
-
return astFunctionReference(sourceStr, loc, qnameTok, [])
|
|
222
|
-
return astQnameLiteral(sourceStr, loc, qnameTok)
|
|
223
|
-
|
|
224
|
-
def compileReportRule( sourceStr, loc, toks ):
|
|
225
|
-
return astReportRule(sourceStr, loc, toks)
|
|
226
|
-
|
|
227
|
-
def compileRuleBase( sourceStr, loc, toks ):
|
|
228
|
-
global lastLoc; lastLoc = loc
|
|
229
|
-
result = [tok for tok in toks if isinstance(tok, astTransform)]
|
|
230
|
-
if len(toks) >= 1 and isinstance(toks[0], astPreconditionReference):
|
|
231
|
-
result.insert(0, astRuleBasePrecondition(sourceStr, loc, toks[0]))
|
|
232
|
-
return result
|
|
233
|
-
|
|
234
|
-
def compileSeverity( sourceStr, loc, toks ):
|
|
235
|
-
global lastLoc; lastLoc = loc
|
|
236
|
-
# construct a severity object and return it
|
|
237
|
-
return astSeverity(sourceStr, loc, toks[0])
|
|
238
|
-
|
|
239
|
-
def compileStringLiteral( sourceStr, loc, toks ):
|
|
240
|
-
global lastLoc; lastLoc = loc
|
|
241
|
-
return astStringLiteral(sourceStr, loc, toks[0])
|
|
242
|
-
|
|
243
|
-
def compileTagAssignment( sourceStr, loc, toks ):
|
|
244
|
-
if len(toks) == 1:
|
|
245
|
-
return toks
|
|
246
|
-
global lastLoc; lastLoc = loc
|
|
247
|
-
return astTagAssignment(sourceStr, loc, toks[2], toks[0])
|
|
248
|
-
|
|
249
|
-
def compileTransform( sourceStr, loc, toks ):
|
|
250
|
-
global lastLoc; lastLoc = loc
|
|
251
|
-
return astTransform(sourceStr, loc, toks[0], toks[1], toks[2])
|
|
252
|
-
|
|
253
|
-
def compileUnaryOperation( sourceStr, loc, toks ):
|
|
254
|
-
if len(toks) == 1:
|
|
255
|
-
return toks
|
|
256
|
-
global lastLoc; lastLoc = loc
|
|
257
|
-
return astUnaryOperation(sourceStr, loc, toks[0], toks[1])
|
|
258
|
-
|
|
259
|
-
def compileValuesIteration( sourceStr, loc, toks ):
|
|
260
|
-
if len(toks) == 1:
|
|
261
|
-
return toks
|
|
262
|
-
global lastLoc; lastLoc = loc
|
|
263
|
-
return astValuesIteration(sourceStr, loc, toks[1])
|
|
264
|
-
|
|
265
|
-
def compileValidationRule( sourceStr, loc, toks ):
|
|
266
|
-
return astValidationRule(sourceStr, loc, toks)
|
|
267
|
-
|
|
268
|
-
def compileVariableAssignment( sourceStr, loc, toks ):
|
|
269
|
-
if len(toks) == 1:
|
|
270
|
-
return toks
|
|
271
|
-
return astVariableAssignment(sourceStr, loc, toks)
|
|
272
|
-
|
|
273
|
-
def compileVariableReference( sourceStr, loc, toks ):
|
|
274
|
-
global lastLoc; lastLoc = loc
|
|
275
|
-
return astVariableReference(sourceStr, loc, toks[0][1:])
|
|
276
|
-
|
|
277
|
-
def compileWith( sourceStr, loc, toks ):
|
|
278
|
-
if len(toks) == 1:
|
|
279
|
-
return toks
|
|
280
|
-
return astWith(sourceStr, loc, toks[1], toks[2:-1], toks[-1])
|
|
281
|
-
|
|
282
|
-
class astNode:
|
|
283
|
-
def __init__(self, sourceStr=None, loc=None):
|
|
284
|
-
self.sphinxFile = sphinxFile
|
|
285
|
-
self.sourceStr = sourceStr
|
|
286
|
-
self.loc = loc
|
|
287
|
-
global lastLoc # for exception handling
|
|
288
|
-
lastLoc = loc
|
|
289
|
-
|
|
290
|
-
def clear(self):
|
|
291
|
-
self.__dict__.clear() # delete local attributes
|
|
292
|
-
|
|
293
|
-
@property
|
|
294
|
-
def sourceLine(self):
|
|
295
|
-
if self.sourceStr and self.loc:
|
|
296
|
-
return lineno(self.loc, self.sourceStr)
|
|
297
|
-
return None # no line number available
|
|
298
|
-
|
|
299
|
-
@property
|
|
300
|
-
def sourceFileLine(self):
|
|
301
|
-
return (self.sphinxFile, self.sourceLine)
|
|
302
|
-
|
|
303
|
-
@property
|
|
304
|
-
def nodeTypeName(self):
|
|
305
|
-
return type(self).__name__[3:]
|
|
306
|
-
|
|
307
|
-
def __repr__(self):
|
|
308
|
-
return "{0}({1})".format(type(self).__name__, "")
|
|
309
|
-
|
|
310
|
-
# subtypes of astNode are arranged alphabetically
|
|
311
|
-
|
|
312
|
-
class astAnnotationDeclaration(astNode):
|
|
313
|
-
def __init__(self, sourceStr, loc, name, annotationType):
|
|
314
|
-
super(astAnnotationDeclaration, self).__init__(sourceStr, loc)
|
|
315
|
-
self.name = name
|
|
316
|
-
self.annotationType = annotationType # "string"
|
|
317
|
-
def __repr__(self):
|
|
318
|
-
return "annotationDeclaration({0}{2}(".format(self.name,
|
|
319
|
-
(" as " + self.annotationType) if self.annotationType else "")
|
|
320
|
-
|
|
321
|
-
class astBinaryOperation(astNode):
|
|
322
|
-
def __init__(self, sourceStr, loc, leftExpr, op, rightExpr):
|
|
323
|
-
super(astBinaryOperation, self).__init__(sourceStr, loc)
|
|
324
|
-
self.op = op
|
|
325
|
-
self.leftExpr = leftExpr
|
|
326
|
-
self.rightExpr = rightExpr
|
|
327
|
-
def __repr__(self):
|
|
328
|
-
return "binaryOperation({0} {1} {2})".format(self.leftExpr, self.op, self.rightExpr)
|
|
329
|
-
|
|
330
|
-
class astComment(astNode):
|
|
331
|
-
def __init__(self, sourceStr, loc, text):
|
|
332
|
-
super(astComment, self).__init__(sourceStr, loc)
|
|
333
|
-
self.text = text
|
|
334
|
-
def __repr__(self):
|
|
335
|
-
return "comment({0})".format(self.text)
|
|
336
|
-
|
|
337
|
-
class astConstant(astNode):
|
|
338
|
-
def __init__(self, sourceStr, loc, toks):
|
|
339
|
-
super(astConstant, self).__init__(sourceStr, loc)
|
|
340
|
-
self.constantName = toks[0]
|
|
341
|
-
self.expr = toks[-1]
|
|
342
|
-
self.value = None # dynamically assigned
|
|
343
|
-
self.tagName = None
|
|
344
|
-
if len(toks) > 2 and toks[1] == "#": # has tag
|
|
345
|
-
if len(toks) > 4: # named tag
|
|
346
|
-
self.tagName = toks[2]
|
|
347
|
-
else: # use name for tag
|
|
348
|
-
self.tagName = self.constantName
|
|
349
|
-
def __repr__(self):
|
|
350
|
-
return "constant({0}{1} = {2})".format(self.constantName,
|
|
351
|
-
("#" + self.tagName) if self.tagName else "",
|
|
352
|
-
self.expr)
|
|
353
|
-
|
|
354
|
-
namedAxes = {"primary": Aspect.CONCEPT,
|
|
355
|
-
"entity": Aspect.ENTITY_IDENTIFIER,
|
|
356
|
-
"period": Aspect.PERIOD,
|
|
357
|
-
"segment": Aspect.NON_XDT_SEGMENT,
|
|
358
|
-
"scenario":Aspect.NON_XDT_SCENARIO,
|
|
359
|
-
"unit": Aspect.UNIT}
|
|
360
|
-
|
|
361
|
-
class astFor(astNode):
|
|
362
|
-
def __init__(self, sourceStr, loc, name, collectionExpr, expr):
|
|
363
|
-
super(astFor, self).__init__(sourceStr, loc)
|
|
364
|
-
self.name = name
|
|
365
|
-
self.collectionExpr = collectionExpr
|
|
366
|
-
self.expr = expr
|
|
367
|
-
def __repr__(self):
|
|
368
|
-
return "for({0} in {1}, {2})".format(self.name, self.collectionExpr, self.expr)
|
|
369
|
-
|
|
370
|
-
class astFunctionDeclaration(astNode):
|
|
371
|
-
def __init__(self, sourceStr, loc, functionType, name, params, expr):
|
|
372
|
-
try:
|
|
373
|
-
super(astFunctionDeclaration, self).__init__(sourceStr, loc)
|
|
374
|
-
self.functionType = functionType # "function", "macro"
|
|
375
|
-
self.name = name
|
|
376
|
-
self.params = params
|
|
377
|
-
if (expr) == "unit": # expr is a QName
|
|
378
|
-
self.expr = astQnameLiteral(sourceStr, loc, expr)
|
|
379
|
-
else:
|
|
380
|
-
self.expr = expr
|
|
381
|
-
except PrefixError as err:
|
|
382
|
-
logMessage("ERROR", "sphinxCompiler:missingXmlnsDeclarations",
|
|
383
|
-
_("Missing xmlns for prefix in %(qname)s"),
|
|
384
|
-
sourceFileLines=((sphinxFile, lineno(loc, sourceStr)),),
|
|
385
|
-
qname=err.qname)
|
|
386
|
-
return None
|
|
387
|
-
def __repr__(self):
|
|
388
|
-
return "functionDeclaration({0}({1})) {2}".format(self.name,
|
|
389
|
-
", ".join(str(p) for p in self.params),
|
|
390
|
-
self.expr)
|
|
391
|
-
|
|
392
|
-
class astFunctionReference(astNode):
|
|
393
|
-
def __init__(self, sourceStr, loc, name, args):
|
|
394
|
-
super(astFunctionReference, self).__init__(sourceStr, loc)
|
|
395
|
-
self.name = name
|
|
396
|
-
self.localVariables = [a for a in args if isinstance(a, astVariableAssignment)]
|
|
397
|
-
self.args = [a for a in args if not isinstance(a, astVariableAssignment)]
|
|
398
|
-
def __repr__(self):
|
|
399
|
-
return "functionReference({0}({1}))".format(self.name,
|
|
400
|
-
", ".join(str(a) for a in self.args))
|
|
401
|
-
|
|
402
|
-
class astHyperspaceAxis(astNode):
|
|
403
|
-
def __init__(self, sourceStr, loc, toks):
|
|
404
|
-
STATE_AXIS_NAME_EXPECTED = 0
|
|
405
|
-
STATE_AXIS_NAMED = 1
|
|
406
|
-
STATE_EQ_VALUE = 10
|
|
407
|
-
STATE_IN_LIST = 11
|
|
408
|
-
STATE_AS_NAME = 20
|
|
409
|
-
STATE_AS_NAMED = 21
|
|
410
|
-
STATE_AS_EQ_VALUE = 22
|
|
411
|
-
STATE_AS_EQ_WHERE = 23
|
|
412
|
-
STATE_AS_RESTRICTION = 30
|
|
413
|
-
STATE_WHERE = 40
|
|
414
|
-
STATE_INDETERMINATE = 99
|
|
415
|
-
|
|
416
|
-
super(astHyperspaceAxis, self).__init__(sourceStr, loc)
|
|
417
|
-
self.aspect = None # case of only a where clause has no specified aspect
|
|
418
|
-
self.name = None
|
|
419
|
-
self.asVariableName = None
|
|
420
|
-
self.restriction = None # qname, expr, * or **
|
|
421
|
-
self.whereExpr = None
|
|
422
|
-
|
|
423
|
-
state = STATE_AXIS_NAME_EXPECTED
|
|
424
|
-
for tok in toks:
|
|
425
|
-
if tok == "where" and state in (STATE_AXIS_NAME_EXPECTED, STATE_AS_EQ_WHERE):
|
|
426
|
-
state = STATE_WHERE
|
|
427
|
-
elif tok == "=" and state == STATE_EQ_VALUE:
|
|
428
|
-
state = STATE_EQ_VALUE
|
|
429
|
-
elif tok == "in" and state == STATE_AXIS_NAMED:
|
|
430
|
-
state = STATE_IN_LIST
|
|
431
|
-
elif tok == "as" and state == STATE_AXIS_NAMED:
|
|
432
|
-
state = STATE_AS_NAME
|
|
433
|
-
elif tok == "=" and state == STATE_AXIS_NAMED:
|
|
434
|
-
state = STATE_EQ_VALUE
|
|
435
|
-
elif tok == "=" and state == STATE_AS_NAMED:
|
|
436
|
-
state = STATE_AS_EQ_VALUE
|
|
437
|
-
elif state == STATE_AXIS_NAME_EXPECTED:
|
|
438
|
-
if isinstance(tok, astQnameLiteral):
|
|
439
|
-
axisQname = tok.value
|
|
440
|
-
if axisQname.namespaceURI is None and axisQname.localName in namedAxes:
|
|
441
|
-
self.name = axisQname.localName
|
|
442
|
-
self.aspect = namedAxes[self.name]
|
|
443
|
-
else:
|
|
444
|
-
self.name = self.aspect = axisQname
|
|
445
|
-
elif isinstance(tok, astVariableReference):
|
|
446
|
-
self.name = '$' + tok.variableName
|
|
447
|
-
self.aspect = tok
|
|
448
|
-
elif tok in namedAxes: # e.g., "primary"
|
|
449
|
-
self.name = tok
|
|
450
|
-
self.aspect = namedAxes[tok]
|
|
451
|
-
state = STATE_AXIS_NAMED
|
|
452
|
-
elif state in (STATE_EQ_VALUE, STATE_AS_EQ_VALUE):
|
|
453
|
-
if isinstance(tok, astNode):
|
|
454
|
-
self.restriction = [tok]
|
|
455
|
-
elif tok == '*':
|
|
456
|
-
self.restriction = (NONDEFAULT,)
|
|
457
|
-
elif tok == '**':
|
|
458
|
-
self.restriction = (DEFAULTorNONDEFAULT,)
|
|
459
|
-
elif tok == 'none':
|
|
460
|
-
self.restriction = (DEFAULT,)
|
|
461
|
-
elif isinstance(tok, str):
|
|
462
|
-
self.restriction = [astQnameLiteral(sourceStr, loc, tok)]
|
|
463
|
-
elif isinstance(tok, astQnameLiteral):
|
|
464
|
-
self.restriction = [tok]
|
|
465
|
-
state = {STATE_EQ_VALUE: STATE_INDETERMINATE,
|
|
466
|
-
STATE_AS_EQ_VALUE: STATE_AS_EQ_WHERE}[state]
|
|
467
|
-
elif state == STATE_IN_LIST:
|
|
468
|
-
self.restriction = tok
|
|
469
|
-
state = STATE_INDETERMINATE
|
|
470
|
-
elif state == STATE_AS_NAME:
|
|
471
|
-
self.asVariableName = tok
|
|
472
|
-
state = STATE_AS_NAMED
|
|
473
|
-
elif state == STATE_WHERE:
|
|
474
|
-
self.whereExpr = tok
|
|
475
|
-
state = STATE_INDETERMINATE
|
|
476
|
-
else:
|
|
477
|
-
logMessage("ERROR", "sphinxCompiler:axisIndeterminate",
|
|
478
|
-
_("Axis indeterminte expression at %(element)s."),
|
|
479
|
-
sourceFileLines=((sphinxFile, lineno(loc, sourceStr)),),
|
|
480
|
-
element=tok)
|
|
481
|
-
def __repr__(self):
|
|
482
|
-
if self.name:
|
|
483
|
-
s = str(self.name)
|
|
484
|
-
else:
|
|
485
|
-
s = ""
|
|
486
|
-
if self.asVariableName:
|
|
487
|
-
s += " as " + str(self.asVariableName) + "=" + str(self.restriction)
|
|
488
|
-
elif self.restriction:
|
|
489
|
-
if isinstance(self.restriction, (tuple,list)) and len(self.restriction) == 1:
|
|
490
|
-
s += "=" + str(self.restriction[0])
|
|
491
|
-
else:
|
|
492
|
-
s += " in " + str(self.restriction)
|
|
493
|
-
if self.whereExpr:
|
|
494
|
-
s += " where " + str(self.whereExpr)
|
|
495
|
-
return s
|
|
496
|
-
|
|
497
|
-
class astHyperspaceExpression(astNode):
|
|
498
|
-
def __init__(self, sourceStr, loc, toks):
|
|
499
|
-
super(astHyperspaceExpression, self).__init__(sourceStr, loc)
|
|
500
|
-
self.isClosed = False
|
|
501
|
-
self.axes = []
|
|
502
|
-
for i, tok in enumerate(toks):
|
|
503
|
-
if tok in ('[', '[['):
|
|
504
|
-
if i == 1:
|
|
505
|
-
self.axes.append(astHyperspaceAxis(sourceStr, loc,
|
|
506
|
-
["primary", "=", toks[i-1]]))
|
|
507
|
-
self.isClosed = tok == '[['
|
|
508
|
-
elif tok in (']', ']]'):
|
|
509
|
-
if self.isClosed != tok == ']]':
|
|
510
|
-
logMessage("ERROR", "sphinxCompiler:mismatchedClosed",
|
|
511
|
-
_("Axis restrictions syntax mismatches closed brackets."),
|
|
512
|
-
sourceFileLines=((sphinxFile, lineno(loc, sourceStr)),))
|
|
513
|
-
elif isinstance(tok, astHyperspaceAxis):
|
|
514
|
-
self.axes.append(tok)
|
|
515
|
-
|
|
516
|
-
def __repr__(self):
|
|
517
|
-
return "{0}{1}{2}".format({False:'[',True:'[['}[self.isClosed],
|
|
518
|
-
"; ".join(str(axis) for axis in self.axes),
|
|
519
|
-
{False:']',True:']]'}[self.isClosed])
|
|
520
|
-
|
|
521
|
-
class astIf(astNode):
|
|
522
|
-
def __init__(self, sourceStr, loc, condition, thenExpr, elseExpr):
|
|
523
|
-
super(astIf, self).__init__(sourceStr, loc)
|
|
524
|
-
self.condition = condition
|
|
525
|
-
self.thenExpr = thenExpr
|
|
526
|
-
self.elseExpr = elseExpr
|
|
527
|
-
def __repr__(self):
|
|
528
|
-
return "if(({0}) {1} else {2})".format(self.condition, self.thenExpr, self.elseExpr)
|
|
529
|
-
|
|
530
|
-
class astMessage(astNode):
|
|
531
|
-
def __init__(self, sourceStr, loc, message):
|
|
532
|
-
super(astMessage, self).__init__(sourceStr, loc)
|
|
533
|
-
self.message = message
|
|
534
|
-
def __repr__(self):
|
|
535
|
-
return "message({0})".format(self.message)
|
|
536
|
-
|
|
537
|
-
class astMethodReference(astNode):
|
|
538
|
-
def __init__(self, sourceStr, loc, name, args):
|
|
539
|
-
super(astMethodReference, self).__init__(sourceStr, loc)
|
|
540
|
-
self.name = name
|
|
541
|
-
self.args = args
|
|
542
|
-
def __repr__(self):
|
|
543
|
-
return "methodReference({0}({1}))".format(self.name,
|
|
544
|
-
", ".join(str(a) for a in self.args))
|
|
545
|
-
|
|
546
|
-
class astNamespaceDeclaration(astNode):
|
|
547
|
-
def __init__(self, sourceStr, loc, prefix, namespace):
|
|
548
|
-
super(astNamespaceDeclaration, self).__init__(sourceStr, loc)
|
|
549
|
-
self.prefix = prefix
|
|
550
|
-
self.namespace = namespace
|
|
551
|
-
def __repr__(self):
|
|
552
|
-
return "xmlns{0}={1}".format((":" + self.prefix) if self.prefix else "",
|
|
553
|
-
self.namespace)
|
|
554
|
-
|
|
555
|
-
class astNoOp(astNode):
|
|
556
|
-
def __init__(self, sourceStr, loc):
|
|
557
|
-
super(astNoOp, self).__init__(sourceStr, loc)
|
|
558
|
-
def __repr__(self):
|
|
559
|
-
return "noOp()"
|
|
560
|
-
|
|
561
|
-
class astNumericLiteral(astNode):
|
|
562
|
-
def __init__(self, sourceStr, loc, value):
|
|
563
|
-
super(astNumericLiteral, self).__init__(sourceStr, loc)
|
|
564
|
-
self.value = value
|
|
565
|
-
def __repr__(self):
|
|
566
|
-
return "numericLiteral({0})".format(self.value)
|
|
567
|
-
|
|
568
|
-
class astPreconditionDeclaration(astNode):
|
|
569
|
-
def __init__(self, sourceStr, loc, name, expr, otherwiseExpr):
|
|
570
|
-
super(astPreconditionDeclaration, self).__init__(sourceStr, loc)
|
|
571
|
-
self.name = name
|
|
572
|
-
self.expr = expr
|
|
573
|
-
self.otherwiseExpr = otherwiseExpr
|
|
574
|
-
def __repr__(self):
|
|
575
|
-
return "preconditionDeclaration({0}, {1}(".format(self.name, self.expr)
|
|
576
|
-
|
|
577
|
-
class astPreconditionReference(astNode):
|
|
578
|
-
def __init__(self, sourceStr, loc, names):
|
|
579
|
-
super(astPreconditionReference, self).__init__(sourceStr, loc)
|
|
580
|
-
self.names = names
|
|
581
|
-
def __repr__(self):
|
|
582
|
-
return "preconditionReference({0})".format(self.names)
|
|
583
|
-
|
|
584
|
-
class astQnameLiteral(astNode):
|
|
585
|
-
def __init__(self, sourceStr, loc, qnameToken):
|
|
586
|
-
super(astQnameLiteral, self).__init__(sourceStr, loc)
|
|
587
|
-
try:
|
|
588
|
-
self.value = qname(qnameToken,
|
|
589
|
-
xmlns,
|
|
590
|
-
prefixException=KeyError,
|
|
591
|
-
noPrefixIsNoNamespace=(qnameToken in methodImplementation or
|
|
592
|
-
qnameToken in reservedWords))
|
|
593
|
-
except KeyError:
|
|
594
|
-
raise PrefixError(qnameToken)
|
|
595
|
-
def __repr__(self):
|
|
596
|
-
return "qnameLiteral({0})".format(self.value)
|
|
597
|
-
|
|
598
|
-
class astRuleBasePrecondition(astNode):
|
|
599
|
-
def __init__(self, sourceStr, loc, precondition):
|
|
600
|
-
super(astRuleBasePrecondition, self).__init__(sourceStr, loc)
|
|
601
|
-
self.precondition = precondition
|
|
602
|
-
def __repr__(self):
|
|
603
|
-
return "ruleBasePrecondition({0})".format(self.precondition)
|
|
604
|
-
|
|
605
|
-
class astSeverity(astNode):
|
|
606
|
-
def __init__(self, sourceStr, loc, severity):
|
|
607
|
-
super(astSeverity, self).__init__(sourceStr, loc)
|
|
608
|
-
self.severity = severity
|
|
609
|
-
def __repr__(self):
|
|
610
|
-
return "severity({0})".format(self.severity)
|
|
611
|
-
|
|
612
|
-
class astSourceFile(astNode):
|
|
613
|
-
def __init__(self, fileName):
|
|
614
|
-
super(astSourceFile, self).__init__(None, 0)
|
|
615
|
-
self.fileName = fileName
|
|
616
|
-
def __repr__(self):
|
|
617
|
-
return "sourceFile({0})".format(self.fileName)
|
|
618
|
-
|
|
619
|
-
escChar = {r"\n": "\n",
|
|
620
|
-
r"\t": "\t",
|
|
621
|
-
r"\b": "\b",
|
|
622
|
-
r"\r": "\r",
|
|
623
|
-
r"\f": "\f",
|
|
624
|
-
r"\\": "\\",
|
|
625
|
-
r"\'": "'",
|
|
626
|
-
r"\"": '"'}
|
|
627
|
-
class astStringLiteral(astNode):
|
|
628
|
-
def __init__(self, sourceStr, loc, quotedString):
|
|
629
|
-
super(astStringLiteral, self).__init__(sourceStr, loc)
|
|
630
|
-
# dequote leading/trailing quotes and backslashed characters in sphinx table
|
|
631
|
-
self.text = re.sub(r"\\[ntbrf\\'\"]",lambda m: escChar[m.group(0)], quotedString[1:-1])
|
|
632
|
-
@property
|
|
633
|
-
def value(self):
|
|
634
|
-
return self.text
|
|
635
|
-
def __repr__(self):
|
|
636
|
-
return "stringLiteral({0})".format(self.text)
|
|
637
|
-
|
|
638
|
-
class astTagAssignment(astNode):
|
|
639
|
-
def __init__(self, sourceStr, loc, tagName, expr):
|
|
640
|
-
super(astTagAssignment, self).__init__(sourceStr, loc)
|
|
641
|
-
self.tagName = tagName
|
|
642
|
-
self.expr = expr
|
|
643
|
-
def __repr__(self):
|
|
644
|
-
return "tagAssignment({0}#{1})".format(self.expr, self.tagName)
|
|
645
|
-
|
|
646
|
-
class astTransform(astNode):
|
|
647
|
-
def __init__(self, sourceStr, loc, transformType, fromExpr, toExpr):
|
|
648
|
-
super(astTransform, self).__init__(sourceStr, loc)
|
|
649
|
-
self.transformType = transformType
|
|
650
|
-
self.fromExpr = fromExpr
|
|
651
|
-
self.toExpr = toExpr
|
|
652
|
-
def __repr__(self):
|
|
653
|
-
return "transform({0}, {1}, {2})".format(self.transformType, self.fromTransform, self.toTransform)
|
|
654
|
-
|
|
655
|
-
class astUnaryOperation(astNode):
|
|
656
|
-
def __init__(self, sourceStr, loc, op, expr):
|
|
657
|
-
super(astUnaryOperation, self).__init__(sourceStr, loc)
|
|
658
|
-
self.op = op
|
|
659
|
-
self.expr = expr
|
|
660
|
-
def __repr__(self):
|
|
661
|
-
return "unaryOperation({0} {1})".format(self.op, self.expr)
|
|
662
|
-
|
|
663
|
-
class astValuesIteration(astNode):
|
|
664
|
-
def __init__(self, sourceStr, loc, expr):
|
|
665
|
-
super(astValuesIteration, self).__init__(sourceStr, loc)
|
|
666
|
-
self.expr = expr
|
|
667
|
-
def __repr__(self):
|
|
668
|
-
return "values {0}".format(self.expr)
|
|
669
|
-
|
|
670
|
-
class astRule(astNode):
|
|
671
|
-
def __init__(self, sourceStr, loc, nodes):
|
|
672
|
-
super(astRule, self).__init__(sourceStr, loc)
|
|
673
|
-
self.name = None
|
|
674
|
-
self.precondition = None
|
|
675
|
-
self.severity = None
|
|
676
|
-
self.message = None
|
|
677
|
-
self.variableAssignments = []
|
|
678
|
-
prev = None
|
|
679
|
-
for node in nodes:
|
|
680
|
-
if isinstance(node, astPreconditionReference):
|
|
681
|
-
self.precondition = node
|
|
682
|
-
elif isinstance(node, astSeverity):
|
|
683
|
-
self.severity = node.severity
|
|
684
|
-
elif isinstance(node, astMessage):
|
|
685
|
-
self.message = node
|
|
686
|
-
elif isinstance(node, astVariableAssignment):
|
|
687
|
-
self.variableAssignments.append(node)
|
|
688
|
-
else:
|
|
689
|
-
if prev in ("formula", "report", "raise"):
|
|
690
|
-
self.name = currentPackage + '.' + node if currentPackage else node
|
|
691
|
-
self.expr = None
|
|
692
|
-
elif prev == "bind": # formula only
|
|
693
|
-
self.bind = node
|
|
694
|
-
elif node not in ("bind", "formula", "report", "raise"):
|
|
695
|
-
self.expr = node
|
|
696
|
-
prev = node
|
|
697
|
-
|
|
698
|
-
class astFormulaRule(astRule):
|
|
699
|
-
def __init__(self, sourceStr, loc, nodes):
|
|
700
|
-
self.bind = None
|
|
701
|
-
super(astFormulaRule, self).__init__(sourceStr, loc, nodes)
|
|
702
|
-
def __repr__(self):
|
|
703
|
-
return "formula({0}name={1}, {2}{3}{4} := {5}{6})".format(
|
|
704
|
-
("str(self.precondition) + ", "" ) if self.precondition else "",
|
|
705
|
-
self.name,
|
|
706
|
-
(str(self.severity) + ", ") if self.severity else "",
|
|
707
|
-
("bind=" + str(self.bind) + ", ") if self.bind else "",
|
|
708
|
-
self.expr,
|
|
709
|
-
(", " + str(self.message)) if self.message else "")
|
|
710
|
-
|
|
711
|
-
class astReportRule(astRule):
|
|
712
|
-
def __init__(self, sourceStr, loc, nodes):
|
|
713
|
-
super(astReportRule, self).__init__(sourceStr, loc, nodes)
|
|
714
|
-
def __repr__(self):
|
|
715
|
-
return "reportRule({0}report={1}, {2}{3}{4})".format(
|
|
716
|
-
(str(self.precondition) + ", " ) if self.precondition else "",
|
|
717
|
-
self.name,
|
|
718
|
-
(str(self.severity) + ", ") if self.severity else "",
|
|
719
|
-
self.expr,
|
|
720
|
-
(", " + str(self.message)) if self.message else "")
|
|
721
|
-
|
|
722
|
-
class astValidationRule(astRule):
|
|
723
|
-
def __init__(self, sourceStr, loc, nodes):
|
|
724
|
-
super(astValidationRule, self).__init__(sourceStr, loc, nodes)
|
|
725
|
-
def __repr__(self):
|
|
726
|
-
return "validationRule({0}raise={1}, {2}{3}{4})".format(
|
|
727
|
-
(str(self.precondition) + ", " ) if self.precondition else "",
|
|
728
|
-
self.name,
|
|
729
|
-
(str(self.severity) + ", ") if self.severity else "",
|
|
730
|
-
self.expr,
|
|
731
|
-
(", " + str(self.message)) if self.message else "")
|
|
732
|
-
|
|
733
|
-
class astVariableAssignment(astNode):
|
|
734
|
-
def __init__(self, sourceStr, loc, toks):
|
|
735
|
-
super(astVariableAssignment, self).__init__(sourceStr, loc)
|
|
736
|
-
self.variableName = toks[0]
|
|
737
|
-
self.expr = toks[-1]
|
|
738
|
-
self.tagName = None
|
|
739
|
-
if len(toks) > 2 and toks[1] == "#": # has tag
|
|
740
|
-
if len(toks) > 3: # named tag
|
|
741
|
-
self.tagName = toks[2]
|
|
742
|
-
else: # use name for tag
|
|
743
|
-
self.tagName = self.variableName
|
|
744
|
-
def __repr__(self):
|
|
745
|
-
return "variableAssignment({0}{1} = {2})".format(self.variableName,
|
|
746
|
-
("#" + self.tagName) if self.tagName else "",
|
|
747
|
-
self.expr)
|
|
748
|
-
|
|
749
|
-
class astVariableReference(astNode):
|
|
750
|
-
def __init__(self, sourceStr, loc, variableName):
|
|
751
|
-
super(astVariableReference, self).__init__(sourceStr, loc)
|
|
752
|
-
self.variableName = variableName
|
|
753
|
-
def __repr__(self):
|
|
754
|
-
return "variableReference({0})".format(self.variableName)
|
|
755
|
-
|
|
756
|
-
class astWith(astNode):
|
|
757
|
-
def __init__(self, sourceStr, loc, withExpr, variableAssignments, bodyExpr):
|
|
758
|
-
super(astWith, self).__init__(sourceStr, loc)
|
|
759
|
-
self.restrictionExpr = withExpr
|
|
760
|
-
self.variableAssignments = variableAssignments
|
|
761
|
-
self.bodyExpr = bodyExpr
|
|
762
|
-
def __repr__(self):
|
|
763
|
-
return "with({0}, {1})".format(self.restrictionExpr, self.bodyExpr)
|
|
764
|
-
|
|
765
|
-
def compileSphinxGrammar( cntlr ):
|
|
766
|
-
global isGrammarCompiled, sphinxProg, lineno
|
|
767
|
-
|
|
768
|
-
if isGrammarCompiled:
|
|
769
|
-
return sphinxProg
|
|
770
|
-
|
|
771
|
-
debugParsing = True
|
|
772
|
-
|
|
773
|
-
cntlr.showStatus(_("Compiling Sphinx Grammar"))
|
|
774
|
-
from pyparsing import (
|
|
775
|
-
Word, Keyword, Literal, CaselessLiteral, Combine, Opt, nums, Forward, ZeroOrMore,
|
|
776
|
-
StringEnd, ParserElement, quoted_string, delimitedList as DelimitedList, Suppress,
|
|
777
|
-
Regex, lineno
|
|
778
|
-
)
|
|
779
|
-
|
|
780
|
-
ParserElement.enable_packrat()
|
|
781
|
-
|
|
782
|
-
"""
|
|
783
|
-
the pyparsing parser constructs are defined in this method to prevent the need to compile
|
|
784
|
-
the grammar when the plug in is loaded (which is likely to be when setting up GUI
|
|
785
|
-
menus or command line parser).
|
|
786
|
-
|
|
787
|
-
instead the grammar is compiled the first time that any sphinx needs to be parsed
|
|
788
|
-
|
|
789
|
-
only the sphinxExpression (result below) needs to be global for the parser
|
|
790
|
-
"""
|
|
791
|
-
|
|
792
|
-
# define grammar
|
|
793
|
-
sphinxComment = Regex(r"/(?:\*(?:[^*]*\*+)+?/|/[^\n]*(?:\n[^\n]*)*?(?:(?<!\\)|\Z))").set_parse_action(compileComment)
|
|
794
|
-
|
|
795
|
-
variableRef = Regex("[$]" # variable prefix
|
|
796
|
-
# localname part
|
|
797
|
-
"([A-Za-z\xC0-\xD6\xD8-\xF6\xF8-\xFF\u0100-\u02FF\u0370-\u037D\u037F-\u1FFF\u200C-\u200D\u2070-\u218F\u2C00-\u2FEF\u3001-\uD7FF\uF900-\uFDCF\uFDF0-\uFFFD_]"
|
|
798
|
-
"[A-Za-z0-9\xC0-\xD6\xD8-\xF6\xF8-\xFF\u0100-\u02FF\u0370-\u037D\u037F-\u1FFF\u200C-\u200D\u2070-\u218F\u2C00-\u2FEF\u3001-\uD7FF\uF900-\uFDCF\uFDF0-\uFFFD\u0300-\u036F\u203F-\u2040\xB7_.-]*)"
|
|
799
|
-
)
|
|
800
|
-
|
|
801
|
-
|
|
802
|
-
qName = Regex("([A-Za-z\xC0-\xD6\xD8-\xF6\xF8-\xFF\u0100-\u02FF\u0370-\u037D\u037F-\u1FFF\u200C-\u200D\u2070-\u218F\u2C00-\u2FEF\u3001-\uD7FF\uF900-\uFDCF\uFDF0-\uFFFD_]"
|
|
803
|
-
"[A-Za-z0-9\xC0-\xD6\xD8-\xF6\xF8-\xFF\u0100-\u02FF\u0370-\u037D\u037F-\u1FFF\u200C-\u200D\u2070-\u218F\u2C00-\u2FEF\u3001-\uD7FF\uF900-\uFDCF\uFDF0-\uFFFD\u0300-\u036F\u203F-\u2040\xB7_.-]*:)?"
|
|
804
|
-
# localname or wildcard-localname part
|
|
805
|
-
"([A-Za-z\xC0-\xD6\xD8-\xF6\xF8-\xFF\u0100-\u02FF\u0370-\u037D\u037F-\u1FFF\u200C-\u200D\u2070-\u218F\u2C00-\u2FEF\u3001-\uD7FF\uF900-\uFDCF\uFDF0-\uFFFD_]"
|
|
806
|
-
"[A-Za-z0-9\xC0-\xD6\xD8-\xF6\xF8-\xFF\u0100-\u02FF\u0370-\u037D\u037F-\u1FFF\u200C-\u200D\u2070-\u218F\u2C00-\u2FEF\u3001-\uD7FF\uF900-\uFDCF\uFDF0-\uFFFD\u0300-\u036F\u203F-\u2040\xB7_.-]*|[*])"
|
|
807
|
-
)
|
|
808
|
-
|
|
809
|
-
ncName = Regex("([A-Za-z\xC0-\xD6\xD8-\xF6\xF8-\xFF\u0100-\u02FF\u0370-\u037D\u037F-\u1FFF\u200C-\u200D\u2070-\u218F\u2C00-\u2FEF\u3001-\uD7FF\uF900-\uFDCF\uFDF0-\uFFFD_]"
|
|
810
|
-
"[A-Za-z0-9\xC0-\xD6\xD8-\xF6\xF8-\xFF\u0100-\u02FF\u0370-\u037D\u037F-\u1FFF\u200C-\u200D\u2070-\u218F\u2C00-\u2FEF\u3001-\uD7FF\uF900-\uFDCF\uFDF0-\uFFFD\u0300-\u036F\u203F-\u2040\xB7_.-]*)"
|
|
811
|
-
).set_name("ncName").set_debug(debugParsing)
|
|
812
|
-
|
|
813
|
-
#annotationName = Word("@",alphanums + '_-.').set_name("annotationName").set_debug(debugParsing)
|
|
814
|
-
annotationName = Regex("@[A-Za-z\xC0-\xD6\xD8-\xF6\xF8-\xFF\u0100-\u02FF\u0370-\u037D\u037F-\u1FFF\u200C-\u200D\u2070-\u218F\u2C00-\u2FEF\u3001-\uD7FF\uF900-\uFDCF\uFDF0-\uFFFD_]\\w*").set_name("annotationName").set_debug(debugParsing)
|
|
815
|
-
|
|
816
|
-
|
|
817
|
-
decimalPoint = Literal('.')
|
|
818
|
-
exponentLiteral = CaselessLiteral('e')
|
|
819
|
-
plusorminusLiteral = Literal('+') | Literal('-')
|
|
820
|
-
digits = Word(nums)
|
|
821
|
-
integerLiteral = Combine( Opt(plusorminusLiteral) + digits )
|
|
822
|
-
decimalFractionLiteral = Combine( Opt(plusorminusLiteral) + decimalPoint + digits )
|
|
823
|
-
infLiteral = Combine( Opt(plusorminusLiteral) + Literal("INF") )
|
|
824
|
-
nanLiteral = Literal("NaN")
|
|
825
|
-
floatLiteral = ( Combine( integerLiteral +
|
|
826
|
-
( ( decimalPoint + Opt(digits) + exponentLiteral + integerLiteral ) |
|
|
827
|
-
( exponentLiteral + integerLiteral ) |
|
|
828
|
-
( decimalPoint + Opt(digits) ) )
|
|
829
|
-
) |
|
|
830
|
-
Combine( decimalFractionLiteral + exponentLiteral + integerLiteral ) |
|
|
831
|
-
decimalFractionLiteral |
|
|
832
|
-
infLiteral | nanLiteral )
|
|
833
|
-
|
|
834
|
-
|
|
835
|
-
#emptySequence = Literal( "(" ) + Literal( ")" )
|
|
836
|
-
lParen = Literal( "(" )
|
|
837
|
-
rParen = Literal( ")" )
|
|
838
|
-
lPred = Literal( "[[" ) | Literal("[")
|
|
839
|
-
rPred = Literal( "]]" ) | Literal("]")
|
|
840
|
-
|
|
841
|
-
commaOp = Literal(",")
|
|
842
|
-
ifOp = Keyword("if")
|
|
843
|
-
elseOp = Keyword("else")
|
|
844
|
-
forOp = Keyword("for")
|
|
845
|
-
inOp = Keyword("in")
|
|
846
|
-
withOp = Keyword("with")
|
|
847
|
-
notOp = Keyword("not")
|
|
848
|
-
valuesOp = Keyword("values")
|
|
849
|
-
andOp = Keyword("and")
|
|
850
|
-
orOp = Keyword("or")
|
|
851
|
-
neOp = Literal("!=")
|
|
852
|
-
leOp = Literal("<=")
|
|
853
|
-
ltOp = Literal("<")
|
|
854
|
-
geOp = Literal(">=")
|
|
855
|
-
gtOp = Literal(">")
|
|
856
|
-
eqOp = Literal("==")
|
|
857
|
-
compOp = leOp | ltOp | geOp | gtOp
|
|
858
|
-
plusOp = Literal("|+|") | Literal("|+") | Literal("+|") | Literal("+")
|
|
859
|
-
minusOp = Literal("|-|") | Literal("|-") | Literal("-|") | Literal("-")
|
|
860
|
-
plusMinusOp = ( plusOp | minusOp ).set_parse_action(compileOp)
|
|
861
|
-
multOp = Literal("*")
|
|
862
|
-
divOp = Literal("/")
|
|
863
|
-
varAssign = Literal("=")
|
|
864
|
-
tagOp = Literal("#")
|
|
865
|
-
asOp = Keyword("as")
|
|
866
|
-
whereOp = Keyword("where")
|
|
867
|
-
wildOp = Literal("**") | Literal("*")
|
|
868
|
-
methodOp = Literal("::")
|
|
869
|
-
formulaOp = Literal(":=")
|
|
870
|
-
|
|
871
|
-
namespaceDeclaration = (Literal("xmlns") + Opt( Suppress(Literal(":")) + ncName ) + Suppress(Literal("=")) + quoted_string ).set_parse_action(compileNamespaceDeclaration).ignore(sphinxComment)
|
|
872
|
-
annotationDeclaration = (Suppress(Keyword("annotation")) + ncName + Opt( Suppress(Keyword("as")) + ncName )).set_parse_action(compileAnnotationDeclaration).ignore(sphinxComment)
|
|
873
|
-
|
|
874
|
-
packageDeclaration = (Suppress(Keyword("package")) + ncName ).set_parse_action(compilePackageDeclaration).ignore(sphinxComment)
|
|
875
|
-
|
|
876
|
-
severity = ( Suppress(Keyword("severity")) + ( ncName ) ).set_parse_action(compileSeverity).ignore(sphinxComment)
|
|
877
|
-
|
|
878
|
-
expr = Forward()
|
|
879
|
-
|
|
880
|
-
atom = (
|
|
881
|
-
( forOp - Suppress(lParen) - ncName - Suppress(inOp) - expr - Suppress(rParen) - expr ).set_parse_action(compileFor) |
|
|
882
|
-
( ifOp - Suppress(lParen) - expr - Suppress(rParen) - expr - Suppress(elseOp) - expr ).set_parse_action(compileIf) |
|
|
883
|
-
( ncName + Suppress(lParen) + Opt(DelimitedList( ZeroOrMore( ( ncName + Opt( tagOp + Opt(ncName) ) + varAssign + expr + Suppress(Literal(";")) ).set_parse_action(compileVariableAssignment) ) +
|
|
884
|
-
Opt( ncName + varAssign ) + expr
|
|
885
|
-
)) + Suppress(rParen) ).set_parse_action(compileFunctionReference) |
|
|
886
|
-
( floatLiteral ).set_parse_action(compileFloatLiteral) |
|
|
887
|
-
( integerLiteral ).set_parse_action(compileIntegerLiteral) |
|
|
888
|
-
( quoted_string ).set_parse_action(compileStringLiteral) |
|
|
889
|
-
( Opt(qName) + lPred + Opt(DelimitedList( ((whereOp + expr) |
|
|
890
|
-
((qName | variableRef) + Opt( tagOp + Opt(ncName) ) +
|
|
891
|
-
Opt( (varAssign + (wildOp | expr) |
|
|
892
|
-
(inOp + expr) |
|
|
893
|
-
(asOp + ncName + varAssign + wildOp + Opt( whereOp + expr ) ) ) ) )
|
|
894
|
-
).set_parse_action(compileHyperspaceAxis),
|
|
895
|
-
delim=';')) + rPred).set_parse_action(compileHyperspaceExpression) |
|
|
896
|
-
( variableRef ).set_parse_action(compileVariableReference) |
|
|
897
|
-
( qName ).set_parse_action(compileQname) |
|
|
898
|
-
( Suppress(lParen) - expr - Opt( commaOp - Opt( expr - ZeroOrMore( commaOp - expr ) ) ) - Suppress(rParen) ).set_parse_action(compileBrackets)
|
|
899
|
-
).ignore(sphinxComment)
|
|
900
|
-
|
|
901
|
-
atom.set_name("atom").set_debug(debugParsing)
|
|
902
|
-
|
|
903
|
-
valueExpr = atom
|
|
904
|
-
taggedExpr = ( valueExpr - Opt(tagOp - ncName) ).set_parse_action(compileTagAssignment).ignore(sphinxComment)
|
|
905
|
-
methodExpr = ( ( methodOp + ncName + ZeroOrMore(methodOp + taggedExpr) ).set_parse_action(compileMethodReference) |
|
|
906
|
-
( ZeroOrMore(taggedExpr + methodOp) + taggedExpr )).set_parse_action(compileMethodReference).ignore(sphinxComment)
|
|
907
|
-
unaryExpr = ( Opt(plusMinusOp) + methodExpr ).set_parse_action(compileUnaryOperation).ignore(sphinxComment)
|
|
908
|
-
negateExpr = ( Opt(notOp) + unaryExpr ).set_parse_action(compileUnaryOperation).ignore(sphinxComment)
|
|
909
|
-
valuesExpr = ( Opt(valuesOp) + negateExpr ).set_parse_action(compileValuesIteration).ignore(sphinxComment)
|
|
910
|
-
method2Expr = ( valuesExpr + Opt( methodOp + methodExpr ) ).set_parse_action(compileMethodReference).ignore(sphinxComment)
|
|
911
|
-
multiplyExpr = ( method2Expr + Opt( multOp + method2Expr ) ).set_parse_action(compileBinaryOperation).ignore(sphinxComment)
|
|
912
|
-
divideExpr = ( multiplyExpr + Opt( divOp + multiplyExpr ) ).set_parse_action(compileBinaryOperation).ignore(sphinxComment)
|
|
913
|
-
addExpr = ( divideExpr + Opt( plusOp + divideExpr ) ).set_parse_action(compileBinaryOperation).ignore(sphinxComment)
|
|
914
|
-
subtractExpr = ( addExpr + Opt( minusOp + addExpr ) ).set_parse_action(compileBinaryOperation).ignore(sphinxComment)
|
|
915
|
-
equalityExpr = ( subtractExpr + Opt( eqOp + subtractExpr ) ).set_parse_action(compileBinaryOperation).ignore(sphinxComment)
|
|
916
|
-
inequalityExpr = ( equalityExpr + Opt( neOp + equalityExpr ) ).set_parse_action(compileBinaryOperation).ignore(sphinxComment)
|
|
917
|
-
comparisonExpr = ( inequalityExpr + Opt( compOp + inequalityExpr ) ).set_parse_action(compileBinaryOperation).ignore(sphinxComment)
|
|
918
|
-
andExpr = ( comparisonExpr + Opt( andOp + comparisonExpr ) ).set_parse_action(compileBinaryOperation ).ignore(sphinxComment)
|
|
919
|
-
orExpr = ( andExpr + Opt( orOp + andExpr ) ).set_parse_action(compileBinaryOperation).ignore(sphinxComment)
|
|
920
|
-
formulaExpr = ( orExpr + Opt( formulaOp + orExpr ) ).set_parse_action(compileBinaryOperation).ignore(sphinxComment)
|
|
921
|
-
withExpr = ( Opt( withOp + Suppress(lParen) + expr + Suppress(rParen) ) +
|
|
922
|
-
ZeroOrMore( ( ncName + Opt( tagOp + Opt(ncName) ) + varAssign + expr + Suppress(Literal(";")) ).set_parse_action(compileVariableAssignment).ignore(sphinxComment) ) +
|
|
923
|
-
formulaExpr ).set_parse_action(compileWith)
|
|
924
|
-
#parsedExpr = withExpr
|
|
925
|
-
#parsedExpr.set_name("parsedExpr").set_debug(debugParsing)
|
|
926
|
-
|
|
927
|
-
#expr << parsedExpr
|
|
928
|
-
expr << withExpr
|
|
929
|
-
expr.set_name("expr").set_debug(debugParsing)
|
|
930
|
-
|
|
931
|
-
annotation = ( annotationName + Opt( Suppress(lParen) + Opt(DelimitedList(expr)) + Suppress(rParen) ) ).set_parse_action(compileAnnotation).ignore(sphinxComment).set_name("annotation").set_debug(debugParsing)
|
|
932
|
-
|
|
933
|
-
constant = ( Suppress(Keyword("constant")) + ncName + Opt( tagOp + Opt(ncName) ) + varAssign + expr ).set_parse_action(compileConstant).ignore(sphinxComment)
|
|
934
|
-
|
|
935
|
-
functionDeclaration = ( (Keyword("function") | Keyword("macro")) + ncName + lParen + Opt(DelimitedList(ncName)) + rParen + expr ).set_parse_action(compileFunctionDeclaration).ignore(sphinxComment)
|
|
936
|
-
|
|
937
|
-
message = ( Suppress(Keyword("message")) + expr ).set_parse_action(compileMessage)
|
|
938
|
-
|
|
939
|
-
preconditionDeclaration = ( Suppress(Keyword("precondition")) + ncName + expr +
|
|
940
|
-
Opt(Keyword("otherwise") + Keyword("raise") + ncName + Opt( severity ) + Opt( message ) )
|
|
941
|
-
).set_parse_action(compilePreconditionDeclaration).ignore(sphinxComment)
|
|
942
|
-
|
|
943
|
-
assignedExpr = ( ncName + Opt( tagOp + Opt(ncName) ) + varAssign + expr + Suppress(Literal(";")) ).set_parse_action(compileVariableAssignment).ignore(sphinxComment)
|
|
944
|
-
|
|
945
|
-
precondition = ( Suppress(Keyword("require")) + DelimitedList(ncName) ).set_parse_action(compilePrecondition).ignore(sphinxComment).set_name("precondition").set_debug(debugParsing)
|
|
946
|
-
|
|
947
|
-
formulaRule = ( Opt( precondition ) +
|
|
948
|
-
Keyword("formula") + ncName +
|
|
949
|
-
Opt( severity ) +
|
|
950
|
-
Opt( ( Keyword("bind") + expr ) ) +
|
|
951
|
-
ZeroOrMore( assignedExpr ) +
|
|
952
|
-
expr +
|
|
953
|
-
Opt( message )).set_parse_action(compileFormulaRule).ignore(sphinxComment)
|
|
954
|
-
reportRule = ( Opt( precondition ) +
|
|
955
|
-
Keyword("report") + ncName +
|
|
956
|
-
Opt( severity ) +
|
|
957
|
-
ZeroOrMore( assignedExpr ) +
|
|
958
|
-
expr +
|
|
959
|
-
Opt( message )).set_parse_action( compileReportRule).ignore(sphinxComment)
|
|
960
|
-
validationRule = ( Opt( precondition ) +
|
|
961
|
-
Keyword("raise") + ncName +
|
|
962
|
-
Opt( severity ) +
|
|
963
|
-
ZeroOrMore( assignedExpr ) +
|
|
964
|
-
expr +
|
|
965
|
-
Opt( message )).set_parse_action(compileValidationRule).ignore(sphinxComment)
|
|
966
|
-
|
|
967
|
-
ruleBase = (Opt( precondition ) +
|
|
968
|
-
Suppress(Keyword("rule-base")) +
|
|
969
|
-
ZeroOrMore( (Suppress(Keyword("transform")) +
|
|
970
|
-
(Keyword("namespace") + expr + Suppress(Keyword("to")) + expr) |
|
|
971
|
-
(Keyword ("qname") + expr + Suppress(Keyword("to")) + expr)
|
|
972
|
-
).set_parse_action(compileTransform)
|
|
973
|
-
)
|
|
974
|
-
).set_parse_action(compileRuleBase).ignore(sphinxComment).set_name("ruleBase").set_debug(debugParsing)
|
|
975
|
-
|
|
976
|
-
sphinxProg = ( ZeroOrMore( namespaceDeclaration | sphinxComment ) +
|
|
977
|
-
ZeroOrMore( annotationDeclaration |
|
|
978
|
-
annotation |
|
|
979
|
-
constant |
|
|
980
|
-
preconditionDeclaration |
|
|
981
|
-
packageDeclaration |
|
|
982
|
-
functionDeclaration |
|
|
983
|
-
ruleBase |
|
|
984
|
-
formulaRule | reportRule | validationRule |
|
|
985
|
-
sphinxComment
|
|
986
|
-
)
|
|
987
|
-
) + StringEnd()
|
|
988
|
-
sphinxProg.ignore(sphinxComment)
|
|
989
|
-
|
|
990
|
-
startedAt = time.time()
|
|
991
|
-
cntlr.modelManager.showStatus(_("initializing sphinx grammar"))
|
|
992
|
-
sphinxProg.parse_string( "// force initialization\n", parseAll=True )
|
|
993
|
-
from arelle.Locale import format_string
|
|
994
|
-
logMessage("INFO", "info",
|
|
995
|
-
format_string(cntlr.modelManager.locale,
|
|
996
|
-
_("Sphinx grammar initialized in %.2f secs"),
|
|
997
|
-
time.time() - startedAt))
|
|
998
|
-
|
|
999
|
-
isGrammarCompiled = True
|
|
1000
|
-
|
|
1001
|
-
return sphinxProg
|
|
1002
|
-
|
|
1003
|
-
def parse(cntlr, _logMessage, sphinxFiles):
|
|
1004
|
-
from pyparsing import ParseException, ParseSyntaxException
|
|
1005
|
-
|
|
1006
|
-
global logMessage
|
|
1007
|
-
logMessage = _logMessage
|
|
1008
|
-
|
|
1009
|
-
sphinxGrammar = compileSphinxGrammar(cntlr)
|
|
1010
|
-
|
|
1011
|
-
sphinxProgs = []
|
|
1012
|
-
|
|
1013
|
-
successful = True
|
|
1014
|
-
|
|
1015
|
-
def parseSourceString(sourceString):
|
|
1016
|
-
global lastLoc, currentPackage
|
|
1017
|
-
successful = True
|
|
1018
|
-
cntlr.showStatus("Compiling sphinx file {0}".format(os.path.basename(sphinxFile)))
|
|
1019
|
-
|
|
1020
|
-
try:
|
|
1021
|
-
lastLoc = 0
|
|
1022
|
-
currentPackage = None
|
|
1023
|
-
prog = sphinxGrammar.parse_string( sourceString, parseAll=True )
|
|
1024
|
-
xmlns.clear() # dereference xmlns definitions
|
|
1025
|
-
prog.insert(0, astSourceFile(sphinxFile)) # keep the source file name
|
|
1026
|
-
sphinxProgs.append( prog )
|
|
1027
|
-
except (ParseException, ParseSyntaxException) as err:
|
|
1028
|
-
from arelle.formula.XPathParser import exceptionErrorIndication
|
|
1029
|
-
file = os.path.basename(sphinxFile)
|
|
1030
|
-
logMessage("ERROR", "sphinxCompiler:syntaxError",
|
|
1031
|
-
_("Parse error: \n%(error)s"),
|
|
1032
|
-
sphinxFile=sphinxFile,
|
|
1033
|
-
sourceFileLines=((file, lineno(err.loc,err.pstr)),),
|
|
1034
|
-
error=exceptionErrorIndication(err))
|
|
1035
|
-
successful = False
|
|
1036
|
-
except (ValueError) as err:
|
|
1037
|
-
file = os.path.basename(sphinxFile)
|
|
1038
|
-
logMessage("ERROR", "sphinxCompiler:valueError",
|
|
1039
|
-
_("Parsing terminated due to error: \n%(error)s"),
|
|
1040
|
-
sphinxFile=sphinxFile,
|
|
1041
|
-
sourceFileLines=((file,lineno(lastLoc,sourceString)),),
|
|
1042
|
-
error=err)
|
|
1043
|
-
successful = False
|
|
1044
|
-
except Exception as err:
|
|
1045
|
-
file = os.path.basename(sphinxFile)
|
|
1046
|
-
logMessage("ERROR", "sphinxCompiler:parserException",
|
|
1047
|
-
_("Parsing of terminated due to error: \n%(error)s"),
|
|
1048
|
-
sphinxFile=sphinxFile,
|
|
1049
|
-
sourceFileLines=((file,lineno(lastLoc,sourceString)),),
|
|
1050
|
-
error=err, exc_info=True)
|
|
1051
|
-
successful = False
|
|
1052
|
-
|
|
1053
|
-
cntlr.showStatus("Compiled sphinx files {0}".format({True:"successful",
|
|
1054
|
-
False:"with errors"}[successful]),
|
|
1055
|
-
clearAfter=5000)
|
|
1056
|
-
xmlns.clear()
|
|
1057
|
-
return successful
|
|
1058
|
-
|
|
1059
|
-
def parseFile(filename):
|
|
1060
|
-
successful = True
|
|
1061
|
-
# parse the xrb zip or individual xsr files
|
|
1062
|
-
global sphinxFile
|
|
1063
|
-
if os.path.isdir(filename):
|
|
1064
|
-
for root, dirs, files in os.walk(filename):
|
|
1065
|
-
for file in files:
|
|
1066
|
-
sphinxFile = os.path.join(root, file)
|
|
1067
|
-
parseFile(sphinxFile)
|
|
1068
|
-
elif filename.endswith(".xrb"): # zip archive
|
|
1069
|
-
archive = zipfile.ZipFile(filename, mode="r")
|
|
1070
|
-
for zipinfo in archive.infolist():
|
|
1071
|
-
zipcontent = zipinfo.filename
|
|
1072
|
-
if zipcontent.endswith(".xsr"):
|
|
1073
|
-
sphinxFile = os.path.join(filename, zipcontent)
|
|
1074
|
-
if not parseSourceString( archive.read(zipcontent).decode("utf-8") ):
|
|
1075
|
-
successful = False
|
|
1076
|
-
archive.close()
|
|
1077
|
-
elif filename.endswith(".xsr"):
|
|
1078
|
-
sphinxFile = filename
|
|
1079
|
-
with open(filename, "r", encoding="utf-8") as fh:
|
|
1080
|
-
if not parseSourceString( fh.read() ):
|
|
1081
|
-
successful = False
|
|
1082
|
-
return successful
|
|
1083
|
-
|
|
1084
|
-
successful = True
|
|
1085
|
-
for filename in sphinxFiles:
|
|
1086
|
-
if not parseFile(filename):
|
|
1087
|
-
successful = False
|
|
1088
|
-
|
|
1089
|
-
logMessage = None # dereference
|
|
1090
|
-
|
|
1091
|
-
return sphinxProgs
|
|
1092
|
-
|
|
1093
|
-
from .SphinxMethods import methodImplementation, aggreateFunctionImplementation
|