+
Skip to content
This repository was archived by the owner on Aug 31, 2023. It is now read-only.

feat(rome_json_parser): JSON Parser #3836

Merged
merged 3 commits into from
Nov 25, 2022
Merged

feat(rome_json_parser): JSON Parser #3836

merged 3 commits into from
Nov 25, 2022

Conversation

MichaReiser
Copy link
Contributor

@MichaReiser MichaReiser commented Nov 23, 2022

Summary

This PR implements a JSON parser. Closes #2351

Comments

The parser handles comments as regular tokens to make use of the syntax factories's automatic conversion to unknown if a node contains any comments. We may change comments to trivia at a later time for all json dialects or only for those supporting comments.

Test Plan

I updated the snapshot tests and reviewed them manually.

I added an assertion to the snapshot tests to flag if:

  • A test that must pass contains any unknown nodes, missing required child, or a diagnostic
  • A test that must fail has no diagnostics.

I had to delete two tests that tested very deep object and array structures with missing closing parentheses (1 million open [ without any closing ]). The parser can handle this, but our diagnostics printer runs into a stack overflow 😆

@MichaReiser MichaReiser added A-Parser Area: parser L-JSON Language: JSON labels Nov 23, 2022
@MichaReiser MichaReiser added this to the 11.0.0 milestone Nov 23, 2022
@@ -691,14 +692,7 @@ impl<'src> Lexer<'src> {
KeywordMatcher::Null => NULL_KW,
KeywordMatcher::True => TRUE_KW,
KeywordMatcher::False => FALSE_KW,
_ => {
self.diagnostics.push(ParseDiagnostic::new(
Copy link
Contributor Author

Choose a reason for hiding this comment

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

The parser emits diagnostics for identifiers.

@MichaReiser MichaReiser marked this pull request as ready for review November 23, 2022 18:15
@MichaReiser MichaReiser requested a review from a team November 23, 2022 18:15
@MichaReiser MichaReiser force-pushed the refactor/parser-trait branch from d596ea1 to df1d539 Compare November 24, 2022 07:30
Copy link
Contributor

@ematipico ematipico left a comment

Choose a reason for hiding this comment

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

No particular concerns, I went through some snapshots to see the errors.

json_member_list: JsonMemberList [
missing element,
COMMA@1..2 "," [] [],
missing element,
Copy link
Contributor

Choose a reason for hiding this comment

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

Is it correct to have a missing element here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, because JSON doesn't allow trailing commas.

Base automatically changed from refactor/parser-trait to main November 25, 2022 08:22
@MichaReiser MichaReiser requested a review from a team as a code owner November 25, 2022 08:22
@netlify
Copy link

netlify bot commented Nov 25, 2022

Deploy Preview for docs-rometools canceled.

Name Link
🔨 Latest commit bc15476
🔍 Latest deploy log https://app.netlify.com/sites/docs-rometools/deploys/6380a3f43b4f74000aae9f05

@calibre-analytics
Copy link

calibre-analytics bot commented Nov 25, 2022

Comparing feat(rome_json_parser): JSON Parser Snapshot #2 to median since last deploy of rome.tools.

LCP? CLS? TBT?
Overall
Median across all pages and test profiles
2.47s
from 258ms
0.0
no change
147ms
no change
Chrome Desktop
Chrome Desktop • Cable
2.47s
from 258ms
0.0
no change
346ms
from 20ms
iPhone, 4G LTE
iPhone 12 • 4G LTE
1.07s
from 241ms
0.0
no change
13ms
no change
Motorola Moto G Power, 3G connection
Motorola Moto G Power • Regular 3G
16.3s
from 1.07s
0.0
no change
147ms
no change

1 page tested

 Home

Browser previews

Chrome Desktop iPhone, 4G LTE Motorola Moto G Power, 3G connection
Chrome Desktop iPhone, 4G LTE Motorola Moto G Power, 3G connection

Most significant changes

Value Budget
JS Parse & Compile
Motorola Moto G Power, 3G connection
1.66s
from 26ms
Total JavaScript Size in Bytes
Chrome Desktop
5.36 MB
from 86.8 KB
Total JavaScript Size in Bytes
iPhone, 4G LTE
5.36 MB
from 86.8 KB
Total JavaScript Size in Bytes
Motorola Moto G Power, 3G connection
5.36 MB
from 86.8 KB
JS Parse & Compile
iPhone, 4G LTE
467ms
from 11ms

27 other significant changes: JS Parse & Compile on Chrome Desktop, Total Blocking Time on Chrome Desktop, Largest Contentful Paint on Motorola Moto G Power, 3G connection, First Contentful Paint on Motorola Moto G Power, 3G connection, Total CSS Size in Bytes on Chrome Desktop, Total CSS Size in Bytes on iPhone, 4G LTE, Total CSS Size in Bytes on Motorola Moto G Power, 3G connection, Time to Interactive on Motorola Moto G Power, 3G connection, Total Page Size in Bytes on Chrome Desktop, Total Page Size in Bytes on iPhone, 4G LTE, Total Page Size in Bytes on Motorola Moto G Power, 3G connection, Largest Contentful Paint on Chrome Desktop, First Contentful Paint on Chrome Desktop, Time to Interactive on Chrome Desktop, Number of Requests on Motorola Moto G Power, 3G connection, Number of Requests on Chrome Desktop, Number of Requests on iPhone, 4G LTE, Speed Index on Motorola Moto G Power, 3G connection, Time to Interactive on iPhone, 4G LTE, First Contentful Paint on iPhone, 4G LTE, Largest Contentful Paint on iPhone, 4G LTE, Speed Index on Chrome Desktop, Total HTML Size in Bytes on Chrome Desktop, Total HTML Size in Bytes on iPhone, 4G LTE, Total HTML Size in Bytes on Motorola Moto G Power, 3G connection, Lighthouse Performance Score on Motorola Moto G Power, 3G connection, Lighthouse Performance Score on Chrome Desktop

Calibre: Site dashboard | View this PR | Edit settings | View documentation

@github-actions
Copy link

Parser conformance results on ubuntu-latest

js/262

Test result main count This PR count Difference
Total 45879 45879 0
Passed 44936 44936 0
Failed 943 943 0
Panics 0 0 0
Coverage 97.94% 97.94% 0.00%

jsx/babel

Test result main count This PR count Difference
Total 39 39 0
Passed 36 36 0
Failed 3 3 0
Panics 0 0 0
Coverage 92.31% 92.31% 0.00%

symbols/microsoft

Test result main count This PR count Difference
Total 5946 5946 0
Passed 1757 1757 0
Failed 4189 4189 0
Panics 0 0 0
Coverage 29.55% 29.55% 0.00%

ts/babel

Test result main count This PR count Difference
Total 588 588 0
Passed 519 519 0
Failed 69 69 0
Panics 0 0 0
Coverage 88.27% 88.27% 0.00%

ts/microsoft

Test result main count This PR count Difference
Total 16257 16257 0
Passed 12397 12397 0
Failed 3860 3860 0
Panics 0 0 0
Coverage 76.26% 76.26% 0.00%

@MichaReiser MichaReiser merged commit 32a1686 into main Nov 25, 2022
@MichaReiser MichaReiser deleted the feat/json-parser branch November 25, 2022 13:51
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
A-Parser Area: parser L-JSON Language: JSON
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

JSON Parser
2 participants
点击 这是indexloc提供的php浏览器服务,不要输入任何密码和下载