Printer for CST Modules#3887
Conversation
| dummyPos = SourcePos 0 0 | ||
| dummyRange = SourceRange dummyPos dummyPos |
There was a problem hiding this comment.
I wonder if the CST should keep the TokEof around instead of just the trailing module comments.
There was a problem hiding this comment.
Yeah I wondered about that as well...
There was a problem hiding this comment.
You can use moduleRange from CST.Position to get the last position. The TokEof should have the last position twice.
There was a problem hiding this comment.
moduleRange uses the endPosition of the last declaration in the module. Shouldn't the Eof range start after "its" leading comments?
There was a problem hiding this comment.
Yes, it should. You can use commentDelta and applyDelta to get that position. It's not great, and I should have just included TokEof in the module, but you can derive the original information.
|
Note for printing purposes you will want to filter out:
|
|
I do need to print the comments on |
|
Oh, that's right. The reason is that the provided token printer will print |
dd223aa to
5ed2190
Compare
|
Allright, this seems to work on all the test files (apart from some unicode nonsense with Haskell on Windows in GHCI) |
|
Anything in particular you'd like me to test here? I could check round tripping for all the layout tests. |
|
The layout tests don't necessarily parse to a module, they only test the lexer. |
|
I feel like testing all passing source files is a little much, but maybe it's fast enough that it doesn't matter. |
|
Allright.... there's no good test body in |
|
Oh right, it's a separate module. I guess we could try it. If they all parse as a module, then that seems fine to me. |
|
FWIW all of After putting the following script into Script.hs in the project root it can be run with {-# language BlockArguments #-}
import Prelude
import Data.Foldable
import Language.PureScript.CST.Types as CST
import Language.PureScript.CST.Parser as CST
import Language.PureScript.CST.Print as CST
import Data.Text (Text)
import Data.Text.IO as Text
import System.Directory
import System.FilePath
readModule :: FilePath -> IO (Text, CST.Module ())
readModule path = do
contents <- Text.readFile path
let module_ = either (error . show) id (snd (CST.parse contents))
pure (contents, module_)
main :: IO ()
main = do
go "tests/purs/passing"
where
go :: FilePath -> IO ()
go dir = do
listDirectory dir >>= traverse_ \path ->
if isExtensionOf "purs" path then do
print path
(content, module_) <- readModule (dir </> path)
if content == CST.printModule module_ then pure () else error path
else if isExtensionOf "js" path then pure ()
else go (dir </> path)
|
|
@joneshf Now that we have the |
|
I'm sorry, I don't really understand the question. Could you rephrase it? |
|
The point of coming up with the separate version scheme for the sub-packages like purescript-cst was so we could release changes and improvements to them without having to make a compiler release. Now I'm wondering how to actually make that happen, because I'd like to use this change in an experiment of mine that doesn't depend on the whole compiler, but it doesn't seem like purescript-cst is published to Hackage. |
|
I'm asking you because I remember you lobbying strongly for it. If you don't know what the process is, no worries. |
|
We could make an initial release of The only potential awkwardness is that this release would include syntax for kind signatures and role declarations, but those don't yet exist in any released compiler version. I'm not sure that's necessarily such a problem that we should wait until 0.14.0 is out, though. |
|
Oh also, if you upload a release, could you please add the rest of us as maintainers? By default only the initial uploader will be permitted to upload subsequent versions. |
|
We should probably add instructions to the RELEASE_GUIDE.md file for making releases of the purescript-ast and purescript-cst libraries at some point, too. |
|
This is awesome! I was just going to ask about this in fp-chat if there was any plan to separate |
Got it, thanks for rephrasing! I would go with what @hdgarrood's laid out.
Nah, I'm pretty much indifferent to what the versioning scheme is. My only preference is that whatever the scheme is, it fosters iteration. We can change it to whatever works, for all that I care. |
Adds flatten functions for all constructions in the CST, that turn a module back into its individual tokens.
Still need to make sure this is proper bidirectional by running it over all our test files