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, untyped]
- #self?.encode_text ⇒ String, Hash[String, String]
- #self?.kinds_document ⇒ Hash[String, untyped]
- #self?.load ⇒ SerializedTree
- #self?.serialization_tree ⇒ SerializedTree
- #self?.trivia_document ⇒ Array[untyped]
Class Method Details
.dump(value, grammar_digest: nil, table_format: nil, state_count: nil, production_count: nil, memo: nil) ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/ibex/runtime/cst/serialize.rb', line 17 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
40 41 42 43 44 45 46 47 |
# File 'lib/ibex/runtime/cst/serialize.rb', line 40 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
15 |
# File 'sig/ibex/runtime/cst/serialize.rbs', line 15
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, untyped]
29 |
# File 'sig/ibex/runtime/cst/serialize.rbs', line 29
def self?.element_document: (GreenNode | GreenToken element) -> Hash[String, untyped]
|
#self?.encode_text ⇒ String, Hash[String, String]
35 |
# File 'sig/ibex/runtime/cst/serialize.rbs', line 35
def self?.encode_text: (String text) -> (String | Hash[String, String])
|
#self?.kinds_document ⇒ Hash[String, untyped]
26 |
# File 'sig/ibex/runtime/cst/serialize.rbs', line 26
def self?.kinds_document: (Kind kinds) -> Hash[String, untyped]
|
#self?.load ⇒ SerializedTree
19 |
# File 'sig/ibex/runtime/cst/serialize.rbs', line 19
def self?.load: (String source, ?grammar_digest: String?, ?state_count: Integer?, ?production_count: Integer?) -> SerializedTree
|
#self?.serialization_tree ⇒ SerializedTree
23 |
# File 'sig/ibex/runtime/cst/serialize.rbs', line 23
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[untyped]
32 |
# File 'sig/ibex/runtime/cst/serialize.rbs', line 32
def self?.trivia_document: (GreenTrivia trivia) -> Array[untyped]
|