Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Move reduction operation into Cursor.!matchify * Hold action method object as Cursor attribute * Create P6Regex grammar for parsing simple Perl 6 regexes * Initial <atom> subrule for P6Regex git-svn-id: https://svn.parrot.org/parrot/branches/pct-rx@41615 d31e2699-5ff4-0310-a27c-f18f2fbe73fe
- Loading branch information
pmichaud
committed
Oct 2, 2009
1 parent
f007d29
commit ad73cd2
Showing
4 changed files
with
102 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
# Copyright (C) 2009, Patrick R. Michaud | ||
# $Id$ | ||
|
||
=head1 NAME | ||
|
||
Regex::P6Regex - Parser/compiler for Perl 6 regexes | ||
|
||
=head1 DESCRIPTION | ||
|
||
=cut | ||
|
||
.namespace ['Regex';'P6Regex'] | ||
|
||
.include 'cclass.pasm' | ||
|
||
.sub '' :anon :load :init | ||
load_bytecode 'P6object.pbc' | ||
.local pmc p6meta | ||
p6meta = new 'P6metaclass' | ||
$P0 = p6meta.'new_class'('Regex::P6Regex', 'parent'=>'Regex::Cursor') | ||
.return () | ||
.end | ||
|
||
=head2 Methods | ||
|
||
=over 4 | ||
|
||
=item atom | ||
|
||
token atom { | ||
:dba('regex atom') | ||
[ | ||
| \w [\w+! <?before \w>] | ||
| <metachar> :: | ||
] | ||
} | ||
|
||
=cut | ||
|
||
.sub 'atom' :method | ||
.param pmc peek :named('peek') :optional | ||
|
||
if null peek goto peek_done | ||
.return () | ||
peek_done: | ||
|
||
.local pmc cur | ||
.local string target | ||
.local int pos, eos | ||
(cur, pos, target) = self.'!cursor_start'() | ||
eos = length target | ||
|
||
# \w [\w+! <?before \w>] | ||
.local int eow, len | ||
eow = find_not_cclass .CCLASS_WORD, target, pos, eos | ||
if eow == pos goto metachar | ||
.local int len | ||
len = eow - pos | ||
if len == 1 goto word_done | ||
dec eow | ||
word_done: | ||
cur.'!matchify'(eow, 'atom') | ||
.return (cur) | ||
|
||
metachar: | ||
.return (cur) | ||
.end | ||
|
||
=back | ||
|
||
=head1 AUTHORS | ||
|
||
Patrick Michaud <pmichaud@pobox.com> is the author and maintainer. | ||
|
||
=cut | ||
|
||
# Local Variables: | ||
# mode: pir | ||
# fill-column: 100 | ||
# End: | ||
# vim: expandtab shiftwidth=4 ft=pir: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters