Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

grammar not behaving as class #70

Closed
p6rt opened this issue Apr 17, 2008 · 7 comments
Closed

grammar not behaving as class #70

p6rt opened this issue Apr 17, 2008 · 7 comments

Comments

@p6rt
Copy link

p6rt commented Apr 17, 2008

Migrated from rt.perl.org#53018 (status was 'resolved')

Searchable as RT53018$

@p6rt
Copy link
Author

p6rt commented Apr 17, 2008

From @cognominal

# grammars don't behave as regular classes.
# I would expect A.WHAT to exist and to behave like with a regular class
# and be able to use A.a in a smart match

class B {}; say B.WHAT;
grammar A { token a { a } }; # say A.WHAT; ==> Method 'WHAT' not
found for non-object

say 'a' ~~ A.a; # ==> Method 'a' not found for non-object

--
cognominal stef

@p6rt
Copy link
Author

p6rt commented Apr 17, 2008

From @cognominal

running the code with --target=pir, I see that the 'token a' regex
is generated as a method with an empty namespace.

--
cognominal stef

@p6rt
Copy link
Author

p6rt commented Apr 17, 2008

From @jnthn

Stéphane Payrard wrote​:

running the code with --target=pir, I see that the 'token a' regex
is generated as a method with an empty namespace.

As far as I'm aware, the grammar keyword isn't properly implemented yet
(it'll parse, but that's probably about it).

Jonathan

@p6rt
Copy link
Author

p6rt commented Apr 17, 2008

The RT System itself - Status changed from 'new' to 'open'

@p6rt
Copy link
Author

p6rt commented Apr 18, 2008

From @cognominal

On Thu, Apr 17, 2008 at 10​:20 PM, Jonathan Worthington via RT
<perl6-bugs-followup@​perl.org> wrote​:

Stéphane Payrard wrote​:

running the code with --target=pir, I see that the 'token a' regex
is generated as a method with an empty namespace.

As far as I'm aware, the grammar keyword isn't properly implemented yet
(it'll parse, but that's probably about it).

Jonathan

There is not much missing.

The following patch already gets .WHAT to work.
The code for grammar methods is apparently correctly generated except
for the namespace.

grammar A { token aa { baba } }; say A.WHAT;

Index​: languages/perl6/src/parser/actions.pm

--- languages/perl6/src/parser/actions.pm (revision 27021)
+++ languages/perl6/src/parser/actions.pm (working copy)
@​@​ -796,11 +796,11 @​@​
  if $key eq 'open' {
  # Start of the block; if it's a class or role, need to make $?CLASS or
  # $?ROLE available for storing current definition in.
- if $&lt;sym&gt; eq 'class' || $&lt;sym> eq 'role' {
+ if $&lt;sym&gt; eq 'class' || $&lt;sym> eq 'role' || $<sym> eq 'grammar' {
  my $decl_past := PAST​::Stmts.new();

  # If it's a class...
- if $<sym> eq 'class' {
+ if $&lt;sym&gt; eq 'class' || $&lt;sym> eq 'grammar' {
  # Call method to create the class.
  $decl_past.push(PAST​::Op.new(
  :pasttype('bind'),
@​@​ -914,7 +914,7 @​@​
  $past.blocktype('declaration');
  $past.pirflags('​:init :load');

- if $<sym> eq 'class' {
+ if $&lt;sym&gt; eq 'class' || $&lt;sym> eq 'grammar' {
  # Make proto-object.
  $?CLASS.push(PAST​::Op.new(
  :pasttype('call'),

--
cognominal stef

@p6rt
Copy link
Author

p6rt commented May 6, 2008

From @jnthn

Hi,

I've now made grammars a whole lot more class like. They get
proto-objects and inheritance works too, plus the regexen go in the
correct namespaces. There is some work to do getting Foo​::bar to work
now (where Foo is a grammar name and bar is a regex name in the
grammar), but that's a separate issue that hits classes and grammars
just as equally.

So I think the issues this ticket wanted to have addressed have been
sorted out now. :-)

Thanks!

Jonathan

@p6rt
Copy link
Author

p6rt commented May 6, 2008

@jnthn - Status changed from 'open' to 'resolved'

@p6rt p6rt closed this as completed May 6, 2008
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant