-
Notifications
You must be signed in to change notification settings - Fork 52
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
Fix pretty-printing of infix operators #8
Comments
Hi, I took a look at what this would look like and from what I found:
Can any other |
Hi, thanks for taking a look at this! You're absolutely right that the pretty printer would need a special case for nested I think I see three levels for a solution here, ranging from the simplest thing that will work and enable #7 , up to the one that will be the most work but will be the best long-term solution. It is totally up to you what approach you want to take here --- e.g. you could just implement the simplest fix for now and spin off other issue(s) to tackle later, or you could just go straight for the more principled approach that is more work. Level 1We can add a function Level 2To correctly handle precedence, we need to make another function Level 3A bigger problem is that now a lot of information about constants is fragmented around the codebase: the A much better way is to define a data type to represent all the information about a constant, and a single function to output this information for each constant, something like data ConstInfo = ConstInfo
{ syntax :: Text
, arity :: Int
, isCmd :: Bool
, isInfix :: Bool
, precedence :: Int
}
constInfo :: Const -> ConstInfo
constInfo = \case
Wait -> ConstInfo "wait" 0 True False 0
...
Arith Add -> ConstInfo "+" 2 False True 6
... This will replace the |
Hi @xsebek , are you thinking of working on this (or are you already)? I'm kind of itching to implement the "Level 3" thing in my comment above, because I'm getting very annoyed having to edit like 7 or 8 files every time I add a single command. But if you're already working on any of this I don't want to step on your toes, and there are plenty of other things I can work on. |
- moves info about constants to `Syntax.hs` - adds `infoConst`&friends functions on `Const` - lot of noise - needs to be simplified - changes the pretty-printing logic for `Term` application - creates parsers for `Const` automatically - ~~adds a heavy dependency to get [something like `Enum`](https://hackage.haskell.org/package/finitary)~~ Closes #8: - #8
Infix operators do not print correctly at the moment; they print as if they were prefix operations, like
+ 2 3
.Fixing this will be critical to being able to round-trip pretty-printing and parsing, which in turn is needed to be able to support #7 .
The text was updated successfully, but these errors were encountered: