Changeset View
Changeset View
Standalone View
Standalone View
parser/conversionGenerator.py
Show First 20 Lines • Show All 114 Lines • ▼ Show 20 Line(s) | 114 | if command[:7] == 'COMMENT' or command == '': | |||
---|---|---|---|---|---|
115 | continue | 115 | continue | ||
116 | elif command[:7] != 'RULE_FO': | 116 | elif command[:7] != 'RULE_FO': | ||
117 | raise SyntaxError('Invalid syntax in sdef file, line: ' + rule) | 117 | raise SyntaxError('Invalid syntax in sdef file, line: ' + rule) | ||
118 | 118 | | |||
119 | rule_for = outline[0].split(' ')[1] | 119 | rule_for = outline[0].split(' ')[1] | ||
120 | kind = outline[1].split(' ')[1] | 120 | kind = outline[1].split(' ')[1] | ||
121 | kind_wo_suffix = kind.replace('_kind', '') | 121 | kind_wo_suffix = kind.replace('_kind', '') | ||
122 | actions = outline[2].split(' ')[1:] | 122 | actions = outline[2].split(' ')[1:] | ||
123 | code = False | 123 | code = None | ||
124 | since_version = None | ||||
124 | if len(outline) > 3: | 125 | if len(outline) > 3: | ||
125 | code = ' '.join(';'.join(outline[3:]).split('CODE')[1:]) + ";" | 126 | if outline[3].startswith('SINCE'): | ||
127 | since_version = [int(n) for n in outline[3][6:].split('.')] | ||||
128 | elif outline[3].startswith('CODE'): | ||||
129 | code = ' '.join(';'.join(outline[3:]).split('CODE')[1:]) + ";" | ||||
130 | else: | ||||
131 | raise SyntaxError('Invalid syntax in sdef file, line: ' + rule) | ||||
126 | 132 | | |||
127 | if rule_for not in results: | 133 | if rule_for not in results: | ||
128 | results[rule_for] = list() | 134 | results[rule_for] = list() | ||
129 | 135 | | |||
130 | current_actions = list() | 136 | current_actions = list() | ||
131 | for action in actions: | 137 | for action in actions: | ||
132 | command = action.split('|')[0] | 138 | command = action.split('|')[0] | ||
133 | try: | 139 | try: | ||
▲ Show 20 Lines • Show All 63 Lines • ▼ Show 20 Line(s) | |||||
197 | if code: | 203 | if code: | ||
198 | current_actions.append(code); | 204 | current_actions.append(code); | ||
199 | 205 | | |||
200 | current_actions = "\n".join(current_actions) | 206 | current_actions = "\n".join(current_actions) | ||
201 | if kind == 'any': | 207 | if kind == 'any': | ||
202 | current_stmt = current_actions | 208 | current_stmt = current_actions | ||
203 | else: | 209 | else: | ||
204 | current_stmt = switch_line.replace('%{KIND}', kind).replace('%{ACTIONS}', current_actions) | 210 | current_stmt = switch_line.replace('%{KIND}', kind).replace('%{ACTIONS}', current_actions) | ||
211 | if since_version: | ||||
212 | version_cpp_if = ("#if PYTHON_VERSION_MAJOR >= %d && PYTHON_VERSION_MINOR >= %d\n" | ||||
213 | %(since_version[0], since_version[1])) | ||||
214 | current_stmt = version_cpp_if + current_stmt + "\n#endif" | ||||
205 | results[rule_for].append(current_stmt) | 215 | results[rule_for].append(current_stmt) | ||
206 | does_match_any[rule_for] = any | 216 | does_match_any[rule_for] = any | ||
207 | 217 | | |||
208 | print('''/* This code is generated by conversiongenerator.py. | 218 | print('''/* This code is generated by conversiongenerator.py. | ||
209 | * I do not recommend editing it. | 219 | * I do not recommend editing it. | ||
210 | * To update, run: python2 conversionGenerator.py > generated.h | 220 | * To update, run: python2 conversionGenerator.py > generated.h | ||
211 | */ | 221 | */ | ||
212 | 222 | | |||
213 | #include <QStack> | 223 | #include <QStack> | ||
224 | #include "kdevpythonversion.h" | ||||
214 | 225 | | |||
215 | class PythonAstTransformer { | 226 | class PythonAstTransformer { | ||
216 | public: | 227 | public: | ||
217 | CodeAst* ast; | 228 | CodeAst* ast; | ||
218 | PythonAstTransformer(int lineOffset) : m_lineOffset(lineOffset) {}; | 229 | PythonAstTransformer(int lineOffset) : m_lineOffset(lineOffset) {}; | ||
219 | void run(mod_ty syntaxtree, QString moduleName) { | 230 | void run(mod_ty syntaxtree, QString moduleName) { | ||
220 | ast = new CodeAst(); | 231 | ast = new CodeAst(); | ||
221 | ast->name = new Identifier(moduleName); | 232 | ast->name = new Identifier(moduleName); | ||
▲ Show 20 Lines • Show All 86 Lines • Show Last 20 Lines |