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

Commit

Permalink
Switch P6Regex to use protoobjects for parsegrammar and parseactions.
Browse files Browse the repository at this point in the history
PCT should do this by default, but doesn't (and it's a pain to patch
it right now).
  • Loading branch information
pmichaud committed Oct 17, 2009
1 parent e335cf9 commit 88f1d40
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/Regex/P6Regex.pir
Expand Up @@ -33,9 +33,9 @@ Regex::P6Regex - Parser/compiler for Perl 6 regexes
p6meta = get_hll_global 'P6metaclass'
p6regex = p6meta.'new_class'('Regex::P6Regex::Compiler', 'parent'=>'HLL::Compiler')
p6regex.'language'('Regex::P6Regex')
$P0 = get_hll_namespace ['Regex';'P6Regex';'Grammar']
$P0 = get_hll_global ['Regex';'P6Regex'], 'Grammar'
p6regex.'parsegrammar'($P0)
$P0 = get_hll_namespace ['Regex';'P6Regex';'Actions']
$P0 = get_hll_global ['Regex';'P6Regex'], 'Actions'
p6regex.'parseactions'($P0)
.end
Expand Down
50 changes: 50 additions & 0 deletions src/cheats/hll-compiler.pir
@@ -0,0 +1,50 @@
# we have to overload PCT::HLLCompiler's parse method to support P6Regex grammars


.namespace ['HLL';'Compiler']

.sub '' :anon :init :load
load_bytecode 'PCT.pbc'
.local pmc p6meta
p6meta = get_hll_global 'P6metaclass'
p6meta.'new_class'('HLL::Compiler', 'parent'=>'PCT::HLLCompiler')
.end
.sub 'parse' :method
.param pmc source
.param pmc options :slurpy :named
.local pmc parsegrammar, parseactions, match
parsegrammar = self.'parsegrammar'()
parseactions = self.'parseactions'()
$I0 = isa parsegrammar, ['Regex';'Cursor']
unless $I0 goto parse_old
match = parsegrammar.'parse'(source, 'from'=>0, 'action'=>parseactions)
unless match goto err_parsefail
.return (match)
err_parsefail:
self.'panic'('Unable to parse source')
.return (match)
parse_old:
$I0 = isa parsegrammar, ['NameSpace']
if $I0 goto parse_old_1
## switch from protoobjects to classes, then call parent
$P0 = parsegrammar.'HOW'()
$P0 = getattribute $P0, 'parrotclass'
parsegrammar = $P0.'get_namespace'()
self.'parsegrammar'(parsegrammar)
$P0 = parseactions.'HOW'()
$P0 = getattribute $P0, 'parrotclass'
parseactions = $P0.'get_namespace'()
self.'parseactions'(parseactions)
parse_old_1:
$P0 = get_hll_global ['PCT'], 'HLLCompiler'
$P1 = find_method $P0, 'parse'
.tailcall self.$P1(source, options :flat :named)
.end

0 comments on commit 88f1d40

Please sign in to comment.