-
Notifications
You must be signed in to change notification settings - Fork 96
[gen] Introduce a new relaxation/edge/atom parser in diy tool.
#1685
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
Open
ShaleXIONG
wants to merge
35
commits into
herd:master
Choose a base branch
from
ShaleXIONG:code-better-parser
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.
Open
Changes from all commits
Commits
Show all changes
35 commits
Select commit
Hold shift + click to select a range
8321e36
[gen] Introduce an AST-based relax parser for diy tools
ShaleXIONG 147c918
[gen] Filter invalid composite relaxations after expansion
ShaleXIONG 2b27aa4
[gen] Unify parser entry points across tools in `/gen`
ShaleXIONG c572138
[gen] Add regression tests for the new parser.
ShaleXIONG 8473fae
[gen] Rework on the ast and parser based on the comments.
ShaleXIONG ba8e35d
[gen] Update the use of `Ast.flatten` and `to_list`.
ShaleXIONG aaf196e
[gen] update the test for parser and lexer.
ShaleXIONG 1e0b41d
[gen] address comment related to unify parser.
ShaleXIONG 019f27b
[gen] address comment on unifying parser in `gen/`
ShaleXIONG 49b9911
[gen] address comment in parser ast.
ShaleXIONG acabe0b
[gen] update the parser for `cumul` argument.
ShaleXIONG 106c620
[gen] address comment in unify parser `gen/`
ShaleXIONG 5b6d162
[gen] use `Ast parsing infrastructure in LogRelax.ml.
ShaleXIONG 16082bb
[gen] Remove unused function in `Ast`.
ShaleXIONG e10024b
[gen] Add parser explanation text in the helper.
ShaleXIONG eadde27
[gen] address commment in new parser.
ShaleXIONG 968cf80
[gen] helper update
ShaleXIONG 0892d7b
[gen] update the comments in `ast.ml`
ShaleXIONG d102a6b
[gen] Update the `ast.expand` in the parsing process in `gen/`
ShaleXIONG a1abf2e
[gen] udpate the test case.
ShaleXIONG e032d86
[gen] remove ( fun .. ) and ( function .. ).
ShaleXIONG 2bcdda5
[gen] update `bind` to the conventional typing in monadic `bind`.
ShaleXIONG e2d2855
[gen] Add backward compatibility in lexutil.mll and remove remove the…
ShaleXIONG f11c7d0
[gen] remove seq_to_choice in unify parsing in `gen/`
ShaleXIONG aa17d9e
[gen] update the test for backward compatibility
ShaleXIONG 39c2dcb
[gen] update helper.
ShaleXIONG a4ed93a
[gen] remove warning in norm.ml
ShaleXIONG d847b36
[gen] remove `mk_seq` and `mk_choice` and introduce `normalise`.
ShaleXIONG 35df659
Update test. (HISTORY REWRITE in code-better-parser-stash)
ShaleXIONG b73374f
[gen] remove `normalise` from the interface.
ShaleXIONG a638a52
Separate top level parser.
ShaleXIONG f46ebf8
Update the parsing in `gen/`
ShaleXIONG e869a2b
[test] update parser tests.
ShaleXIONG d0e165f
[gen] Expose AutoArch as a library so we can use it in testing.
ShaleXIONG dff3d4e
Test remove invalid input.
ShaleXIONG 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
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
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,65 @@ | ||
| type 'prim t = | ||
| | One of 'prim | ||
| | Opt of 'prim t | ||
| | Seq of 'prim t list | ||
| | Choice of 'prim t list | ||
|
ShaleXIONG marked this conversation as resolved.
|
||
|
|
||
| let rec normalise ast = | ||
| let normalise_seq_items items = | ||
| List.fold_right | ||
| (fun item acc -> | ||
| match normalise item with | ||
| | Seq nested -> nested @ acc | ||
| | item -> item :: acc) | ||
| items [] in | ||
| let normalise_choice_items items = | ||
| List.fold_right | ||
| (fun item acc -> | ||
| match normalise item with | ||
| | Choice nested -> nested @ acc | ||
| | item -> item :: acc) | ||
| items [] in | ||
| match ast with | ||
| | One _ -> ast | ||
| | Opt opt -> Opt (normalise opt) | ||
| | Seq ss -> Seq (normalise_seq_items ss) | ||
| | Choice ss -> Choice (normalise_choice_items ss) | ||
|
|
||
| let rec bind ast func = | ||
| let bind_func ast = bind ast func in | ||
| match ast with | ||
| | One s -> func s | ||
| | Opt opt -> Opt (bind_func opt) | ||
| | Seq ss -> Seq (List.map bind_func ss) | ||
| | Choice ss -> Choice (List.map bind_func ss) | ||
|
|
||
| let rec pp pp_prim ast = | ||
| let pp_with_prim = pp pp_prim in | ||
| let ast = normalise ast in | ||
| match ast with | ||
| | One s -> Printf.sprintf "%s" (pp_prim s) | ||
| | Opt opt -> Printf.sprintf "%s?" (pp_with_prim opt) | ||
| | Seq ss -> | ||
| Printf.sprintf "[%s]" (String.concat "," (List.map pp_with_prim ss)) | ||
| | Choice ss -> | ||
| Printf.sprintf "[%s]" (String.concat "|" (List.map pp_with_prim ss)) | ||
|
|
||
| let list_cross_product_map f lhs rhs = | ||
| List.map ( fun l -> | ||
| List.map ( fun r -> | ||
| f l r | ||
| ) rhs | ||
| ) lhs | ||
| |> List.flatten | ||
|
|
||
| let rec expand t = | ||
| let result = match t with | ||
| | One str -> [[str]] | ||
| | Opt opt -> [] :: expand opt | ||
| | Seq seq -> List.fold_left | ||
| ( fun acc s -> | ||
| expand s | ||
| |> list_cross_product_map ( @ ) acc | ||
| ) [[]] seq | ||
| | Choice choice -> List.map expand choice |> List.flatten in | ||
| result | ||
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,34 @@ | ||
| (* Abstract syntax tree for the relax-input grammar. | ||
| The type parameter `'prim` is the leaf token type produced by the parser. | ||
| - `One x` is a single primitive token. | ||
| - `Opt t` is an optional sub-expression, i.e., `(t)?`. | ||
| - `Seq ts` is an ordered sequence of sub-expressions, i.e., `A B C` | ||
| or `A,B,C`. | ||
| - `Choice ts` is a choice between alternatives, i.e., `A|B|C`. *) | ||
| type 'prim t = | ||
| | One of 'prim | ||
| | Opt of 'prim t | ||
| | Seq of 'prim t list | ||
| | Choice of 'prim t list | ||
|
|
||
| val bind : 'a t -> ('a -> 'b t) -> 'b t | ||
| val pp : ('a -> string) -> 'a t -> string | ||
|
|
||
| (* Flatten the AST into the list of concrete sequences. | ||
| - `One x` expands to `[[x]]`. | ||
| - `Opt t` expands to the alternatives of `t`, plus the empty sequence. | ||
| - `Choice list` concatenates the expansions of each alternative. | ||
| For example, `Choice [A; B]` becomes `[[A]; [B]]`. | ||
| - `Seq list` computes the ordered cross-product. | ||
| If `A` expands to `[[X; Y]; [Z]]` and `B` to `[[K]; [M; N]]`, | ||
| then `Seq [A; B]` expands to | ||
| `[ [X; Y; K]; [X; Y; M; N]; [Z; K]; [Z; M; N] ]`. | ||
| A concrete example is | ||
| `Seq [Choice [One x; One y]; Opt (Seq [One z; One k])]`, | ||
| which expands to `[[x]; [x; z; k]; [y]; [y; z; k]]`, where: | ||
| - `[x]` comes from `One x` followed by the empty alternative of `Opt`. | ||
| - `[x; z; k]` comes from `One x` followed by `Seq [One z; One k]`. | ||
| - `[y]` comes from `One y` followed by the empty alternative of `Opt`. | ||
| - `[y; z; k]` comes from `One y` followed by `Seq [One z; One k]`. | ||
| *) | ||
| val expand : 'a t -> 'a list list |
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 |
|---|---|---|
| @@ -1,5 +1,8 @@ | ||
| (ocamllex lexUtil) | ||
|
|
||
| (menhir | ||
| (modules parser)) | ||
|
|
||
| (rule | ||
| (copy ../../Version.ml Version.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
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
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.