- Notifications
You must be signed in to change notification settings - Fork471
[WIP] Embed lang 2.0#7959
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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Draft
zth wants to merge25 commits intomasterChoose a base branch fromembed-lang-2
base:master
Could not load branches
Branch not found:{{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline, and old review comments may become outdated.
+5,452 −85
Draft
[WIP] Embed lang 2.0#7959
Changes fromall commits
Commits
Show all changes
25 commits Select commitHold shift + click to select a range
3cf1e87 initial plan
zth41c511e phase 1
zth5b9a9f0 more work
zth835f7a7 more work
zthb75cd4c more work
zth8c0b6ee more work
zth8ee127d formatting + fix warnings
zth8973e35 fix warnings
zth8abc29a fix lints
zth1afbcc2 more fixes
ztha7cc8fb more fixes
zth2d82ad1 ci
zth40f26a8 more work
zth46415e6 dedicated embed syntax
zthd5daba7 work
zth5c7e4f9 work
zth337705c fix lint
zth96a87bd generator modes plan
zth54b487d ci
zthbae349e add perf optimizations section
zthe0f5de3 refactor
zth83a8c4c refactor
zth33a49c1 format
zth00284dd skip embed lang tests on windows for now
zthdabd223 work
zthFile filter
Filter by extension
Conversations
Failed to load comments.
Loading
Uh oh!
There was an error while loading.Please reload this page.
Jump to
Jump to file
Failed to load files.
Loading
Uh oh!
There was an error while loading.Please reload this page.
Diff view
Diff view
There are no files selected for viewing
8 changes: 7 additions & 1 deletionMakefile
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
9 changes: 9 additions & 0 deletionscompiler/bsc/rescript_compiler_main.ml
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
5 changes: 5 additions & 0 deletionscompiler/common/js_config.ml
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
7 changes: 7 additions & 0 deletionscompiler/common/js_config.mli
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
8 changes: 7 additions & 1 deletioncompiler/core/js_implementation.ml
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
48 changes: 48 additions & 0 deletionscompiler/ext/ext_embed.ml
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,48 @@ | ||
| let get_embed_tag (name : string) : string option = | ||
| let prefix = "embed." in | ||
| let plen = String.length prefix in | ||
| if String.length name > plen && String.sub name 0 plen = prefix then | ||
| Some (String.sub name plen (String.length name - plen)) | ||
| else None | ||
| let is_valid_embed_id (s : string) : bool = | ||
| let len = String.length s in | ||
| if len = 0 then false | ||
| else | ||
| let lead = s.[0] in | ||
| let is_letter = function | ||
| | 'A' .. 'Z' | 'a' .. 'z' -> true | ||
| | _ -> false | ||
| in | ||
| let is_ident_char = function | ||
| | 'A' .. 'Z' | 'a' .. 'z' | '0' .. '9' | '_' -> true | ||
| | _ -> false | ||
| in | ||
| if not (is_letter lead) then false | ||
| else | ||
| let rec loop i = | ||
| if i >= len then true | ||
| else if is_ident_char s.[i] then loop (i + 1) | ||
| else false | ||
| in | ||
| loop 1 | ||
| let invalid_id_error_message = | ||
| "Invalid `id` for embed. Embed `id` must start with a letter, and only \ | ||
| contain letters, digits, and underscores." | ||
| let missing_id_error_message = "Embed config record must include `id: string`." | ||
| let invalid_payload_error_message = | ||
| "Embed payload must be either a string literal or a record literal." | ||
| let normalize_tag_for_symbol (tag : string) : string = | ||
| (* Embed tags are already validated by the parser as extension identifiers | ||
| (attr-id with optional dot-separated segments). We only need to make the | ||
| tag segment safe for inclusion in a single identifier by mapping '.' to | ||
| '_'. *) | ||
| let b = Bytes.of_string tag in | ||
| for i = 0 to Bytes.length b - 1 do | ||
| if Bytes.get b i = '.' then Bytes.set b i '_' | ||
| done; | ||
| Bytes.unsafe_to_string b |
20 changes: 20 additions & 0 deletionscompiler/ext/ext_embed.mli
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,20 @@ | ||
| val get_embed_tag : string -> string option | ||
| (** [get_embed_tag name] returns [Some base] when [name] starts with | ||
| the embed prefix "embed." and has a non-empty remainder; otherwise [None]. *) | ||
| val is_valid_embed_id : string -> bool | ||
| (** Validate embed `id`: must start with a letter and contain only | ||
| letters, digits, and underscores. *) | ||
| val invalid_id_error_message : string | ||
| (** Centralized error message for invalid embed `id`. *) | ||
| val missing_id_error_message : string | ||
| (** Error when a config record omits `id` or provides a non-string `id`. *) | ||
| val invalid_payload_error_message : string | ||
| (** Error when embed payload is not a string literal or record literal. *) | ||
| val normalize_tag_for_symbol : string -> string | ||
| (** Convert an embed tag (validated as an attribute id) into a safe fragment | ||
| for inclusion in a single identifier, by replacing '.' with '_'. *) |
12 changes: 11 additions & 1 deletioncompiler/frontend/ast_exp_extension.ml
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
16 changes: 15 additions & 1 deletioncompiler/frontend/bs_ast_invariant.ml
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
Oops, something went wrong.
Uh oh!
There was an error while loading.Please reload this page.
Oops, something went wrong.
Uh oh!
There was an error while loading.Please reload this page.
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.