On Fri, 4 Jun 2010, Stefan O'Rear wrote:

On Sat, Jun 05, 2010 at 09:19:01AM +1000, Timothy S. Nelson wrote:
        Hi.  I've been thinking more about reversible grammars.  Specifically,
I'm wondering if the following pseudo-code will be possible:

## Match a grammar here
$match = Grammar.match($text)
## Need some code here to get $submatch from $match
....
$submatch.Str = "fred"
## Reverse Grammar
$text = Grammar.reverse($match)

        My idea is that I could read in a file, find the part I wanted in the
match tree, change that part, and then write it back to the file.  Is
that going to be a possibility?

Look at emit_p5 in viv, where we do basically exactly that (but combined with
a recursive traversal).

Thanks. What I guess I'm really asking is, can we add an "emit" method to the Match object in the P6 spec? Usually I just be bold and add things, but I thought people might want to discuss this one first :).

        Also, while I was trying to investigate this, I was wondering about
S32/Rules.  I've added a few more lines to it, but there are some things
I'm having trouble figuring out (this may be due to a few months absence
from the p6 community -- sorry :) ).  Anyway, my questions are:

Higher-numbered synopses are much more speculative, poorly implemented, and
get little love from the janitorial staff; so, in case of disagreement, the
lower number has the correct answer.

Yes, I know the lower ones are correct, but sometimes I have trouble finding where they mention things (eg. I skimmed over S02 before posting this, but because I was only looking at the tables of types, and not reading the text, I missed StrPos).

-       I note that, while S32/Rules says that .from returns an Int, S05 has a
        call $/.from.bytes .  Does this mean that there's a StringSize type

S32 is wrong.

        Yes, I know that.  I wrote most of it myself :).


        that does maybe .bytes, .chars, .graphs, and .codes that's returned by
        maybe .from, .to, and .pos ?

Yes, it's called StrPos; see S02:813.

        Thanks!  :)

I've also added "does Positional does Associative" to the Match role. Does that make sense, or should I instead be adding methods with postfix () and postfix [] ?

        :)


---------------------------------------------------------------------
| Name: Tim Nelson                 | Because the Creator is,        |
| E-mail: wayl...@wayland.id.au    | I am                           |
---------------------------------------------------------------------

----BEGIN GEEK CODE BLOCK----
Version 3.12
GCS d+++ s+: a- C++$ U+++$ P+++$ L+++ E- W+ N+ w--- V- PE(+) Y+>++ PGP->+++ R(+) !tv b++ DI++++ D G+ e++>++++ h! y-
-----END GEEK CODE BLOCK-----

Reply via email to