[patch] Keep string, float and long literals through a YAML round trip - #108
Merged
Merged
Conversation
A string literal whose text YAML reads as another scalar (null, ~) was
written bare and came back as ''. The serializer now quotes any string
the reader would take for a non-string.
Float and long literals had no serializer case, so they were written as
{} and read back as nothing, and every generator threw for them. They
now round-trip through the serializer and deserializer, and the shared
generator path, C# (f/L suffixes) and Go's type inference know them.
Fixes #83
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01YLYtHwwqdY3Tk9vpkwT6Sw
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.



Fixes #83
What changed
String literals.
YamlSerializerlet the emitter choose whether to quote a string. It already quotedtrueand123, but it wrotenull,Nulland~bare, so they came back as''. The serializer is now built withWithQuotingNecessaryStrings(), which quotes any string the reader would take for a non-string scalar.Float and long literals. The issue offered two options: support these end to end, or remove
Literal.SingleValueandLiteral.BigNumberValue. Removing them would break the public API, so this PR supports them.YamlSerializerhas a case forLiteralExpression<float>andLiteralExpression<long>. Before, both were written as{}.YamlDeserializerreadsLiteral<Single>andLiteral<Int64>. A float is parsed as afloatdirectly, which avoids rounding twice. It also accepts the.inf,-.infand.nanspellings: the non-finite parsing moved out ofTryParseDoubleinto a sharedTryParseNonFinite.LanguageGeneratorBase:TryGenerateCommonNodewrites both types. A newFormatSingleformats a float as a float, so0.1fstays0.1instead of widening to0.10000000149011612. It adds.0to a whole number the same wayFormatDoubledoes.CanGenerateStandardNodesandLeadingSignknow both types, so-(-5000000000)is not written as--.CSharpGeneratoradds thefandLsuffixes.GoGeneratortreats both as compile-time values and infersfloat32andint64for them.Not changed: the graph editor (
Coder.Graph/AstFields,AstSchema) still has no editable field for float or long literals. That is a separate UI change. This PR is about data loss on save and load.Tests
New file:
Coder.Test/Serialization/LiteralRoundTripTests.cs.null,Null,~,true,False,123,-4.5,1e3,.inf,.nan, the empty string and plain text.MaxValueand non-finite values.MaxValueandMinValue, and as a variable initialiser..0, and a negated negative long doesn't fuse its signs.With the
Coder/changes reverted, 19 of the 28 new cases fail. The 9 that pass are strings the emitter already quoted. With the fix, the full suite passes (962/962) anddotnet build Coder.slnreports no errors.🤖 Generated with Claude Code
https://claude.ai/code/session_01YLYtHwwqdY3Tk9vpkwT6Sw
Generated by Claude Code