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 =

Signature:

  • Integer

Returns:

  • (Integer)
1

Class Method Summary collapse

Instance 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



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

RBS:

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



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?.dumpString

RBS:

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

Parameters:

  • value (SyntaxNode, SerializedTree)
  • grammar_digest: (String, nil)
  • table_format: (Integer, nil)
  • state_count: (Integer, nil)
  • production_count: (Integer, nil)
  • memo: (ParseMemo, nil)

Returns:

  • (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_documentHash[String, untyped]

RBS:

  • (GreenNode | GreenToken element) -> Hash[String, untyped]

Parameters:

Returns:

  • (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_textString, Hash[String, String]

RBS:

  • (String text) -> (String | Hash[String, String])

Parameters:

  • text (String)

Returns:

  • (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_documentHash[String, untyped]

RBS:

  • (Kind kinds) -> Hash[String, untyped]

Parameters:

Returns:

  • (Hash[String, untyped])


26
# File 'sig/ibex/runtime/cst/serialize.rbs', line 26

def self?.kinds_document: (Kind kinds) -> Hash[String, untyped]

#self?.loadSerializedTree

RBS:

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

Parameters:

  • source (String)
  • grammar_digest: (String, nil)
  • state_count: (Integer, nil)
  • production_count: (Integer, nil)

Returns:



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_treeSerializedTree

RBS:

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

Parameters:

  • value (SyntaxNode, SerializedTree)
  • grammar_digest: (String, nil)
  • table_format: (Integer, nil)
  • state_count: (Integer, nil)
  • production_count: (Integer, nil)
  • memo: (ParseMemo, nil)

Returns:



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_documentArray[untyped]

RBS:

  • (GreenTrivia trivia) -> Array[untyped]

Parameters:

Returns:

  • (Array[untyped])


32
# File 'sig/ibex/runtime/cst/serialize.rbs', line 32

def self?.trivia_document: (GreenTrivia trivia) -> Array[untyped]