-
Notifications
You must be signed in to change notification settings - Fork 458
KDL Parser #2064
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
KDL Parser #2064
Changes from 25 commits
Commits
Show all changes
33 commits
Select commit
Hold shift + click to select a range
73855ea
chore: install deps
Bashamega 82c47f9
Parser
Bashamega ac0e253
patch: types
Bashamega 99e1b99
-
Bashamega 28cdf7d
chore: ignore mdn and idl folders
Bashamega ae4e21b
Merge branch 'microsoft:main' into kdl/parser
Bashamega b68c508
Update src/build/utils/kdl.ts
Bashamega 761bc35
Update src/build/utils/kdl.ts
Bashamega 1aaee0d
Update src/build/utils/kdl.ts
Bashamega fc238c7
Update src/build/utils/kdl.ts
Bashamega 56f7ebf
Update src/build/utils/kdl.ts
Bashamega 4f15c5d
-
Bashamega 4625aa4
chore: rename
Bashamega 3f1bd04
chore: create patches folder
Bashamega 97e5390
patch: rename url
Bashamega 4c85911
-
Bashamega 16c4f14
KDL parser
Bashamega 2d3d3e4
-
Bashamega da909af
feat: rename
Bashamega 3e236c4
chore: remove EnumDescriptor
Bashamega 1f4e523
chore: remove an extra variable
Bashamega c9c4eee
rename
Bashamega f69385e
rename
Bashamega 7213180
lint
Bashamega a5176a7
rename
Bashamega b056cf1
split into smaller functions
Bashamega 609c174
Update src/build/patches.ts
Bashamega 72303fd
Update src/build/patches.ts
Bashamega 2552032
Integrate more enums
Bashamega 4d1ab0f
Revert "Integrate more enums" (#3)
Bashamega 811a217
Update patches.ts
saschanaz e7e2597
Update and rename autoFills.kdl to autocomplete.kdl
saschanaz 7ff687c
Update build.ts
saschanaz File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,70 @@ | ||
| enum AutoFillBase { | ||
| // Off | ||
| value "off" | ||
| // Automatic | ||
| value "on" | ||
| value "" | ||
| } | ||
| enum AutoFillAddressKind { | ||
| value "shipping" | ||
| value "billing" | ||
| } | ||
| enum AutoFillNormalField { | ||
| value "name" | ||
| value "honorific-prefix" | ||
| value "given-name" | ||
| value "additional-name" | ||
| value "family-name" | ||
| value "honorific-suffix" | ||
| value "username" | ||
| value "new-password" | ||
| value "current-password" | ||
| // Supported in iOS Safari too even though WPT tests | ||
| // for Safari currently fail as of 2023-06. | ||
| value "one-time-code" | ||
| value "organization" | ||
| value "street-address" | ||
| value "address-line1" | ||
| value "address-line2" | ||
| value "address-line3" | ||
| value "address-level4" | ||
| value "address-level3" | ||
| value "address-level2" | ||
| value "address-level1" | ||
| value "country" | ||
| value "country-name" | ||
| value "postal-code" | ||
| value "cc-name" | ||
| value "cc-given-name" | ||
| value "cc-family-name" | ||
| value "cc-number" | ||
| value "cc-exp" | ||
| value "cc-exp-month" | ||
| value "cc-exp-year" | ||
| value "cc-csc" | ||
| value "cc-type" | ||
| value "transaction-currency" | ||
| value "transaction-amount" | ||
| value "bday-day" | ||
| value "bday-month" | ||
| value "bday-year" | ||
| } | ||
| enum AutoFillContactKind { | ||
| value "home" | ||
| value "work" | ||
| value "mobile" | ||
| } | ||
| enum AutoFillContactField { | ||
| value "tel" | ||
| value "tel-country-code" | ||
| value "tel-national" | ||
| value "tel-area-code" | ||
| value "tel-local" | ||
| value "tel-local-prefix" | ||
| value "tel-local-suffix" | ||
| value "tel-extension" | ||
| value "email" | ||
| } | ||
| enum AutoFillCredentialField { | ||
| value "webauthn" | ||
| } |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,70 @@ | ||
| import { parse } from "kdljs"; | ||
| import { Enum } from "./types"; | ||
| import { readdir, readFile } from "fs/promises"; | ||
| import { merge } from "./helpers.js"; | ||
|
|
||
| /** | ||
| * Converts patch files in KDL to match the [types](types.d.ts). | ||
| */ | ||
| export function parseKDL(kdlText: string) { | ||
Bashamega marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| const { output, errors } = parse(kdlText); | ||
|
|
||
| if (errors.length) { | ||
| throw new Error("KDL parse errors", { cause: errors }); | ||
| } | ||
|
|
||
| const nodes = output!; | ||
| const enums: Record<string, Enum> = {}; | ||
|
|
||
| for (const node of nodes) { | ||
| if (node.name === "enum") { | ||
| // Handle enum | ||
| const name = node.values[0]; | ||
Bashamega marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| if (typeof name !== "string") { | ||
| throw new Error("Missing enum name"); | ||
| } | ||
| const values: string[] = []; | ||
|
|
||
| for (const child of node.children ?? []) { | ||
| if (child.name !== "value" || typeof child.values[0] !== "string") { | ||
| throw new Error( | ||
| "enum values should be in the form of `value {name}`", | ||
| ); | ||
| } | ||
| values.push(child.values[0]); | ||
| } | ||
|
|
||
| enums[name] = { name, value: values }; | ||
| } | ||
| } | ||
|
|
||
| return { enums: { enum: enums } }; | ||
| } | ||
|
|
||
| /** | ||
| * Collect all file URLs in a directory. | ||
| */ | ||
| async function getAllKDLFileURLs(folder: URL): Promise<URL[]> { | ||
| const entries = await readdir(folder, { withFileTypes: true }); | ||
| return entries.map((entry) => new URL(entry.name, folder)); | ||
| } | ||
|
|
||
| /** | ||
| * Read and parse a single KDL file. | ||
| */ | ||
| export async function readPatch(fileUrl: URL): Promise<any> { | ||
| const text = await readFile(fileUrl, "utf8"); | ||
| return parseKDL(text); | ||
| } | ||
|
|
||
| /** | ||
| * Read, parse, and merge all KDL files under the input folder. | ||
| */ | ||
| export default async function readPatches(): Promise<any> { | ||
| const patchDirectory = new URL("../../inputfiles/patches/", import.meta.url); | ||
| const fileUrls = await getAllKDLFileURLs(patchDirectory); | ||
|
|
||
| const parsedContents = await Promise.all(fileUrls.map(readPatch)); | ||
|
|
||
| return parsedContents.reduce((acc, current) => merge(acc, current), {}); | ||
| } | ||
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.
Uh oh!
There was an error while loading. Please reload this page.