After the conversation below... I came to the following conclussion:

$match = $souce ~~ /<Grammar::Perl6::grammar>/;

should emit something like (perl 5);

$match = (my $_MATCH = Perl6::Match->new(Grammar::Perl6->grammar($source)));

16/03/2006
<ruoso> When someone declares a grammar (which is like a package in
Perl 5, right?) the rules are scoped to that Grammar. right? which is
the syntax to load an external grammar and to match with some rule of
that grammar?
<nothingmuch> a grammar is just a class
<nothingmuch> so Grammar::rule
<nothingmuch> and use Grammar <rule>;
<nothingmuch> but
<nothingmuch> remember that both exports are lexical
<nothingmuch> and rules can be lexical
<nothingmuch> my rule foo { }
<nothingmuch> and rule foo is export { }
<ruoso> hmmm
<ruoso> ok... but if one wants to avoid the export and use it where it is
<nothingmuch> Grammar::rule
<nothingmuch> but only for 'our rule foo' or 'rule foo', not for 'my
rule foo'
<ruoso> but Grammar::rule is a subroutine call, isn't it?
<ruoso> shouldn't it be Grammar.rule?
<nothingmuch> ruoso: no, that invokes the class method 'rule'
<nothingmuch> or the class rule 'rule'
<nothingmuch> but all rules are instance methods on the match object
<ruoso> now I'm confused
<nothingmuch> okay
<nothingmuch> here's how rules work
<nothingmuch> in theory
<nothingmuch> the domain specific language for rules is parsed into an
AST defining rules
<nothingmuch> which is mostly a lambda calculus
<ruoso> ok
<ruoso> this part I understood
<nothingmuch> there are combinator rules, like +, (), and so forth
<ruoso> ok
<nothingmuch> the rule methods in perl space are perl wrappers that
execute those ASTs
<nothingmuch> the methods are invoked on the rule evalutor state
object thing
<nothingmuch> the match object
<nothingmuch> which is like an interpreter env
<nothingmuch> this match object contains:
<nothingmuch> the current state
<nothingmuch> the current match data
<nothingmuch> various control structures
<nothingmuch> etc
<nothingmuch> and the rules-compiled-into-methods are invoked on it
<nothingmuch> now, this is just at the semantic level
<nothingmuch> the implementation may in fact compile the rules into a
different language
<nothingmuch> like PIR
<nothingmuch> but at the seam it should always pretend to look like
regular perl methods
<ruoso> but... the match object isn't the return of a rule execution?
<nothingmuch> that move match data around
<nothingmuch> it's implied
<nothingmuch> when you start a match
<nothingmuch> then it constructs a new match object
<ruoso> ah ok...
<nothingmuch> and binds it to $/
<ruoso> the ~~ operator already starts the match
<nothingmuch> and then starts executing the anonymous method
<nothingmuch> right
<nothingmuch> so rx:/..../ is an anonymous method
<nothingmuch> this is just invoked on the $/ object
<nothingmuch> $/ contains the input data too
<nothingmuch> and the method will cause changes to the internal state
<nothingmuch> pulling in input, accumilating oputput
<nothingmuch> and backtracking
<ruoso> so rx:/..../ will be compiled also
<nothingmuch> yes
<nothingmuch> it's essentially like saying 'my method { }' with no
name
<ruoso> but...
<nothingmuch> now, what goes on inside is obviously different
<ruoso> how can $/.rulexxx be invoked if rulexxx is defined in a
external grammar?
<nothingmuch> okay
<nothingmuch> so the way this works is that all invocations on rulexxx
etc are *normally* done as:
<nothingmuch> rx:/ <Grammar::rulexxx> /;
<nothingmuch> as a parallel to:
<nothingmuch> $/.Grammar::rulexxx
<nothingmuch> but i think $/.Grammar::rulexxx is not enough
<nothingmuch> the API is not specced enough
<nothingmuch> and there is a handwavy hole in the middle
<nothingmuch> basically:
<nothingmuch> do grammars inherit from Match?
<nothingmuch> or does Match have a Grammar object that it internally
invokes rules on?
<ruoso> do it?
<nothingmuch> this stuff isi underspecced
<nothingmuch> we don't know
<nothingmuch> that's what I'm hoping pX will sort out
<nothingmuch> see Hierarchy.pod in docs
<nothingmuch> this details all the parts I could think of that are
either specced or not yet specced
<nothingmuch> and is also missing parts which i couldn't think of
<ruoso> ok...
<nothingmuch> if you like, try to expand on the areas where the
match/grammar lower level API can be detailed
<nothingmuch> also
<nothingmuch> luqui created Parse-Rule
<ruoso> where?
<nothingmuch> parse-rules is in misc somewhere, i think
<nothingmuch> it's a proposition for the Match object interface
<nothingmuch> that tries to make sure it can compile to many backend
systems
<nothingmuch> ruoso: sorry, it's in ext/
<nothingmuch> despite having just stubs
<ruoso> nothingmuch, ok...
<* ruoso> still wondering how "$match =
Grammar::Perl6::grammar($source);" should look like in real perl 6
<nothingmuch> ruoso: explain
<nothingmuch> I think it'll be something like
<nothingmuch> my $c = Perl::Grammar::Compiler.new();
<nothingmuch> my $parse_tree = $c.parse( $rule_source ); # whatever
hooks
<nothingmuch> err, that's a parser, not a compiler
<nothingmuch> and then it compiles depending on the backend
<nothingmuch> either to Perl 6
<nothingmuch> or to PIR
<nothingmuch> or to both
<nothingmuch> depending on what can be done
<nothingmuch> i have a billion ideas on this topic of compiling, if
you want to talk about it later
<nothingmuch> but i have to go now
<ruoso> so $c.parse means "$c is the grammar object and parse is a
rule"
<nothingmuch> oh
<nothingmuch> on that level
<nothingmuch> i think you're forgettin ghtat rules need to be emitted
and stuff
<nothingmuch> if you have a single step parse-rule-syntax-and-execute
method
<nothingmuch> then there's not enough separation for later
<nothingmuch> or do you mean something else?
<nothingmuch> $c is the rule compiler
<nothingmuch> and .parse is a method defined on the rule compiler
<nothingmuch> this stuff is invoked by the Perl 6 compiler extension
that handles the DSL for rules
<ruoso> hmmm... for runtime rule compilation... ok....
<ruoso> but I don't have a single step
<ruoso> but in this case, I'm using a pre-defined set of rules, that
are already compiled...
<ruoso> so... it would looks like: "$source ~~
/<Grammar::Perl6::grammar>/; $match = $/;"
<ruoso> hmmm... better yet "$match = $source ~~
/<Grammar::Perl6::grammar>/;"
