Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Perlito5 - Perlito5::Grammar::Regex5 more details
  • Loading branch information
fglock committed Apr 18, 2014
1 parent f4c2b3e commit 3eecee9
Showing 1 changed file with 15 additions and 16 deletions.
31 changes: 15 additions & 16 deletions src5/lib/Perlito5/Grammar/Regex5.pm
Expand Up @@ -6,22 +6,13 @@ use warnings;

token any { . };

# TODO
token ws { '' };

# TODO
token string_code {
token string_of_code {
[ \\ .
| \{ <.string_code> \}
| <!before \} > .
]+
};

token parsed_code {
<.string_code>
{ $MATCH->{capture} = Perlito5::Match::flat($MATCH) }
};

token rule_term {
| '^' { $MATCH->{capture} = 'beginning_of_line' }
| '$' { $MATCH->{capture} = 'end_of_line' }
Expand All @@ -30,12 +21,20 @@ token rule_term {
| '(?'
[ ':' <rule> ')'
{ $MATCH->{capture} = Perlito5::Match::flat($MATCH->{rule}) }
| '=' <.ws> <rule> ')'
| '=' <rule> ')'
{ $MATCH->{capture} = Perlito5::Rul::Before->new( rule_exp => Perlito5::Match::flat($MATCH->{rule}) ) }
| '!' <.ws> <rule> ')'
| '!' <rule> ')'
{ $MATCH->{capture} = Perlito5::Rul::NotBefore->new( rule_exp => Perlito5::Match::flat($MATCH->{rule}) ) }
| '{' <parsed_code> '})'
{ $MATCH->{capture} = Perlito5::Rul::Block->new( closure => Perlito5::Match::flat($MATCH->{parsed_code}) ) }
| '>' <rule> ')'
{ $MATCH->{capture} = { 'possessive_quantifier' => Perlito5::Match::flat($MATCH->{rule}) } }
| '<' <Perlito5::Grammar.ident> '>' <rule> ')'
{ $MATCH->{capture} = { 'named_capture' => { name => Perlito5::Match::flat($MATCH->{'Perlito5::Grammar.ident'}),
term => Perlito5::Match::flat($MATCH->{rule}) } }
}
| '{' <string_of_code> '})'
{ $MATCH->{capture} = Perlito5::Rul::Block->new( closure => Perlito5::Match::flat($MATCH->{string_of_code}) ) }
| '#' [ <!before ')' > . ]* ')'
{ $MATCH->{capture} = 'comment' }
]

| '(' <rule> ')'
Expand Down Expand Up @@ -69,8 +68,8 @@ token quant_exp {
};

token quantifier {
<.ws>? <rule_term> <.ws>?
[ <quant_exp> <.ws>?
<rule_term>
[ <quant_exp>
{ $MATCH->{capture} = Perlito5::Rul::Quantifier->new(
term => Perlito5::Match::flat($MATCH->{rule_term}),
quant => Perlito5::Match::flat($MATCH->{quant_exp}),
Expand Down

0 comments on commit 3eecee9

Please sign in to comment.