Skip to content
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

[#6] Add a switch for allowing comments #16

Open
wants to merge 8 commits into
base: master
Choose a base branch
from

Conversation

nalkuatov
Copy link

@nalkuatov nalkuatov commented Jun 10, 2022

This implements a switch to allow having comments

Description

Related issue(s)

Resolves #6

✅ Checklist for your Pull Request

Related changes (conditional)

  • Tests

    • If I added new functionality, I added tests covering it.
    • If I fixed a bug, I added a regression test to prevent the bug from
      silently reappearing again.
  • Documentation

  • Public contracts

    • Any modifications of public contracts comply with the Evolution
      of Public Contracts
      policy.
    • I added an entry to the changelog if my changes are visible to the users
      and
    • provided a migration guide for breaking changes if possible

Stylistic guide (mandatory)

@Martoon-00
Copy link
Member

Martoon-00 commented Jun 14, 2022

Good, I see you are delving into the project quite well.

One thing to note: to me it seems like we could handle comments skipping at parsing stage directly, this should be simpler. It is fine to pass commenting switch to intPieceP parser, it just happened that no switches managed parser behaviour till now.

@nalkuatov nalkuatov force-pushed the nalkuatov/#6-allow-comments branch from 9a1614f to 3e2d1e1 Compare June 15, 2022 12:52
@Martoon-00
Copy link
Member

You probably was thinking about whether to add this too: I would also skip {- ... -} comments, just as in Haskell.

@Martoon-00
Copy link
Member

Functionally this looks great 👍

Now you also need to update documentation. I would include the new switch description in Tutorial.hs into the list of switches.

Plus, in Switches interaction it would be nice to mention that comments are not visible by other switches, e.g.

txt = [int||
  My text
// comment
  other text
  |]

would have ... result. And if we guarantee that in docs, we will also need a test on such case.

@@ -223,6 +223,10 @@ The quoter will return concrete t'Builder'.

The quoter will return any type with t'FromBuilder' instance.

==== c ([c]omments handling)

Ignore line comments starting with @--@ and/or block comments enclosed in @{- ... -}@.
Copy link
Member

Choose a reason for hiding this comment

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

I would use some different wording, as "ignore" may mean "ignore it in processing, do not treat it in a special way" and so "leave it intact".

Copy link
Author

@nalkuatov nalkuatov Jun 29, 2022

Choose a reason for hiding this comment

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

Sure, I've decided to go for Handle comments and providing some clarifying examples. Hope it makes more sense now :)

BTW I've moved the lines upwards a little, now the section's before the ones about the return types.

Copy link
Member

Choose a reason for hiding this comment

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

Oh that's actually good that you moved this section above, right.

full/src/Text/Interpolation/Nyan/Tutorial.hs Outdated Show resolved Hide resolved
@Martoon-00
Copy link
Member

We are approaching the perfect solution, should be mostly it.

One probably last concern that I have: the examples you provided in documentation make it fully evident that currently block comments handling has inconvenient spacing. Writing My {- comment -} text produces two spaces in between the text, and getting one space requires putting text glued with the comment from one side.

Let's make block comments ignore the space before them, if any? "Before" to make trailing block comments handled well too.

@nalkuatov nalkuatov force-pushed the nalkuatov/#6-allow-comments branch from 4ae43ac to fc4c8d2 Compare June 30, 2022 11:42
@nalkuatov
Copy link
Author

In this case, as far as I can see the comment does not affect the indentation just because it is already aligned with the other text, comments enabling would not change the result in this regard?

Oh, right. That test actually didn't contain the evidence, sorry

skipBlockComment' = asum
[ skipBlockComment "{-" "-}"
, try $ spaceChar *> skipBlockComment "{-" "-}"
]
Copy link
Member

Choose a reason for hiding this comment

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

I would rather write the clause with space removal as an extension of the "fast spacing" section above - to avoid extra rollbacks.

Generally, I find this approach good, you got the code grouped by the logic it is related to. But in our case performance matters (as we write a library), and the grammar is quite small, so we can afford some complication.

Copy link
Author

Choose a reason for hiding this comment

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

But in our case performance matters

Yup, totally agree

comments in the middle -}
The end
|] @?= "The beginning\nThe end\n"
]
Copy link
Member

Choose a reason for hiding this comment

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

I would also like tests on:

  1. Unusual space - e.g. tab;
  2. On several spaces before comment.

Behaviour in such cases should be fixed.

And documented (no need to mention edge cases, just write the rule in one-two sentences so that it is unambiguous in regard to these edge cases).

Copy link
Author

Choose a reason for hiding this comment

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

Behaviour in such cases should be fixed.

"My text (4 spaces) { - comments -} " -> do you mean that, in this case, the result should be "My text "? Do several spaces should get truncated to a single one?

And, aside from that, please consider this one:

{int|tc|
      My text
  -- comments
      end
|]

results in " My text\n\n end" - the indentation becomes two spaces, since the line comment has two leading empty spaces. Intuitively, one might expect the indentation to be totally stripped, and since we now support extra spaces removal for block comments, shouldn't we handle this case too?

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.

Add a switch for allowing comments
2 participants