This repository has been archived by the owner on Feb 3, 2021. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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
Showing
4 changed files
with
101 additions
and
1 deletion.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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: |
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,3 @@ | ||
class Regex::P6Grammar::Actions; | ||
|
||
|
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,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> \} | ||
} | ||
|