Skip to content
This repository has been archived by the owner on Feb 3, 2021. It is now read-only.

Commit

Permalink
Add parsing of some basic assertions.
Browse files Browse the repository at this point in the history
  • Loading branch information
pmichaud committed Oct 9, 2009
1 parent ff8603b commit a17b445
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 1 deletion.
23 changes: 22 additions & 1 deletion src/Regex/P6Regex/Grammar.pm
Expand Up @@ -53,9 +53,13 @@ grammar Regex::P6Regex::Grammar is PCT::Grammar;
token metachar:sym<^^> { $<sym>:=['^^'] {*} }
token metachar:sym<$> { $<sym>:=['$'] {*} }
token metachar:sym<$$> { $<sym>:=['$$'] {*} }
token metachar:sym<bs> { \\ <backslash> {*} }
token metachar:sym<lwb> { $<sym>:=['<<'|'«'] {*} }
token metachar:sym<rwb> { $<sym>:=['>>'|'»'] {*} }
token metachar:sym<bs> { \\ <backslash> {*} }
token metachar:sym<assert> {
'<' <assertion>
[ '>' || <.panic: "regex assertion not terminated by angle bracket"> ]
}

# proto token backslash { <...> }
token backslash:sym<w> { $<sym>:=[<[dswnDSWN]>] {*} }
Expand All @@ -66,3 +70,20 @@ grammar Regex::P6Regex::Grammar is PCT::Grammar;
token backslash:sym<Q> { 'Q' <.obs: '\\Q as quotemeta;quotes or literal variable match'> }
token backslash:sym<misc> { \W {*} }

# proto token assertion { <...> }

token assertion:sym<?> { '?' [ <?before '>' > | <assertion> ] }
token assertion:sym<!> { '!' [ <?before '>' > | <assertion> ] }

token assertion:sym<method> {
'.' <assertion>
}

token assertion:sym<name> {
$<longname>=[\w+]
[
| <?before '>'>
| '=' <assertion>
]?
{*}
}
6 changes: 6 additions & 0 deletions src/parrot/p6regex-grammar.pir
Expand Up @@ -18,6 +18,12 @@
.tailcall self.'!protoregex'('backslash', 'action'=>action)
.end

.sub 'assertion' :method
.param pmc action :named('action') :optional
.param pmc dba :named('dba') :optional
.tailcall self.'!protoregex'('assertion', 'action'=>action)
.end

.sub 'obs' :method
.param string oldstr
.param pmc action :named('action') :optional
Expand Down

0 comments on commit a17b445

Please sign in to comment.