What does ~ mean inside grammar (in Perl 6)?

I found the tilde ~ in this Config :: INI Perl 6 Grammar :

 token header { ^^ \h* '[' ~ ']' $<text>=<-[ \] \n ]>+ \h* <.eol>+ } 

There are no tildes in the text I am processing ~ . I know that '[' ~ ']' is important, because the exclusion of any or all of '[' , ~ and ']' makes the grammar no longer relevant to my text.

Since I knew that the pattern was what I matched, I changed it so that the square brackets were around the text expression, like this:

 token header { ^^ \h* '[' $<text>=<-[ \] \n ]>+ ']' \h* <.eol>+ } 

So, it seems to me that the '[' ~ ']' really says that there is a square bracket, and after that a closing bracket is expected.

In any case, I know that the regular Perl 6 syntax uses the ~ tilde to concatenate strings. But this obviously means something else inside this grammar . (In Perl 6, you can use Grammars to extract complex data structures from text. They are like regular expressions taken to the next level.).

In any case, I was looking for documentation for Grammars and for Regular expressions for one ~ , but I did not find any inside the grammar or inside the regular expression.


intersection located at StackOverflow en español

+5
source share
1 answer

In the project documents you can find an explanation: https://github.com/perl6/roast/blob/master/S05-metachars/tilde.t#L6-L81

It basically does what you find: replaces the tilde with the expression that follows the right bracket, and searches for it between the characters of the bracket. However, it adds extra magic to help recognize the end bracket and provide a more useful error message if the end bracket is not found. Thus, you usually get the same results, doing it anyway, but not always.

+6
source

Source: https://habr.com/ru/post/1238002/


All Articles