-
Notifications
You must be signed in to change notification settings - Fork 2
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
match raw pretty printing of optional_else and indented_block #51
match raw pretty printing of optional_else and indented_block #51
Conversation
Thanks! This is a notable inconsistency in the pp-raw output. If it's not too much trouble, do you have an example of the new format, in particular with chained else-if cases? Instead of finding an example opcode, it is probably easiest to manually construct a In any case, I will take a closer look next week! |
I just saw you have a grammar for parsing this AST output, and it accounts for this else syntax: For what it's worth, in my fork I additionally changed the raw dump such that it wraps these blocks in braces
I can provide an example of the new |
The partial evaluation translates else-if into nested if/else statements, which is why you won't see it in disassembly results. |
Ah! Yes that would explain it.
@katrinafyi Would you be okay with me putting up a PR for this change ^ also? |
I have tested it with the following code and output: let t = [Stmt_Assert (Expr_LitInt "0", Unknown); Stmt_TCall (FIdent ("asdf", 0), [], [], Unknown)] in
let els = [S_Elsif_Cond (Expr_LitInt "2", t); S_Elsif_Cond (Expr_LitInt "3", t)] in
let s = [Stmt_If (Expr_LitInt "1", t, els, t, Unknown)] in
List.iter (fun x -> print_endline @@ Utils.to_string @@ Asl_parser_pp.pp_raw_stmt x) s; Stmt_If(Expr_LitInt("1"),[
Stmt_Assert(Expr_LitInt("0"))
Stmt_TCall(asdf.0,[],[])
],[(S_Elsif_Cond(Expr_LitInt("2"),[
Stmt_Assert(Expr_LitInt("0"))
Stmt_TCall(asdf.0,[],[])
]));(S_Elsif_Cond(Expr_LitInt("3"),[
Stmt_Assert(Expr_LitInt("0"))
Stmt_TCall(asdf.0,[],[])
]))],[
Stmt_Assert(Expr_LitInt("0"))
Stmt_TCall(asdf.0,[],[])
]) This looks to be reasonable, it just replaces As we do rely on this format, do you mind retargeting this PR to the newly-created aslt-changes branch? I'll bundle this up with some more changes we've wanted to make, then merge them when the ANTLR grammars have been updated.
We don't have syntax for array literals (?) so I'm not sure where this could be confused. In any case, I'd prefer to keep the aslt format minimal and not add another set of brackets. |
Done.
I have changed my parser so I don't need this anymore. My new approach has context to know which type of list to expect at each argument position. My approach before was a two stage parser. In the first stage I parsed the ASLT into generic nodes, and the second stage converted from nodes into Thanks. |
If you are working on the ASLT format, another annoyance that might be nice to fix up is redundant wrapping parentheses. You see things like: My guess is this has something to do with the wrapper Anyway, this really isn't that important because it can be trivially fixed up in the parser. But it is a little odd, that's all. |
Thanks!
I see, that is fair and we would like to support this kind of generic parser. You could say lists are either whitespace or semicolon separated, but that is certainly less preferred. The changes we plan to make will be aimed at making it easier to parse and reducing ambiguities.
I can look at this as well. (I don't think it's related to |
* pp-raw for optional_else uses same format as indented_block * call pp_raw_indented_block from optional_else
* pp-raw for optional_else uses same format as indented_block * call pp_raw_indented_block from optional_else
Currently
optional_else
AST is printed in the format(else ...)
whichis inconsistent with the format used for other comparable blocks such as
indented_block
.This PR changes the format to directly invoke
pp_raw_indented_block
.