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

New parsing code #572

Open
wants to merge 2 commits into
base: master
from

Conversation

Projects
None yet
5 participants
@spinda
Copy link
Member

spinda commented Jan 13, 2016

Please don't merge this - I'm still working on it. I'm creating this PR now just to track progress.

Outline:

  • Language.Haskell.Liquid.Parse2 - New parser based on the code I developed in GSoC '15, adapted for the current state of the codebase.
  • Language.Haskell.Liquid.Unparse - Pretty-printer exclusively for generating formatted code from AST. Should be the inverse of Parse2's parser, in that the output AST of parse ∘ unparse ∘ parse should be semantically equivalent to the input AST. Featuring colored output (via ansi-wl-pprint) for prettier user messages.
@ranjitjhala

This comment has been minimized.

Copy link
Member

ranjitjhala commented Jan 13, 2016

Nice! I've been wanting the colored output. However note that that stuff was also added to HughesPJ per a GitHub comment I saw...

On Jan 12, 2016, at 6:50 PM, Michael Smith notifications@github.com wrote:

Please don't merge this - I'm still working on it. I'm creating this PR now just to track progress.

Outline:

Language.Haskell.Liquid.Parse2 - New parser based on the code I developed in GSoC '15, adapted for the current state of the codebase.
Language.Haskell.Liquid.Unparse - Pretty-printer exclusively for generating formatted code from AST. Should be the inverse of Parse2's parser, in that the output AST of parse ∘ unparse ∘ parse should be semantically equivalent to the input AST. Featuring colored output (via ansi-wl-pprint) for prettier user messages.
You can view, comment on, or merge this pull request online at:

#572

Commit Summary

Start on new parsing/unparsing code
File Changes

M liquidhaskell.cabal (13)
A src/Language/Haskell/Liquid/Parse2.hs (12)
A src/Language/Haskell/Liquid/Parse2/Base.hs (8)
A src/Language/Haskell/Liquid/Parse2/Declarations.hs (8)
A src/Language/Haskell/Liquid/Parse2/Refinements.hs (8)
A src/Language/Haskell/Liquid/Parse2/Types.hs (8)
A src/Language/Haskell/Liquid/Unparse.hs (10)
A src/Language/Haskell/Liquid/Unparse/Base.hs (171)
A src/Language/Haskell/Liquid/Unparse/Fixpoint.hs (82)
A src/Language/Haskell/Liquid/Unparse/LH.hs (15)
M stack.yaml (2)
Patch Links:

https://github.com/ucsd-progsys/liquidhaskell/pull/572.patch
https://github.com/ucsd-progsys/liquidhaskell/pull/572.diff

Reply to this email directly or view it on GitHub.

@gridaphobe

This comment has been minimized.

Copy link
Contributor

gridaphobe commented Jan 13, 2016

Very excited about the new parser! But can we please not call the printer unparse? :D

@spinda

This comment has been minimized.

Copy link
Member Author

spinda commented Jan 13, 2016

@ranjitjhala - Oh, cool! I guess that's what Text.PrettyPrint.Annotated.HughesPJ is. It looks like it allows you to attach arbitrary metadata (i.e. colors) to Docs and then convert them into Strings during renderDecorated. Do you know if there's already a package implementing color codes on top of this system? Otherwise I can implement them myself.

@gridaphobe - Sure, I had a hard time coming up with what to call it and am not attached at all to Unparse. Any suggestions?

@gridaphobe

This comment has been minimized.

Copy link
Contributor

gridaphobe commented Jan 13, 2016

I guess that's what Text.PrettyPrint.Annotated.HughesPJ is. It looks like it allows you to attach arbitrary metadata (i.e. colors) to Docs and then convert them into Strings during renderDecorated.

Yes, also common are type annotations and other useful metadata. Idris does a ton of neat things with the annotated printers.

Any suggestions?

Pretty or PrettyPrint! GHC uses Outputable which is not bad either.

@ranjitjhala

This comment has been minimized.

Copy link
Member

ranjitjhala commented Jan 13, 2016

We cannot use a GHC dependency on liquid-fixpoint.

Is "Outputable" a package? It was part of GHC last I checked...

I think @spinda wants to know if there are any libraries for implementing
color.

Short answer: I don't know, there is the ansi-terminal but perhaps it would
be
best to see the docs for Annotate.HughesPJ? We could switch to
ansi-wl-pprint too
(but that may cause changes all across LH, but probably easy to fix...)

On Tue, Jan 12, 2016 at 8:46 PM, Eric Seidel notifications@github.com
wrote:

I guess that's what Text.PrettyPrint.Annotated.HughesPJ is. It looks like
it allows you to attach arbitrary metadata (i.e. colors) to Docs and then
convert them into Strings during renderDecorated.

Yes, also common are type annotations and other useful metadata. Idris
does a ton of neat things with the annotated printers.

Any suggestions?

Pretty or PrettyPrint! GHC uses Outputable which is not bad either.


Reply to this email directly or view it on GitHub
#572 (comment)
.

@spinda

This comment has been minimized.

Copy link
Member Author

spinda commented Jan 13, 2016

I'm pretty sure @gridaphobe meant that Outputable is an example of a name we could use for this typeclass, instead of Unparse. Which would work, but since we're also using the GHC API we would run into issues with naming clashes. I didn't want to call it PrettyPrint because we already have PPrint which isn't necessarily an inverse of the parser and is used for other things besides source printing.

I was asking if there were any pre-made libraries out there that use Annotate.HughesPJ annotations to implement color code annotations (like Red, Green, etc). It doesn't look like there are any at the moment, so I'll use ansi-terminal and write something LiquidHaskell-specific for that. Something like:

data TokenType = Keyword | Symbol | Literal

which will be converted to color codes in the render step. At the moment I have blue for keywords (like not, int, real...), yellow for symbols (parentheses, brackets, commas...), and green for literals (ints, floats, string literals...).

@gridaphobe

This comment has been minimized.

Copy link
Contributor

gridaphobe commented Jan 13, 2016

Yes I was just referring to Outputable as an example name.

I didn't want to call it PrettyPrint because we already have PPrint which isn't necessarily an inverse of the parser and is used for other things besides source printing.

Ah, I thought that Unparse was meant to replace PPrint. I would just fix the PPrint instances then, they should be inverses of Parse. That we also PPrint some things that we don't parse is irrelevant IMO.

@spinda

This comment has been minimized.

Copy link
Member Author

spinda commented Jan 13, 2016

Okay. I'll call it PPrint2 for now (while I'm working on it) to match Parse2.

@chrisdone

This comment has been minimized.

Copy link
Contributor

chrisdone commented Mar 14, 2017

@spinda what's the status on this? I wouldn't go as far to say Liquid Haskell is unusable at this point, but I can't seem to write anything without hitting Leftover while parsing. It's been one year so far, did you make any progress?

@alanz

This comment has been minimized.

Copy link
Contributor

alanz commented Mar 16, 2017

Question: If I want to look at reworking the parser, should I start here, or from the current develop branch?

@ranjitjhala

This comment has been minimized.

Copy link
Member

ranjitjhala commented Mar 16, 2017

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment