Skip to content

Comments

Add support for flow map syntax (e.g., {key: value})#108

Open
guanchzhou wants to merge 1 commit intokubkon:mainfrom
guanchzhou:feat/flow-map-support
Open

Add support for flow map syntax (e.g., {key: value})#108
guanchzhou wants to merge 1 commit intokubkon:mainfrom
guanchzhou:feat/flow-map-support

Conversation

@guanchzhou
Copy link

This commit adds support for flow map syntax in YAML documents. Previously, the parser failed when encountering flow maps (e.g., {} or {key: value}) because the value() function did not handle .flow_map_start tokens.

The issue manifested when parsing documents like:

preferences: {}
current-context: test

The parser would fail with "expected end of document" error because:

  1. It encountered { but had no handler for .flow_map_start
  2. Returned .none as the value for preferences
  3. Then failed when looking for document end, finding more content

This fix adds:

  • A new mapBracketed() function similar to listBracketed() to properly parse flow map syntax
  • Handling for .flow_map_start case in the value() function
  • Support for empty flow maps {}, single-entry maps, and multi-entry maps

This makes the parser compatible with kubectl-generated kubeconfig files and other YAML documents that use flow map syntax.

Fixes parsing of YAML 1.2 flow maps as specified in the spec.

@guanchzhou guanchzhou force-pushed the feat/flow-map-support branch from 83cad99 to be8225d Compare September 30, 2025 22:04
This commit adds support for flow map syntax in YAML documents.
Previously, the parser failed when encountering flow maps (e.g., `{}`
or `{key: value}`) because the `value()` function did not handle
`.flow_map_start` tokens.

The issue manifested when parsing documents like:
```yaml
preferences: {}
current-context: test
```

The parser would fail with "expected end of document" error because:
1. It encountered `{` but had no handler for `.flow_map_start`
2. Returned `.none` as the value for `preferences`
3. Then failed when looking for document end, finding more content

This fix adds:
- A new `mapBracketed()` function similar to `listBracketed()` to
  properly parse flow map syntax
- Handling for `.flow_map_start` case in the `value()` function
- Support for empty flow maps `{}`, single-entry maps, and
  multi-entry maps

This makes the parser compatible with kubectl-generated kubeconfig
files and other YAML documents that use flow map syntax.

Fixes parsing of YAML 1.2 flow maps as specified in the spec.
@guanchzhou guanchzhou force-pushed the feat/flow-map-support branch from be8225d to b35bc9c Compare September 30, 2025 22:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant