Raku / Raku/doc

Grammar tutorial should clarify what "ignore whitespace" means

Open
#3,985 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

docs
Dominant language
Raku
Stars
308
Forks
288
Avg merge
3d 49m
Merged PRs (30d)
2

Description

Problem or new feature

https://docs.raku.org/language/grammar_tutorial describes regex, token, and rule as follows:

  • Regex methods are slow but thorough, they will look back in the string and really try.
  • Token methods are faster than regex methods and ignore whitespace. Token methods don't backtrack; they give up after the first possible match.
  • Rule methods are the same as token methods except whitespace is not ignored.

It's not clear to me what "Token methods... ignore whitespace" means, and in what way tokens ignore whitespace while rules do not. For example,

'foo' ~~ token { 'f' 'o'+ }  # OUTPUT: 「foo」
'f oo' ~~ token { 'f' 'o'+ }  # OUTPUT: Nil
'foo' ~~ rule { 'f' 'o'+ }  # Nil
'f oo' ~~ rule { 'f' 'o'+ }  # OUTPUT: 「f oo」
'foo' ~~ rule { 'f' 'o'+ }  # Nil
'fo o' ~~ rule { 'f' 'o'+ }  # Nil
'f   o o' ~~ rule { 'f' 'o'+ }  # 「f   o 」

This suggests that tokens do not ignore whitespace; any whitespace between the component parts of a token prevents the token from matching. And in this example, whitespace seems to be mandatory, in that 'foo' doesn't match the rule "f followed by one or more o". (I think the latter is because the default ws token is <!ww> \s* which doesn't match between f and o.)

Suggestions

The "ignore" verb in this context is ambiguous: I think the documentation is saying that whitespace inside the body of the token definition doesn't have any effect. But the first few times I read that section, I thought it was saying that token methods will ignore whitespace inside the string being matched.

One way to clarify this would be something like:

  • Regex methods are slow and ... really try. Whitespace inside the token method body has no effect.
  • Token methods are faster than regex methods. Token methods ... match. Whitespace inside the token method body has no effect.
  • Rule methods behave like token methods, except each run of whitespace in the body matches a word boundary and any amount of whitespace.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Open the grammar tutorial at https://docs.raku.org/language/grammar_tutorial and review the descriptions of regex, token, and rule methods alongside the examples in the issue. Clarify what whitespace in a token or rule body does, and consider the suggested wording; done means the documentation no longer implies that tokens ignore whitespace in the input string.

Written by the indexing model from the issue text.

Assessment

Domain
documentation
Issue type
Documentation
Difficulty
1/5
Estimated time
Under an hour
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.