Skip to content

Commit

Permalink
21206: Fixes issue where unparsed code (e.g., camls, etc.) that had n…
Browse files Browse the repository at this point in the history
…ull as a key to an assoc would be emitted without the key (#220)
  • Loading branch information
howsohazard authored Aug 12, 2024
1 parent fd5a9a6 commit 6ad2c45
Show file tree
Hide file tree
Showing 3 changed files with 172 additions and 67 deletions.
24 changes: 15 additions & 9 deletions src/Amalgam/Parser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -783,19 +783,25 @@ void Parser::AppendAssocKeyValuePair(UnparseData &upd, StringInternPool::StringI
upd.result.push_back(' ');
}

auto key_str = string_intern_pool.GetStringFromID(key_sid);

//surround in quotes only if needed
if(key_sid != string_intern_pool.NOT_A_STRING_ID
&& HasCharactersBeyondIdentifier(key_str))
if(key_sid == string_intern_pool.NOT_A_STRING_ID)
{
upd.result.push_back('"');
upd.result.append(Backslashify(key_str));
upd.result.push_back('"');
upd.result.append("(null)");
}
else
{
upd.result.append(key_str);
auto key_str = string_intern_pool.GetStringFromID(key_sid);

//surround in quotes only if needed
if(HasCharactersBeyondIdentifier(key_str))
{
upd.result.push_back('"');
upd.result.append(Backslashify(key_str));
upd.result.push_back('"');
}
else
{
upd.result.append(key_str);
}
}

//space between key and value
Expand Down
1 change: 1 addition & 0 deletions src/Amalgam/amlg_code/full_test.amlg
Original file line number Diff line number Diff line change
Expand Up @@ -1186,6 +1186,7 @@

(print "--assoc--\n")
(print (assoc b 2 c 3))
(print (assoc (null) 3))

(print "--get_type--\n")
(print (get_type (lambda (+ 3 4))))
Expand Down
Loading

0 comments on commit 6ad2c45

Please sign in to comment.