|
|
|
@ -4,17 +4,17 @@
|
|
|
|
|
|
|
|
|
|
import re, codecs
|
|
|
|
|
import fileinput
|
|
|
|
|
import sys, traceback, exceptions, os
|
|
|
|
|
import sys, traceback, os
|
|
|
|
|
from xml.sax.saxutils import escape, quoteattr
|
|
|
|
|
from copy import deepcopy
|
|
|
|
|
from glob import glob
|
|
|
|
|
from pyPEG import code, parse, parseLine, u, Symbol
|
|
|
|
|
from pyPEG import code, parse, parseLine, Symbol
|
|
|
|
|
from yml2 import ymlCStyle, comment, _inner
|
|
|
|
|
|
|
|
|
|
ymlFunc, pointers, pythonFunc = {}, {}, {}
|
|
|
|
|
in_ns = u""
|
|
|
|
|
in_ns = ""
|
|
|
|
|
operator = []
|
|
|
|
|
included = u""
|
|
|
|
|
included = ""
|
|
|
|
|
includePath = []
|
|
|
|
|
emitlinenumbers = False
|
|
|
|
|
encoding = "utf-8"
|
|
|
|
@ -29,9 +29,9 @@ ymlFunc["operator"] = "#error"
|
|
|
|
|
def clearAll():
|
|
|
|
|
global ymlFunc, pointers, pythonFunc, in_ns, operator, included
|
|
|
|
|
ymlFunc, pointers, pythonFunc = {}, {}, {}
|
|
|
|
|
in_ns = u""
|
|
|
|
|
in_ns = ""
|
|
|
|
|
operator = []
|
|
|
|
|
included = u""
|
|
|
|
|
included = ""
|
|
|
|
|
|
|
|
|
|
lq = re.compile(r"\|(\>*)(.*)")
|
|
|
|
|
sq = re.compile(r"(\d*)\>(.*)")
|
|
|
|
@ -45,82 +45,82 @@ line = 1
|
|
|
|
|
|
|
|
|
|
def pointer(name):
|
|
|
|
|
try:
|
|
|
|
|
return u(pointers[name[1:]])
|
|
|
|
|
return pointers[name[1:]]
|
|
|
|
|
except:
|
|
|
|
|
if name == "*_trace_info":
|
|
|
|
|
return u'""'
|
|
|
|
|
return '""'
|
|
|
|
|
if included:
|
|
|
|
|
raise LookupError(u"in " + included + u":" + u(line) + u": pointer " + name)
|
|
|
|
|
raise LookupError("in " + included + ":" + line + ": pointer " + name)
|
|
|
|
|
else:
|
|
|
|
|
raise LookupError(u"in " + u(line) + u": pointer " + name)
|
|
|
|
|
raise LookupError("in " + line + ": pointer " + name)
|
|
|
|
|
|
|
|
|
|
def evalPython(expr):
|
|
|
|
|
try:
|
|
|
|
|
result = eval(u(expr), pythonFunc)
|
|
|
|
|
result = eval(expr, pythonFunc)
|
|
|
|
|
if type(result) is str:
|
|
|
|
|
return codecs.decode(result, encoding)
|
|
|
|
|
else:
|
|
|
|
|
return result
|
|
|
|
|
except:
|
|
|
|
|
name, parm, tb = sys.exc_info()
|
|
|
|
|
msg = u"in python expression: " + u(parm)
|
|
|
|
|
msg = "in python expression: " + parm
|
|
|
|
|
if name is exceptions.SyntaxError:
|
|
|
|
|
tbl = traceback.format_exception(name, parm, tb)
|
|
|
|
|
msg += u"\n" + tbl[-3] + tbl[-2]
|
|
|
|
|
msg += "\n" + tbl[-3] + tbl[-2]
|
|
|
|
|
else:
|
|
|
|
|
msg += u": " + expr + u"\n"
|
|
|
|
|
msg += ": " + expr + "\n"
|
|
|
|
|
if included:
|
|
|
|
|
raise name(u"in " + included + u":" + u(line) + u": " + msg)
|
|
|
|
|
raise name("in " + included + ":" + line + ": " + msg)
|
|
|
|
|
else:
|
|
|
|
|
raise name(u"in " + u(line) + u": " + msg)
|
|
|
|
|
raise name("in " + line + ": " + msg)
|
|
|
|
|
|
|
|
|
|
def execPython(script):
|
|
|
|
|
try:
|
|
|
|
|
if type(script) is unicode:
|
|
|
|
|
exec script in pythonFunc
|
|
|
|
|
if type(script) is str:
|
|
|
|
|
exec(script, pythonFunc)
|
|
|
|
|
else:
|
|
|
|
|
exec codecs.decode(script, encoding) in pythonFunc
|
|
|
|
|
exec(codecs.decode(script, encoding), pythonFunc)
|
|
|
|
|
except:
|
|
|
|
|
name, parm, tb = sys.exc_info()
|
|
|
|
|
msg = u"in python script: " + u(parm)
|
|
|
|
|
msg = "in python script: " + parm
|
|
|
|
|
if name is exceptions.SyntaxError:
|
|
|
|
|
tbl = traceback.format_exception(name, parm, tb)
|
|
|
|
|
msg += u"\n" + tbl[-3] + tbl[-2]
|
|
|
|
|
msg += "\n" + tbl[-3] + tbl[-2]
|
|
|
|
|
else:
|
|
|
|
|
msg += u": " + expr + u"\n"
|
|
|
|
|
msg += ": " + expr + "\n"
|
|
|
|
|
if included:
|
|
|
|
|
raise name(u"in " + included + u":" + u(line) + u": " + msg)
|
|
|
|
|
raise name("in " + included + ":" + line + ": " + msg)
|
|
|
|
|
else:
|
|
|
|
|
raise name(u"in " + u(line) + u": " + msg)
|
|
|
|
|
raise name("in " + line + ": " + msg)
|
|
|
|
|
|
|
|
|
|
def textOut(text):
|
|
|
|
|
if not text:
|
|
|
|
|
return u""
|
|
|
|
|
if type(text) is not unicode:
|
|
|
|
|
return ""
|
|
|
|
|
if type(text) is not str:
|
|
|
|
|
text = codecs.decode(text, encoding)
|
|
|
|
|
text = text.replace(r'\"', r'\\"')
|
|
|
|
|
text = u'u"""' + text.replace('"', r'\"') + u'"""'
|
|
|
|
|
text = '"""' + text.replace('"', r'\"') + '"""'
|
|
|
|
|
try:
|
|
|
|
|
textFunc = ymlFunc["text"]
|
|
|
|
|
parms = ['text', ('parm', [text])]
|
|
|
|
|
c, result = textFunc(parms)
|
|
|
|
|
if c:
|
|
|
|
|
if type(textFunc.alias) is unicode:
|
|
|
|
|
result += u"</" + textFunc.alias + u">"
|
|
|
|
|
if type(textFunc.alias) is str:
|
|
|
|
|
result += "</" + textFunc.alias + ">"
|
|
|
|
|
else:
|
|
|
|
|
result += u"</" + codecs.decode(textFunc.alias, encoding) + u">"
|
|
|
|
|
result += "</" + codecs.decode(textFunc.alias, encoding) + ">"
|
|
|
|
|
return result
|
|
|
|
|
except:
|
|
|
|
|
return escape(eval(text))
|
|
|
|
|
|
|
|
|
|
def strRepl(text):
|
|
|
|
|
if not text:
|
|
|
|
|
return u""
|
|
|
|
|
if type(text) is not unicode:
|
|
|
|
|
return ""
|
|
|
|
|
if type(text) is not str:
|
|
|
|
|
text = codecs.decode(text, encoding)
|
|
|
|
|
text = text.replace(r'\"', r'\\"')
|
|
|
|
|
text = u'u"""' + text.replace('"', r'\"') + u'"""'
|
|
|
|
|
if type(text) is unicode:
|
|
|
|
|
text = '"""' + text.replace('"', r'\"') + '"""'
|
|
|
|
|
if type(text) is str:
|
|
|
|
|
return escape(eval(text))
|
|
|
|
|
|
|
|
|
|
def applyMacros(macros, text):
|
|
|
|
@ -139,12 +139,12 @@ class YF:
|
|
|
|
|
self.pointers = {}
|
|
|
|
|
self.macros = {}
|
|
|
|
|
if in_ns:
|
|
|
|
|
self.alias = in_ns + u":" + name.replace("_", "-")
|
|
|
|
|
self.alias = in_ns + ":" + name.replace("_", "-")
|
|
|
|
|
else:
|
|
|
|
|
self.alias = name.replace("_", "-")
|
|
|
|
|
pythonFunc["yml_" + name] = self
|
|
|
|
|
if emitlinenumbers:
|
|
|
|
|
self.values["yml:declared"] = u(line)
|
|
|
|
|
self.values["yml:declared"] = line
|
|
|
|
|
|
|
|
|
|
def copy(self, newName):
|
|
|
|
|
yf = YF(newName)
|
|
|
|
@ -197,23 +197,23 @@ class YF:
|
|
|
|
|
val = evalPython(val[1][0])
|
|
|
|
|
if val[0] == "*":
|
|
|
|
|
val = pointer(val)
|
|
|
|
|
if u(val)[0] == '"' or u(val)[0] == "'":
|
|
|
|
|
vals[parm] = evalPython(u(val))
|
|
|
|
|
if val[0] == '"' or val[0] == "'":
|
|
|
|
|
vals[parm] = evalPython(val)
|
|
|
|
|
else:
|
|
|
|
|
vals[parm] = u(val)
|
|
|
|
|
vals[parm] = val
|
|
|
|
|
elif data[0] == "content":
|
|
|
|
|
hasContent = True
|
|
|
|
|
|
|
|
|
|
if enable_tracing:
|
|
|
|
|
text = u(parms) + u", " + u(vals)
|
|
|
|
|
pointers["_trace_info"] = u'"' + u(line) + u": " + u(self.name) + u" " + text.replace(u'"', u'#') + u'"'
|
|
|
|
|
text = parms + ", " + vals
|
|
|
|
|
pointers["_trace_info"] = '"' + line + ": " + self.name + " " + text.replace('"', '#') + '"'
|
|
|
|
|
|
|
|
|
|
if emitlinenumbers:
|
|
|
|
|
global first
|
|
|
|
|
if first:
|
|
|
|
|
vals["xmlns:yml"] = u"http://fdik.org/yml"
|
|
|
|
|
vals["xmlns:yml"] = "http://fdik.org/yml"
|
|
|
|
|
first = False
|
|
|
|
|
vals["yml:called"] = u(line)
|
|
|
|
|
vals["yml:called"] = line
|
|
|
|
|
return self.xml(parms, vals, hasContent, avoidTag)
|
|
|
|
|
|
|
|
|
|
def addParm(self, parm):
|
|
|
|
@ -231,17 +231,17 @@ class YF:
|
|
|
|
|
self.descends.append(desc)
|
|
|
|
|
|
|
|
|
|
def addValue(self, parm, value):
|
|
|
|
|
if type(value) is str or type(value) is unicode:
|
|
|
|
|
if type(value) is str:
|
|
|
|
|
if value[0] != "'" and value[0] != '"':
|
|
|
|
|
self.values[parm] = u(value)
|
|
|
|
|
self.values[parm] = value
|
|
|
|
|
else:
|
|
|
|
|
self.values[parm] = u(evalPython(value))
|
|
|
|
|
self.values[parm] = evalPython(value)
|
|
|
|
|
else:
|
|
|
|
|
self.values[parm] = u(evalPython(u(value)))
|
|
|
|
|
self.values[parm] = evalPython(value)
|
|
|
|
|
|
|
|
|
|
def xml(self, callParms, callValues, hasContent, avoidTag = False):
|
|
|
|
|
global pointers
|
|
|
|
|
extraContent = u""
|
|
|
|
|
extraContent = ""
|
|
|
|
|
if self.content:
|
|
|
|
|
hasContent = True
|
|
|
|
|
resultParms = self.values.copy()
|
|
|
|
@ -259,34 +259,33 @@ class YF:
|
|
|
|
|
for cp in callParms:
|
|
|
|
|
if i < len(self.parms):
|
|
|
|
|
if self.parms[i][0] == "*":
|
|
|
|
|
cp = u(cp)
|
|
|
|
|
if "'" in cp:
|
|
|
|
|
pointers[self.parms[i][1:]] = u'"' + cp + u'"'
|
|
|
|
|
pointers[self.parms[i][1:]] = '"' + cp + '"'
|
|
|
|
|
else:
|
|
|
|
|
pointers[self.parms[i][1:]] = u"'" + cp + u"'"
|
|
|
|
|
pointers[self.parms[i][1:]] = "'" + cp + "'"
|
|
|
|
|
elif self.parms[i][0] == "%":
|
|
|
|
|
macros[self.parms[i]] = u(cp)
|
|
|
|
|
macros[self.parms[i]] = cp
|
|
|
|
|
else:
|
|
|
|
|
resultParms[self.parms[i]] = cp
|
|
|
|
|
else:
|
|
|
|
|
extraContent += u(cp)
|
|
|
|
|
extraContent += cp
|
|
|
|
|
hasContent = True
|
|
|
|
|
i += 1
|
|
|
|
|
result = u""
|
|
|
|
|
result = ""
|
|
|
|
|
for p, v in resultParms.iteritems():
|
|
|
|
|
if p[0] == "'" or p[0] == '"':
|
|
|
|
|
p = eval(p)
|
|
|
|
|
result += u" "+ p + u"=" + quoteattr(applyMacros(macros, u(v)))
|
|
|
|
|
result += " "+ p + "=" + quoteattr(applyMacros(macros, v))
|
|
|
|
|
if hasContent:
|
|
|
|
|
if avoidTag:
|
|
|
|
|
return True, strRepl(extraContent)
|
|
|
|
|
else:
|
|
|
|
|
return True, u"<" + self.alias + result + u">" + strRepl(extraContent)
|
|
|
|
|
return True, "<" + self.alias + result + ">" + strRepl(extraContent)
|
|
|
|
|
else:
|
|
|
|
|
if avoidTag:
|
|
|
|
|
return False, u""
|
|
|
|
|
return False, ""
|
|
|
|
|
else:
|
|
|
|
|
return False, u"<" + self.alias + result + u"/>"
|
|
|
|
|
return False, "<" + self.alias + result + "/>"
|
|
|
|
|
|
|
|
|
|
def replaceContent(tree, subtree):
|
|
|
|
|
n = 0
|
|
|
|
@ -313,7 +312,7 @@ def replaceContent(tree, subtree):
|
|
|
|
|
return tree
|
|
|
|
|
|
|
|
|
|
def executeCmd(text):
|
|
|
|
|
if type(text) is not unicode:
|
|
|
|
|
if type(text) is not str:
|
|
|
|
|
text = codecs.decode(text, encoding)
|
|
|
|
|
for (regex, pattern) in operator:
|
|
|
|
|
match = re.search(regex, text)
|
|
|
|
@ -321,11 +320,11 @@ def executeCmd(text):
|
|
|
|
|
cmd = pattern
|
|
|
|
|
opt = match.groups()
|
|
|
|
|
for i in range(len(opt)):
|
|
|
|
|
cmd = cmd.replace(u"%" + u(i+1), opt[i])
|
|
|
|
|
text = text[:match.start()] + u"`" + cmd + u"`"+ text[match.end():]
|
|
|
|
|
cmd = cmd.replace("%" + str(i+1), opt[i])
|
|
|
|
|
text = text[:match.start()] + "`" + cmd + "`"+ text[match.end():]
|
|
|
|
|
match = re.search(regex, text)
|
|
|
|
|
|
|
|
|
|
result = u""
|
|
|
|
|
result = ""
|
|
|
|
|
m = re.search(bq, text)
|
|
|
|
|
while text and m:
|
|
|
|
|
cmd = m.group(1)
|
|
|
|
@ -336,9 +335,9 @@ def executeCmd(text):
|
|
|
|
|
if rest: raise SyntaxError(cmd)
|
|
|
|
|
except SyntaxError:
|
|
|
|
|
if included:
|
|
|
|
|
raise SyntaxError(u"in " + included + u":" + u(line) + u": syntax error in executing command: " + cmd.strip())
|
|
|
|
|
raise SyntaxError("in " + included + ":" + line + ": syntax error in executing command: " + cmd.strip())
|
|
|
|
|
else:
|
|
|
|
|
raise SyntaxError(u"in " + u(line) + u": syntax error in executing command: " + cmd.strip())
|
|
|
|
|
raise SyntaxError("in " + line + ": syntax error in executing command: " + cmd.strip())
|
|
|
|
|
inner = _finish(r)
|
|
|
|
|
result += head + inner
|
|
|
|
|
m = re.search(bq, text)
|
|
|
|
@ -358,20 +357,20 @@ def codegen(obj):
|
|
|
|
|
except: pass
|
|
|
|
|
|
|
|
|
|
if ctype == "empty":
|
|
|
|
|
return code(u"")
|
|
|
|
|
return code("")
|
|
|
|
|
|
|
|
|
|
if ctype == "in_ns":
|
|
|
|
|
in_ns = obj[1][0]
|
|
|
|
|
subtree = obj[1]
|
|
|
|
|
for sel in subtree:
|
|
|
|
|
codegen(sel)
|
|
|
|
|
in_ns = u""
|
|
|
|
|
return code(u"")
|
|
|
|
|
in_ns = ""
|
|
|
|
|
return code("")
|
|
|
|
|
|
|
|
|
|
elif ctype == "decl":
|
|
|
|
|
name = u""
|
|
|
|
|
name = ""
|
|
|
|
|
for data in obj[1]:
|
|
|
|
|
if type(data) is unicode or type(data) is str:
|
|
|
|
|
if type(data) is str:
|
|
|
|
|
name = data
|
|
|
|
|
try:
|
|
|
|
|
yf = ymlFunc[name]
|
|
|
|
@ -380,7 +379,7 @@ def codegen(obj):
|
|
|
|
|
ymlFunc[name] = YF(name)
|
|
|
|
|
yf = ymlFunc[name]
|
|
|
|
|
if in_ns:
|
|
|
|
|
yf.alias = in_ns + u":" + name
|
|
|
|
|
yf.alias = in_ns + ":" + name
|
|
|
|
|
if not enable_tracing:
|
|
|
|
|
if in_ns == "xsl" and (name == "debug" or name=="assert" or name[:7]=="_trace_"):
|
|
|
|
|
yf.alias = "-"
|
|
|
|
@ -394,9 +393,9 @@ def codegen(obj):
|
|
|
|
|
yf = ymlFunc[name] = ymlFunc[base].copy(name)
|
|
|
|
|
except KeyError:
|
|
|
|
|
if included:
|
|
|
|
|
raise KeyError(u"in " + included + u":" + u(line) + u": " + base + u" as base for " + name)
|
|
|
|
|
raise KeyError("in " + included + ":" + line + ": " + base + " as base for " + name)
|
|
|
|
|
else:
|
|
|
|
|
raise KeyError(u"in " + u(line) + u": " + base + u" as base for " + name)
|
|
|
|
|
raise KeyError("in " + line + ": " + base + " as base for " + name)
|
|
|
|
|
elif data[0] == "shape":
|
|
|
|
|
shape = ymlFunc[data[1]]
|
|
|
|
|
try:
|
|
|
|
@ -404,9 +403,9 @@ def codegen(obj):
|
|
|
|
|
yf.patch(shape)
|
|
|
|
|
except KeyError:
|
|
|
|
|
if included:
|
|
|
|
|
raise KeyError(u"in " + included + u":" + u(line) + u": " + base + u" as shape for " + name)
|
|
|
|
|
raise KeyError("in " + included + ":" + line + ": " + base + " as shape for " + name)
|
|
|
|
|
else:
|
|
|
|
|
raise KeyError(u"in " + u(line) + u": " + base + u" as shape for " + name)
|
|
|
|
|
raise KeyError("in " + line + ": " + base + " as shape for " + name)
|
|
|
|
|
elif data[0] == "descend":
|
|
|
|
|
yf.addDescend(data[1])
|
|
|
|
|
elif data[0] == "declParm":
|
|
|
|
@ -422,23 +421,23 @@ def codegen(obj):
|
|
|
|
|
yf.pointers[parmName[1:]] = value
|
|
|
|
|
yf.addParm(parmName)
|
|
|
|
|
elif parmName[0] == "%":
|
|
|
|
|
if type(value) is unicode or type(value) is str:
|
|
|
|
|
yf.macros[parmName] = u(evalPython(value))
|
|
|
|
|
if type(value) is str:
|
|
|
|
|
yf.macros[parmName] = evalPython(value)
|
|
|
|
|
else:
|
|
|
|
|
yf.macros[parmName] = u(evalPython(u(value)))
|
|
|
|
|
yf.macros[parmName] = evalPython(value)
|
|
|
|
|
yf.addParm(parmName)
|
|
|
|
|
elif data[0] == "alias":
|
|
|
|
|
if in_ns:
|
|
|
|
|
yf.alias = in_ns + u":" + data[1][0]
|
|
|
|
|
yf.alias = in_ns + ":" + data[1][0]
|
|
|
|
|
else:
|
|
|
|
|
yf.alias = data[1][0]
|
|
|
|
|
elif data[0] == "content":
|
|
|
|
|
yf.content = data[1]
|
|
|
|
|
|
|
|
|
|
return code(u"")
|
|
|
|
|
return code("")
|
|
|
|
|
|
|
|
|
|
elif ctype == "funclist":
|
|
|
|
|
result = u""
|
|
|
|
|
result = ""
|
|
|
|
|
for f in obj[1]:
|
|
|
|
|
result += codegen(f)
|
|
|
|
|
return code(result)
|
|
|
|
@ -447,13 +446,13 @@ def codegen(obj):
|
|
|
|
|
if len(obj[1]):
|
|
|
|
|
return codegen(('func', ['_parentheses', ('content', [obj[1][0]])]))
|
|
|
|
|
else:
|
|
|
|
|
return u""
|
|
|
|
|
return ""
|
|
|
|
|
|
|
|
|
|
elif ctype == "fparm":
|
|
|
|
|
if len(obj[1]):
|
|
|
|
|
return codegen(('func', ['_parm', ('content', [obj[1][0]])]))
|
|
|
|
|
else:
|
|
|
|
|
return u""
|
|
|
|
|
return ""
|
|
|
|
|
|
|
|
|
|
elif ctype == "generic":
|
|
|
|
|
return codegen(('func', ['_generic', ('content', [obj[1][0]])]))
|
|
|
|
@ -468,15 +467,15 @@ def codegen(obj):
|
|
|
|
|
if name == "decl":
|
|
|
|
|
if ymlFunc[name] == "#error":
|
|
|
|
|
if included:
|
|
|
|
|
raise SyntaxError(u"in " + included + u":" + u(line) + u": syntax error in decl statement")
|
|
|
|
|
raise SyntaxError("in " + included + ":" + line + ": syntax error in decl statement")
|
|
|
|
|
else:
|
|
|
|
|
raise SyntaxError(u"in " + u(line) + u": syntax error in decl statement")
|
|
|
|
|
raise SyntaxError("in " + line + ": syntax error in decl statement")
|
|
|
|
|
if name == "define" or name == "operator":
|
|
|
|
|
if ymlFunc[name] == "#error":
|
|
|
|
|
if included:
|
|
|
|
|
raise SyntaxError(u"in " + included + u":" + u(line) + u": syntax error in define statement")
|
|
|
|
|
raise SyntaxError("in " + included + ":" + line + ": syntax error in define statement")
|
|
|
|
|
else:
|
|
|
|
|
raise SyntaxError(u"in " + u(line) + u": syntax error in define statement")
|
|
|
|
|
raise SyntaxError("in " + line + ": syntax error in define statement")
|
|
|
|
|
|
|
|
|
|
if name[0] == "&":
|
|
|
|
|
avoidTag = True
|
|
|
|
@ -485,7 +484,7 @@ def codegen(obj):
|
|
|
|
|
|
|
|
|
|
if len(name) > 2:
|
|
|
|
|
if name[0:2] == "**":
|
|
|
|
|
return code(eval('u'+pointer(name[1:])))
|
|
|
|
|
return code(eval(''+pointer(name[1:])))
|
|
|
|
|
|
|
|
|
|
if name[0] == "*":
|
|
|
|
|
name = eval(pointer(name))
|
|
|
|
@ -508,9 +507,9 @@ def codegen(obj):
|
|
|
|
|
if len(ymlFunc[name].descends):
|
|
|
|
|
if obj[1][-1][0] != 'content':
|
|
|
|
|
if included:
|
|
|
|
|
raise KeyError(u"in " + included + u":" + u(line) + u": " + name + u" has descending attributes, but no descendants are following")
|
|
|
|
|
raise KeyError("in " + included + ":" + line + ": " + name + " has descending attributes, but no descendants are following")
|
|
|
|
|
else:
|
|
|
|
|
raise KeyError(u"in " + u(line) + u": " + name + u" has descending attributes, but no descendants are following")
|
|
|
|
|
raise KeyError("in " + line + ": " + name + " has descending attributes, but no descendants are following")
|
|
|
|
|
|
|
|
|
|
def first_func(obj):
|
|
|
|
|
if type(obj) is tuple or type(obj) is Symbol:
|
|
|
|
@ -559,7 +558,7 @@ def codegen(obj):
|
|
|
|
|
if dname[0] == "*":
|
|
|
|
|
pointers[dname[1:]] = "'" + f[1][0] + "'"
|
|
|
|
|
else:
|
|
|
|
|
add_params.append( ('parm', [dname, u"'" + f[1][0] + u"'"]) )
|
|
|
|
|
add_params.append( ('parm', [dname, "'" + f[1][0] + "'"]) )
|
|
|
|
|
try:
|
|
|
|
|
add_params.extend( get_parms(f) )
|
|
|
|
|
except: pass
|
|
|
|
@ -571,14 +570,14 @@ def codegen(obj):
|
|
|
|
|
to_add.append( ('func', new_things ) )
|
|
|
|
|
except:
|
|
|
|
|
if included:
|
|
|
|
|
raise KeyError(u"in " + included + u":" + u(line) + u": " + name + u" has descending attributes, and too less descendants are following")
|
|
|
|
|
raise KeyError("in " + included + ":" + line + ": " + name + " has descending attributes, and too less descendants are following")
|
|
|
|
|
else:
|
|
|
|
|
raise KeyError(u"in " + u(line) + u": " + name + u" has descending attributes, and too less descendants are following")
|
|
|
|
|
raise KeyError("in " + line + ": " + name + " has descending attributes, and too less descendants are following")
|
|
|
|
|
|
|
|
|
|
if not to_add:
|
|
|
|
|
to_add = ( obj, )
|
|
|
|
|
|
|
|
|
|
complete = u""
|
|
|
|
|
complete = ""
|
|
|
|
|
|
|
|
|
|
for obj in to_add:
|
|
|
|
|
subtree = None
|
|
|
|
@ -602,14 +601,14 @@ def codegen(obj):
|
|
|
|
|
result += codegen(sel)
|
|
|
|
|
|
|
|
|
|
if hasContent and not(avoidTag):
|
|
|
|
|
result += u"</" + ymlFunc[name].alias + u">"
|
|
|
|
|
result += "</" + ymlFunc[name].alias + ">"
|
|
|
|
|
|
|
|
|
|
complete += result
|
|
|
|
|
|
|
|
|
|
return code(complete)
|
|
|
|
|
|
|
|
|
|
elif ctype == "textsection":
|
|
|
|
|
result = u''
|
|
|
|
|
result = ''
|
|
|
|
|
ll = obj[1].splitlines()
|
|
|
|
|
space = len(ll[-1]) - 2
|
|
|
|
|
for l in ll[1:-1]:
|
|
|
|
@ -622,15 +621,15 @@ def codegen(obj):
|
|
|
|
|
result += _finish(r)
|
|
|
|
|
except SyntaxError:
|
|
|
|
|
if included:
|
|
|
|
|
raise SyntaxError(u"in " + included + u":" + u(line) + u": syntax error in executing command: " + cmd.strip())
|
|
|
|
|
raise SyntaxError("in " + included + ":" + line + ": syntax error in executing command: " + cmd.strip())
|
|
|
|
|
else:
|
|
|
|
|
raise SyntaxError(u"in " + u(line) + u": syntax error in executing command: " + cmd.strip())
|
|
|
|
|
raise SyntaxError("in " + line + ": syntax error in executing command: " + cmd.strip())
|
|
|
|
|
else:
|
|
|
|
|
result += codegen(Symbol(u'lineQuote', u'| ' + l[space:]))
|
|
|
|
|
result += codegen(Symbol('lineQuote', '| ' + l[space:]))
|
|
|
|
|
return code(result)
|
|
|
|
|
|
|
|
|
|
elif ctype == "textsectionu":
|
|
|
|
|
result = u''
|
|
|
|
|
elif ctype == "textsection":
|
|
|
|
|
result = ''
|
|
|
|
|
ll = obj[1].splitlines()
|
|
|
|
|
space = len(ll[-1]) - 2
|
|
|
|
|
for l in ll[1:-1]:
|
|
|
|
@ -643,16 +642,16 @@ def codegen(obj):
|
|
|
|
|
result += _finish(r)
|
|
|
|
|
except SyntaxError:
|
|
|
|
|
if included:
|
|
|
|
|
raise SyntaxError(u"in " + included + u":" + u(line) + u": syntax error in executing command: " + cmd.strip())
|
|
|
|
|
raise SyntaxError("in " + included + ":" + line + ": syntax error in executing command: " + cmd.strip())
|
|
|
|
|
else:
|
|
|
|
|
raise SyntaxError(u"in " + u(line) + u": syntax error in executing command: " + cmd.strip())
|
|
|
|
|
raise SyntaxError("in " + line + ": syntax error in executing command: " + cmd.strip())
|
|
|
|
|
else:
|
|
|
|
|
if result != u'': result += u' '
|
|
|
|
|
result += codegen(Symbol(u'quote', [u'> ' + l[space:]]))
|
|
|
|
|
if result != '': result += ' '
|
|
|
|
|
result += codegen(Symbol('quote', ['> ' + l[space:]]))
|
|
|
|
|
return code(result)
|
|
|
|
|
|
|
|
|
|
elif ctype == "lineQuote" or ctype == "quote":
|
|
|
|
|
m, text, base, inds = None, u"", 0, 0
|
|
|
|
|
m, text, base, inds = None, "", 0, 0
|
|
|
|
|
|
|
|
|
|
if ctype == "lineQuote":
|
|
|
|
|
text = obj[1]
|
|
|
|
@ -670,20 +669,20 @@ def codegen(obj):
|
|
|
|
|
inds = int(m.group(1))
|
|
|
|
|
text = m.group(2)[1:]
|
|
|
|
|
else:
|
|
|
|
|
if type(text) is unicode or type(text) is str:
|
|
|
|
|
text = u(evalPython(text))
|
|
|
|
|
if type(text) is str:
|
|
|
|
|
text = evalPython(text)
|
|
|
|
|
|
|
|
|
|
ind = u""
|
|
|
|
|
ind = ""
|
|
|
|
|
if inds > -1:
|
|
|
|
|
try:
|
|
|
|
|
cmd = evalPython(u"indent(" + u(inds) + u")")
|
|
|
|
|
result, rest = parseLine(u(cmd), _inner, [], True, comment)
|
|
|
|
|
cmd = evalPython("indent(" + inds + ")")
|
|
|
|
|
result, rest = parseLine(cmd, _inner, [], True, comment)
|
|
|
|
|
if rest:
|
|
|
|
|
raise SyntaxError()
|
|
|
|
|
ind = _finish(result)
|
|
|
|
|
except: pass
|
|
|
|
|
|
|
|
|
|
if ctype == "lineQuote": text += u"\n"
|
|
|
|
|
if ctype == "lineQuote": text += "\n"
|
|
|
|
|
|
|
|
|
|
hasTextFunc = False
|
|
|
|
|
try:
|
|
|
|
@ -697,13 +696,13 @@ def codegen(obj):
|
|
|
|
|
elif ctype == "tagQuote":
|
|
|
|
|
m = tq.match(obj[1])
|
|
|
|
|
if m.group(1) == "<":
|
|
|
|
|
return code(u"<" + m.group(2))
|
|
|
|
|
return code("<" + m.group(2))
|
|
|
|
|
else:
|
|
|
|
|
return code(m.group(2))
|
|
|
|
|
|
|
|
|
|
elif ctype == "operator":
|
|
|
|
|
operator.append((re.compile(evalPython(obj[1][0])), obj[1][1]))
|
|
|
|
|
return code(u"")
|
|
|
|
|
return code("")
|
|
|
|
|
|
|
|
|
|
elif ctype == "constant":
|
|
|
|
|
name = obj[1][0]
|
|
|
|
@ -711,7 +710,7 @@ def codegen(obj):
|
|
|
|
|
name = name[1:]
|
|
|
|
|
value = obj[1][1]
|
|
|
|
|
pointers[name] = value
|
|
|
|
|
return code(u"")
|
|
|
|
|
return code("")
|
|
|
|
|
|
|
|
|
|
elif ctype == "include":
|
|
|
|
|
reverse = False
|
|
|
|
@ -724,7 +723,7 @@ def codegen(obj):
|
|
|
|
|
ktext = True
|
|
|
|
|
elif arg[0] == "kxml":
|
|
|
|
|
kxml = True
|
|
|
|
|
elif type(arg) is unicode or type(arg) is str:
|
|
|
|
|
elif type(arg) is str:
|
|
|
|
|
filemask = arg
|
|
|
|
|
|
|
|
|
|
if filemask[0] == '/' or filemask[0] == '.':
|
|
|
|
@ -740,14 +739,14 @@ def codegen(obj):
|
|
|
|
|
|
|
|
|
|
if not(files):
|
|
|
|
|
if included:
|
|
|
|
|
raise IOError(u"in " + included + ":" + u(line) + u": include file(s) '" + filemask + u"' not found")
|
|
|
|
|
raise IOError("in " + included + ":" + line + ": include file(s) '" + filemask + "' not found")
|
|
|
|
|
else:
|
|
|
|
|
raise IOError(u"in " + u(line) + u": include file(s) '" + filemask + u"' not found")
|
|
|
|
|
raise IOError("in " + line + ": include file(s) '" + filemask + "' not found")
|
|
|
|
|
|
|
|
|
|
includeFile = fileinput.input(files, mode="rU", openhook=fileinput.hook_encoded(encoding))
|
|
|
|
|
_included = included
|
|
|
|
|
if ktext or kxml:
|
|
|
|
|
text = u""
|
|
|
|
|
text = ""
|
|
|
|
|
for line in includeFile:
|
|
|
|
|
included = includeFile.filename()
|
|
|
|
|
if kxml:
|
|
|
|
@ -759,7 +758,7 @@ def codegen(obj):
|
|
|
|
|
return code(text)
|
|
|
|
|
else:
|
|
|
|
|
result = parse(ymlCStyle(), includeFile, True, comment)
|
|
|
|
|
included = u(filemask)
|
|
|
|
|
included = filemask
|
|
|
|
|
x = _finish(result)
|
|
|
|
|
included = _included
|
|
|
|
|
return code(x)
|
|
|
|
@ -767,7 +766,7 @@ def codegen(obj):
|
|
|
|
|
elif ctype == "pyExp":
|
|
|
|
|
exp = obj[1][0]
|
|
|
|
|
cmd = evalPython(exp)
|
|
|
|
|
result, rest = parseLine(u(cmd), _inner, [], True, comment)
|
|
|
|
|
result, rest = parseLine(cmd, _inner, [], True, comment)
|
|
|
|
|
if rest:
|
|
|
|
|
raise SyntaxError(cmd)
|
|
|
|
|
return code(_finish(result))
|
|
|
|
@ -776,7 +775,7 @@ def codegen(obj):
|
|
|
|
|
parms = []
|
|
|
|
|
data = obj[1]
|
|
|
|
|
for p in data:
|
|
|
|
|
if type(p) is unicode or type(p) is str:
|
|
|
|
|
if type(p) is str:
|
|
|
|
|
name = p
|
|
|
|
|
elif type(p) is tuple or type(p) is Symbol:
|
|
|
|
|
ptype = p[0]
|
|
|
|
@ -786,43 +785,43 @@ def codegen(obj):
|
|
|
|
|
else:
|
|
|
|
|
parms.append(p[1][0])
|
|
|
|
|
if len(parms) == 0:
|
|
|
|
|
exp = name + u"()"
|
|
|
|
|
exp = name + "()"
|
|
|
|
|
elif len(parms) == 1:
|
|
|
|
|
exp = name + u"(" + u(parms[0]) + u")"
|
|
|
|
|
exp = name + "(" + parms[0] + ")"
|
|
|
|
|
else:
|
|
|
|
|
exp = name + u(tuple(parms))
|
|
|
|
|
exp = name + tuple(parms)
|
|
|
|
|
cmd = evalPython(exp)
|
|
|
|
|
result, rest = parseLine(u(cmd), _inner, [], True, comment)
|
|
|
|
|
result, rest = parseLine(cmd, _inner, [], True, comment)
|
|
|
|
|
if rest:
|
|
|
|
|
raise SyntaxError()
|
|
|
|
|
return code(_finish(result))
|
|
|
|
|
|
|
|
|
|
else:
|
|
|
|
|
return code(u"")
|
|
|
|
|
return code("")
|
|
|
|
|
|
|
|
|
|
def _finish(tree):
|
|
|
|
|
result = u""
|
|
|
|
|
python = u""
|
|
|
|
|
result = ""
|
|
|
|
|
python = ""
|
|
|
|
|
|
|
|
|
|
for el in tree:
|
|
|
|
|
if el[0] == "python":
|
|
|
|
|
if el[1][0][:2] == "!!":
|
|
|
|
|
python += el[1][0][2:-2]
|
|
|
|
|
else:
|
|
|
|
|
python += el[1][0][1:] + u"\n"
|
|
|
|
|
python += el[1][0][1:] + "\n"
|
|
|
|
|
continue
|
|
|
|
|
else:
|
|
|
|
|
if python:
|
|
|
|
|
execPython(python)
|
|
|
|
|
python = u""
|
|
|
|
|
python = ""
|
|
|
|
|
|
|
|
|
|
try:
|
|
|
|
|
result += codegen(el)
|
|
|
|
|
except RuntimeError:
|
|
|
|
|
if included:
|
|
|
|
|
raise RuntimeError(u"in " + included + u":" + u(line))
|
|
|
|
|
raise RuntimeError("in " + included + ":" + line)
|
|
|
|
|
else:
|
|
|
|
|
raise RuntimeError(u"in " + u(line))
|
|
|
|
|
raise RuntimeError("in " + line)
|
|
|
|
|
|
|
|
|
|
if python:
|
|
|
|
|
execPython(python)
|
|
|
|
|