Skip to content

Cst rewrite #4

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

Closed
wants to merge 69 commits into from
Closed

Cst rewrite #4

wants to merge 69 commits into from

Conversation

srghma
Copy link

@srghma srghma commented May 7, 2020

WIP

#1

@flip111
Copy link
Member

flip111 commented May 11, 2020

Hey thanks a lot for your pull request. Could you keep a summary in the first post of what you are changing? Right now it's a lot of changes and i'm not sure what to look for.

@srghma
Copy link
Author

srghma commented May 11, 2020

hi @flip111, I have changed types to the types from purescript-cst

http://hackage.haskell.org/package/purescript-0.13.6/docs/src/Language.PureScript.CST.Types.html#Declaration

all types from there are added

but not all are printed (e.g. 1, 2)

the Expected.txt was added to some tests, but these tests are not yet implemented

tests are working https://travis-ci.org/github/srghma/purescript-ps-ast/builds/685609928#L3307

in readme you can find

Objectives:
- types are copy of purescript-cst
- parentheses are added automatically, there is no need to use ExprParens or TypeParens (they are added by purescript parser on parsing phase)

the only difference from purescript-cst is the comments field in Declarations

newlines are added between all declarations except of DeclSignature and DeclValue IF their identifiers are the same

I'm not using purescript-matryoshka (maybe this is bad)


I think everything that I need is implemented and I'm going to test how it works in https://github.com/srghma/purescript-fernet

@srghma
Copy link
Author

srghma commented May 11, 2020

the functions in Imports module are commented now, this module was adding imports during printing from fully qualified names in type and value level (and was making fully qualified names in type and value level non-qualified / was simplifying them)

this is cool feature, maybe in future we will re-add it

@flip111
Copy link
Member

flip111 commented May 11, 2020

Looks great so far, give us a notice when you think it's finished and we can do a proper review.

but not all are printed

Do you mean there is no printer code the stringify some types? I know the purescript compiler doesn't have a full pretty printer. There is this project https://gitlab.com/joneshf/purty which has a pretty printer, but i'm not sure how much it is compatible with the code from the purescript compiler.

the only difference from purescript-cst is the comments field in Declarations

What is the change in the comments field? I think to be able to print comments would be very useful because in case not all typescript definition information (this repo is supposed to work together with purescript-dts later) can be transformed into purescript, it can then be put in some comments at least.

@paluh
Copy link
Member

paluh commented May 12, 2020

@srghma Thanks a lot for your huge contribution. I'm not sure if it is the best place to ask but we have decided that it would be really cool if you join our independent purescript-codegen org team, so I can assure you that you are very welcome :-)
Would you like to join the team?

tests are working https://travis-ci.org/github/srghma/purescript-ps-ast/builds/685609928#L3307

This is huge!
P.S. For sure we have to cleanup some warnings :-P

I'm not using purescript-matryoshka (maybe this is bad)

From my perspective it is really good choice. I think that it is better to preserve consistency with the original library than to reach for fancier API in this case.

I think everything that I need is implemented and I'm going to test how it works in https://github.com/srghma/purescript-fernet

I'm not sure when I find time but I want to cleanup read-dts once again and rewrite codegen for MUI as well using this new API of yours.

@srghma
Copy link
Author

srghma commented May 13, 2020

@flip111

Do you mean there is no printer code the stringify some types?

yes

sorry, wrong links, updated 1, 2

the only difference from purescript-cst is the comments field in Declarations

What is the change in the comments field?

I have added comments for now only to the declarations, but in purescript-cst every element can have comments, before or after the element

e.g. SourceToken contains comment

2020-05-13-15:08:31-screenshot

@srghma
Copy link
Author

srghma commented May 13, 2020

@paluh

Would you like to join the team?

yes, of course! finally)

P.S. For sure we have to cleanup some warnings :-P

yes, ok, will do

I'm not using purescript-matryoshka (maybe this is bad)

From my perspective it is really good choice. I think that it is better to preserve consistency with the original library than to reach for fancier API in this case.

👍

@flip111
Copy link
Member

flip111 commented May 14, 2020

but in purescript-cst every element can have comments, before or after the element

I don't know if this makes sense in this context. But i once wrote an AST that had a terminal type that had support for the piece of source code + a comment. That way i didn't need to implement the comment for each type separately.

@srghma
Copy link
Author

srghma commented May 15, 2020

@flip111 terminal type? could you make an example?


I dont think it makes sense to add comments for every type

yes, it could be useful to be able to write someday

foo = bar {- COMMENT1 -} {- COMMENT2 -} foo {- COMMENT3 -}

but I dont need this for now

for now I need comments only at Declaration

@srghma
Copy link
Author

srghma commented May 15, 2020

@paluh @flip111 @jvliwanag I think it's ready, could you please make a review?

should we make another repo called purescript-ps-cst OR merge to this repo?

@flip111
Copy link
Member

flip111 commented May 15, 2020

@flip111 terminal type? could you make an example?

In the grammer you have non-terminal rules, and terminal rules (tokens). Your tokens can be a String or so. But you can also make it a record of String for the token and a Maybe String for a comment.

should we make another repo called purescript-ps-cst OR merge to this repo?

We can merge here and then rename in to purescript-ps-cst IMO

@flip111
Copy link
Member

flip111 commented May 15, 2020

@srghma Do you think we can do the following:

Generate random AST with quickcheck
Print it into source code
Read source code with parser
Verify that AST from parser matches the AST we put in

@srghma
Copy link
Author

srghma commented May 15, 2020

In the grammer you have non-terminal rules, and terminal rules (tokens). Your tokens can be a String or so. But you can also make it a record of String for the token and a Maybe String for a comment.

that's basically Haskell types, with Wrapped and everything else

Generate random AST with quickcheck
Print it into source code
Read source code with parser
Verify that AST from parser matches the AST we put in

we don't have parser implemented in purescript

@paluh
Copy link
Member

paluh commented May 15, 2020

(...) I think it's ready, could you please make a review?

@srghma this is great! Please give me "a moment" - I hope to do the review on the next few days... I'm just not sure if I'm able to add anything valuable to this PR ;-)

Copy link
Member

@paluh paluh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@srghma your PR is so huge that I'm not really able to make valuable review. I'm not sure if there is a place for style related comments etc.
You have implemented also so extensive test suite which proofs that this library works nicely. I really can't wait to test it soon in a real life setting :-)

I hope that you are not disappointed about my approach. I'm leaving few minor review comments for the beginning of your PR.

And once again: Thanks a lot!

@@ -1,6 +1,5 @@
module Language.PS.AST
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we consider migration to the original namespace: Language.PureScript.CST? What do you think Guys?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done Guys)

@srghma
Copy link
Author

srghma commented May 16, 2020

@paluh thanks for kind words, did as for myself

review notes are resolved)

@srghma
Copy link
Author

srghma commented May 21, 2020

created https://github.com/purescript-codegen/purescript-ps-cst

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants