[svn:parrot] r44709 - branches/ops_pct/compilers/opsc/src/Ops
cotto at svn.parrot.org
cotto at svn.parrot.org
Sat Mar 6 22:05:38 UTC 2010
Author: cotto
Date: Sat Mar 6 22:05:26 2010
New Revision: 44709
URL: https://trac.parrot.org/parrot/changeset/44709
Log:
[opsc] break up new, allow initialization from a string via new_str
Modified:
branches/ops_pct/compilers/opsc/src/Ops/File.pm
Modified: branches/ops_pct/compilers/opsc/src/Ops/File.pm
==============================================================================
--- branches/ops_pct/compilers/opsc/src/Ops/File.pm Sat Mar 6 18:53:43 2010 (r44708)
+++ branches/ops_pct/compilers/opsc/src/Ops/File.pm Sat Mar 6 22:05:26 2010 (r44709)
@@ -176,6 +176,11 @@
Returns a new instance initialized by calling C<read_ops()> on each of
the specified op files.
+=item C<new_str($str)>
+
+Returns a new instance initialized by compiling C<$str> as the contents of an
+ops file.
+
=end
method new(*@files, :$nolines) {
@@ -190,6 +195,18 @@
self;
}
+method new_str($str) {
+ self<ops> := list(); # Ops
+ self<preamble>:= '';
+
+ self._set_version();
+
+ self.compile_ops($str);
+
+ self;
+}
+
+
=begin
=back
@@ -205,11 +222,15 @@
=end
method read_ops($file, $nolines) {
- my $compiler := pir::compreg__Ps('Ops');
say("# Parsing $file");
my $buffer := slurp($file);
- my $past := $compiler.compile($buffer, :target('past'));
+ compile_ops($buffer);
+}
+
+method compile_ops($str) {
+ my $compiler := pir::compreg__Ps('Ops');
+ my $past := $compiler.compile($str, :target('past'));
for @($past<ops>) {
self<ops>.push($_);
@@ -218,8 +239,10 @@
for @( $past<preamble> ) {
self<preamble> := self<preamble> ~ $_;
}
+ $past;
}
+
method preamble() { self<preamble> };
method ops() { self<ops> };
More information about the parrot-commits
mailing list