Module: Ibex::Runtime::JSONLTracer::Hooks
- Defined in:
- lib/ibex/runtime/jsonl_tracer.rb,
sig/ibex/runtime/jsonl_tracer.rbs
Overview
Hook layer installed on an individual parser's singleton class.
Instance Method Summary collapse
- #ibex_jsonl_trace_output=(output) ⇒ void
- #on_error_recover(token_id, value, value_stack) ⇒ void
- #on_reduce(production_id, values, result) ⇒ void
- #on_shift(token_id, value, state) ⇒ void
- #safe_inspect(value) ⇒ String
- #token_to_str ⇒ String
- #write_trace(**event) ⇒ void
Instance Method Details
#ibex_jsonl_trace_output=(output) ⇒ void
This method returns an undefined value.
46 47 48 |
# File 'lib/ibex/runtime/jsonl_tracer.rb', line 46 def ibex_jsonl_trace_output=(output) @ibex_jsonl_trace_output = output end |
#on_error_recover(token_id, value, value_stack) ⇒ void
This method returns an undefined value.
37 38 39 40 41 |
# File 'lib/ibex/runtime/jsonl_tracer.rb', line 37 def on_error_recover(token_id, value, value_stack) write_trace(event: "error_recover", token_id: token_id, token: token_to_str(token_id), value: safe_inspect(value), value_stack: value_stack.map { |item| safe_inspect(item) }) super end |
#on_reduce(production_id, values, result) ⇒ void
This method returns an undefined value.
30 31 32 33 34 |
# File 'lib/ibex/runtime/jsonl_tracer.rb', line 30 def on_reduce(production_id, values, result) write_trace(event: "reduce", production_id: production_id, values: values.map { |value| safe_inspect(value) }, result: safe_inspect(result)) super end |
#on_shift(token_id, value, state) ⇒ void
This method returns an undefined value.
23 24 25 26 27 |
# File 'lib/ibex/runtime/jsonl_tracer.rb', line 23 def on_shift(token_id, value, state) write_trace(event: "shift", token_id: token_id, token: token_to_str(token_id), value: safe_inspect(value), state: state) super end |
#safe_inspect(value) ⇒ String
58 59 60 61 62 |
# File 'lib/ibex/runtime/jsonl_tracer.rb', line 58 def safe_inspect(value) value.inspect.encode(Encoding::UTF_8, invalid: :replace, undef: :replace) rescue StandardError "<inspect failed>" end |
#token_to_str ⇒ String
13 |
# File 'sig/ibex/runtime/jsonl_tracer.rbs', line 13
def token_to_str: (Integer) -> String
|
#write_trace(**event) ⇒ void
This method returns an undefined value.
51 52 53 54 55 |
# File 'lib/ibex/runtime/jsonl_tracer.rb', line 51 def write_trace(**event) @ibex_jsonl_trace_output&.puts(JSON.generate(event)) rescue StandardError nil end |