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

Multi-line comments on .pest grammar format #330

Closed
felix91gr opened this issue Nov 2, 2018 · 3 comments
Closed

Multi-line comments on .pest grammar format #330

felix91gr opened this issue Nov 2, 2018 · 3 comments

Comments

@felix91gr
Copy link
Contributor

Hi all,

I'm currently working on documenting the grammar of my language (an extension of Tiny-C) and the line comments are nice, but I'd like to be able to write multi-line comments for two reasons: format and ergonomics.

Format

Single-line comments tends towards this kind of formatting:

////////////////////////////////////////////////
//                   Terms                    //
////////////////////////////////////////////////

//  Terms are the smallest concept in this grammar.
//  A term can either be:
//   - An expression (nested between two parenthesis)
//   - An integer literal
//   - A variable's id

//  Terms can be evaluated to have a value. In the 
//  case of the "expression" kind of Term, their
//  value is propagated to the left like this:
//   "a = 5"          // Value is 5
//   "1 < 2"          // Value is 1
//   "1 - (2 < 3)"    // Value is 0

Whereas with multi-line comments it would look like this:

////////////////////////////////////////////////
//                   Terms                    //
////////////////////////////////////////////////

/*
  Terms are the smallest concept in this grammar.
  A term can either be:
   - An expression (nested between two parenthesis)
   - An integer literal
   - A variable's id

  Terms can be evaluated to have a value. In the 
  case of the "expression" kind of Term, their
  value is propagated to the left like this:
   "a = 5"          // Value is 5
   "1 < 2"          // Value is 1
   "1 - (2 < 3)"    // Value is 0
*/

Multi-line comments are usually easier to read and feel less cluttered.

Ergonomics

With single-line comments you have to manually start a comment every time you want to write another line, which isn't as good as it could be in the ergonomic sense.

Editing is also easier with multi-line comments: the two slashes (//) that you would otherwise have to manually edit alongside your text aren't there anymore. This makes documenting the grammar inside its own file that much easier.


Anyway, I might be completely wrong here. I've only been using Pest for like 3-4 weeks. But I'd love to have multi-line comments inside the grammar files.

If you agree with me, I'll happily make the PR. What file should I edit? I get the feeling that I should add the multi-line option here.

Have a good weekend 🙂

@dragostis
Copy link
Contributor

Thanks for writing this out. 😃 I'm generally in favor of this change. Keeping this similar to Rust is a good trend and I guess it should be as easy as possible to change from Rust to pest and back. Would you like to give this a try?

@felix91gr
Copy link
Contributor Author

Sure! I'll make a couple test cases as well and issue a PR :)

bors bot added a commit that referenced this issue Nov 6, 2018
332: [WIP] Add multiline comments to Pest's PEG format r=dragostis a=felix91gr

Implementation of #330. At least, that's what I think.

Probably needs tests. How do I make one, or update the existing ones?

And how can I test it manually?

Thanks <3

Co-authored-by: Félix Fischer <[email protected]>
Co-authored-by: Félix Fischer <[email protected]>
@felix91gr
Copy link
Contributor Author

Solved by #332

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

No branches or pull requests

2 participants