Module: Ibex::Runtime::CST::Serialize
- Defined in:
- lib/ibex/runtime/cst/serialize.rb,
sig/ibex/runtime/cst/serialize.rbs
Overview
Stable JSON serialization for ibex_cst schema version 1.
Constant Summary collapse
- SCHEMA_VERSION =
1
Class Method Summary collapse
- .dump(value, grammar_digest: nil, table_format: nil, state_count: nil, production_count: nil, memo: nil) ⇒ Object
- .load(source, grammar_digest: nil, state_count: nil, production_count: nil) ⇒ Object
Instance Method Summary collapse
- #self?.dump ⇒ String
- #self?.element_document ⇒ Hash[String, json_value]
- #self?.encode_text ⇒ String, Hash[String, String]
- #self?.kinds_document ⇒ Hash[String, json_value]
- #self?.load ⇒ SerializedTree
- #self?.serialization_tree ⇒ SerializedTree
- #self?.trivia_document ⇒ Array[json_value]
Class Method Details
.dump(value, grammar_digest: nil, table_format: nil, state_count: nil, production_count: nil, memo: nil) ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/ibex/runtime/cst/serialize.rb', line 20 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
43 44 45 46 47 48 49 50 |
# File 'lib/ibex/runtime/cst/serialize.rb', line 43 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 |
Instance Method Details
#self?.dump ⇒ String
17 |
# File 'sig/ibex/runtime/cst/serialize.rbs', line 17
def self?.dump: (SyntaxNode | SerializedTree value, ?grammar_digest: String?, ?table_format: Integer?, ?state_count: Integer?, ?production_count: Integer?, ?memo: ParseMemo?) -> String
|
#self?.element_document ⇒ Hash[String, json_value]
31 |
# File 'sig/ibex/runtime/cst/serialize.rbs', line 31
def self?.element_document: (GreenNode | GreenToken element) -> Hash[String, json_value]
|
#self?.encode_text ⇒ String, Hash[String, String]
37 |
# File 'sig/ibex/runtime/cst/serialize.rbs', line 37
def self?.encode_text: (String text) -> (String | Hash[String, String])
|
#self?.kinds_document ⇒ Hash[String, json_value]
28 |
# File 'sig/ibex/runtime/cst/serialize.rbs', line 28
def self?.kinds_document: (Kind kinds) -> Hash[String, json_value]
|
#self?.load ⇒ SerializedTree
21 |
# File 'sig/ibex/runtime/cst/serialize.rbs', line 21
def self?.load: (String source, ?grammar_digest: String?, ?state_count: Integer?, ?production_count: Integer?) -> SerializedTree
|
#self?.serialization_tree ⇒ SerializedTree
25 |
# File 'sig/ibex/runtime/cst/serialize.rbs', line 25
def self?.serialization_tree: (SyntaxNode | SerializedTree value, grammar_digest: String?, table_format: Integer?, state_count: Integer?, production_count: Integer?, memo: ParseMemo?) -> SerializedTree
|
#self?.trivia_document ⇒ Array[json_value]
34 |
# File 'sig/ibex/runtime/cst/serialize.rbs', line 34
def self?.trivia_document: (GreenTrivia trivia) -> Array[json_value]
|