Skip to content

Conversation

@CyrusNajmabadi
Copy link
Member

@CyrusNajmabadi CyrusNajmabadi commented Mar 28, 2020

Adds json parsing support for both Ecma404 json, as well as the json extensions supported by json.net.

There will be two followup PRs for this change. One adding all the test, and one adding the IDE feature. They are broken up to make things easier to review.

Tests are in: #42873

Todo:

  • Move code into Features layer.

CyrusNajmabadi and others added 30 commits May 5, 2018 12:53
…/embeddedJson

Merge master to features/embeddedJson
…/embeddedJson

Merge master to features/embeddedJson
…/embeddedJson

Merge master to features/embeddedJson
…/embeddedJson

Merge master to features/embeddedJson
…/embeddedJson

Merge master to features/embeddedJson
…/embeddedJson

Merge master to features/embeddedJson
…/embeddedJson

Merge master to features/embeddedJson
…/embeddedJson

Merge master to features/embeddedJson
…/embeddedJson

Merge master to features/embeddedJson
…/embeddedJson

Merge master to features/embeddedJson
…/embeddedJson

Merge master to features/embeddedJson
…/embeddedJson

Merge master to features/embeddedJson
…/embeddedJson

Merge master to features/embeddedJson
…/embeddedJson

Merge master to features/embeddedJson
…/embeddedJson

Merge master to features/embeddedJson
…/embeddedJson

Merge master to features/embeddedJson
…/embeddedJson

Merge master to features/embeddedJson
…/embeddedJson

Merge master to features/embeddedJson
…/embeddedJson

Merge master to features/embeddedJson
…/embeddedJson

Merge master to features/embeddedJson
@tmat
Copy link
Member

tmat commented Jan 26, 2022

@CyrusNajmabadi Would you mind squashing commits? CodeFlow does not handle more than 255

@CyrusNajmabadi
Copy link
Member Author

@CyrusNajmabadi Would you mind squashing commits? CodeFlow does not handle more than 255

I will die.

Not kidding. I have several branches off of this. It will kill me to try to squash. @KirillOsenkov can you make codeflow handle more commits plz :(

@tmat
Copy link
Member

tmat commented Jan 27, 2022

No worries, I'll deal with github

Copy link
Contributor

@ryzngard ryzngard left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Mostly LGTM. Follow up questions and some suggested changes

return _regex.Replace(name, "_");
}

//private void Test(string stringText, string expected, bool runJsonNetCheck = true, bool runJsonNetSubTreeTests = true, [CallerMemberName]string name = "")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here, is this all part of some generation of tests that needs to be uncommented? If so... is there a readme or something about this?

using JsonTrivia = EmbeddedSyntaxTrivia<JsonKind>;
using JsonSeparatedList = EmbeddedSeparatedSyntaxNodeList<JsonKind, JsonNode, JsonValueNode>;

public partial class CSharpJsonParserTests
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yea this would be great to have some sort of Readme.md or a giant comment on how this stuff works. It's very hard to follow in a PR :(

It looks really impressive though, and I can confirm that there are a lot of tests.


private JsonTree ParseTree(bool strict)
{
var arraySequence = this.ParseSequence();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit/style question: Do we now advocate for not using this? Is that a style enforced/recommended anywhere?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we leave that entirely at the discretion of the dev. i personally use either depending on how i feel about it aesthetically.

// we then check for any incorrect tree structure (that would be incorrect for both json.net or
// strict-mode). If we don't run into any problems, we'll then perform specific json.net or strict-mode
// checks.
var diagnostic1 = GetFirstDiagnostic(root);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we avoid computing all diagnostics and instead conditionally computer?

var diagnostic = GetFirstDiagnostic(root);
diagnostic ??= CheckTopLevel(_lexer.Text, root);
diagnostic ??= strict ? ... : ... ;

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oh I see, it's still determined based on start location. The comment indicates different than the behavior. First, we ... if not, we ... indicates conditional computation but the code always tries to compute them.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

indeed. comments are bogus. f ixed.

var sequence = compilationUnit.Sequence;
if (sequence.IsEmpty)
{
// json is not allowed to be just whitespace.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

but it is allowed to be empty?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

with empty we don't even want to get here (use has just an empty literal, so there are no features we can offer). i explicitly now test for thsi.


private static bool Matches(JsonToken token, string val)
{
var chars = token.VirtualChars;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if this should be an extension/method on VirtualChars. I'm pretty sure I had to do similar things for stack parsing.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if you link me, i can check!

// This approach of keeping track of the parse contexts we're in, and using them to
// determine if we should consume or pop-out when encountering an error token, mirrors the
// same approach that we use in the C# and TS/JS parsers.
private bool _inObject;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

since I'm using a browser I'm just going to pose this as question since it's hard to verify:

Are there tests for embedded sequences to make sure we still get the behavior we want? [ 1, [ 2, [ 3]] ] and other weird things like [ 1, { 2, [ 3, { 4 }]}] and various permutations of the closing tokens

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

there are def tests for the former. but i'll beef both sorts up now.

auto-merge was automatically disabled January 28, 2022 05:40

Pull Request is not mergeable

@CyrusNajmabadi CyrusNajmabadi merged commit 7ba92d6 into dotnet:main Jan 28, 2022
@CyrusNajmabadi CyrusNajmabadi deleted the jsonParsing branch January 28, 2022 09:06
@ghost ghost added this to the Next milestone Jan 28, 2022
@RikkiGibson RikkiGibson modified the milestones: Next, 17.2.P1 Feb 4, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Area-IDE Need Design Review The end user experience design needs to be reviewed and approved.

Projects

Archived in project

Development

Successfully merging this pull request may close these issues.