-
Notifications
You must be signed in to change notification settings - Fork 16
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
first prototype of randicheck #417
base: main
Are you sure you want to change the base?
Conversation
…leans and functions with case statements
Code and Documentation Coverage ReportDocumentation CoverageClick to view documentation coverage for this PR
Click to view documentation coverage for main
Code Coverage SummaryThis PR: Detailed Report
Main: Detailed Report
Coverage Main & PR Coverage ChangeLines coverage changed by 0.00% and covered lines changed by 0
Functions coverage changed by 0.00% and covered lines changed by 0
Branches... coverage: No comparison data available |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
looks good. I think the adt you have can directly be converted to the model object in oxide.
//a constructor for an adt is just a list of types | ||
#[derive(Clone,Debug)] | ||
struct Constructor { | ||
Types: Box<[Type]>, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
would it not make sense for constructors to remember their name too?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Assuming you mean name as in L Bool, We can do, I mainly did it like this for simplicity in implementation. so we don't have to deal with optionals in cases like Maybe None where there is no type in the box, and in functions it all just gets referred to generally as constructor (at least in haskell's parser, Rust etc may do this differently), so there would have to be logic to differentiate between these anyway down the line.
|
||
// the full haskell file is a list of data types and functions, where we only support custom types, bools, and functions with case statements | ||
#[derive(Debug)] | ||
struct Haskell { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would call this something like Program. our aspiration is that this is not haskell specific.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think that's valid in future, but considering that currently this is only targetting haskell, and when adding additional languages this will likely be refactored to a seperate ast file, pushing a change for one word isn't vitally important. I'll make sure to change it for my next commit though.
.expect("Error loading Haskell language"); | ||
// query to get the body of a function, which is a case statement, note that there is a recursion issue here at the apply function component | ||
// as a function may be curried and we can't represent that in the current query language | ||
let query_function = r#" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am still slightly worried about these queries. how do you know you consumed everything in the input?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In short the plan is basically to purposely not do that, as we're only querying for the parts of haskell we can deal with right now, In terms of a more production style deployment, we can add or's with wildcards in areas to throw warnings/errors when potentially valuable input is skipped. eg for the function body we can add
_ @giveWarning]
This is generally how I expect to handle recursion using queries as well. My main concern would probably be performance as I'm unsure how efficient queries are compared to manual traversal, but once using multiple languages it should be possible to nicely create language agnostic functions to pull data out of a rust enum or haskell adt just by loading a query cursor with the relevant query.
let me know when you think we can merge this @TAswan - there are a few comments from last week. |
Didn't use Oz's code, so doing a seperate PR as Leia seemed to get use out of reading #408 and it'd be nice to keep that seperate. Created using tree sitter queries primarily, and currently supports ADT's with Booleans, and functions using case statements.
converts:
to
Haskell { adt: [DataType { Name: "X", Constructors: [Constructor { Types: [Custom("L"), Bool] }, Constructor { Types: [Custom("R"), Bool, Bool] }] }], fun: [Function { Name: "f", Inputs: [Custom("X")], Output: Bool, Body: [Case("x", Pattern { True_On: [Custom("L"), Custom("True")], gives: True }), Case("x", Pattern { True_On: [Custom("R"), Custom("False"), Custom("_")], gives: True }), Case("x", Pattern { True_On: [Custom("otherwise")], gives: False })] }] }