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

Document /<foo ...>/ syntax somewhere #1858

Open
zoffixznet opened this issue Mar 20, 2018 · 8 comments
Open

Document /<foo ...>/ syntax somewhere #1858

zoffixznet opened this issue Mar 20, 2018 · 8 comments
Labels
docs Documentation issue (primary issue type) new part of "docs" - indicates that this documentation is for a new, currently undoc'd section

Comments

@zoffixznet
Copy link
Contributor

It's a special syntax that lets users write stuff like their own versions of stuff like <before ...>. (description copied from rakudo/rakudo#1634 (comment))

[…] it is the syntax that lets us parse <before abc> and similar. Unlike with <foo: ...> and <foo(...)>, where the args are parsed by the MAIN language, the <foo ...> form parses the rest of the assertion using the regex language, wraps it in a closure, and passes it to foo. Thus it's a general syntax for higher-order regex operators - which is just what before/after are.

I guess maybe somewhere in the "advanced" section or grammars is a good place to put this. Just to separate it from all the common syntax novice users might be reading through.

@zoffixznet zoffixznet added docs Documentation issue (primary issue type) LHF new part of "docs" - indicates that this documentation is for a new, currently undoc'd section labels Mar 20, 2018
@JJ
Copy link
Contributor

JJ commented Mar 20, 2018

Grammars or regexes?

@zoffixznet
Copy link
Contributor Author

🤷‍♀️

@coke coke added good first issue If you want to dive in, this would be a good place to start and removed LHF labels Apr 9, 2018
@mryan mryan self-assigned this May 5, 2018
@mryan
Copy link
Contributor

mryan commented May 6, 2018

OK. Had a look at this on and off during the day. A few preliminary points (as I see it - correct where necessary):

  • Using this feature, , requires the user to define a method in the grammar that will receive a compiled regex as it's only argument.
  • You can't do anything with that regex other than run it "against" a cursor object
  • A method in a grammar must return a cursor to its caller
  • Looking at all the existing documentation, I can't see a case where a method is declared in a grammar which (necessarily) returns a cursor with one exception here: https://docs.perl6.org/language/grammars#Methods_in_Grammar
    That example is a very specific case in that the method is TOP and hence it's called first thing which means that any regex/token/rule in the grammar can be returned as the "cursor that must be returned" because the "slate is clean" so to speak. [I wish I could explain this better but I cant :-)]
  • Looking at the cases where this feature is used in the existing language ( <before ...> and <after ...> , you can see the call to '!cursor_start_cur' and the work to populate the new cursor before running the regex against it passing it as a return value - what I'm getting at is I can't see a way to make this available to users without dragging them into the a lot of detail about cursor creation and management.
  • despite that, I did make some head way with creating an example, <SOLscan ...> (Start-of-line scan) which will look at the current line being passed for the regex supplied but the use case is complicated and contrived and requires explaining a fair bit of the internal regex-parsing/cursor details.

So, before I go further, I need to know if

  • there's a whole heap of stuff I'm not getting; and

  • if I'm reasonably on track, do we want to expose some of the cursor management details to end users so they can build there own meta parsing rules with this feature; or

  • "take away" this feature. i.e. make it an "internals only" type thing; or

  • leave things as is - its exposed for you to use if you can, but there's no documentation on it.

None of these options look all that good to me. I need some advice.
Lastly, either this isn't really a "good first issue" or I've got a lot to learn...

@mryan mryan removed their assignment May 6, 2018
@JJ
Copy link
Contributor

JJ commented May 6, 2018

You look reasonably on track, but you probably need to show your examples to see how it goes. You can't take away this feature; if it's internal, it should not be documented, but if it's not...

@JJ JJ removed the good first issue If you want to dive in, this would be a good place to start label May 6, 2018
@JJ
Copy link
Contributor

JJ commented May 6, 2018

Gist documented what's been done so far here: https://gist.github.com/mryan/dc8c890de862876abc4f87f55d974070
Thanks @mryan

@AlexDaniel
Copy link
Member

AlexDaniel commented May 6, 2018

This looks extremely useful, I'm +1 for adding it. Generally, we should first look if there are any tests in roast for it. If there are, then we document it right away. If not, then we don't…

If there are no tests for it right now, maybe add some? I'm not sure which part of it exactly is implementation-specific…

@mryan
Copy link
Contributor

mryan commented May 7, 2018

I've posted a question to stack overflow asking how to use this feature. Need to see how it's used before being able to document how it's used.
https://stackoverflow.com/questions/50210456/how-can-i-use-the-perl6-regex-metasyntax-foo-regex

@JJ
Copy link
Contributor

JJ commented Jul 21, 2019

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
docs Documentation issue (primary issue type) new part of "docs" - indicates that this documentation is for a new, currently undoc'd section
Projects
None yet
Development

No branches or pull requests

5 participants