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

Commit

Permalink
Browse files Browse the repository at this point in the history
Add Regex::P6Grammar as temporary scaffolding for bootstrapping the p…
…arser.
  • Loading branch information
pmichaud committed Oct 15, 2009
1 parent a3bc5aa commit c5a7893
Show file tree
Hide file tree
Showing 4 changed files with 101 additions and 1 deletion.
25 changes: 24 additions & 1 deletion build/Makefile.in
Expand Up @@ -44,6 +44,12 @@ CLEANUPS = \
p6regex.pbc \
src/gen/*.pir \

P6GRAMMAR_SOURCES = \
src/Regex/P6Grammar.pir \
src/Regex/P6Grammar/Grammar.pm \
src/Regex/P6Grammar/Actions.pm \
src/gen/p6grammar-grammar.pir \
src/gen/p6grammar-actions.pir \

P6REGEX_SOURCES = \
src/Regex/P6Regex.pir \
Expand All @@ -59,7 +65,24 @@ P6REGEX_SOURCES = \
src/Regex/Match.pir \
src/Regex/Dumper.pir \

all: p6regex$(EXE)
all: p6regex$(EXE) p6grammar$(EXE)



p6grammar$(EXE): p6grammar.pbc
$(PBC_TO_EXE) p6grammar.pbc

p6grammar.pbc: p6regex.pbc $(P6GRAMMAR_SOURCES)
$(PARROT) -o p6grammar.pbc src/Regex/P6Grammar.pir

src/gen/p6grammar-grammar.pir: $(PARROT) $(PERL6GRAMMAR_PBC) src/Regex/P6Grammar/Grammar.pm
$(PARROT) $(PARROT_ARGS) $(PERL6GRAMMAR_PBC) \
--output=src/gen/p6grammar-grammar.pir --encoding=utf8 \
src/Regex/P6Grammar/Grammar.pm

src/gen/p6grammar-actions.pir: $(NQP) src/Regex/P6Grammar/Actions.pm
$(NQP) --target=pir --output=src/gen/p6grammar-actions.pir \
--encoding=fixed_8 src/Regex/P6Grammar/Actions.pm

p6regex$(EXE): p6regex.pbc
$(PBC_TO_EXE) p6regex.pbc
Expand Down
52 changes: 52 additions & 0 deletions src/Regex/P6Grammar.pir
@@ -0,0 +1,52 @@
# Copyright (C) 2009, Patrick R. Michaud
# $Id$

=head1 NAME

Regex::P6Grammar - scaffolding compiler for NQP / Perl 6 grammars

=head1 DESCRIPTION

=cut

.namespace ['Regex';'P6Grammar';'Compiler']

.sub '' :anon :load :init
load_bytecode 'PCT.pbc'
load_bytecode 'p6regex.pbc'
.local pmc p6meta, p6grammar
p6meta = get_hll_global 'P6metaclass'
p6grammar = p6meta.'new_class'('Regex::P6Grammar', 'parent'=>'PCT::HLLCompiler')
p6grammar.'language'('Regex::P6Grammar')
$P0 = get_hll_namespace ['Regex';'P6Grammar';'Grammar']
p6grammar.'parsegrammar'($P0)
$P0 = get_hll_namespace ['Regex';'P6Grammar';'Actions']
p6grammar.'parseactions'($P0)
.end
.sub 'main' :main
.param pmc args_str
$P0 = compreg 'Regex::P6Grammar'
$P1 = $P0.'command_line'(args_str, 'encoding'=>'utf8', 'transcode'=>'ascii iso-8859-1')
exit 0
.end
.include 'src/gen/p6grammar-grammar.pir'
.include 'src/gen/p6grammar-actions.pir'
.sub '' :anon :load :init
.local pmc p6grammar
p6grammar = get_hll_global ['Regex';'P6Grammar'], 'Grammar'
$P0 = get_hll_global ['PGE';'Perl6Regex'], 'regex'
$P1 = get_class ['Regex';'P6Grammar';'Grammar']
$P1.'add_method'('regex', $P0)
.end
=cut
# Local Variables:
# mode: pir
# fill-column: 100
# End:
# vim: expandtab shiftwidth=4 ft=pir:
3 changes: 3 additions & 0 deletions src/Regex/P6Grammar/Actions.pm
@@ -0,0 +1,3 @@
class Regex::P6Grammar::Actions;


22 changes: 22 additions & 0 deletions src/Regex/P6Grammar/Grammar.pm
@@ -0,0 +1,22 @@
grammar Regex::P6Grammar::Grammar is Regex::P6Regex::Grammar;

token TOP {
<grammar_stmt>
<regex_stmt>*
$
}

token name { <.ident> ** [\:\:] }

token arg {
| <.ident> [ \: sym \< <-[>]>*: \> ]?
}

rule grammar_stmt { grammar <name> [ is <base=name> ]? \; }

rule regex_stmt {
$<sym>=[regex|token|rule]
<name=arg>
\{ <nibbler> \}
}

0 comments on commit c5a7893

Please sign in to comment.