Module: Toml::Merge::NodeTypeNormalizer
- Extended by:
- Ast::Merge::NodeTyping::Normalizer
- Defined in:
- lib/toml/merge/node_type_normalizer.rb
Overview
Normalizes backend-specific node types to canonical TOML types.
Uses Ast::Merge::NodeTyping::Wrapper to wrap nodes with canonical
merge_type, allowing portable merge rules across backends.
Thread Safety
All backend registration and lookup operations are thread-safe via
the shared Ast::Merge::NodeTyping::Normalizer module.
Backends
Currently supports:
:tree_sitter- tree-sitter-toml grammar (via ruby_tree_sitter, tree_stump, FFI):citrus- toml-rb gem with Citrus parser:parslet- toml gem with Parslet parser
Extensibility
New backends can be registered at runtime:
Canonical Types
The following canonical types are used for portable merge rules:
Document Structure
:document- Root document node:table- Table/section header[section]:array_of_tables- Array of tables[[section]]:pair- Key-value pairkey = value
Key Types
:bare_key- Unquoted key:quoted_key- Quoted key"key"or'key':dotted_key- Dotted keya.b.c
Value Types
:string- String values (basic or literal):integer- Integer values:float- Floating point values:boolean- Booleantrue/false:array- Array values[1, 2, 3]:inline_table- Inline table{ key = value }
Date/Time Types
:datetime- Date/time values (offset, local, date-only, time-only)
Other
:comment- Comment lines
Constant Summary collapse
- DEFAULT_BACKEND =
Default backend for TOML normalization
:tree_sitter
Class Method Summary collapse
-
.canonical_type(backend_type, backend = DEFAULT_BACKEND) ⇒ Symbol?
Get the canonical type for a backend-specific type.
-
.container_type?(type) ⇒ Boolean
Check if a type is a container type (can have children).
-
.key_type?(type) ⇒ Boolean
Check if a type is a key type.
-
.table_type?(type) ⇒ Boolean
Check if a type is a table type (regular or array of tables).
-
.value_type?(type) ⇒ Boolean
Check if a type is a value type (string, integer, etc.).
-
.wrap(node, backend = DEFAULT_BACKEND) ⇒ Ast::Merge::NodeTyping::Wrapper
Wrap a node with its canonical type as merge_type.
Class Method Details
.canonical_type(backend_type, backend = DEFAULT_BACKEND) ⇒ Symbol?
Get the canonical type for a backend-specific type.
Overrides the shared Normalizer to default to :tree_sitter backend.
245 246 247 |
# File 'lib/toml/merge/node_type_normalizer.rb', line 245 def canonical_type(backend_type, backend = DEFAULT_BACKEND) super(backend_type, backend) end |
.container_type?(type) ⇒ Boolean
Check if a type is a container type (can have children)
290 291 292 293 |
# File 'lib/toml/merge/node_type_normalizer.rb', line 290 def container_type?(type) canonical = type.to_sym %i[document table array_of_tables array inline_table].include?(canonical) end |
.key_type?(type) ⇒ Boolean
Check if a type is a key type
281 282 283 284 |
# File 'lib/toml/merge/node_type_normalizer.rb', line 281 def key_type?(type) canonical = type.to_sym %i[bare_key quoted_key dotted_key].include?(canonical) end |
.table_type?(type) ⇒ Boolean
Check if a type is a table type (regular or array of tables)
263 264 265 266 |
# File 'lib/toml/merge/node_type_normalizer.rb', line 263 def table_type?(type) canonical = type.to_sym %i[table array_of_tables].include?(canonical) end |
.value_type?(type) ⇒ Boolean
Check if a type is a value type (string, integer, etc.)
272 273 274 275 |
# File 'lib/toml/merge/node_type_normalizer.rb', line 272 def value_type?(type) canonical = type.to_sym %i[string integer float boolean array inline_table datetime].include?(canonical) end |
.wrap(node, backend = DEFAULT_BACKEND) ⇒ Ast::Merge::NodeTyping::Wrapper
Wrap a node with its canonical type as merge_type.
Overrides the shared Normalizer to default to :tree_sitter backend.
255 256 257 |
# File 'lib/toml/merge/node_type_normalizer.rb', line 255 def wrap(node, backend = DEFAULT_BACKEND) super(node, backend) end |