Class: Python2QueryHook

Inherits:
BasePythonQueryHook show all
Defined in:
lib/python2/query_hook.rb

Instance Method Summary collapse

Methods inherited from BasePythonQueryHook

#command_line, #compile_cookie, #compile_file_content, #compile_file_header, #compile_state, #error_patterns, #syntax_error_regexp

Instance Method Details

#compile_query(query, output_prefix = "=> ") ⇒ Object



2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/python2/query_hook.rb', line 2

def compile_query(query, output_prefix = "=> ")
  if query.match /print *(\(| ).*|.*[^=><!]=[^=].*|^raise\b/
    query
  else
<<~python
__mumuki_error__ = None
try:
  __mumuki_args__ = {'mumuki_query_result': eval("""#{query.gsub('"', '\"')}""")}
  print(string.Template(\"\${mumuki_query_result}\").safe_substitute(**__mumuki_args__))
except SyntaxError as e:
  __mumuki_error__ = SyntaxError(e.msg, ('<console>', e.lineno, e.offset, e.text))
if __mumuki_error__:
  print(__mumuki_error__.text)
  print(" "*(__mumuki_error__.offset - 1) + "^")
  print('SyntheticMumukiSyntaxError: SyntaxError: ' + str(__mumuki_error__))
  exit(1)
python
  end
end