Added Support for explicit-key and Refactored TokenStream
TokenStream Refactoring
- Converted boolean state fields (such as
quotedandnewLined) intoint-based bitmasks. - Modified the logic of
nextToken:- Added
ignoreIndexto ignore characters at specific positions when reading tokens fromsource, while simultaneously increasingcurrentIndent. - Updated the parsing conditions for
Token: ForToken.COLON,Token.MULTILINE_LIST_FLAG, and the newly addedToken.EXPLICIT_MAPPING_KEY,
the next character must be a space; otherwise, it will be parsed as a string.
Additionally, the behavior forToken.COMMAdepends onstopOnComma. If this parameter istrue, the behavior remains unchanged; otherwise, it aligns with the above logic.
As a result, the original compensation for misparsed tokens has been removed.
- Added
- Modified the unquoted string escape logic (
Escape.kt):- A string ending with a
:character will only terminate if the next character is a space. -
currentIndentis no longer reset upon encountering a newline character. Instead,curis rolled back to the position before the newline (the responsibility of resettingcurrentIndentshould be handled by the subsequentnextTokencall).
- A string ending with a
New Features
explicit-key (complex key)
c-mapping-key ::= '?'
[189] c-l-block-map-explicit-entry(n) ::=
c-l-block-map-explicit-key(n)
(
l-block-map-explicit-value(n)
| e-node # ""
)
[190] c-l-block-map-explicit-key(n) ::=
c-mapping-key # '?' (not followed by non-ws char)
s-l+block-indented(n,BLOCK-OUT)
Enabled the use of non-primitive elements as mapping keys. Implemented parsing and serialization for the explicit-key specification (during serialization, explicit specification of whether to provide '?' is not supported; it will only appear automatically when the key is non-primitive).
Requirements:
- A space must follow the '?'.
- Supported only for
map; not supported in (de)serializers for classes. - The key and value must be on separate lines (this requirement does not apply in
flowformat). - The indentation of the nested content of the key must be greater than the indentation of the '?' (this requirement does not apply in
flowformat). -
?and:must be at the same indentation level; otherwise, the colon will be treated as part of the nested element (inflowformat, only requires all{and}to be matched).
Additionally, the following requirements from the specification have been implemented for BlockMap:
-
: <value>will be parsed asnull: <value>. - For string keys, the length will be checked to ensure it does not exceed
1024characters.
Changes to YamlDecodingException
The original error messages included meaningless stack traces, which could impair user judgment. Therefore, on the jvm platform, the corresponding stack traces have been removed.
Theoretically, this PR resolves the following issues:
close #70 #66 #45 #36
@Him188 ping❤️ I forgot to sync the main branch when I started writing, please forgive me.🙁