author | Hartmut Goebel <h.goebel@crazy-compilers.com> |
Thu, 27 Oct 2016 12:51:47 +0200 | |
changeset 42 | 700f4d003349 |
parent 41 | 98a53c3282c3 |
child 65 | d659b8c2ed22 |
child 72 | e52ee17bca47 |
permissions | -rw-r--r-- |
41
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
1 |
# 2.6.1 backend |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
2 |
|
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
3 |
# written by VB. |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
4 |
|
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
5 |
import re, codecs |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
6 |
import fileinput |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
7 |
import sys, traceback, os |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
8 |
from xml.sax.saxutils import escape, quoteattr |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
9 |
from copy import copy, deepcopy |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
10 |
from glob import glob |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
11 |
from .pyPEG import code, parse, parseLine, u, Symbol |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
12 |
from . import ymlCStyle, comment, _inner |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
13 |
|
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
14 |
ymlFunc, pointers, pythonFunc = {}, {}, {} |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
15 |
in_ns = "" |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
16 |
operator = [] |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
17 |
included = "" |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
18 |
includePath = [] |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
19 |
emitlinenumbers = False |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
20 |
encoding = "utf-8" |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
21 |
|
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
22 |
first = True |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
23 |
enable_tracing = False |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
24 |
|
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
25 |
ymlFunc["decl"] = "#error" |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
26 |
ymlFunc["define"] = "#error" |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
27 |
ymlFunc["operator"] = "#error" |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
28 |
|
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
29 |
def clearAll(): |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
30 |
global ymlFunc, pointers, pythonFunc, in_ns, operator, included |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
31 |
ymlFunc, pointers, pythonFunc = {}, {}, {} |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
32 |
in_ns = "" |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
33 |
operator = [] |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
34 |
included = "" |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
35 |
|
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
36 |
lq = re.compile(r"\|(\>*)(.*)") |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
37 |
sq = re.compile(r"(\d*)\>(.*)") |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
38 |
ts = re.compile(r'(\|\|(?P<inds>\>*)\s*\n(?P<text1>.*?)\n(?P<base>\s*)\|\|)|("""(?P<text2>.*?)""")|(\>\>(?P<text3>.*?)\>\>)', re.S) |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
39 |
tq = re.compile(r"(\]|\<)\s*(.*)") |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
40 |
bq = re.compile(r"\`(.*?)\`", re.S) |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
41 |
bqq = re.compile(r"\s*\`\`(.*)") |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
42 |
all = re.compile(r".*", re.S) |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
43 |
|
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
44 |
line = 1 |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
45 |
|
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
46 |
def pointer(name): |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
47 |
try: |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
48 |
return u(pointers[name[1:]]) |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
49 |
except: |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
50 |
if name == "*_trace_info": |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
51 |
return '""' |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
52 |
if included: |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
53 |
raise LookupError("in " + included + ":" + u(line) + ": pointer " + name) |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
54 |
else: |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
55 |
raise LookupError("in " + u(line) + ": pointer " + name) |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
56 |
|
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
57 |
def evalPython(expr): |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
58 |
try: |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
59 |
result = eval(u(expr), pythonFunc) |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
60 |
if type(result) is bytes: |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
61 |
return codecs.decode(result, encoding) |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
62 |
else: |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
63 |
return result |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
64 |
except: |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
65 |
name, parm, tb = sys.exc_info() |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
66 |
msg = "in python expression: " + u(parm) |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
67 |
if name is SyntaxError: |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
68 |
tbl = traceback.format_exception(name, parm, tb) |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
69 |
msg += "\n" + tbl[-3] + tbl[-2] |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
70 |
else: |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
71 |
msg += ": " + expr + "\n" |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
72 |
if included: |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
73 |
raise name("in " + included + ":" + u(line) + ": " + msg) |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
74 |
else: |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
75 |
raise name("in " + u(line) + ": " + msg) |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
76 |
|
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
77 |
def execPython(script): |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
78 |
try: |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
79 |
if type(script) is str: |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
80 |
exec(script, pythonFunc) |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
81 |
else: |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
82 |
exec(codecs.decode(script, encoding), pythonFunc) |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
83 |
except: |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
84 |
name, parm, tb = sys.exc_info() |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
85 |
msg = "in python script: " + u(parm) |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
86 |
if name is SyntaxError: |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
87 |
tbl = traceback.format_exception(name, parm, tb) |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
88 |
msg += "\n" + tbl[-3] + tbl[-2] |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
89 |
else: |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
90 |
msg += ": " + expr + "\n" |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
91 |
if included: |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
92 |
raise name("in " + included + ":" + u(line) + ": " + msg) |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
93 |
else: |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
94 |
raise name("in " + u(line) + ": " + msg) |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
95 |
|
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
96 |
def textOut(text): |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
97 |
if not text: |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
98 |
return "" |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
99 |
if type(text) is not str: |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
100 |
text = codecs.decode(text, encoding) |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
101 |
text = text.replace(r'\"', r'\\"') |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
102 |
text = '"""' + text.replace('"', r'\"') + '"""' |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
103 |
try: |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
104 |
textFunc = ymlFunc["text"] |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
105 |
parms = ['text', ('parm', [text])] |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
106 |
c, result = textFunc(parms) |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
107 |
if c: |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
108 |
if type(textFunc.alias) is str: |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
109 |
result += "</" + textFunc.alias + ">" |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
110 |
else: |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
111 |
result += "</" + codecs.decode(textFunc.alias, encoding) + ">" |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
112 |
return result |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
113 |
except: |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
114 |
return escape(eval(text)) |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
115 |
|
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
116 |
def strRepl(text): |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
117 |
if not text: |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
118 |
return "" |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
119 |
if type(text) is not str: |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
120 |
text = codecs.decode(text, encoding) |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
121 |
text = text.replace(r'\"', r'\\"') |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
122 |
text = '"""' + text.replace('"', r'\"') + '"""' |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
123 |
if type(text) is str: |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
124 |
return escape(eval(text)) |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
125 |
|
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
126 |
def applyMacros(macros, text): |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
127 |
result = text |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
128 |
for key, value in macros.items(): |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
129 |
result = result.replace(key, value) |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
130 |
return result |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
131 |
|
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
132 |
class YF: |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
133 |
def __init__(self, name): |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
134 |
self.name = name |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
135 |
self.parms = [] |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
136 |
self.descends = [] |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
137 |
self.values = {} |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
138 |
self.content = None |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
139 |
self.pointers = {} |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
140 |
self.macros = {} |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
141 |
if in_ns: |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
142 |
self.alias = in_ns + ":" + name.replace("_", "-") |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
143 |
else: |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
144 |
self.alias = name.replace("_", "-") |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
145 |
pythonFunc["yml_" + name] = self |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
146 |
if emitlinenumbers: |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
147 |
self.values["yml:declared"] = u(line) |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
148 |
|
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
149 |
def copy(self, newName): |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
150 |
yf = YF(newName) |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
151 |
yf.parms.extend(self.parms) |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
152 |
yf.descends.extend(self.descends) |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
153 |
yf.values = self.values.copy() |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
154 |
yf.content = self.content |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
155 |
yf.pointers = self.pointers.copy() |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
156 |
yf.macros = self.macros.copy() |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
157 |
yf.alias = self.alias |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
158 |
return yf |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
159 |
|
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
160 |
def patch(self, second): |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
161 |
self.parms.extend(second.parms) |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
162 |
self.descends.extend(second.descends) |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
163 |
self.values.update(second.values) |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
164 |
if second.content: |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
165 |
self.content = second.content |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
166 |
self.pointers.update(second.pointers) |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
167 |
self.macros.update(second.macros) |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
168 |
|
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
169 |
def __call__(self, called_with, hasContent = False, avoidTag = False): |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
170 |
global pointers |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
171 |
parms = [] |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
172 |
vals = {} |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
173 |
if self.pointers: |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
174 |
pointers.update(self.pointers) |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
175 |
|
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
176 |
for data in called_with: |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
177 |
if type(data) is tuple or type(data) is Symbol: |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
178 |
if data[0] == "parm": |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
179 |
l = data[1] |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
180 |
parm = l[0] |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
181 |
if parm[0] == "*": |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
182 |
parm = pointer(parm) |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
183 |
if len(l) == 1: |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
184 |
if type(parm) is tuple or type(parm) is Symbol: |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
185 |
if parm[0] == "pyExp": |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
186 |
val = evalPython(parm[1][0]) |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
187 |
parms.append(val) |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
188 |
else: |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
189 |
parms.append(evalPython((parm))) |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
190 |
else: |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
191 |
if type(parm) is tuple or type(parm) is Symbol: |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
192 |
if parm[0] == "pyExp": |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
193 |
parm = evalPython(parm[1][0]) |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
194 |
val = l[1] |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
195 |
if type(val) is tuple or type(val) is Symbol: |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
196 |
if val[0] == "pyExp": |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
197 |
val = evalPython(val[1][0]) |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
198 |
if val[0] == "*": |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
199 |
val = pointer(val) |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
200 |
if u(val)[0] == '"' or u(val)[0] == "'": |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
201 |
vals[parm] = evalPython(u(val)) |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
202 |
else: |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
203 |
vals[parm] = u(val) |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
204 |
elif data[0] == "content": |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
205 |
hasContent = True |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
206 |
|
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
207 |
if enable_tracing: |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
208 |
text = u(parms) + ", " + u(vals) |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
209 |
pointers["_trace_info"] = '"' + u(line) + ": " + u(self.name) + " " + text.replace('"', '#') + '"' |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
210 |
|
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
211 |
if emitlinenumbers: |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
212 |
global first |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
213 |
if first: |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
214 |
vals["xmlns:yml"] = "http://fdik.org/yml" |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
215 |
first = False |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
216 |
vals["yml:called"] = u(line) |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
217 |
return self.xml(parms, vals, hasContent, avoidTag) |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
218 |
|
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
219 |
def addParm(self, parm): |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
220 |
if parm[0] == "%": |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
221 |
for i in range(len(self.parms)): |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
222 |
if self.parms[i][0] != "%": |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
223 |
self.parms.insert(i, parm) |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
224 |
return |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
225 |
self.parms.append(parm) |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
226 |
|
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
227 |
def addDescend(self, desc): |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
228 |
if desc[0] == "+" or desc[0] == "@": |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
229 |
self.descends.append(desc[1:]) |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
230 |
else: |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
231 |
self.descends.append(desc) |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
232 |
|
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
233 |
def addValue(self, parm, value): |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
234 |
if type(value) is str or type(value) is str: |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
235 |
if value[0] != "'" and value[0] != '"': |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
236 |
self.values[parm] = u(value) |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
237 |
else: |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
238 |
self.values[parm] = u(evalPython(value)) |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
239 |
else: |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
240 |
self.values[parm] = u(evalPython(u(value))) |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
241 |
|
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
242 |
def xml(self, callParms, callValues, hasContent, avoidTag = False): |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
243 |
global pointers |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
244 |
extraContent = "" |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
245 |
if self.content: |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
246 |
hasContent = True |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
247 |
resultParms = self.values.copy() |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
248 |
macros = self.macros.copy() |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
249 |
toDelete = [ key for key in resultParms.keys() ] |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
250 |
for key in toDelete: |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
251 |
if key[0] == "*": |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
252 |
del resultParms[key] |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
253 |
for key, value in callValues.items(): |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
254 |
if key[0] == "%": |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
255 |
macros[key] = value |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
256 |
else: |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
257 |
resultParms[key] = value |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
258 |
i = 0 |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
259 |
for cp in callParms: |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
260 |
if i < len(self.parms): |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
261 |
if self.parms[i][0] == "*": |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
262 |
cp = u(cp) |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
263 |
if "'" in cp: |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
264 |
pointers[self.parms[i][1:]] = '"' + cp + '"' |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
265 |
else: |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
266 |
pointers[self.parms[i][1:]] = "'" + cp + "'" |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
267 |
elif self.parms[i][0] == "%": |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
268 |
macros[self.parms[i]] = u(cp) |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
269 |
else: |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
270 |
resultParms[self.parms[i]] = cp |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
271 |
else: |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
272 |
extraContent += u(cp) |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
273 |
hasContent = True |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
274 |
i += 1 |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
275 |
result = "" |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
276 |
for p, v in resultParms.items(): |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
277 |
if p[0] == "'" or p[0] == '"': |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
278 |
p = eval(p) |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
279 |
result += " "+ p + "=" + quoteattr(applyMacros(macros, u(v))) |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
280 |
if hasContent: |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
281 |
if avoidTag: |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
282 |
return True, strRepl(extraContent) |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
283 |
else: |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
284 |
return True, "<" + self.alias + result + ">" + strRepl(extraContent) |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
285 |
else: |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
286 |
if avoidTag: |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
287 |
return False, "" |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
288 |
else: |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
289 |
return False, "<" + self.alias + result + "/>" |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
290 |
|
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
291 |
def replaceContent(tree, subtree): |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
292 |
n = 0 |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
293 |
while n < len(tree): |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
294 |
obj = tree[n] |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
295 |
if obj[0] == "func": |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
296 |
l = obj[1] |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
297 |
if l[0] == "content": |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
298 |
d = 1 |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
299 |
if subtree: |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
300 |
for el in subtree: |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
301 |
tree.insert(n+d, el) |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
302 |
d += 1 |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
303 |
del tree[n] |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
304 |
n += d |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
305 |
else: |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
306 |
try: |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
307 |
if l[-1][0] == "content": |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
308 |
replaceContent(l[-1][1], subtree) |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
309 |
except: pass |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
310 |
elif obj[0] == "funclist": |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
311 |
replaceContent(obj[1], subtree) |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
312 |
n += 1 |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
313 |
return tree |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
314 |
|
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
315 |
def executeCmd(text): |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
316 |
if type(text) is not str: |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
317 |
text = codecs.decode(text, encoding) |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
318 |
for (regex, pattern) in operator: |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
319 |
match = re.search(regex, text) |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
320 |
while match: |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
321 |
cmd = pattern |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
322 |
opt = match.groups() |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
323 |
for i in range(len(opt)): |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
324 |
cmd = cmd.replace("%" + u(i+1), opt[i]) |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
325 |
text = text[:match.start()] + "`" + cmd + "`"+ text[match.end():] |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
326 |
match = re.search(regex, text) |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
327 |
|
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
328 |
result = "" |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
329 |
m = re.search(bq, text) |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
330 |
while text and m: |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
331 |
cmd = m.group(1) |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
332 |
head = textOut(text[:m.start()]) |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
333 |
text = text[m.end():] |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
334 |
try: |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
335 |
r, rest = parseLine(cmd, _inner, [], True, comment) |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
336 |
if rest: raise SyntaxError(cmd) |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
337 |
except SyntaxError: |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
338 |
if included: |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
339 |
raise SyntaxError("in " + included + ":" + u(line) + ": syntax error in executing command: " + cmd.strip()) |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
340 |
else: |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
341 |
raise SyntaxError("in " + u(line) + ": syntax error in executing command: " + cmd.strip()) |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
342 |
inner = _finish(r) |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
343 |
result += head + inner |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
344 |
m = re.search(bq, text) |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
345 |
result += textOut(text) |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
346 |
|
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
347 |
return result |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
348 |
|
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
349 |
def codegen(obj): |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
350 |
global in_ns, pointers, line, included |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
351 |
ctype = obj[0] |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
352 |
|
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
353 |
if type(obj) is code: |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
354 |
return obj |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
355 |
|
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
356 |
try: |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
357 |
if ctype.line: line = ctype.line |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
358 |
except: pass |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
359 |
|
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
360 |
if ctype == "empty": |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
361 |
return code("") |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
362 |
|
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
363 |
if ctype == "in_ns": |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
364 |
in_ns = obj[1][0] |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
365 |
subtree = obj[1] |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
366 |
for sel in subtree: |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
367 |
codegen(sel) |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
368 |
in_ns = "" |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
369 |
return code("") |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
370 |
|
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
371 |
elif ctype == "decl": |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
372 |
name = "" |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
373 |
for data in obj[1]: |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
374 |
if type(data) is str: |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
375 |
name = data |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
376 |
try: |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
377 |
yf = ymlFunc[name] |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
378 |
yf.alias |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
379 |
except: |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
380 |
ymlFunc[name] = YF(name) |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
381 |
yf = ymlFunc[name] |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
382 |
if in_ns: |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
383 |
yf.alias = in_ns + ":" + name |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
384 |
if not enable_tracing: |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
385 |
if in_ns == "xsl" and (name == "debug" or name=="assert" or name[:7]=="_trace_"): |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
386 |
yf.alias = "-" |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
387 |
yf.addParm("skip1") |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
388 |
yf.addParm("skip2") |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
389 |
break |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
390 |
elif type(data) is tuple or type(data) is Symbol: |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
391 |
if data[0] == "base": |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
392 |
base = data[1][0] |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
393 |
try: |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
394 |
yf = ymlFunc[name] = ymlFunc[base].copy(name) |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
395 |
except KeyError: |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
396 |
if included: |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
397 |
raise KeyError("in " + included + ":" + u(line) + ": " + base + " as base for " + name) |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
398 |
else: |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
399 |
raise KeyError("in " + u(line) + ": " + base + " as base for " + name) |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
400 |
elif data[0] == "shape": |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
401 |
shape = ymlFunc[data[1]] |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
402 |
try: |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
403 |
yf = ymlFunc[name] |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
404 |
yf.patch(shape) |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
405 |
except KeyError: |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
406 |
if included: |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
407 |
raise KeyError("in " + included + ":" + u(line) + ": " + base + " as shape for " + name) |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
408 |
else: |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
409 |
raise KeyError("in " + u(line) + ": " + base + " as shape for " + name) |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
410 |
elif data[0] == "descend": |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
411 |
yf.addDescend(data[1]) |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
412 |
elif data[0] == "declParm": |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
413 |
l = data[1] |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
414 |
parmName = l[0] |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
415 |
if len(l)==1: |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
416 |
yf.addParm(parmName) |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
417 |
else: |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
418 |
value = l[1] |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
419 |
if parmName[0] != "%": |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
420 |
yf.addValue(parmName, value) |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
421 |
if parmName[0] == "*": |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
422 |
yf.pointers[parmName[1:]] = value |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
423 |
yf.addParm(parmName) |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
424 |
elif parmName[0] == "%": |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
425 |
if type(value) is str: |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
426 |
yf.macros[parmName] = u(evalPython(value)) |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
427 |
else: |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
428 |
yf.macros[parmName] = u(evalPython(u(value))) |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
429 |
yf.addParm(parmName) |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
430 |
elif data[0] == "alias": |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
431 |
if in_ns: |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
432 |
yf.alias = in_ns + ":" + data[1][0] |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
433 |
else: |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
434 |
yf.alias = data[1][0] |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
435 |
elif data[0] == "content": |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
436 |
yf.content = data[1] |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
437 |
|
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
438 |
return code("") |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
439 |
|
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
440 |
elif ctype == "funclist": |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
441 |
result = "" |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
442 |
for f in obj[1]: |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
443 |
result += codegen(f) |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
444 |
return code(result) |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
445 |
|
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
446 |
elif ctype == "parentheses": |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
447 |
if len(obj[1]): |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
448 |
return codegen(('func', ['_parentheses', ('content', [obj[1][0]])])) |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
449 |
else: |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
450 |
return "" |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
451 |
|
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
452 |
elif ctype == "fparm": |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
453 |
if len(obj[1]): |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
454 |
return codegen(('func', ['_parm', ('content', [obj[1][0]])])) |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
455 |
else: |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
456 |
return "" |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
457 |
|
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
458 |
elif ctype == "generic": |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
459 |
return codegen(('func', ['_generic', ('content', [obj[1][0]])])) |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
460 |
|
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
461 |
elif ctype == "xbase": |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
462 |
return codegen(('func', ['_base', ('content', [obj[1][0]])])) |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
463 |
|
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
464 |
elif ctype == "func": |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
465 |
avoidTag = False |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
466 |
name = obj[1][0] |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
467 |
|
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
468 |
if name == "decl": |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
469 |
if ymlFunc[name] == "#error": |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
470 |
if included: |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
471 |
raise SyntaxError("in " + included + ":" + u(line) + ": syntax error in decl statement") |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
472 |
else: |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
473 |
raise SyntaxError("in " + u(line) + ": syntax error in decl statement") |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
474 |
if name == "define" or name == "operator": |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
475 |
if ymlFunc[name] == "#error": |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
476 |
if included: |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
477 |
raise SyntaxError("in " + included + ":" + u(line) + ": syntax error in define statement") |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
478 |
else: |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
479 |
raise SyntaxError("in " + u(line) + ": syntax error in define statement") |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
480 |
|
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
481 |
if name[0] == "&": |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
482 |
avoidTag = True |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
483 |
name = name[1:] |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
484 |
hasContent = False |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
485 |
|
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
486 |
if len(name) > 2: |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
487 |
if name[0:2] == "**": |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
488 |
return code(eval(''+pointer(name[1:]))) |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
489 |
|
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
490 |
if name[0] == "*": |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
491 |
name = eval(pointer(name)) |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
492 |
if name[0] == "&": |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
493 |
avoidTag = True |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
494 |
name = name[1:] |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
495 |
|
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
496 |
try: |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
497 |
ymlFunc[name] |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
498 |
except KeyError: |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
499 |
try: |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
500 |
if ymlFunc["_"].alias != "-": |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
501 |
return codegen(('func', ['_', ('content', [('funclist', [obj])])])) |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
502 |
else: |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
503 |
ymlFunc[name] = copy(ymlFunc["_"]) |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
504 |
ymlFunc[name].alias = name.replace("_", "-") |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
505 |
return codegen(obj) |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
506 |
except KeyError: |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
507 |
ymlFunc[name] = YF(name) |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
508 |
|
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
509 |
if ymlFunc[name].alias == "-": avoidTag = True |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
510 |
|
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
511 |
to_add = [] |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
512 |
if len(ymlFunc[name].descends): |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
513 |
if obj[1][-1][0] != 'content': |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
514 |
if included: |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
515 |
raise KeyError("in " + included + ":" + u(line) + ": " + name + " has descending attributes, but no descendants are following") |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
516 |
else: |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
517 |
raise KeyError("in " + u(line) + ": " + name + " has descending attributes, but no descendants are following") |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
518 |
|
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
519 |
def first_func(obj): |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
520 |
if type(obj) is tuple or type(obj) is Symbol: |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
521 |
if obj[0] == 'func': |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
522 |
return obj |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
523 |
elif obj[0] == 'funclist': |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
524 |
return first_func(obj[1]) |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
525 |
elif obj[0] == 'content': |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
526 |
return first_func(obj[1]) |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
527 |
else: |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
528 |
return None |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
529 |
elif type(obj) == list: |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
530 |
for e in obj: |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
531 |
f = first_func(e) |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
532 |
if f: return f |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
533 |
return None |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
534 |
|
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
535 |
def copy_without_first_func(o, found = False): |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
536 |
c = [] |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
537 |
for obj in o: |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
538 |
if found: |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
539 |
c.append(obj) |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
540 |
else: |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
541 |
if obj[0] == 'func': |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
542 |
if obj[1][-1][0] == 'content': |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
543 |
c.extend( obj[1][-1][1] ) |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
544 |
found = True |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
545 |
else: |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
546 |
c.append( ( obj[0], copy_without_first_func(obj[1], False ) ) ) |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
547 |
return c |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
548 |
|
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
549 |
def get_parms(obj): |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
550 |
result = [] |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
551 |
for e in obj[1]: |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
552 |
if type(e) is tuple or type(e) is Symbol: |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
553 |
if e[0] == "parm": |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
554 |
result.append( e ) |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
555 |
return result |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
556 |
|
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
557 |
try: |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
558 |
add_params = get_parms(obj) |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
559 |
for e in obj[1][-1][1]: |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
560 |
c = e[1] |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
561 |
for dname in ymlFunc[name].descends: |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
562 |
f, c = first_func(c), copy_without_first_func(c) |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
563 |
if dname[0] == "*": |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
564 |
pointers[dname[1:]] = "'" + f[1][0] + "'" |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
565 |
else: |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
566 |
add_params.append( ('parm', [dname, "'" + f[1][0] + "'"]) ) |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
567 |
try: |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
568 |
add_params.extend( get_parms(f) ) |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
569 |
except: pass |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
570 |
|
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
571 |
new_things = [ e[1][0] ] |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
572 |
new_things.extend( add_params ) |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
573 |
new_things.append( ('content', c) ) |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
574 |
|
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
575 |
to_add.append( ('func', new_things ) ) |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
576 |
except: |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
577 |
if included: |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
578 |
raise KeyError("in " + included + ":" + u(line) + ": " + name + " has descending attributes, and too less descendants are following") |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
579 |
else: |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
580 |
raise KeyError("in " + u(line) + ": " + name + " has descending attributes, and too less descendants are following") |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
581 |
|
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
582 |
if not to_add: |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
583 |
to_add = ( obj, ) |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
584 |
|
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
585 |
complete = "" |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
586 |
|
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
587 |
for obj in to_add: |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
588 |
subtree = None |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
589 |
try: |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
590 |
if obj[1][-1][0] == "content": |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
591 |
subtree = obj[1][-1][1] |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
592 |
except: pass |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
593 |
|
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
594 |
if ymlFunc[name].content: |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
595 |
hasContent = True |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
596 |
treetemplate = deepcopy(ymlFunc[name].content) |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
597 |
subtree = replaceContent(treetemplate, subtree) |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
598 |
|
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
599 |
if subtree: |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
600 |
hasContent = True |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
601 |
|
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
602 |
hasContent, result = ymlFunc[name](obj[1], hasContent, avoidTag) |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
603 |
|
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
604 |
if subtree: |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
605 |
for sel in subtree: |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
606 |
result += codegen(sel) |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
607 |
|
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
608 |
if hasContent and not(avoidTag): |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
609 |
result += "</" + ymlFunc[name].alias + ">" |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
610 |
|
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
611 |
complete += result |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
612 |
|
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
613 |
return code(complete) |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
614 |
|
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
615 |
elif ctype == "textsection": |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
616 |
result = '' |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
617 |
ll = obj[1].splitlines() |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
618 |
space = len(ll[-1]) - 2 |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
619 |
for l in ll[1:-1]: |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
620 |
m = re.match(bqq, l) |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
621 |
if m: |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
622 |
cmd = m.group(1) |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
623 |
try: |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
624 |
r, x = parseLine(cmd, _inner, [], True, comment) |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
625 |
if x: raise SyntaxError(cmd) |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
626 |
result += _finish(r) |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
627 |
except SyntaxError: |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
628 |
if included: |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
629 |
raise SyntaxError("in " + included + ":" + u(line) + ": syntax error in executing command: " + cmd.strip()) |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
630 |
else: |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
631 |
raise SyntaxError("in " + u(line) + ": syntax error in executing command: " + cmd.strip()) |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
632 |
else: |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
633 |
result += codegen(Symbol('lineQuote', '| ' + l[space:])) |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
634 |
return code(result) |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
635 |
|
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
636 |
elif ctype == "textsectionu": |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
637 |
result = '' |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
638 |
ll = obj[1].splitlines() |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
639 |
space = len(ll[-1]) - 2 |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
640 |
for l in ll[1:-1]: |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
641 |
m = re.match(bqq, l) |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
642 |
if m: |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
643 |
cmd = m.group(1) |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
644 |
try: |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
645 |
r, x = parseLine(cmd, _inner, [], True, comment) |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
646 |
if x: raise SyntaxError(cmd) |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
647 |
result += _finish(r) |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
648 |
except SyntaxError: |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
649 |
if included: |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
650 |
raise SyntaxError("in " + included + ":" + u(line) + ": syntax error in executing command: " + cmd.strip()) |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
651 |
else: |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
652 |
raise SyntaxError("in " + u(line) + ": syntax error in executing command: " + cmd.strip()) |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
653 |
else: |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
654 |
if result != '': result += ' ' |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
655 |
result += codegen(Symbol('quote', ['> ' + l[space:]])) |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
656 |
return code(result) |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
657 |
|
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
658 |
elif ctype == "lineQuote" or ctype == "quote": |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
659 |
m, text, base, inds = None, "", 0, 0 |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
660 |
|
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
661 |
if ctype == "lineQuote": |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
662 |
text = obj[1] |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
663 |
m = lq.match(text) |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
664 |
if m: |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
665 |
inds = len(m.group(1)) |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
666 |
text = m.group(2)[1:] |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
667 |
else: inds = 0 |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
668 |
elif ctype == "quote": |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
669 |
inds = -1 |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
670 |
text = obj[1][0] |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
671 |
m = sq.match(text) |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
672 |
if m: |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
673 |
if m.group(1): |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
674 |
inds = int(m.group(1)) |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
675 |
text = m.group(2)[1:] |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
676 |
else: |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
677 |
if type(text) is str: |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
678 |
text = u(evalPython(text)) |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
679 |
|
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
680 |
ind = "" |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
681 |
if inds > -1: |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
682 |
try: |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
683 |
cmd = evalPython("indent(" + u(inds) + ")") |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
684 |
result, rest = parseLine(u(cmd), _inner, [], True, comment) |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
685 |
if rest: |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
686 |
raise SyntaxError() |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
687 |
ind = _finish(result) |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
688 |
except: pass |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
689 |
|
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
690 |
if ctype == "lineQuote": text += "\n" |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
691 |
|
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
692 |
hasTextFunc = False |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
693 |
try: |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
694 |
ymlFunc["text"] |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
695 |
hasTextFunc = True |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
696 |
except: pass |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
697 |
|
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
698 |
text = executeCmd(text) |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
699 |
return code(ind + text) |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
700 |
|
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
701 |
elif ctype == "tagQuote": |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
702 |
m = tq.match(obj[1]) |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
703 |
if m.group(1) == "<": |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
704 |
return code("<" + m.group(2)) |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
705 |
else: |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
706 |
return code(m.group(2)) |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
707 |
|
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
708 |
elif ctype == "operator": |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
709 |
operator.append((re.compile(evalPython(obj[1][0])), obj[1][1])) |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
710 |
return code("") |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
711 |
|
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
712 |
elif ctype == "constant": |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
713 |
name = obj[1][0] |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
714 |
if name[0] == "*": |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
715 |
name = name[1:] |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
716 |
value = obj[1][1] |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
717 |
pointers[name] = value |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
718 |
return code("") |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
719 |
|
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
720 |
elif ctype == "include": |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
721 |
reverse = False |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
722 |
ktext, kxml = False, False |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
723 |
for arg in obj[1]: |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
724 |
if type(arg) is tuple or type(arg) is Symbol: |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
725 |
if arg[0] == "reverse": |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
726 |
reverse = True |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
727 |
elif arg[0] == "ktext": |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
728 |
ktext = True |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
729 |
elif arg[0] == "kxml": |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
730 |
kxml = True |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
731 |
elif type(arg) is str: |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
732 |
filemask = arg |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
733 |
|
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
734 |
if filemask[0] == '/' or filemask[0] == '.': |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
735 |
files = sorted(glob(filemask)) |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
736 |
else: |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
737 |
files = [] |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
738 |
for directory in includePath: |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
739 |
path = os.path.join(directory, filemask) |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
740 |
files.extend(sorted(glob(path))) |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
741 |
|
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
742 |
if files and reverse: |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
743 |
files = files[-1::-1] |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
744 |
|
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
745 |
if not(files): |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
746 |
if included: |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
747 |
raise IOError("in " + included + ":" + u(line) + ": include file(s) '" + filemask + "' not found") |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
748 |
else: |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
749 |
raise IOError("in " + u(line) + ": include file(s) '" + filemask + "' not found") |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
750 |
|
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
751 |
includeFile = fileinput.input(files, mode="rU", openhook=fileinput.hook_encoded(encoding)) |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
752 |
_included = included |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
753 |
if ktext or kxml: |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
754 |
text = "" |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
755 |
for line in includeFile: |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
756 |
included = includeFile.filename() |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
757 |
if kxml: |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
758 |
if (not line[:6] == '<?xml ') and (not line[:6] == '<?XML '): |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
759 |
text += line |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
760 |
else: |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
761 |
text += executeCmd(line) |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
762 |
included = _included |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
763 |
return code(text) |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
764 |
else: |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
765 |
result = parse(ymlCStyle(), includeFile, True, comment) |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
766 |
included = u(filemask) |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
767 |
x = _finish(result) |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
768 |
included = _included |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
769 |
return code(x) |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
770 |
|
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
771 |
elif ctype == "pyExp": |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
772 |
exp = obj[1][0] |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
773 |
cmd = evalPython(exp) |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
774 |
result, rest = parseLine(u(cmd), _inner, [], True, comment) |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
775 |
if rest: |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
776 |
raise SyntaxError(cmd) |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
777 |
return code(_finish(result)) |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
778 |
|
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
779 |
elif ctype == "pythonCall": |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
780 |
parms = [] |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
781 |
data = obj[1] |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
782 |
for p in data: |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
783 |
if type(p) is str: |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
784 |
name = p |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
785 |
elif type(p) is tuple or type(p) is Symbol: |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
786 |
ptype = p[0] |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
787 |
if ptype == "parm": |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
788 |
if p[1][0][0] == "*": |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
789 |
parms.append(pointer(p[1][0])) |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
790 |
else: |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
791 |
parms.append(p[1][0]) |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
792 |
if len(parms) == 0: |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
793 |
exp = name + "()" |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
794 |
elif len(parms) == 1: |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
795 |
exp = name + "(" + u(parms[0]) + ")" |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
796 |
else: |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
797 |
exp = name + u(tuple(parms)) |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
798 |
cmd = evalPython(exp) |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
799 |
result, rest = parseLine(u(cmd), _inner, [], True, comment) |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
800 |
if rest: |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
801 |
raise SyntaxError() |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
802 |
return code(_finish(result)) |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
803 |
|
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
804 |
else: |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
805 |
return code("") |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
806 |
|
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
807 |
def _finish(tree): |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
808 |
result = "" |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
809 |
python = "" |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
810 |
|
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
811 |
for el in tree: |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
812 |
if el[0] == "python": |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
813 |
if el[1][0][:2] == "!!": |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
814 |
python += el[1][0][2:-2] |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
815 |
else: |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
816 |
python += el[1][0][1:] + "\n" |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
817 |
continue |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
818 |
else: |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
819 |
if python: |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
820 |
execPython(python) |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
821 |
python = "" |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
822 |
|
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
823 |
try: |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
824 |
result += codegen(el) |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
825 |
except RuntimeError: |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
826 |
if included: |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
827 |
raise RuntimeError("in " + included + ":" + u(line)) |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
828 |
else: |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
829 |
raise RuntimeError("in " + u(line)) |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
830 |
|
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
831 |
if python: |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
832 |
execPython(python) |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
833 |
|
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
834 |
return result |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
835 |
|
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
836 |
def finish(tree): |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
837 |
global first |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
838 |
first = True |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
839 |
return _finish(tree) |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
840 |
|
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
841 |
ymlFunc["_parentheses"] = YF("parms") |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
842 |
ymlFunc["_parm"] = YF("parm") |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
843 |
ymlFunc["_generic"] = YF("generic") |
98a53c3282c3
Convert yml2 into a Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff
changeset
|
844 |
ymlFunc["_base"] = YF("base") |