Course of Raku / Regexes and grammars / Grammars / Creating grammars / Parsing with parse
Quiz — Creating grammars
What does the following program print?
grammar Word {
token TOP { \w+ }
}
say Word.parse('hello world').defined;| 0 | True |
| 1 | False |
| 0 | 「hello」 |
| 0 | Nil |
.parse succeeds only when the grammar matches the
whole string. \w+ matches
hello, but then a space and world are left
over, so the input is not fully consumed: .parse returns
Nil and .defined is False.