Revision 95c4bc24
Added by Vincent Le Goff over 4 years ago
src/sharp/engine.py | ||
---|---|---|
90 | 90 |
""" |
91 | 91 |
function_name = statement[0][1:].lower() |
92 | 92 |
arguments = [] |
93 |
kwargs = {} |
|
93 | 94 |
for argument in statement[1:]: |
94 | 95 |
if argument.startswith("{+"): |
95 | 96 |
argument = argument[3:-2] |
... | ... | |
97 | 98 |
argument = "compile(" + argument + ", 'SharpScript', 'exec')" |
98 | 99 |
elif argument.startswith("{"): |
99 | 100 |
argument = repr(argument[1:-1]) |
100 |
elif argument.endswith("=True") or argument.endswith("=False"): |
|
101 |
pass |
|
101 |
elif argument[0] in "-+": |
|
102 |
kwargs[argument[1:]] = True if argument[0] == "+" else False |
|
103 |
continue |
|
102 | 104 |
else: |
103 | 105 |
argument = repr(argument) |
104 | 106 |
|
105 | 107 |
arguments.append(argument) |
106 | 108 |
|
107 |
return function_name + "(" + ", ".join(arguments) + ")" |
|
109 |
code = function_name + "(" + ", ".join(arguments) |
|
110 |
if arguments and kwargs: |
|
111 |
code += ", " |
|
112 |
|
|
113 |
code += ", ".join([name + "=" + repr(value) for name, value in \ |
|
114 |
kwargs.items()]) |
|
115 |
|
|
116 |
return code + ")" |
|
108 | 117 |
|
109 | 118 |
def split_statements(self, content): |
110 | 119 |
"""Split the given string content into different statements. |
... | ... | |
155 | 164 |
argument = remaining.splitlines()[0] |
156 | 165 |
i += len(argument) |
157 | 166 |
arguments = [argument] |
158 |
elif remaining[0] in "+-": |
|
159 |
argument = remaining.splitlines()[0].split(" ")[0] |
|
160 |
flag = argument[1:] |
|
161 |
if argument.startswith("+"): |
|
162 |
arguments.append(flag + "=True") |
|
163 |
else: |
|
164 |
arguments.append(flag + "=False") |
|
165 |
i += len(flag) + 1 |
|
166 | 167 |
elif remaining[0] == "{": |
167 | 168 |
end = self.find_right_brace(remaining) |
168 | 169 |
argument = remaining[:end + 1] |
Also available in: Unified diff
Restructure the flag system to enhance stability