Module: Ibex::Runtime::CST::Serialize

Defined in:
lib/json5/generated_parser.rb

Overview

Stable JSON serialization for ibex_cst schema version 1.

Constant Summary collapse

SCHEMA_VERSION =

RBS:

  • type json_value = String | Integer | bool | nil | Array[json_value] | Hash[String, json_value]
1

Class Method Summary collapse

Class Method Details

.dump(value, grammar_digest: nil, table_format: nil, state_count: nil, production_count: nil, memo: nil) ⇒ Object

RBS:

  • (SyntaxNode | SerializedTree value, ?grammar_digest: String?, ?table_format: Integer?, ?state_count: Integer?, ?production_count: Integer?, ?memo: ParseMemo?) -> String



2610
2611
2612
2613
2614
2615
2616
2617
2618
2619
2620
2621
2622
2623
2624
2625
2626
2627
2628
# File 'lib/json5/generated_parser.rb', line 2610

def dump(value, grammar_digest: nil, table_format: nil, state_count: nil, production_count: nil, memo: nil)
  tree = serialization_tree(
    value, grammar_digest: grammar_digest, table_format: table_format,
           state_count: state_count, production_count: production_count, memo: memo
  )
  document = {
    "ibex_ir" => "cst",
    "schema_version" => SCHEMA_VERSION,
    "grammar_digest" => tree.grammar_digest,
    "table_format" => tree.table_format,
    "state_count" => tree.state_count,
    "production_count" => tree.production_count,
    "trivia_policy" => tree.trivia_policy.to_s,
    "kinds" => kinds_document(tree.kinds),
    "root" => element_document(tree.green_root),
    "memo" => tree.memo&.to_h
  }
  "#{JSON.pretty_generate(document)}\n"
end

.load(source, grammar_digest: nil, state_count: nil, production_count: nil) ⇒ Object

RBS:

  • (String source, ?grammar_digest: String?, ?state_count: Integer?, ?production_count: Integer?) -> SerializedTree



2633
2634
2635
2636
2637
2638
2639
2640
# File 'lib/json5/generated_parser.rb', line 2633

def load(source, grammar_digest: nil, state_count: nil, production_count: nil)
  Validator.validate(
    source,
    grammar_digest: grammar_digest,
    state_count: state_count,
    production_count: production_count
  )
end